-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathDCGrid.h
210 lines (173 loc) · 7.22 KB
/
DCGrid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#pragma once
#include "Geometry\IndexingGrid.h"
class CDCGrid :
public CIndexingGrid
{
public:
CDCGrid(void);
~CDCGrid(void);
public:
friend class CDCContourer;
public:
//////////////////////////////////////////////////////////////////////////
// definition of all the auxiliary data structures
//////////////////////////////////////////////////////////////////////////
typedef std::vector< CVector3D * > CVector3DPointer_Vector;
struct NodeLocator {
int l;
int i;
int j;
NodeLocator( int ll, int ii, int jj ) : l(ll), i(ii), j(jj) {}
NodeLocator() {}
};
struct HermiteData {
CVector3D v; // position
CVector3D n; // normal
};
typedef std::vector< HermiteData > HermiteData_Vector;
struct DistanceSorting {
int index;
double distance;
DistanceSorting( int i, double d ) { index = i; distance = d; }
DistanceSorting() { index = 0; distance = 0.0; }
};
typedef std::vector< DistanceSorting > DistanceSorting_Vector;
struct HermiteDataIndex {
int i;
int l;
HermiteDataIndex( int ii, int ll ) : i(ii), l(ll) {}
};
typedef std::vector< HermiteDataIndex > HermiteDataIndex_Vector;
struct ClusterAssignment {
int l[2][2];
ClusterAssignment() { l[0][0] = l[0][1] = l[1][0] = l[1][1] = -1; }
};
typedef std::vector< ClusterAssignment > ClusterAssignment_Vector;
struct DCGridNode {
bool pass; // if the subtree collapse passed the geometry error testing
char level; // at which level
bool is_ground; // if all the data in this node is ground data
char num_of_layers; // total roof layer number in this node. ** IMPORTATNT variable **
std::vector< CVector3D > means; // centroid of the intersection points on each roof layer, as "guessed" solution
std::vector< CVector3D > points; // final result, ** OUTPUT **
std::vector< float > r;
std::vector< int > cluster;
std::vector< int > leaf_cluster_to_root_cluster;
double error;
bool mean_based_on_z;
// for contouring
int vi;
DistanceSorting_Vector seq;
int split_direction;
// for shape analysis
CVector3D v[ 3 ];
double sigma2[ 3 ];
};
typedef std::vector< DCGridNode > DCGridNode_Vector;
protected:
//////////////////////////////////////////////////////////////////////////
// member variables
//////////////////////////////////////////////////////////////////////////
bool m_bTopologyCheck;
int m_nAcceptNumber;
double m_dbSegmentationDistance;
double m_dbSegmentationZ;
double m_dbBoundaryWeight;
double m_dbErrorTolerance;
double m_dbSingularTolerance;
int m_nLevel;
int m_nHDSideNumber;
HermiteData_Vector m_vecHermiteDataXY;
HermiteData_Vector m_vecHermiteDataZ;
std::vector< DCGridNode_Vector > m_vecNodes;
ClusterAssignment_Vector m_vecClusterAssignment;
public:
//////////////////////////////////////////////////////////////////////////
// entrance functions
//////////////////////////////////////////////////////////////////////////
void AssignPointCloud( CPointCloud * pointcloud, double unit_length, double ground_z, bool enable_topology_check = true );
void ComputeHermiteData( int accept_number = 4, double relative_distance = 1.0, double relative_z = 0.6 );
void DualContouringGeometry( double boundary_weight, double error_tolerance, double singular_tolerance );
protected:
//////////////////////////////////////////////////////////////////////////
// HermiteData functions
//////////////////////////////////////////////////////////////////////////
void ComputeHermiteData_XY();
void ComputeHermiteData_XY( int i, int j );
void ComputeHermiteData_Z();
void ComputeHermiteData_Z( int i, int j, int dir /*along_y=0; along_x=1*/ );
void ComputeHermiteData_Z( HermiteData & hd, CVector3D v[ 2 ], CVector3DPointer_Vector & points );
void ComputeHermiteData_Z_Key( HermiteData & hd, CVector3D v[ 2 ], CVector3D & v_key, CVector3D & v_dir );
void ComputeHermiteData_Z_Ill( HermiteData & hd, CVector3D v[ 2 ] );
protected:
//////////////////////////////////////////////////////////////////////////
// geometry simplification
//////////////////////////////////////////////////////////////////////////
void BuildQuadTreeAtLevel0();
void BuildQuadTreeAtLevelN( int l );
void DualContouringGeometryNode( DCGridNode & node );
bool TopologyCheck( NodeLocator & loc );
protected:
//////////////////////////////////////////////////////////////////////////
// clustering functions
//////////////////////////////////////////////////////////////////////////
int ClusterFromLeafNodes( NodeLocator & loc );
void DistanceSegmentation( CVector3DPointer_Vector & points, std::vector< int > & cluster, double dis2 );
void DistanceSegmentationEx( CVector3DPointer_Vector & points, std::vector< int > & cluster, double dis2, double dis_z );
void InitializeCluster( std::vector< int > & cluster );
int CompressCluster( std::vector< int > & cluster );
int CompressClusterEx( std::vector< int > & cluster, int resize_number );
void FlattenCluster( std::vector< int > & cluster );
void UnionCluster( std::vector< int > & cluster, int i, int j );
int FindCluster( std::vector< int > & cluster, int start );
protected:
//////////////////////////////////////////////////////////////////////////
// sorting functions
//////////////////////////////////////////////////////////////////////////
void SortDistance2D( CVector3DPointer_Vector & points, CVector3D & ref_v, std::vector< int > & cluster, int cluster_index, DistanceSorting_Vector & sorting_result );
void QSort( DistanceSorting_Vector & sorting_result );
protected:
//////////////////////////////////////////////////////////////////////////
// numerical solvers, see DCGridNumerical.cpp
//////////////////////////////////////////////////////////////////////////
void svdcmp_ext(float **a, int m, int n, float w[], float **v);
void qrdcmp_ext(float **a, int n, float *c, float *d, int *sing);
float pythag_ext(float a, float b);
public:
//////////////////////////////////////////////////////////////////////////
// print and debug functions
//////////////////////////////////////////////////////////////////////////
void HermiteData_SaveToTxt( char filename[] );
void PrintLayerNumber();
void PrintMatrix( float **a, int matrix_size );
void PrintVector( float *w, int vector_size );
protected:
//////////////////////////////////////////////////////////////////////////
// small, inline functions
//////////////////////////////////////////////////////////////////////////
int HDIndex( int i, int j ) {
return ( i * m_nHDSideNumber + j );
}
DCGridNode & LocateNode( NodeLocator & loc ) {
return m_vecNodes[ loc.l ][ ( loc.i << ( m_nLevel - loc.l ) ) + loc.j ];
}
NodeLocator Leaf( NodeLocator & loc, int i, int j, bool is_leaf = false ) {
return is_leaf ? loc : NodeLocator( loc.l - 1, ( loc.i << 1 ) + i, ( loc.j << 1 ) + j );
}
bool HermiteDataXY_IsGround( CVector3D & v ) { return v[ 2 ] == m_pPointCloud->m_dbGroundZ; }
bool HermiteDataZ_IsInvalid( CVector3D & v ) { return v[ 2 ] == 0.0; }
CVector3D AbsoluteToRelative( CVector3D & v )
{
return v - m_pPointCloud->m_cBoundingBox.m_vMin;
}
CVector3D RelativeToAbsolute( CVector3D & u )
{
return u + m_pPointCloud->m_cBoundingBox.m_vMin;
}
int Cluster_Index( int i, int j, int l ) {
return ( i * ( ( 1 << l ) + 1 ) + j );
}
int RootCluster_Index( int i, int j ) {
return Cluster_Index( i, j, m_nLevel );
}
};