Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
TrackInfo.h
1#ifndef __CRUNCHER_TRACKINFO
2#define __CRUNCHER_TRACKINFO
3
5#include "3DType.h"
6#include "OffsetArray.h"
7#include "3DPoint.h"
8#include "3DFace.h"
9#include "UVWFace.h"
10#include "UVWPoint.h"
11
12BEGIN_MOOTOOLS_NAMESPACE
13
14//////////////////////////////
15// Minimum informations change
16//////////////////////////////
17#define CELL_INDEX_TO_ACTION(a) ((NewCellState)(a + 2))
18#ifdef _DEBUG
19 int CELL_ACTION_TO_INDEX(int a);
20#else
21# define CELL_ACTION_TO_INDEX(a) (a-2)
22#endif
23
24typedef enum XEnumType(unsigned char)
25{
26 CELL_ACTION_UNDEFINED = 0,
27
28 // Cell action contains CELL_FACE_INDEX0...CELL_FACE_INDEX3
29 // or a number of isolated points for CTrackInvalidFace (it must be the LOW part of the byte (CTrackInvalidFace::SetIsolatedFacePointNumber)
30 CELL_ACTION = 0x0F,
31 CELL_INDEX_TO_VALUE = 2, // Beware check CELL_FACE_NOINDEX - CELL_INDEX_TO_VALUE is negative, check CELL_FACE_NOINDEX value before
32 CELL_FACE_NOINDEX = 0x01, // The faces indexes remain the same (Occurs when interpolating, see ReplacePointInFaceList)
33 CELL_FACE_INDEX0 = 0x02, // Index of the face change (beware we do CELL_FACE_INDEX0+j sometime, number must follows)
34 CELL_FACE_INDEX1 = 0x03,
35 CELL_FACE_INDEX2 = 0x04,
36 CELL_SAME_AS_REMAINING = 0x01, // for CELL_KINDOF_MOVE_POINT
37 CELL_SAME_AS_REMOVED = 0x02,
38
39 // Defines the cell class
40 CELL_KINDOF_MASK = 0xF0,
41 CELL_KINDOF_EDGE_CONTRACTION = 0x10, // Refers to CTrackEdgeContraction
42 CELL_KINDOF_UV_CONTRACTION = 0x20, // Refers to CTrackUVContraction
43 CELL_KINDOF_NORMAL_CONTRACTION = 0x30, // Refers to CTrackNormalContraction
44 CELL_KINDOF_INVALIDFACE = 0x40, // Refers to CTrackInvalidFace
45 CELL_KINDOF_FACE = 0x50, // Refers to CTrackFace
46 CELL_KINDOF_UVFACE = 0x60, // Refers to CTrackChannelFace
47 CELL_KINDOF_NORMALFACE = 0x70, // Refers to CTrackNormalFace
48 CELL_KINDOF_MOVE_DUPLICATED_POINT = 0x80, // Refers to CTrackMoveDuplicatedPoint
49#ifdef PLY_FLIP_EDGES
50 CELL_KINDOF_FACE2 = 0x90, // Refers to CTrackFace2
51 CELL_KINDOF_UVFACE2 = 0xA0, // Refers to CUVTrackFace2
52#endif
53
54#ifdef MOOTOOLS_PRIVATE_DEBUG
55 // These allows to follow the flag state for point and face
56 CELL_KINDOF_POINTFLAGS = 0xD0, // Refers to CTrackFlags
57 CELL_KINDOF_FACEFLAGS = 0xE0, // Refers to CTrackFlags
58 CELL_KINDOF_NORMALPTFLAGS = 0xF0, // Refers to CTrackFlags
59#endif // MOOTOOLS_PRIVATE_DEBUG
60 // beware state is a char
61} NewCellState;
62
63class CTrackContractions;
64class CTrackInfo
65{
66 friend CTrackContractions;
67
68protected:
69 unsigned char state;
70
71 void Init();
72 void SetKindOf(NewCellState apply);
73
74public:
75 void SetChange(NewCellState state);
76 unsigned char GetChange();
77 unsigned int GetKindOf();
78};
79
80#ifndef MOOTOOLS_NO_INLINE
81inline void CTrackInfo::Init()
82{
83 state = CELL_ACTION_UNDEFINED;
84}
85
86inline void CTrackInfo::SetKindOf(NewCellState apply)
87{
88 state &= (unsigned char)(~CELL_KINDOF_MASK);
89 state |= (unsigned char)apply;
90}
91
92inline void CTrackInfo::SetChange(NewCellState state)
93{
94 this->state &= (unsigned char)(~CELL_ACTION);
95 this->state |= (unsigned char)state;
96}
97
98inline unsigned char CTrackInfo::GetChange()
99{
100 return (state & CELL_ACTION);
101}
102
103inline unsigned int CTrackInfo::GetKindOf() // unsigned int for KINDOF2OFFSET
104{
105 return (state & CELL_KINDOF_MASK);
106}
107#endif // MOOTOOLS_NO_INLINE
108///////////////////////////////////////////
109// Tracking point / normal / uv contraction
110
111// Stack of all change that appears when contracting one pair
112class DLLFUNCTION CTrackEdgeContraction : public CTrackInfo
113{
114 friend CTrackContractions;
115
116protected:
117 float pos[3];
118
119 int ptIndexWas;
120 int ptIndexBecome;
121
122public:
123 void SetPoint(C3DPoint& point);
124 void GetPoint(C3DPoint& point);
125 const float *GetPoint() const;
126 void SetEdgeContraction(int indexwas, int indexbecome);
127 void GetEdgeContraction(int& indexwas, int& indexbecome);
128};
129
130#ifndef MOOTOOLS_NO_INLINE
131inline void CTrackEdgeContraction::SetPoint(C3DPoint& point)
132{
133 // We store the old position. The new one is stored in the mesh while it is created
134 // Then we swap the position when modifying the resolution
135 memcpy(pos, point.ValPtr(), 3 * sizeof(float));
136}
137
138inline void CTrackEdgeContraction::GetPoint(C3DPoint& point)
139{
140 memcpy(point.ValPtr(), pos, 3 * sizeof(float));
141}
142
143inline const float *CTrackEdgeContraction::GetPoint() const
144{
145 return pos;
146}
147
148inline void CTrackEdgeContraction::SetEdgeContraction(int indexwas, int indexbecome)
149{
150 ptIndexWas = indexwas;
151 ptIndexBecome = indexbecome;
152}
153
154inline void CTrackEdgeContraction::GetEdgeContraction(int& indexwas, int& indexbecome)
155{
156 indexwas = ptIndexWas;
157 indexbecome = ptIndexBecome;
158}
159#endif // MOOTOOLS_NO_INLINE
160
161class DLLFUNCTION CTrackMoveDuplicatedPoint : public CTrackInfo
162{
163 friend CTrackContractions;
164
165protected:
166 int index;
167
168public:
169 void SetIndex(int index);
170 int GetIndex() const;
171};
172
173#ifndef MOOTOOLS_NO_INLINE
174inline void CTrackMoveDuplicatedPoint::SetIndex(int index)
175{
176 this->index = index;
177}
178
179inline int CTrackMoveDuplicatedPoint::GetIndex() const
180{
181 return index;
182}
183#endif // MOOTOOLS_NO_INLINE
184
185class DLLFUNCTION CTrackNormalContraction : public CTrackInfo
186{
187 friend CTrackContractions;
188
189protected:
190 float pos[3];
191 int index;
192
193public:
194 void SetNormalIndex(int index);
195 int GetNormalIndex() const;
196 void SetNormal(C3DVector& normal);
197 void GetNormal(C3DVector& normal);
198};
199
200#ifndef MOOTOOLS_NO_INLINE
201inline void CTrackNormalContraction::SetNormalIndex(int index)
202{
203 this->index = index;
204}
205
206inline int CTrackNormalContraction::GetNormalIndex() const
207{
208 return index;
209}
210
211inline void CTrackNormalContraction::SetNormal(C3DVector& normal)
212{
213 memcpy(pos, normal.ValPtr(), 3 * sizeof(float));
214}
215
216inline void CTrackNormalContraction::GetNormal(C3DVector& normal)
217{
218 memcpy(normal.ValPtr(), pos, 3 * sizeof(float));
219}
220#endif // MOOTOOLS_NO_INLINE
221
222class DLLFUNCTION CTrackUVContraction : public CTrackInfo
223{
224 friend CTrackContractions;
225
226protected:
227 float pos[3];
228 int index;
229 unsigned char channel;
230
231public:
232 void SetUVWIndex(int index);
233 int GetUVWIndex() const;
234
235 void SetUVWPoint(CUVWPoint& point);
236 void GetUVWPoint(CUVWPoint& point);
237 const float *GetUVWPoint() const;
238 unsigned char GetChannel() const;
239 void SetChannel(unsigned char channel);
240};
241
242#ifndef MOOTOOLS_NO_INLINE
243inline void CTrackUVContraction::SetUVWIndex(int index)
244{
245 this->index = index;
246}
247
248inline int CTrackUVContraction::GetUVWIndex() const
249{
250 return index;
251}
252
253inline void CTrackUVContraction::SetUVWPoint(CUVWPoint& point)
254{
255 memcpy(pos, point.ValPtr(), 3 * sizeof(float));
256}
257
258inline void CTrackUVContraction::GetUVWPoint(CUVWPoint& point)
259{
260 memcpy(point.ValPtr(), pos, 3 * sizeof(float));
261}
262
263inline const float *CTrackUVContraction::GetUVWPoint() const
264{
265 return pos;
266}
267
268inline unsigned char CTrackUVContraction::GetChannel() const
269{
270 return channel;
271}
272
273inline void CTrackUVContraction::SetChannel(unsigned char channel)
274{
275 this->channel = channel;
276}
277#endif // MOOTOOLS_NO_INLINE
278
279///////////////////////////////////////////
280// Tracking face contraction
281
282class DLLFUNCTION CTrackFace : public CTrackInfo
283{
284 friend CTrackContractions;
285
286protected:
287 int faceIndex; // index of the element which change
288
289public:
290 void SetCurrentFace(int faceIndex);
291 int GetCurrentFace();
292
293};
294
295#ifndef MOOTOOLS_NO_INLINE
296inline void CTrackFace::SetCurrentFace(int faceIndex)
297{
298 this->faceIndex = faceIndex;
299}
300
301inline int CTrackFace::GetCurrentFace()
302{
303 return faceIndex;
304}
305#endif // MOOTOOLS_NO_INLINE
306
307class DLLFUNCTION CTrackInvalidFace : public CTrackFace
308{
309public:
310 // This value indicate how many points are removed when an isolated face
311 // is removed (the edge contraction make the face invalid).
312 // Others points of the face are then removed.
313 int GetIsolatedFacePointNumber() const;
314 void SetIsolatedFacePointNumber(int ptnbr);
315};
316
317#ifndef MOOTOOLS_NO_INLINE
318inline int CTrackInvalidFace::GetIsolatedFacePointNumber() const
319{
320 return (state & CELL_ACTION);
321}
322
323inline void CTrackInvalidFace::SetIsolatedFacePointNumber(int ptnbr)
324{
325 XASSERT(ptnbr >= 0 && ptnbr <= CELL_ACTION); // Should not be more than 3
326 this->state = (unsigned char)(((unsigned char)(ptnbr) & CELL_ACTION) | (state & CELL_KINDOF_MASK));
327}
328#endif // MOOTOOLS_NO_INLINE
329
330class DLLFUNCTION CTrackCell : public CTrackInfo
331{
332 friend CTrackContractions;
333
334protected:
335 int index; // index (it could changes when decreasing or increasing ratio, swap occurs for channels)
336
337public:
338 void SetIndexChange(int index);
339 int GetIndexChange();
340};
341
342#ifndef MOOTOOLS_NO_INLINE
343inline void CTrackCell::SetIndexChange(int index)
344{
345 this->index = index;
346}
347
348inline int CTrackCell::GetIndexChange()
349{
350 return index;
351}
352#endif // MOOTOOLS_NO_INLINE
353
354#ifdef PLY_FLIP_EDGES
355class DLLFUNCTION CTrackFace2 : public CTrackCell
356{
357 friend CTrackContractions;
358
359protected:
360 int faceIndex; // index of the element which change
361
362public:
363 void SetCurrentFace(int faceIndex);
364 int GetCurrentFace();
365};
366
367#ifndef MOOTOOLS_NO_INLINE
368inline void CTrackFace2::SetCurrentFace(int faceIndex)
369{
370 this->faceIndex = faceIndex;
371}
372
373inline int CTrackFace2::GetCurrentFace()
374{
375 return faceIndex;
376}
377#endif // MOOTOOLS_NO_INLINE
378
379class DLLFUNCTION CTrackUVFace2 : public CTrackFace2
380{
381 friend CTrackContractions;
382
383protected:
384 unsigned char channel;
385
386public:
387 unsigned char GetChannel() const;
388 void SetChannel(unsigned char channel);
389};
390
391#ifndef MOOTOOLS_NO_INLINE
392inline unsigned char CTrackUVFace2::GetChannel() const
393{
394 return channel;
395}
396
397inline void CTrackUVFace2::SetChannel(unsigned char channel)
398{
399 this->channel = channel;
400}
401#endif // MOOTOOLS_NO_INLINE
402
403#endif
404
405class DLLFUNCTION CTrackChannelFace : public CTrackCell
406{
407 friend CTrackContractions;
408
409protected:
410 unsigned char channel;
411
412public:
413 // In debug mode store the face index.
414 // This is just for ensuring we are reading contraction data in the correct order
415 // The faceindex is included in CTrackFace and UV contraction info refers to this faceindex
416 // The contraction data are stored in the following order:
417 //
418 // 1 CTrackEdgeContraction (first edge contraction)
419 // 2 CTrackFace (face #2)
420 // 3 CTrackChannelFace (face #2)
421 // 4 CTrackChannelFace (face #2)
422 // 4 CTrackChannelNormal (face #2)
423 // 5 CTrackFace (face #10)
424 // 6 CTrackChannelFace (face #10)
425 // 7 CTrackChannelFace (face #10)
426 // 4 CTrackChannelNormal (face #10)
427 // 8 CTrackEdgeContraction (2nd edge contraction)
428 // 9 CTrackFace (face #5)
429 // 10 CTrackChannelFace (face #5)
430 // ...
431 // When reading contraction for adding or removing face of the multiresolution object we read these information
432 // in the following order:
433 // Decreasing faces: 1, 2, 3, 4, 5, 6, 7, 8, 9 (this is the real optimization order)
434 // Increasing faces: 8, 9, 10, 1, 2, 3, 4, 5, 6, 7 (this is not the optimization order but the it gives the same result)
435 // Following that order we always have CTrackFace before CTrackChannel
436
437#ifdef MOOTOOLS_PRIVATE_DEBUG
438 unsigned int chnCurrentIndex;
439 unsigned int chnFaceIndex;
440#endif
441
442 unsigned char GetChannel() const;
443 void SetChannel(unsigned char channel);
444};
445
446#ifndef MOOTOOLS_NO_INLINE
447inline unsigned char CTrackChannelFace::GetChannel() const
448{
449 return channel;
450}
451
452inline void CTrackChannelFace::SetChannel(unsigned char channel)
453{
454 this->channel = channel;
455}
456#endif // MOOTOOLS_NO_INLINE
457
458// The same thing as CTrackChannel except that there is only one normal channel handled
459// The channelIndex is always 0
460class DLLFUNCTION CTrackNormalFace : public CTrackCell
461{
462 friend CTrackContractions;
463
464public:
465#ifdef MOOTOOLS_PRIVATE_DEBUG
466 unsigned int chnCurrentIndex;
467 unsigned int chnFaceIndex;
468#endif
469};
470
471#ifdef MOOTOOLS_PRIVATE_DEBUG
472///////////////////////////////////////////
473// Tracking flags changes
474
475class DLLFUNCTION CTrackFlags : public CTrackInfo
476{
477 friend CTrackContractions;
478
479protected:
480 unsigned int index, flags;
481
482public:
483 unsigned int GetIndex() const;
484 void SetIndex(unsigned int index);
485 unsigned int GetFlags() const;
486 void SetFlags(unsigned int flags);
487};
488
489#ifndef MOOTOOLS_NO_INLINE
490inline unsigned int CTrackFlags::GetIndex() const
491{
492 return index;
493}
494
495inline void CTrackFlags::SetIndex(unsigned int index)
496{
497 this->index = index;
498}
499
500inline unsigned int CTrackFlags::GetFlags() const
501{
502 return flags;
503}
504
505inline void CTrackFlags::SetFlags(unsigned int flags)
506{
507 this->flags = flags;
508}
509#endif // MOOTOOLS_NO_INLINE
510
511#endif
512
513class C3DFaceList;
514class CExtPointList;
515class C3DExtObject;
516
517// CStack of all edge contraction...
518class CTrackContractions : public CInstanciatedObject
519{
520protected:
521 unsigned int revertTrackPos;
523 COffsetArray edgesContractionArray;
524 unsigned char *data;
525 SIZET dataSize, dataOffset;
526 unsigned int edgeContractionNbr;
527 unsigned int staticPtNbr, staticFaceNbr;
528
529 int currentContraction; // Very important: must be signed
530
531 virtual ~CTrackContractions(); // Use Delete instead
532
533 void CheckSize(SIZET neededsize);
534 CTrackInfo *GetNextTrackInfo(CTrackInfo *trackinfo) const;
535
536 int GetNumberOfInvalidFaces();
537 void InitStaticElements(int srcFaceNbr, int srcPointNbr);
538
539public:
540 CTrackContractions(int staticFaceSize = -1, int staticPtSize = -1);
541
542 void InitSize(unsigned int edges, unsigned int channelnbr);
543 void InitSizeFrom(const CTrackContractions *info);
544 void Free();
545 void FreeExtra();
546 void SetCurrentContraction(int currentContraction); // Cursor point for constructing/deconstructing object
547 int GetCurrentContraction() const;
548 int GetContractionsNbr() const;
549 int GetStaticFaceNbr() const;
550 int GetStaticPointNbr() const;
551
552#ifdef MOOTOOLS_PRIVATE_DEBUG
554#else
556#endif
557
558#ifdef _DEBUG
559 void Dump(C3DGeomObject *object, bool changeRatio = true) const;
560 int GetRemovedFaceInContraction(CTrackEdgeContraction *edge) const;
561#endif
562
563 CTrackEdgeContraction *GetNewEdgeContraction();
564 CTrackMoveDuplicatedPoint *GetNewMoveDuplicatedPoint();
565 CTrackUVContraction *GetNewUVContraction();
566 CTrackNormalContraction *GetNewNormalContraction();
567 CTrackFace *GetNewTrackFace();
568 CTrackInvalidFace *GetNewTrackInvalidFace();
569 CTrackChannelFace *GetNewTrackChannelFace(NewCellState channeltype);
570 CTrackNormalFace *GetNewTrackNormalFace();
571#ifdef PLY_FLIP_EDGES
574#endif
575
576#ifdef MOOTOOLS_PRIVATE_DEBUG
578#endif
579
580 CTrackEdgeContraction *GetEdgeContraction(unsigned int contractionNbr) const;
581 CTrackInfo *GetFirstCell(CTrackEdgeContraction *contraction) const;
582 CTrackInfo *GetNextCell(CTrackInfo *cell) const;
583 CTrackInfo *GetLastCell(CTrackEdgeContraction *contraction);
584 CTrackInfo *GetPrevCell(CTrackInfo *cell);
585 bool AddCell(CTrackInfo *cell);
586
587 SIZET GetDataSize() const;
588 const void *GetData(SIZET& size) const;
589 bool InitFromData(const void *data, SIZET size);
590};
591
592END_MOOTOOLS_NAMESPACE
593
594#endif // __CRUNCHER_TRACKINFO
C3DFace class definition for a 3D face, which is a list of indexes that refers to a 3D point list.
C3DTPoint template class definition for handling x, y, z 3D point coordinate.
The file contains enum and type declarations used by the SDK.
CUVWFace is a face that refers to an UV in a CUVWPointList.
CUVWPoint is a point that have u, v, w coordinates.
This class handles static optimization of an object.
Definition 3DExtObject.h:66
C3DFaceList class which implement a list of C3DFace. Each face contains indexes to 3D points stored i...
Definition 3DFaceList.h:249
This is the base class for any object containing geometry (curve, polygonal object,...
Definition 3DGeomObject.h:49
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition InstanciatedObject.h:16
CUVWPoint is a point that have u, v, w for handling object texturing.
Definition UVWPoint.h:21
CXArray is an array of simple data information which does not requires to call a constructor / destru...
Definition XTemplate.h:34