cisst-saw
Loading...
Searching...
No Matches
msh2DirPDTreeNode.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 _msh2DirPDTreeNode_h
38#define _msh2DirPDTreeNode_h
39
40#include <stdio.h>
41#include <assert.h>
42
44
47
48//#define DebugDirPDTree2D
49//#define DEBUG_DirPDTree2dNode
50
51// Always include last!
52#include <cisstMesh/mshExport.h>
53
55{
56 // This class represents a node in a directed PD tree (a PD tree
57 // for oriented points); there are no derived versions of this class.
58
59 //friend class msh2DirPDTreeBase;
60
61
62 //--- Variables ---//
63
64 public:
65
69 size_t NData;
70 size_t myDepth;
72
73 vctFrm2 F; // transforms world -> local node coords
74 msh2BoundingBox Bounds; // bounding box for this node
75
77 unsigned int splitDim; // X: 0, y: 1 -- only applies when not using OBB
78
81 vct2 Navg; // avg orientation of the datums in this node
82 double dThetaMax; // max deviation (in radians) from the avg orientation
83
84 // efficiency variables to speed-up building the tree
85 vct2 posSum; // summation of positions in this node
86 vct2x2 covSum; // summation of outer products of positions
87 vct2 Nsum; // summation of the orientations in this node
88
89
90
91 //--- Methods ---//
92
93 public:
94
95 // constructor
97 int *pDataIndexArray, size_t numIndexes,
98 msh2DirPDTreeBase* pTree, msh2DirPDTreeNode* pParent,
99 bool bComputeOBB = true, unsigned int splitDimension = 0);
100
101 // debug constructor
103 MyTree(NULL),
104 Parent(NULL),
105 DataIndices(NULL),
106 NData(0),
107 LEq(NULL),
108 More(NULL)
109 {};
110
111 // destructor
113
114 // Check if a datum in this node has a lower match error than the error bound
115 // If a lower match error is found, set the new closest point, update error
116 // bound, and return the global datum index of the closest datum.
117 // Otherwise, return -1.
118 int FindClosestDatum(const vct2 &v, const vct2 &n,
119 vct2 &closestPoint, vct2 &closestPointNorm,
120 double &ErrorBound,
121 unsigned int &numNodesVisited,
122 unsigned int &numNodesSearched);
123
124 inline size_t NumData() const { return NData; };
125 inline int IsTerminalNode() const { return LEq == NULL; };
126
127 int ConstructTree(const size_t CountThresh, double DiagThresh);
128
130
131 //virtual void Print(FILE* chan, int indent);
132
133 // Return the global datum index of the ith datum in this node
134 inline int Datum(int i) const
135 {
136#ifdef DEBUG_DirPDTree2dNode
137 assert(i >= 0 && i < NData);
138#endif
139 return DataIndices[i];
140 }
141
142 int& Datum(int i)
143 {
144#ifdef DEBUG_DirPDTree2dNode
145 assert(i >= 0 && i < NData);
146#endif
147 return DataIndices[i];
148 }
149
150 protected:
151
154
155 //vct2 ComputePositionSum();
156 //vct2x2 ComputeCovarianceSum();
161
162 public:
163
164 // debug routines
165 int FindTerminalNode(int datum, msh2DirPDTreeNode **termNode);
166 void PrintTerminalNodes(std::ofstream &fs);
167 inline bool NodeContainsDatum(int datum) {
168 for (size_t i = 0; i < NData; i++) {
169 if (datum == DataIndices[i]) return true;
170 }
171 return false;
172 }
173
174};
175
176#endif
177
186//int FindClosestDatum( const vct3 &v, const vct3 &n,
187// vct3 &closestPoint, vct3 &closestPointNorm,
188// double posWeight, double normWeight,
189// double &ErrorBound,
190// unsigned int &numNodesVisited,
191// unsigned int &numNodesSearched,
192// double geomDistBound );
Definition msh2BoundingBox.h:46
Definition msh2DirPDTreeBase.h:51
void PrintTerminalNodes(std::ofstream &fs)
vct2x2 posCov
Definition msh2DirPDTreeNode.h:80
vct2 Navg
Definition msh2DirPDTreeNode.h:81
double ComputeOrientationThetaMax(vct2 Navg)
vctFrm2 F
Definition msh2DirPDTreeNode.h:73
int FindClosestDatum(const vct2 &v, const vct2 &n, vct2 &closestPoint, vct2 &closestPointNorm, double &ErrorBound, unsigned int &numNodesVisited, unsigned int &numNodesSearched)
vctFrm2 ComputeCovFrame(vct2x2 posCov, vct2 posMean)
vct2 posSum
Definition msh2DirPDTreeNode.h:85
msh2DirPDTreeNode * GetChildSplitNode(const vct2 &datumPos)
msh2DirPDTreeNode(double)
Definition msh2DirPDTreeNode.h:102
msh2DirPDTreeNode(int *pDataIndexArray, size_t numIndexes, msh2DirPDTreeBase *pTree, msh2DirPDTreeNode *pParent, bool bComputeOBB=true, unsigned int splitDimension=0)
int IsTerminalNode() const
Definition msh2DirPDTreeNode.h:125
int Datum(int i) const
Definition msh2DirPDTreeNode.h:134
msh2BoundingBox Bounds
Definition msh2DirPDTreeNode.h:74
size_t NumData() const
Definition msh2DirPDTreeNode.h:124
msh2DirPDTreeNode * Parent
Definition msh2DirPDTreeNode.h:67
vct2 posAvg
Definition msh2DirPDTreeNode.h:79
int FindTerminalNode(int datum, msh2DirPDTreeNode **termNode)
bool NodeContainsDatum(int datum)
Definition msh2DirPDTreeNode.h:167
bool bUsingOBB
Definition msh2DirPDTreeNode.h:76
double dThetaMax
Definition msh2DirPDTreeNode.h:82
msh2DirPDTreeNode * LEq
Definition msh2DirPDTreeNode.h:71
size_t myDepth
Definition msh2DirPDTreeNode.h:70
vct2x2 covSum
Definition msh2DirPDTreeNode.h:86
vct2 Nsum
Definition msh2DirPDTreeNode.h:87
int ConstructTree(const size_t CountThresh, double DiagThresh)
msh2DirPDTreeBase * MyTree
Definition msh2DirPDTreeNode.h:66
msh2DirPDTreeNode * More
Definition msh2DirPDTreeNode.h:71
size_t NData
Definition msh2DirPDTreeNode.h:69
int * DataIndices
Definition msh2DirPDTreeNode.h:68
vct2 ComputeOrientationAverage(vct2 &Nsum)
vct2 ComputeOrientationSum()
unsigned int splitDim
Definition msh2DirPDTreeNode.h:77
int & Datum(int i)
Definition msh2DirPDTreeNode.h:142
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Macros to export the symbols of cisstMesh (in a Dll).
Forward declarations and #define for cisstMesh.
vctFixedSizeMatrix< double, 2, 2 > vct2x2
Definition vctFixedSizeMatrixTypes.h:48
vctFixedSizeVector< double, 2 > vct2
Definition vctFixedSizeVectorTypes.h:41
Typedef for different transformations.
vctFrameBase< vctRot2 > vctFrm2
Definition vctTransformationTypes.h:199