Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DPointList.h
Go to the documentation of this file.
1//! @file 3DPointList.h
2//! @brief C3DPointList class definition for handling a list of C3DPoint
3//
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_3DPOINTLIST_H__CA6BC2A5_FAC2_11D1_A0DE_000000000000__INCLUDED_)
7#define AFX_3DPOINTLIST_H__CA6BC2A5_FAC2_11D1_A0DE_000000000000__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "PointList.h"
14#include "3DPoint.h"
15#include "AssociationMap.h"
16
17BEGIN_MOOTOOLS_NAMESPACE
18
20{
21public:
22 int x, y, z;
23
24 bool operator!=(const IntCoord& pt) const;
25 bool operator==(const IntCoord& pt) const;
26};
27
28inline bool IntCoord::operator!=(const IntCoord& pt) const
29{
30 if (x != pt.x)
31 return true;
32 if (y != pt.y)
33 return true;
34 if (z != pt.z)
35 return true;
36
37 return false;
38}
39
40inline bool IntCoord::operator==(const IntCoord& pt) const
41{
42 if (x != pt.x)
43 return false;
44 if (y != pt.y)
45 return false;
46 if (z != pt.z)
47 return false;
48
49 return true;
50}
51
52template <> class CHashMethods<IntCoord>
53{
54public:
55 static inline bool HashCompare(const IntCoord& pt1, const IntCoord& pt2)
56 {
57 if (pt1.x != pt2.x || pt1.y != pt2.y || pt1.z != pt2.z)
58 return false;
59
60 return true;
61 }
62
63 static inline unsigned int HashValue(const IntCoord& pt)
64 {
65 #ifdef OLD_HASH_FUNCTIONS
66 return (unsigned int)(pt.x + pt.y + pt.z);
67 #else
68 return HashMixValue(HashMixValue(pt.x) + pt.y) + pt.z;
69 #endif
70 }
71};
72
73//! @class C3DPointGridMap
74//! @brief C3DPointGridMap is a compact class for retrieving quickly points which are in the same voxel of a provided C3DPoint
75//! @details The class is used by C3DFaceGridMap for performing ray cast or retrieve the closest face to a point.
76class C3DPointGridMap : public CAssociationMap<C3DPointI, int, unsigned int>
77{
78 friend C3DPointList;
79
80protected:
81 C3DPointD center; //!< The center of the points bounding box, which allows to perform the computation around the origin for better precision
82 double cellDistance[3];
83
84 // Center is the center of the points bounding box
86 C3DPointGridMap(const C3DPoint& center, double distanceX, double distanceY = 0.0f, double distanceZ = 0.0f);
87
88 template<typename TYPE> int *Lookup(const C3DTPoint<TYPE>& point, int& size) const; // Return the element indexes which are at the given x, y, z position
89 int* Lookup(const C3DPointI& point, int& size) const; // Return the element indexes which are at the cell position
91
92#ifdef _DEBUG
93 void CheckLimits(const C3DVector& limits);
94#endif
95
96public:
97 void GetVoxelSize(C3DPointD& voxel) const;
98 template<typename TYPE> void ConvertToLongIntCoord(const C3DTPoint<TYPE>& pt, longint *intcoord) const;
99 template<typename TYPE> void ConvertToIntCoord(const C3DTPoint<TYPE>& pt, C3DPointI& intcoord) const;
100 template<typename TYPE> void ConvertToCheckedIntCoord(const C3DTPoint<TYPE>& pt, C3DPointI& intcoord) const;
101 template<typename TYPE> void ConvertFromIntCoord(const C3DPointI& intcoord, C3DTPoint<TYPE>& pt) const;
102 int XYZToIntCoord(double coordinate, int index) const; //!< index: 0, 1 or 2 [x, y or z]
103 int XToIntCoord(double coordinate) const;
104 int YToIntCoord(double coordinate) const;
105 int ZToIntCoord(double coordinate) const;
106 double XYZFromIntCoord(int intcoord, int index) const; //!< index: 0, 1 or 2 [x, y or z]
107 double XFromIntCoord(int intcoord) const;
108 double YFromIntCoord(int intcoord) const;
109 double ZFromIntCoord(int intcoord) const;
110 double GetMaxDistance(unsigned char XYZ = 0) const; //!< Return the max distance between two points when using Get3DProximityPoints (cf note in C3DPointGridMap // Get3DProximityPoints)
111
112 // Static to init C3DPointGridMap based on a relative value of the bounding box and retrieve the max absolute value between points to be considered equals
113 static DLL_3DFUNCTION double GetAbsoluteDistance(double threshold, const C3DBBox& bboxCorner); //!< Return the absolute distance to use to construct C3DPointGridMap based on a threshold value between 0.0 and 1.0 and giving the object bounding box corners
114 static DLL_3DFUNCTION double GetMaxDistance(double threshold, const C3DBBox& bboxCorner); //!< Return the max distance between two points considered to be equal (returned by Get3DProximityPoints)
115};
116
117template<typename TYPE>
118int* C3DPointGridMap::Lookup(const C3DTPoint<TYPE>& point, int& size) const
119{
121 ConvertToIntCoord(point, coord);
123}
124
125inline int* C3DPointGridMap::Lookup(const C3DPointI& coord, int& size) const
126{
128}
129
130inline void C3DPointGridMap::GetVoxelSize(C3DPointD& voxel) const
131{
132 voxel.x = cellDistance[0];
133 voxel.y = cellDistance[1];
134 voxel.z = cellDistance[2];
135}
136
137template<typename TYPE>
138inline void C3DPointGridMap::ConvertToLongIntCoord(const C3DTPoint<TYPE>& pt, longint* intcoord) const
139{
140 intcoord[0] = (longint)((pt.x - center.x) / cellDistance[0]);
141 intcoord[1] = (longint)((pt.y - center.y) / cellDistance[1]);
142 intcoord[2] = (longint)((pt.z - center.z) / cellDistance[2]);
143}
144
145template<typename TYPE>
146inline void C3DPointGridMap::ConvertToIntCoord(const C3DTPoint<TYPE>& pt, C3DPointI& intcoord) const
147{
148 intcoord.x = (int)((pt.x - center.x) / cellDistance[0]);
149 intcoord.y = (int)((pt.y - center.y) / cellDistance[1]);
150 intcoord.z = (int)((pt.z - center.z) / cellDistance[2]);
151}
152
153template<typename TYPE>
154inline void C3DPointGridMap::ConvertToCheckedIntCoord(const C3DTPoint<TYPE>& pt, C3DPointI& intcoord) const
155{
156 TYPE values[3];
157
158 values[0] = ((pt.x - center.x) / cellDistance[0]);
159 values[1] = ((pt.y - center.y) / cellDistance[1]);
160 values[2] = ((pt.z - center.z) / cellDistance[2]);
161
162 intcoord.x = (int)ceil(values[0]); // Use the ceil value first (avoid multiple call)
163 intcoord.y = (int)ceil(values[1]);
164 intcoord.z = (int)ceil(values[2]);
165
166 if (intcoord.x - values[0] > FLOAT_EPSILON3) // If value is 12.999998, then it should be 13.0, otherwise 12
167 intcoord.x = (int)values[0];
168
169 if (intcoord.y - values[1] > FLOAT_EPSILON3)
170 intcoord.y = (int)values[1];
171
172 if (intcoord.z - values[2] > FLOAT_EPSILON3)
173 intcoord.z = (int)values[2];
174}
175
176template<typename TYPE>
177inline void C3DPointGridMap::ConvertFromIntCoord(const C3DPointI& intcoord, C3DTPoint<TYPE>& pt) const
178{
179 pt.x = (TYPE)((intcoord.x*cellDistance[0]) + center.x);
180 pt.y = (TYPE)((intcoord.y*cellDistance[1]) + center.y);
181 pt.z = (TYPE)((intcoord.z*cellDistance[2]) + center.z);
182}
183
184inline int C3DPointGridMap::XYZToIntCoord(double coordinate, int index) const
185{
186 return (int)((coordinate - center[index]) / cellDistance[index]);
187}
188
189inline int C3DPointGridMap::XToIntCoord(double coordinate) const
190{
191 return (int)((coordinate - center.x) / cellDistance[0]);
192}
193
194inline int C3DPointGridMap::YToIntCoord(double coordinate) const
195{
196 return (int)((coordinate - center.y) / cellDistance[1]);
197}
198
199inline int C3DPointGridMap::ZToIntCoord(double coordinate) const
200{
201 return (int)((coordinate - center.z) / cellDistance[2]);
202}
203
204inline double C3DPointGridMap::XYZFromIntCoord(int intcoord, int index) const
205{
206 return (intcoord * cellDistance[index]) + center[index];
207}
208
209inline double C3DPointGridMap::XFromIntCoord(int intcoord) const
210{
211 return (intcoord*cellDistance[0])+center.x;
212}
213
214inline double C3DPointGridMap::YFromIntCoord(int intcoord) const
215{
216 return (intcoord*cellDistance[1]) + center.y;
217}
218
219inline double C3DPointGridMap::ZFromIntCoord(int intcoord) const
220{
221 return (intcoord*cellDistance[2]) + center.z;
222}
223
224typedef struct WeldProximityMap WeldProximityMap;
225
226class DLL_3DFUNCTION C3DPointSymetryMap : public CIntMap, public CInstanciatedObject
227{
228 public:
229 typedef enum SymetricEdgeInfo
230 {
231 SYM_NONE = 0,
232 SYM_EXISTS,
233 SYM_IS_SAME,
234 } SymetricEdgeInfo;
235
236 SymetricEdgeInfo GetSymetricEdge(const CFaceList *faces, const C3DEdge& edge, C3DEdge& symetricEdge, bool preventEdgeOrdering);
237};
238
239class DLL_3DFUNCTION C3DPointMethods : public CPointMethods
240{
241 DECLARE_SERIAL_XOBJECT(C3DPointMethods);
242
243 SIZET GetSizeof() const;
244 ElementType GetType() const;
245 void ConstructElement(void* pNewData);
246
247};
248
249inline SIZET C3DPointMethods::GetSizeof() const
250{
251 return sizeof(C3DPoint);
252}
253
254inline ElementType C3DPointMethods::GetType() const
255{
256 return MAKE_CUSTOM_ID('3', 'D', 'P', 'T');
257}
258
259inline void C3DPointMethods::ConstructElement(void* pNewData)
260{
261 xConstruct(C3DPoint, pNewData);
262}
263
264//! @class
265//! C3DPointList is the class which contains the x, y, z C3DPoint. The data is stored internally as a C3DPoint array (Cf. CElementArray).
266class DLL_3DFUNCTION C3DPointList : public CPointList
267{
268protected:
269 // Material shared by a point
270 CMaterialGraph *materialGraph, *materialBackGraph;
271 int materialGraphLock;
272
273 // Proximity graph information
274 virtual bool UpdateList();
275
276 // Protected material graph functions
277 void CreatePointMaterialGraph(const CGeomInfo *info, bool front);
278 C3DPointGridMap *GetGridCoordMap(double distance, bool absolute, bool offset = false);
279
280public:
281 DECLARE_SERIAL_XOBJECT(C3DPointList)
282
284 virtual ~C3DPointList(); //!< Use Delete instead, unless the C3DPointList is created on the stack (take care that it is referenced once only in this case)
285
286 static C3DPointList *Create(C3DPointList *srcPoints = NULL); //!< Allocates and creates an empty set of 3d points. Use C3DPointList::Delete to delete it
287
288 virtual void RemoveAll();
289
290 //! @name Access functions
291 //! Get access to the C3DPoint data contained in the array
292 //!
293 //! @{
294 const C3DPoint *GetFirst() const;
295 const C3DPoint *GetNext(const C3DPoint *point) const;
296 C3DPoint *GetFirst();
297 C3DPoint *GetNext(C3DPoint *pointList);
298 C3DPoint *ElementAt(int i);
299 C3DPoint *operator[](int i);
300 const C3DPoint *operator[](int i) const;
301
302 //! @}
303
304 bool SwapCoordinates(unsigned int swap);
305 bool MatrixTransform(const C4x4Matrix& matrix, POINT_PROPERTIES property = POINT_NONE, bool set = TRUE, int index = 0, int count = -1);
306
307 // Flags initialisation functions
308 // void InitShareCoplanarFacesFlag(const CGeomInfo *info, double maxAngle);
309
310 // Material graph functions
311 void InitPointMaterialGraph(const CGeomInfo *info);
312 void DeletePointMaterialGraph();
313 bool InitShareSeveralMaterialsFlag();
314 int GetNumberOfMaterialsConnectedToPoint(int ptindex);
315 MaterialID *GetMaterialsConnectedToPoint(int ptindex, int& size);
316
317 // operators
318
319 // others functions
320 C3DPointGridMap *InitSlicerMap(bool initMap, unsigned int sliceX, unsigned int sliceY, unsigned int sliceZ, unsigned int pointFlags = POINT_NONE, bool flagsSet = true);
321 C3DPointGridMap *InitGridCoordMap(double distance, bool absolute);
322 WeldProximityMap *InitWeldMap(double distance, bool absolute);
323 void DeleteWeldMap(WeldProximityMap *map) const; //!< Free the weld map returned by InitWeldMap
324 int *Get3DProximityPoints(int index, WeldProximityMap *weldMap, int& size); //!< Return the point indexes which are close to the given index. The return array should not be freed
325 C3DPointSymetryMap *InitSymetryMap(AXIS_INFO symetry, double precision = FLOAT_EPSILON);
326
327 void InitShareCoplanarFacesFlag(const CGeomInfo *info, double maxAngle);
328 unsigned int Set2DCornerPointsStatus(CEdgeGraph& graph, double radianAngle);
329 unsigned int Set3DCornerPointsStatus(CFaceList *faces, double radianAngle);
330
331 double GetCompacityFactor(const int *indexes) const; //!< indexes is an array of 3 point indexes
332 bool GetNormal(const int *indexes, C3DVector& normal) const; //!< indexes is an array of 3 point indexes
333
334 // 3D modification functions
335 C3DPoint GetCenterOfBoundingBox();
336 bool GetObjectBoundingBox(C3DPoint *bbox8Pts, unsigned int flags = POINT_NONE, bool set = true, C4x4Matrix *matrix = NULL); //!< Compute OBB bounding box. bbox8Pts are the returned eight corners of the bounding box that are transformed by matrix if any provided.
337 bool GetBoundingBox(C3DBBox& bbox, unsigned int flags = POINT_NONE, bool set = false, C4x4Matrix *matrix = NULL);
338 bool GetBoundingBox(C3DPoint& min, C3DPoint& max, unsigned int flags = POINT_NONE, bool set = true, C4x4Matrix *matrix = NULL); //!< Compute AABB bounding box. Points are transformed by matrix if any provided
339 void NoisyWaveFunc(const C3DPoint& upperleft, const C3DVector& length, double amplitude, double wavelength, double phase, POINT_PROPERTIES property = POINT_NONE, bool set = TRUE);
340
341 virtual unsigned int GetChecksum(unsigned int checksumFlags = CHECKSUM_POINTS| CHECKSUM_POINTS_EXTRA) const; //!< Return a value that is a simple way to check if the geometry changed between two call to the method
342
343 C3DPointList& operator=(const C3DPointList& refpoints);
344 virtual CPointList& operator=(const CPointList& refpoints);
345
346#ifdef _DEBUG
348#endif
349};
350
351inline const C3DPoint *C3DPointList::GetFirst() const
352{
353 return (const C3DPoint *)CElementArray::GetFirst();
354}
355
356inline const C3DPoint *C3DPointList::GetNext(const C3DPoint *point) const
357{
358 return (const C3DPoint *)CElementArray::GetNext(point);
359}
360
361inline C3DPoint *C3DPointList::GetFirst()
362{
363 return (C3DPoint *)CElementArray::GetFirst();
364}
365
366inline C3DPoint *C3DPointList::GetNext(C3DPoint *pointList)
367{
368 return (C3DPoint *)CElementArray::GetNext(pointList);
369}
370
371inline C3DPoint *C3DPointList::ElementAt(int i)
372{
373 return ((C3DPoint *)CElementArray::ElementAt(i));
374}
375
376inline C3DPoint *C3DPointList::operator[](int i)
377{
378 return ((C3DPoint *)CElementArray::operator[](i));
379}
380inline const C3DPoint *C3DPointList::operator[](int i) const
381{
382 return ((const C3DPoint *)CElementArray::operator[](i));
383}
384
385END_MOOTOOLS_NAMESPACE
386
387#endif // !defined(AFX_3DPOINTLIST_H__CA6BC2A5_FAC2_11D1_A0DE_000000000000__INCLUDED_)
C3DTPoint template class definition for handling x, y, z 3D point coordinate.
@ CHECKSUM_POINTS
Point position is taken into account (geometry and channel if CHECKSUM_CHANNELS set)
Definition 3DType.h:428
@ CHECKSUM_POINTS_EXTRA
Point flags (geometry and channel if CHECKSUM_CHANNELS set)
Definition 3DType.h:429
AXIS_INFO
Definition 3DType.h:320
POINT_PROPERTIES
Point flags used by any classes that inherit from CPt (C3DPoint, C3DVector...)
Definition Point.h:19
C3DEdge is a class containing 2 point indexes that represent the edge of a face.
Definition FaceList.h:72
C3DPointGridMap is a compact class for retrieving quickly points which are in the same voxel of a pro...
Definition 3DPointList.h:77
double XYZFromIntCoord(int intcoord, int index) const
index: 0, 1 or 2 [x, y or z]
Definition 3DPointList.h:204
static DLL_3DFUNCTION double GetMaxDistance(double threshold, const C3DBBox &bboxCorner)
Return the max distance between two points considered to be equal (returned by Get3DProximityPoints)
double GetMaxDistance(unsigned char XYZ=0) const
Return the max distance between two points when using Get3DProximityPoints (cf note in C3DPointGridMa...
static DLL_3DFUNCTION double GetAbsoluteDistance(double threshold, const C3DBBox &bboxCorner)
Return the absolute distance to use to construct C3DPointGridMap based on a threshold value between 0...
int XYZToIntCoord(double coordinate, int index) const
index: 0, 1 or 2 [x, y or z]
Definition 3DPointList.h:184
Definition 3DPointList.h:267
bool GetNormal(const int *indexes, C3DVector &normal) const
indexes is an array of 3 point indexes
int * Get3DProximityPoints(int index, WeldProximityMap *weldMap, int &size)
Return the point indexes which are close to the given index. The return array should not be freed.
double GetCompacityFactor(const int *indexes) const
indexes is an array of 3 point indexes
bool GetBoundingBox(C3DPoint &min, C3DPoint &max, unsigned int flags=POINT_NONE, bool set=true, C4x4Matrix *matrix=NULL)
Compute AABB bounding box. Points are transformed by matrix if any provided.
bool GetObjectBoundingBox(C3DPoint *bbox8Pts, unsigned int flags=POINT_NONE, bool set=true, C4x4Matrix *matrix=NULL)
Compute OBB bounding box. bbox8Pts are the returned eight corners of the bounding box that are transf...
virtual ~C3DPointList()
Use Delete instead, unless the C3DPointList is created on the stack (take care that it is referenced ...
static C3DPointList * Create(C3DPointList *srcPoints=NULL)
Allocates and creates an empty set of 3d points. Use C3DPointList::Delete to delete it.
virtual unsigned int GetChecksum(unsigned int checksumFlags=CHECKSUM_POINTS|CHECKSUM_POINTS_EXTRA) const
Return a value that is a simple way to check if the geometry changed between two call to the method.
void DeleteWeldMap(WeldProximityMap *map) const
Free the weld map returned by InitWeldMap.
Definition 3DPointList.h:227
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
This class handles an association between a key and its associated values.
Definition AssociationMap.h:240
ASSOCTYPE * Lookup(const MAPTYPE &entry, int &size) const
Giving a key return an array with the associates data and the number of element in that array.
Definition AssociationMap.h:268
CFaceList is the common base class for a lot of different classes (C3DFaceList, CUVWFaceList....
Definition FaceList.h:179
CGeomInfo is an helper class oftenly required by different methods.
Definition GeomInfo.h:71
Definition Hash.h:146
Definition InstanciatedObject.h:16
Definition HashMap.h:672
CPointList is the base class for different classes (C3DPointList, CUVWPointList......
Definition PointList.h:50
Definition 3DPointList.h:20