cisst-saw
Loading...
Searching...
No Matches
msh2DirPDTreeBase.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3// ****************************************************************************
4//
5// Copyright (c) 2014, Seth Billings, Russell Taylor, Johns Hopkins University
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are
10// met:
11//
12// 1. Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14//
15// 2. Redistributions in binary form must reproduce the above copyright
16// notice, this list of conditions and the following disclaimer in the
17// documentation and/or other materials provided with the distribution.
18//
19// 3. Neither the name of the copyright holder nor the names of its
20// contributors may be used to endorse or promote products derived from
21// this software without specific prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34//
35// ****************************************************************************
36
37#ifndef _msh2DirPDTreeBase_h
38#define _msh2DirPDTreeBase_h
39
40#include <stdio.h>
41#include <assert.h>
42
46
47// Always include last!
48#include <cisstMesh/mshExport.h>
49
51{
52 //
53 // This is the base class for a directional PD tree
54 // (i.e. for oriented data).
55 // This class defines the entry point for performing
56 // a search. The type of datum (i.e. triangle, point, etc.)
57 // is unknown to this class and must be defined within a
58 // derived class, making this class abstract.
59 // This class stores a pointer to an pAlgorithm object
60 // which implements the key search routines.
61 //
62
63 friend class msh2DirPDTreeNode;
64
65 //--- Variables ---//
66
67 public:
68
69 // reference to algorithm must exist here so that all nodes
70 // may access it
72
73 //protected:
74
75#ifdef DebugDirPDTree2D
76 FILE *debugFile;
77 FILE *debugFile2;
78#endif
79
82 size_t NData;
83 size_t NNodes;
85
86 //--- Methods ---//
87
88 public:
89
90 // constructors
92 algorithm(NULL),
93 Top(NULL),
94 DataIndices(NULL),
95 NData(0), NNodes(0), treeDepth(0)
96 {
97#ifdef DebugDirPDTree2D
98 //debugFile = fopen("D:/Code/Repos_Git/SinusProject/MATLAB/debugDirPDTree.txt", "w");
99 //debugFile2 = fopen("D:/Code/Repos_Git/SinusProject/MATLAB/debugDirPDTree2.txt", "w");
100 debugFile = fopen("./debugDirPDTree.txt", "w");
101 debugFile2 = fopen("./debugDirPDTree2.txt", "w");
102 //debugFile = fopen("../ICP_TestData/LastRun/debugDirPDTree.txt","w");
103 //debugFile2 = fopen("../ICP_TestData/LastRun/debugDirPDTree2.txt","w");
104
105 //int printReturn;
106 //printReturn = fprintf(debugFile, "Debug File Open\n");
107 //printReturn = fprintf(debugFile2, "Debug File2 Open\n");
108 //fflush(debugFile);
109 //fflush(debugFile2);
110#endif
111 };
112
114
116 {
117 algorithm = alg;
118 }
119
120 // Return the index for the datum in the tree that has lowest match error for
121 // the given point and set the closest point values
122 int FindClosestDatum(const vct2 &v, const vct2 &n,
123 vct2 &closestPoint, vct2 &closestPointNorm,
124 int prevDatum,
125 double &matchError,
126 unsigned int &numNodesSearched);
127
128 // quickly computes a nearby (not best matching) datum point
129 // used for initializing the closest datums prior to
130 // performing a true tree search
131 int FastInitializeProximalDatum(const vct2 &v, const vct2 &n,
132 vct2 &proxPoint, vct2 &proxNorm);
133
134 size_t NumData() const { return NData; };
135 size_t NumNodes() const { return NNodes; };
136 int TreeDepth() const { return treeDepth; };
137
138 // debug routines
139 int ValidateClosestDatum(const vct2 &v, const vct2 &n, vct2 &closestPoint, vct2 &closestPointNorm);
140 int FindTerminalNode(int datum, msh2DirPDTreeNode **termNode);
141 void PrintTerminalNodes(std::ofstream &fs);
142
143
144 //--- Virtual Methods ---//
145 //
146 // These methods require a known datum type
147 //
148
149 virtual vct2 DatumSortPoint(int datum) const = 0; // reference point for assigning datum to a node
150 virtual vct2 DatumNorm(int datum) const = 0; // datum orientation (normal vector)
151 virtual void EnlargeBounds(const vctFrm2& F, int datum, msh2BoundingBox& BB) const = 0;
152 virtual void EnlargeBounds(int datum, msh2BoundingBox& BB) const = 0;
153
154 //virtual void Print(FILE* chan, int indent);
155 //virtual void PrintDatum(FILE* chan, int indent, int datum);
156
157};
158
159#endif
Definition msh2AlgDirPDTree.h:47
Definition msh2BoundingBox.h:46
int treeDepth
Definition msh2DirPDTreeBase.h:84
int * DataIndices
Definition msh2DirPDTreeBase.h:81
msh2DirPDTreeBase()
Definition msh2DirPDTreeBase.h:91
void PrintTerminalNodes(std::ofstream &fs)
msh2AlgDirPDTree * algorithm
Definition msh2DirPDTreeBase.h:71
virtual void EnlargeBounds(int datum, msh2BoundingBox &BB) const =0
int FastInitializeProximalDatum(const vct2 &v, const vct2 &n, vct2 &proxPoint, vct2 &proxNorm)
size_t NumData() const
Definition msh2DirPDTreeBase.h:134
void SetSearchAlgorithm(msh2AlgDirPDTree *alg)
Definition msh2DirPDTreeBase.h:115
int ValidateClosestDatum(const vct2 &v, const vct2 &n, vct2 &closestPoint, vct2 &closestPointNorm)
int FindClosestDatum(const vct2 &v, const vct2 &n, vct2 &closestPoint, vct2 &closestPointNorm, int prevDatum, double &matchError, unsigned int &numNodesSearched)
int FindTerminalNode(int datum, msh2DirPDTreeNode **termNode)
virtual vct2 DatumSortPoint(int datum) const =0
friend class msh2DirPDTreeNode
Definition msh2DirPDTreeBase.h:63
int TreeDepth() const
Definition msh2DirPDTreeBase.h:136
msh2DirPDTreeNode * Top
Definition msh2DirPDTreeBase.h:80
size_t NumNodes() const
Definition msh2DirPDTreeBase.h:135
virtual ~msh2DirPDTreeBase()
Definition msh2DirPDTreeBase.h:113
virtual vct2 DatumNorm(int datum) const =0
size_t NNodes
Definition msh2DirPDTreeBase.h:83
size_t NData
Definition msh2DirPDTreeBase.h:82
virtual void EnlargeBounds(const vctFrm2 &F, int datum, msh2BoundingBox &BB) const =0
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Macros to export the symbols of cisstMesh (in a Dll).
vctFixedSizeVector< double, 2 > vct2
Definition vctFixedSizeVectorTypes.h:41
vctFrameBase< vctRot2 > vctFrm2
Definition vctTransformationTypes.h:199