Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
3DExtObject.h
Go to the documentation of this file.
1//! @file 3DExtObject.h
2//! C3DExtObject class is a geom object that can be optimize. It is generally used with a CSceneOptimizer.
3//!
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_3DExtObject_H__BB3D80E9_003C_11D2_A0E3_000000000000__INCLUDED_)
7#define AFX_3DExtObject_H__BB3D80E9_003C_11D2_A0E3_000000000000__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
14#include "SceneOptimizer.h"
15#include "3DObject.h"
16#include "3DExtPoint.h"
17#include "TrackInfo.h"
18#include "CustomHeap.h"
19
20BEGIN_MOOTOOLS_NAMESPACE
21
22#define FACE_HAS_AT_LEAST_ONE_POINT_TO_BE_OPTIMIZED FACE_USER_PROPERTIES1
23#define FACE_HAS_ALL_POINTS_TO_BE_OPTIMIZED FACE_USER_PROPERTIES2
24
25#define POINT_OPTIMIZE_FLAG POINT_USER_PROPERTIES1 // Point is to be optimized
26#define POINT_OPTIMIZE_PROTECTED POINT_USER_PROPERTIES2 // Point has been constraint
27#define POINT_OPTIMIZE_PRESERVED POINT_USER_PROPERTIES3 // Point is only preserved
28
29typedef enum _MOVE_FACTOR
30{
31 FIND_BEST_MOVE = 1,
32 MOVE_CONSTRAINT_LEVEL1 = 2,
33 MOVE_CONSTRAINT_LEVEL2 = 3,
34 MOVE_CONSTRAINT_LEVEL3 = 4,
35 MOVE_CONSTRAINT_LEVEL4 = 5,
36 MOVE_CONSTRAINT_LEVEL5 = 6,
37 MOVE_CONSTRAINT_LEVEL6 = 7,
38 MOVE_CONSTRAINT_HIGHEST_LEVEL = 8,
40
41#define MULTIRES_DATA_FILE MAKE_CUSTOM_ID('M', 'R', 'F', 'L')
42#define MULTIRES_DATA_POINTS_ORDER MAKE_CUSTOM_ID('P', 'O', 'R', 'D')
43#define MULTIRES_DATA_FACES_ORDER MAKE_CUSTOM_ID('F', 'O', 'R', 'D')
44#define MULTIRES_DATA_TRIANGULATION MAKE_CUSTOM_ID('T', 'R', 'D', 'A')
45
48
49//! @class C3DExtObject
50//! @brief This class handles static optimization of an object.
51//! @details CSceneOptimizer handles optimization for a set of C3DExtObject objects.
52//! CSceneOptimizer::Optimize calls the C3DExtObject::Optimize for each objects it contains.
53//!
54//! When optimizing an object there is two phases:
55//! * Optimization initialization, which might changes any time SetOptimizeMode is called
56//! * Optimization itself which consist in point removal and which occurs in C3DExtObject::Optimize\n
57//! This step can be "recorded" when using SCENEOPTIMIZER_TRACK_CHANGES is set.\n
58//! Tracking the changes provides a way to have dynamic optmization through CMultiresolutionObject which is get from the C3DExtObject.
59//!
60//! Calling C3DExtObject directly give you some additional possibilities compared to accessing them only through CSceneOptimizer.
61//! * It is possible to call Optimize with a specific ratio for each C3DExtObject
62//! * It is possible to exclude some materials from the optimization using C3DExtObject::SelectMaterial
63//! * It is possible to perform optimization only on the selected points using POINT_IS_SELECTED and one of the OPTIMIZE_SELECTION_MASK flag.
64//!
65class DLLFUNCTION C3DExtObject : public C3DObject
66{
67public:
68 DECLARE_SERIAL_XOBJECT(C3DExtObject);
69
70protected:
71 // optimized results
72 CExtPointList *optimizedPoints;
73 C3DFaceList *optimizedFaces;
74 CDependentChannels *optimizedChannels;
75
76 // initial points
77 C3DFaceList *initFaces;
78 C3DPointList *initPoints; // Is a C3DPointList (SCENEOPTIMIZER_INTERACTIVE_MODE is set) or a CExtPointList (!SCENEOPTIMIZER_INTERACTIVE_MODE)
79 CDependentChannels *initChannels;
80
81 // Symetry map...
82 C3DPointSymetryMap *initSymetryMap;
83 C3DPointSymetryMap *optimizedSymetryMap;
84
85 // Tracking informations...
86 CTrackContractions *trackInfo;
87
88 // pairs map (unordered pairs) used to generate single pair
89 // (avoid to have twice the same pair) only used when Init is call
92 CostHeap costlist; // Heap list used for the pairs removal
93
94 CFaceGraphHelper graphHelper; // Optimization
95
96 double prevRatio, sceneRatio, progressiveThreshold;
97 int initialRemovablePointNbr, initialRemovableFaceNbr; // Number of faces that can be optimised at the beginning of the process
98 int removedPointNbr, removedFaceNbr; // Number of removed point of the current optimisation
99 longuint optimizationMode, optimizationExtMode;
100
101 CMaterialHashMap excludedMaterials;
102 CSceneOptimizer *optimizer;
103 C3DSceneNode *refnode;
104
105 typedef enum ExtObjectFlags
106 {
107 EO_NONE = 0x00,
108
109 // Internal state flags
110 EO_INTERNAL_FLAGS = 0x0000FF00, // These flags cannot be set by the user
111 EO_ALREADY_TRIANGULAR = 0x00000100, // No triangulation is required, the mesh is already a trimesh
112 EO_ALREADY_PERVERTEX = 0x00000200, // No pervertex computation is required, the mesh is pervertex compatible
113
114 EO_INVALIDATION_FLAGS = 0xFFFF0000,
115 EO_INIT_OPTIMIZATION_DATA_DONE = 0x00010000, // the face and points are ready to optimized (triangulation is done)
116 EO_INIT_SELECTION_DONE = 0x00020000, // Is the faces and points to be optimised is done
117 EO_OBJECT_CLEANUP_DONE = 0x00040000, // Clean and prepare object flags for the initial data information...
118 EO_UVTOLERANCE_DONE = 0x00080000, // Is UV the tolerance must be initialized
119 EO_VCTOLERANCE_DONE = 0x00100000, // Is VC the tolerance must be initialized
120 EO_NORMALTHRESHOLD_DONE = 0x00200000, // Is normal the tolerance must be initialized
121 EO_SYMETRY_DONE = 0x00400000, // Is symetry map must be initialized
122 EO_WEIGHT_DONE = 0x00800000, // Is symetry map must be initialized
123 EO_PERVERTEX_DONE = 0x01000000, // Is confused map
124 EO_INIT_COST_DONE = 0x02000000, // The computation of the costs has been done
125 EO_OPTIMIZATION_STARTED = 0x04000000, // The optimization has been started (but might have been canceled)
126 EO_OPTIMIZATION_DONE = 0x08000000, // The optimization has been done (and not canceled)
127 } ExtObjectFlags;
128
129 unsigned int extflags;
130
131 bool hasSeveralMaterials, hasSelectedPoints;
132 int workOnInitialObjectLock; // Allow the object to be modified by an external tool
133 int lockInit; // lock initialization (allow to call SetOptimizeMode without initialize each time)
134 int VCTolerance;
135 float UVWTolerance;
136 float symetryTolerance;
137 double normalThreshold;
138 float constraintRatio;
139
140 // temporary data for fastest computation
141 CSymMatrix tmpSymMatrix;
142 C3DPoint resultingPt, bboxPt1, bboxPt2, inflateBBox1, inflateBBox2;
143 C3DVectorD lineQv2, lineQd, lineD, lineV2;
144 double invmatrix[6];
145
146#ifdef MOOTOOLS_PRIVATE_DEBUG
148#endif
149
150 static bool CheckMultiresolutionData(C3DObject *object, CTrackContractions *&trackInfo);
151
154
155public:
156 bool ContainSelection() const;
157 bool ContainMaterialFrontier() const;
158 bool ContainUVWInfo() const;
159 bool ContainVCInfo() const;
160 bool ContainNormalInfo() const;
161
162 bool SetConstraintRatio(float constraint);
163 float GetConstraintRatio();
164
165 bool SetUVWTolerance(float tolerance);
166 float GetUVWTolerance();
167
168 bool SetVCTolerance(int tolerance);
169 int GetVCTolerance();
170
171 bool SetNormalThreshold(double radianThreshold);
172 double GetNormalThreshold();
173
174 bool SetSymetryTolerance(float tolerance);
175 float GetSymetryTolerance();
176 int GetSymetricPairsNumber();
177
178 virtual ~C3DExtObject();
179 C3DExtObject();
181
182 // Initialisation of the object
183 virtual void SetPointList(C3DPointList *, bool deletePrevious = true);
184 virtual void SetFaceList(C3DFaceList *, bool deletePrevious = true);
185 virtual void SetChannels(CDependentChannels *, bool deletePrevious = true);
186
187 CTrackContractions *GetTrackInfo() { return trackInfo; }
188 C3DSceneNode *GetNode() { return refnode; }
189 inline CExtPointList* GetPointList() const;
190 CMultiresolutionObject1 *GetMultiresolutionObject(bool& userCancel);
191
192 void SetOptimizer(CSceneOptimizer& optimizer, C3DSceneNode *node);
193
194 void BeginModifyInitialObject();
195 void EndModifyInitialObject(bool objectChanged);
196 void ResetOptimization();
197
198 //////////////////////////////////////////////
199 // Multiresolution data serialization methods
200 //////////////////////////////////////////////
201
202 // Return multiresolution data memory block after an optimization was performed (using the extended mode OPTIMIZE_EXT_MULTIRESOLUTION_DATA)
203 // Memory must be release using FreeMultiresolutionData
204 bool GetMultiresolutionData(void *&data, unsigned long& size);
205
206 // Init a CMultiresolutionObject object from multiresolution data.
207 // The method always free the provided data block that must have been prealocated using AllocMultiresolutionData
208 static CMultiresolutionObject1 *SetMultiresolutionData(C3DObject *object, void *data, unsigned long size, unsigned optimizationMode = OPTIMIZE_NONE);
209 // static CMultiresolutionObject2 *SetMultiresolutionData2(C3DObject *object, void *data, unsigned long size);
210 static void *AllocMultiresolutionData(unsigned long size);
211 static void FreeMultiresolutionData(void *data);
212
213 void SetExtFlags(unsigned int flags, bool set);
214 void SetExtFlag(ExtObjectFlags flag, bool set);
215 bool IsExtFlagSet(ExtObjectFlags flag) const;
216
217 longuint GetOptimizeMode(); //!< Returns the optimization mode which is a combination of OPTIMIZE_MODE flags
218 longuint GetOptimizeExtMode(); //!< Returns the optimization mode which is a combination of OPTIMIZE_EXTMODE flags
219 bool SetOptimizeMode(longuint mode, bool cleanNotNeedParameters); //!< Set optimization mode has a combination of OPTIMIZE_MODE flags
220 bool SetOptimizeMode(OPTIMIZE_MODE newflag, bool set); //!< Set one OPTIMIZE_MODE flag
221 bool SetOptimizeExtMode(longuint extmode, bool cleanNotNeedParameters); //!< Set optimization mode has a combination of OPTIMIZE_EXTMODE flags
222 void LockInitialization(); //!< A good pratice is to lock and unlock initialization before changing one or several OPTIMIZE_MODE. Doing that initialization occurs a single time.
223 void UnlockInitialization();
224
225 //! @name Select Materials to optimize
226 //! It is possible to exclude some materials of the optimization, inserting some MaterialID in the has map provided GetExcludedMaterials.\n
227 //! If you modify the list of excluded materials, you have to invalidate optimization.
228 //! @code{.cpp}
229 //! SetExtFlag(EO_INIT_SELECTION_DONE, false);
230 //! InvalidateOptimization();
231 //! @endcode
232 //!
233 //! You can also use SelectMaterial to exclude a particular material.\n
234 //! If you make several call to SelectMaterial, set them between a LockInitialization / UnlockInitialization calls.
235 //!
236 //! @{
237 CMaterialHashMap *GetExcludedMaterials() { return &excludedMaterials; };
238 bool SelectMaterial(MaterialID id, bool optimised);
239 bool SelectAllMaterials();
240
241 //! @}
242
243 // Select the faces to be shown
244 // Select the object to be displayed (original or optimised)
245 // void ShowSelectedFaces(bool hideFrozenFaces);
246 bool PrepareDisplayedObject(bool getOptimizedObject);
247
248 void SetProgressiveThreshold(double threshold);
249 double GetProgressiveThreshold() const;
250
251 //! @name Get information about the object (original and optimised)
252 //! @{
253 int GetInitialRemovablePointsNumber() const;
254 int GetInitialRemovableFacesNumber() const;
255 int GetRemovedFacesNumber() const;
256 int GetRemovedPointsNumber() const;
257
258 //! @}
259
260 int Optimize(double ratio, bool& userCancel, unsigned int ratioMode = OPTIMIZE_TO_RATIO|OPTIMIZE_TO_FACE); //!< Optimize the object at the given ratio using MRRATIO_MODE
261 void InvalidateOptimization();
262
263 // Helper functions
264#ifdef MOOTOOLS_PRIVATE_DEBUG
265 void Dump() const;
266 void CostPointerChange(CContractionCost **NewPairCostPtr);
267#endif
268
269protected:
270 // Initialisation of the object
271 void CleanObject();
272 void InitObject();
273
274 // Select points and faces to be optimised
275 void SetSelectedFaces(C3DPointList &points, C3DFaceList &faces);
276 void SetSelectedPoints(C3DPointList &points, C3DFaceList& faces);
277
278 // Initialisation of the process : pairs computation
279 // Called each time the optimisation mode changed
280 bool CleanAndPrepareObject();
281 bool InitOptimization(bool minimalInitialization = true);
282 bool InitSelectionMode(C3DFaceList& faces, C3DPointList& points);
283 bool InitOptimizedFacesAndPoints();
284 void InitPointsQuadric(C3DFaceList *faces);
285 void InitConstraints(C3DFaceList *faces);
286 bool InitUVWFlags();
287 bool InitVCFlags();
288 bool InitNormalFlags();
289 bool InitSymetryMap();
290
291 void InitOrderedCostList();
292 void InsertCost(CContractionCost *cost, unsigned char order);
293
294
295#ifdef PLY_ALPHA_FEATURE
296#ifdef PLY_STRENGTH
298
299 bool SetStrength(OPTIMIZE_STRENGTH_TYPE type, float powerStrength); // power is a value > 0.0f, 1.0f is default
300 float GetStrength(OPTIMIZE_STRENGTH_TYPE type); // power is a value > 0.0f, 1.0f is default
301#endif
302
303#ifdef PLY_PERVERTEX
304 // Confused vertex map
305 unsigned int duplicatedPoints;
306 int duplicatedIndex;
310
311 bool InitPerVertexMap();
312#endif
313
314#ifdef PLY_WEIGHT
315 bool InitWeightMap();
316 bool ContainWeightInfo() const;
317#endif
318
319#ifdef PLY_FLIP_EDGES
320 bool FlipEdge(CGeomInfo& info, C3DEdge& edge, const int *connectedFaces, bool track);
321 unsigned int FlipEdges(unsigned int index);
322 unsigned int FlipEdges(CGeomInfo& info);
323#endif
324
325#ifdef PLY_COMPARE_METHOD
326// void ComputePlanarAreaPairCost(CExtPointList& points, C3DFaceList& faces, CInitialCost *cost);
327// void ComputePlanarLengthPairCost(CExtPointList& points, C3DFaceList& faces, CInitialCost *cost);
328// void ComputeNewPairCost(CExtPointList& points, C3DFaceList& faces, CInitialCost *cost);
329
330 int GetMethod() const;
331 unsigned int ReplaceStandardPointInFaceList(unsigned int replacedindex, unsigned int newindex, CContractionCost *cost);
332 void ComputeStandardPairCost(CExtPointList& points, C3DFaceList& faces, CInitialCost *cost);
335#endif
336#endif
337
338 double ComputePointCost(CSymMatrix& matrix, const C3DPoint& point);
339 MOVE_FACTOR GetPointMoveFactor(const C3DPoint *point, int index, bool& online);
340 CONTRACTION_PRIORITY VerifyPairQuality(CExtPointList& points, C3DFaceList& faces, CContractionCost *contration, int remainingindex, int removedindex, const C3DPoint& pos);
341 bool FindBestPosOnLine(const CSymMatrix& matrix, const C3DExtPoint& pt1, const C3DExtPoint& pt2, CInitialCost *factor);
342 bool InverseExist(const CSymMatrix& refmatrix, C3DPoint& point);
343 void ComputePairCost(CExtPointList& points, C3DFaceList& faces, CInitialCost *cost);
344 unsigned int ReplacePointInFaceList(unsigned int replacedindex, unsigned int newindex, CContractionCost * const cost);
345};
346
347#ifndef MOOTOOLS_NO_INLINE
348inline CExtPointList *C3DExtObject::GetPointList() const
349{
350 return (CExtPointList*)points;
351}
352#endif
353
354END_MOOTOOLS_NAMESPACE
355
356#endif // !defined(AFX_3DExtObject_H__BB3D80E9_003C_11D2_A0E3_000000000000__INCLUDED_)
C3DExtPoint class is used internally by C3DExtObject during optimization computation.
The file contains C3DObject class definition which handles N-Gons polygonal object.
OPTIMIZE_MODE
Definition PolygonCruncherType.h:53
C3DEdge is a class containing 2 point indexes that represent the edge of a face.
Definition FaceList.h:72
This class handles static optimization of an object.
Definition 3DExtObject.h:66
int Optimize(double ratio, bool &userCancel, unsigned int ratioMode=OPTIMIZE_TO_RATIO|OPTIMIZE_TO_FACE)
Optimize the object at the given ratio using MRRATIO_MODE.
longuint GetOptimizeExtMode()
Returns the optimization mode which is a combination of OPTIMIZE_EXTMODE flags.
bool SetOptimizeExtMode(longuint extmode, bool cleanNotNeedParameters)
Set optimization mode has a combination of OPTIMIZE_EXTMODE flags.
virtual void SetPointList(C3DPointList *, bool deletePrevious=true)
Set the object point list and delete existing one, unless deletePrevious = false.
longuint GetOptimizeMode()
Returns the optimization mode which is a combination of OPTIMIZE_MODE flags.
virtual void SetFaceList(C3DFaceList *, bool deletePrevious=true)
Set the object face list and delete existing one, unless deletePrevious = false.
virtual void SetChannels(CDependentChannels *, bool deletePrevious=true)
Set the object channellist and delete existing one, unless deletePrevious = false.
void LockInitialization()
A good pratice is to lock and unlock initialization before changing one or several OPTIMIZE_MODE....
bool SetOptimizeMode(OPTIMIZE_MODE newflag, bool set)
Set one OPTIMIZE_MODE flag.
bool SetOptimizeMode(longuint mode, bool cleanNotNeedParameters)
Set optimization mode has a combination of OPTIMIZE_MODE flags.
C3DFaceList class which implement a list of C3DFace. Each face contains indexes to 3D points stored i...
Definition 3DFaceList.h:249
C3DPointList * GetPointList()
Get the object point list.
C3DObject handles polygonal mesh.
Definition 3DObject.h:24
Definition 3DPointList.h:267
Definition 3DPointList.h:227
A node matches one element that is part of the C3DScene graph. It references a C3DBaseObject and has ...
Definition 3DSceneNode.h:64
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
This class contains an array of CChannel information which are associated to the object.
Definition DependentChannels.h:56
This class allows to increase performance on repetitive calls to specific CFaceList methods.
Definition FaceList.h:94
CGeomInfo is an helper class oftenly required by different methods.
Definition GeomInfo.h:71
CMultiresolutionObject1 is a the multiresolution object class computed from C3DSceneOptimizer::GetSce...
Definition MultiresolutionObject.h:102
CMultiresolutionObject is the base class for multiresolution object. There is two kind of multiresolu...
Definition MultiresolutionObject.h:33
CSceneOptimizer is the main entry to optimize a scene. There are various optimization modes and which...
Definition SceneOptimizer.h:147