cisst-saw
Loading...
Searching...
No Matches
msh3PDTreeNode.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 _msh3PDTreeNode_h
38#define _msh3PDTreeNode_h
39
40#include <stdio.h>
41#include <assert.h>
42
44
46#include <cisstMesh/msh3Mesh.h>
47
48// if the PDTree noise model is not needed then PDTree construction
49// time may be reduced by disabling it
50#define ENABLE_PDTREE_NOISE_MODEL
51
52// Always include last!
53#include <cisstMesh/mshExport.h>
54
56{
57 //
58 // This class implements a node of a PD tree;
59 // there are no derived versions of this class.
60 //
61
62 //--- Variables ---//
63
64 public:
65
68 msh3PDTreeNode *pLEq, *pMore; // child nodes
69
71 int NData;
73
74 vctFrm3 F; // transforms world -> local node coords
75 msh3BoundingBox Bounds; // bounding box for this node
76
77#ifdef ENABLE_PDTREE_NOISE_MODEL
78
79 // Noise Model for this Node
80 // Note: this group of variables depend only on the node and are
81 // computed only once when the tree is built
82 double EigMax; // largest eigenvector of covariances in the node
83 vct3 EigRankMin; // min eigenvalues by rank w/in node
84 // Switch to use parent noise model instead of local noise model bounds
86 // this is for the spherical node bounds where the effective bound
87 // is comprised of only the log term and eigenvalues of the node and
88 // sample noise models
90
91 // these point to local values if using local noise model for this node
92 // or to parent's "values in use" if using parent's noise model for this node
93 double *pEigMax;
95
96#endif
97
98 //--- Methods ---//
99
100 public:
101
102 // constructor
103 msh3PDTreeNode(int *pDataIndexArray, int numIndexes,
105
106 // debug constructor
108 : pMyTree(NULL),
109 pParent(NULL),
110 pLEq(NULL),
111 pMore(NULL),
112 pDataIndices(NULL),
113 NData(0)
115 ,pEigMax(NULL),
116 pEigRankMin(NULL)
117#endif
118 {}
119
120 // destructor
122
123 // Check if a datum in this node has a lower match error than the error bound
124 // If a lower match error is found, set the new closest point, update error
125 // bound, and return the global datum index of the closest datum.
126 // Otherwise, return -1.
127 int FindClosestDatum(const vct3 &v,
128 vct3 &closestPoint,
129 double &ErrorBound,
130 unsigned int &numNodesVisited,
131 unsigned int &numNodesSearched);
132
133 // Find intersected points in node given a point and bounding distance
135 const double boundingDistance,
136 msh3Mesh& mesh,
137 std::vector<int> &faceIdx);
138
139 inline int NumData() const { return NData; };
140 inline int IsTerminalNode() const { return pLEq == NULL; };
141
143 vctFrm3 ComputeCovFrame(int i0, int i1);
144 int ConstructSubtree(int CountThresh, double DiagThresh);
145
146 void AccumulateCentroid(int datum, vct3 &sum) const;
147 void AccumulateVariances(int datum, const vct3 &mean, vctDouble3x3 &C) const;
148
149 // Return the global datum index of the ith datum in this node
150 inline int Datum(int i) const
151 {
152 assert(i >= 0 && i < NData);
153 return pDataIndices[i];
154 };
155 inline int& Datum(int i)
156 {
157 assert(i >= 0 && i < NData);
158 return pDataIndices[i];
159 };
160
162
163 // debug routines
164 int FindTerminalNode(int datum, msh3PDTreeNode **termNode);
165 void PrintTerminalNodes(std::ofstream &fs);
166 inline bool NodeContainsDatum(int datum)
167 {
168 for (int i = 0; i < NData; i++) {
169 if (datum == pDataIndices[i]) return true;
170 }
171 return false;
172 }
173
174};
175
176#endif
Definition msh3Mesh.h:57
Definition msh3PDTreeBase.h:55
vct3 EigRankMin
Definition msh3PDTreeNode.h:83
int & Datum(int i)
Definition msh3PDTreeNode.h:155
msh3PDTreeNode(double)
Definition msh3PDTreeNode.h:107
bool bUseParentEigMaxBound
Definition msh3PDTreeNode.h:85
msh3PDTreeNode(int *pDataIndexArray, int numIndexes, msh3PDTreeBase *pTree, msh3PDTreeNode *pParent)
msh3PDTreeNode * pParent
Definition msh3PDTreeNode.h:67
int SortNodeForSplit()
msh3BoundingBox Bounds
Definition msh3PDTreeNode.h:75
vctFrm3 ComputeCovFrame(int i0, int i1)
int Datum(int i) const
Definition msh3PDTreeNode.h:150
int NData
Definition msh3PDTreeNode.h:71
int NumData() const
Definition msh3PDTreeNode.h:139
vct3 * pEigRankMin
Definition msh3PDTreeNode.h:94
void AccumulateCentroid(int datum, vct3 &sum) const
bool bUseParentEigRankMinBounds
Definition msh3PDTreeNode.h:89
vctFrm3 F
Definition msh3PDTreeNode.h:74
double EigMax
Definition msh3PDTreeNode.h:82
int ConstructSubtree(int CountThresh, double DiagThresh)
msh3PDTreeNode * pMore
Definition msh3PDTreeNode.h:68
bool NodeContainsDatum(int datum)
Definition msh3PDTreeNode.h:166
msh3PDTreeNode * pLEq
Definition msh3PDTreeNode.h:68
int myDepth
Definition msh3PDTreeNode.h:72
int IsTerminalNode() const
Definition msh3PDTreeNode.h:140
int * pDataIndices
Definition msh3PDTreeNode.h:70
void AccumulateVariances(int datum, const vct3 &mean, vctDouble3x3 &C) const
int FindTerminalNode(int datum, msh3PDTreeNode **termNode)
msh3PDTreeBase * pMyTree
Definition msh3PDTreeNode.h:66
double * pEigMax
Definition msh3PDTreeNode.h:93
void FindIntersectedPoints(const vct3 &v, const double boundingDistance, msh3Mesh &mesh, std::vector< int > &faceIdx)
msh3PDTreeNode * GetChildSplitNode(const vct3 &datumPos)
int FindClosestDatum(const vct3 &v, vct3 &closestPoint, double &ErrorBound, unsigned int &numNodesVisited, unsigned int &numNodesSearched)
void PrintTerminalNodes(std::ofstream &fs)
#define CISST_EXPORT
Definition cmnExportMacros.h:50
vctBoundingBox3 msh3BoundingBox
Definition msh3BoundingBox.h:42
#define ENABLE_PDTREE_NOISE_MODEL
Definition msh3PDTreeNode.h:50
Macros to export the symbols of cisstMesh (in a Dll).
Forward declarations and #define for cisstMesh.
vctFixedSizeMatrix< double, 3, 3 > vctDouble3x3
Definition vctFixedSizeMatrixTypes.h:58
vctFixedSizeVector< double, 3 > vct3
Definition vctFixedSizeVectorTypes.h:46
vctFrameBase< vctRot3 > vctFrm3
Definition vctTransformationTypes.h:137