cisst-saw
Loading...
Searching...
No Matches
msh3PDTreeBase.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 _msh3PDTreeBase_h
38#define _msh3PDTreeBase_h
39
40#include <stdio.h>
41#include <assert.h>
42
44
48
49//#define DEBUG_PD_TREE
50
51// Always include last!
52#include <cisstMesh/mshExport.h>
53
55{
56 //
57 // This is the base class for a PD tree.
58 // This class defines the entry point for performing
59 // a search. The type of datum (i.e. triangle, point, etc.)
60 // is unknown to this class and must be defined within a
61 // derived class, making this class abstract.
62 // This class stores a pointer to an algorithm object
63 // which implements the key search routines.
64 //
65
66 friend class msh3PDTreeNode;
67
68 //--- Variables ---//
69
70 public:
71
72 // reference to algorithm must exist here so that all nodes
73 // may access it
75
76 protected:
77
78#ifdef DEBUG_PD_TREE
79 FILE *debugFile;
80 FILE *debugFile2;
81#endif
82
86
87 //--- Methods ---//
88
89 public:
90
91 // constructors
93 pAlgorithm(NULL),
94 NData(0), NNodes(0), treeDepth(0),
95 DataIndices(NULL), Top(NULL)
96 {
97#ifdef DEBUG_PD_TREE
98 debugFile = fopen("debugPDTree.txt","w");
99 debugFile2 = fopen("debugPDTree2.txt","w");
100#endif
101 };
102
103 // destructor
104 virtual ~msh3PDTreeBase() {}
105
106 int FastInitializeProximalDatum(const vct3 &v, vct3 &proxPoint);
107
109 pAlgorithm = pAlg;
110 }
111
112 // Returns the index for the datum in the tree that has lowest match error for
113 // the given point and set the closest point values
114 int FindClosestDatum(const vct3 &v,
115 vct3 &closestPoint,
116 int prevDatum,
117 double &matchError,
118 unsigned int &numNodesSearched);
119
120 // // Finds the intersected points of a PDTree given a bounding distance
121 // virtual int FindIntersectedPoints(
122 // const vct3 &v, const double boundingDistance, std::vector<vct3> &intersectedPoints,
123 // std::vector<int> &datumPoints,
124 // std::vector<bool> &edgePointFlag);
125
126 inline int NumData() const { return NData; };
127 inline int NumNodes() const { return NNodes; };
128 inline int TreeDepth() const { return treeDepth; };
129
130 // debug routines
131 int ValidateClosestDatum(const vct3 &v, vct3 &closestPoint);
132 int ValidateClosestDatum_ByEuclideanDist(const vct3 &v, vct3 &closestPoint);
133 int FindTerminalNode(int datum, msh3PDTreeNode **termNode);
134 void PrintTerminalNodes(std::ofstream &fs);
135
136 //--- Virtual Methods ---//
137 //
138 // These methods require a known datum type
139 //
140 virtual vct3 DatumSortPoint(int datum) const = 0;
141 virtual void EnlargeBounds(const vctFrm3& F, int datum, msh3BoundingBox& BB) const = 0;
142
143#ifdef ENABLE_PDTREE_NOISE_MODEL
144
145 //--- Noise Model Methods ---//
146
147 virtual vct3x3& DatumCov(int datum) = 0; // return measurement noise model for this datum
148 virtual vct3x3* DatumCovPtr(int datum) = 0; // return measurement noise model for this datum
149 virtual vct3& DatumCovEig(int datum) = 0;
150 virtual vct3* DatumCovEigPtr(int datum) = 0;
151
152 // may have to be manually called by user after defining the noise
153 // model of the datums
154 // (depending on the PD tree type and constructor used)
155 void ComputeNodeNoiseModels();
156 void ComputeSubNodeNoiseModel(msh3PDTreeNode *node, bool useLocalVarsOverride);
157
158#endif // ENABLE_PDTREE_NOISE_MODEL
159
160};
161
162#endif
Definition msh3AlgPDTree.h:47
msh3PDTreeBase()
Definition msh3PDTreeBase.h:92
int TreeDepth() const
Definition msh3PDTreeBase.h:128
int NData
Definition msh3PDTreeBase.h:83
void PrintTerminalNodes(std::ofstream &fs)
int FindClosestDatum(const vct3 &v, vct3 &closestPoint, int prevDatum, double &matchError, unsigned int &numNodesSearched)
int ValidateClosestDatum_ByEuclideanDist(const vct3 &v, vct3 &closestPoint)
msh3AlgPDTree * pAlgorithm
Definition msh3PDTreeBase.h:74
int NumData() const
Definition msh3PDTreeBase.h:126
int FastInitializeProximalDatum(const vct3 &v, vct3 &proxPoint)
int treeDepth
Definition msh3PDTreeBase.h:83
virtual vct3 DatumSortPoint(int datum) const =0
virtual void EnlargeBounds(const vctFrm3 &F, int datum, msh3BoundingBox &BB) const =0
friend class msh3PDTreeNode
Definition msh3PDTreeBase.h:66
int FindTerminalNode(int datum, msh3PDTreeNode **termNode)
int NumNodes() const
Definition msh3PDTreeBase.h:127
msh3PDTreeNode * Top
Definition msh3PDTreeBase.h:85
virtual ~msh3PDTreeBase()
Definition msh3PDTreeBase.h:104
int NNodes
Definition msh3PDTreeBase.h:83
int * DataIndices
Definition msh3PDTreeBase.h:84
int ValidateClosestDatum(const vct3 &v, vct3 &closestPoint)
void SetSearchAlgorithm(msh3AlgPDTree *pAlg)
Definition msh3PDTreeBase.h:108
#define CISST_EXPORT
Definition cmnExportMacros.h:50
vctBoundingBox3 msh3BoundingBox
Definition msh3BoundingBox.h:42
Macros to export the symbols of cisstMesh (in a Dll).
Forward declarations and #define for cisstMesh.
vctFixedSizeMatrix< double, 3, 3 > vct3x3
Definition vctFixedSizeMatrixTypes.h:59
vctFixedSizeVector< double, 3 > vct3
Definition vctFixedSizeVectorTypes.h:46
vctFrameBase< vctRot3 > vctFrm3
Definition vctTransformationTypes.h:137