[774] | 1 | #ifndef __GEO_TREE_SIMPLIFIER__
|
---|
| 2 | #define __GEO_TREE_SIMPLIFIER__
|
---|
| 3 |
|
---|
| 4 | #include "GeoMesh.h"
|
---|
| 5 | #include "GeoTreeSimpSequence.h"
|
---|
| 6 |
|
---|
[1007] | 7 | #define K1 0.8f //distance factor
|
---|
| 8 | #define K2 0.2f //coplanar factor
|
---|
[774] | 9 |
|
---|
[1007] | 10 | class LeafOctree;
|
---|
[1019] | 11 | class Leaf;
|
---|
[1007] | 12 |
|
---|
[774] | 13 | namespace Geometry
|
---|
| 14 | {
|
---|
| 15 | /// Tree Simplifier interface
|
---|
| 16 | /*** This module is used by LODTree to simplify leaves of a tree. It contains functions that generate simplified
|
---|
| 17 | versions of 3D objects made out of quads (represented as pairs of texture-mapped triangles). Given a 3D object, this
|
---|
| 18 | module computes a sequence of geometric transformations that reduce the objects geometric detail while preserving
|
---|
| 19 | its appearance.\n\n
|
---|
| 20 |
|
---|
| 21 | For each simplification step, the module returns a simplification sequence containing the leaf collapsed, the two
|
---|
| 22 | leaves being removed, and the resulting leaf for that contraction.\n\n
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | Inputs:\n
|
---|
| 26 | - A pointer to the Geometry::Mesh object containing the tree to be simplified.
|
---|
| 27 | .
|
---|
| 28 |
|
---|
| 29 | Outputs:\n
|
---|
| 30 | -# The simplified mesh, contained in a Geometry::Mesh object.
|
---|
| 31 | -# Simplification sequence, represented by a Geometry::TreeSimplificationSequence object.
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | class TreeSimplifier
|
---|
| 35 | {
|
---|
| 36 | public:
|
---|
| 37 | /// Class constructor. Retrieves a pointer to a valid Mesh object to simplify
|
---|
[1007] | 38 | TreeSimplifier(const Geometry::Mesh *, Geometry::TIPOFUNC upb=0);
|
---|
[774] | 39 |
|
---|
| 40 | /// Class destructor.
|
---|
| 41 | ~TreeSimplifier(void);
|
---|
| 42 |
|
---|
| 43 | /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1].
|
---|
| 44 | void Simplify(Geometry::Real,Geometry::Index);
|
---|
| 45 |
|
---|
| 46 | /// Returns the simplified mesh.
|
---|
| 47 | Mesh *GetMesh();
|
---|
| 48 |
|
---|
| 49 | /// Returns the simplification sequence for leaves.
|
---|
| 50 | TreeSimplificationSequence *GetSimplificationSequence();
|
---|
| 51 |
|
---|
[1007] | 52 | private:
|
---|
[1019] | 53 | void CalculateLeafCenter(Leaf &);
|
---|
| 54 | void CalculateLeafNormal(Leaf &);
|
---|
| 55 | float CalculateLeafArea(Leaf &) const;
|
---|
[1007] | 56 | void CoplanarBetweenLeaves(void);
|
---|
| 57 | float BoundingSphereDiameter() const;
|
---|
| 58 | // void SetCriteria(float); // to be erased: obsolete!
|
---|
| 59 | void SetCriteriaOptimized(float);
|
---|
[774] | 60 |
|
---|
[1007] | 61 | float max(float, float) const;
|
---|
| 62 | float min(float, float) const;
|
---|
[774] | 63 |
|
---|
[1007] | 64 | long int Collapse(float);
|
---|
| 65 | void TwoGreater(float*, int* );
|
---|
[1019] | 66 | void ChooseVertices(Leaf& , Leaf& , long int);
|
---|
| 67 | float HausdorffOptimized(const Leaf &, const Leaf&) const;
|
---|
| 68 | float DistanceFromCenters(const Leaf &, const Leaf &) const;
|
---|
[1007] | 69 | float distan(float, float, float, float, float, float) const;
|
---|
| 70 | long int MinDistance(void);
|
---|
| 71 | void NormalizeDistance(float diametro);
|
---|
| 72 | // void SetCriteria2(float, long int); obsolete!
|
---|
| 73 | void SetCriteria2Optimized(float, long int);
|
---|
| 74 | long int MinCriteria(void);
|
---|
[774] | 75 |
|
---|
[1007] | 76 | void Mesh2Structure(const Geometry::Mesh *,Index);
|
---|
| 77 | void BuildOutputMesh(int);
|
---|
| 78 | void CrossProduct(const float *v1, const float *v2, float *res) const;
|
---|
| 79 | float SquaredModule(const float *v) const;
|
---|
[774] | 80 |
|
---|
[1007] | 81 | Mesh *mesh; // simplified mesh object (for output)
|
---|
[774] | 82 | const Mesh *objmesh;
|
---|
| 83 | float (*Vertex)[3];
|
---|
[1019] | 84 | Leaf *Leaves;
|
---|
[1007] | 85 | long int activeLeaves, countLeaves;
|
---|
[774] | 86 | TreeSimplificationSequence *mtreesimpsequence;
|
---|
| 87 |
|
---|
| 88 | // Update progress bar.
|
---|
| 89 | Geometry::TIPOFUNC mUPB;
|
---|
[1007] | 90 |
|
---|
| 91 | // the octree used to speed up the simplification process
|
---|
| 92 | LeafOctree *octree;
|
---|
| 93 | void RecursiveCreateLeafOctree(LeafOctree*, int deep); // this is called from CreateLeafNode
|
---|
| 94 | void RecursiveFillOctreeWithLeaves(LeafOctree*);
|
---|
| 95 | LeafOctree* CreateLeafOctree(int deep); // generates a new leaf octree and returns its root node
|
---|
[1070] | 96 | size_t vertex_count;
|
---|
[1007] | 97 | LeafOctree ** octree_owning_leaf;
|
---|
[1019] | 98 | LeafOctree *GetMinOctreeNodeForLeaf(LeafOctree *start, const Leaf &leaf);
|
---|
[1007] | 99 | bool PruneOctree(LeafOctree *); // erases one octree level and translates its leaves to the parent. Returns true if the node itself was pruned
|
---|
[774] | 100 | };
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | #endif
|
---|