#ifndef __GEO_TREE_SIMPLIFIER__ #define __GEO_TREE_SIMPLIFIER__ #include "GeoMesh.h" #include "GeoTreeSimpSequence.h" #define K1 0.8f //distance factor #define K2 0.2f //coplanar factor class LeafOctree; class Leaf; namespace Geometry { /// Tree Simplifier interface /*** This module is used by LODTree to simplify leaves of a tree. It contains functions that generate simplified versions of 3D objects made out of quads (represented as pairs of texture-mapped triangles). Given a 3D object, this module computes a sequence of geometric transformations that reduce the object’s geometric detail while preserving its appearance.\n\n For each simplification step, the module returns a simplification sequence containing the leaf collapsed, the two leaves being removed, and the resulting leaf for that contraction.\n\n Inputs:\n - A pointer to the Geometry::Mesh object containing the tree to be simplified. . Outputs:\n -# The simplified mesh, contained in a Geometry::Mesh object. -# Simplification sequence, represented by a Geometry::TreeSimplificationSequence object. */ class TreeSimplifier { public: /// Class constructor. Retrieves a pointer to a valid Mesh object to simplify TreeSimplifier(const Geometry::Mesh *, Geometry::TIPOFUNC upb=0); /// Class destructor. ~TreeSimplifier(void); /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. void Simplify(Geometry::Real,Geometry::Index); /// Returns the simplified mesh. Mesh *GetMesh(); /// Returns the simplification sequence for leaves. TreeSimplificationSequence *GetSimplificationSequence(); private: void CalculateLeafCenter(Leaf &); void CalculateLeafNormal(Leaf &); float CalculateLeafArea(Leaf &) const; void CoplanarBetweenLeaves(void); float BoundingSphereDiameter() const; // void SetCriteria(float); // to be erased: obsolete! void SetCriteriaOptimized(float); float max(float, float) const; float min(float, float) const; long int Collapse(float); void TwoGreater(float*, int* ); void ChooseVertices(Leaf& , Leaf& , long int); float HausdorffOptimized(const Leaf &, const Leaf&) const; float DistanceFromCenters(const Leaf &, const Leaf &) const; float distan(float, float, float, float, float, float) const; long int MinDistance(void); void NormalizeDistance(float diametro); // void SetCriteria2(float, long int); obsolete! void SetCriteria2Optimized(float, long int); long int MinCriteria(void); void Mesh2Structure(const Geometry::Mesh *,Index); void BuildOutputMesh(int); void CrossProduct(const float *v1, const float *v2, float *res) const; float SquaredModule(const float *v) const; Mesh *mesh; // simplified mesh object (for output) const Mesh *objmesh; float (*Vertex)[3]; Leaf *Leaves; long int activeLeaves, countLeaves; TreeSimplificationSequence *mtreesimpsequence; // Update progress bar. Geometry::TIPOFUNC mUPB; // the octree used to speed up the simplification process LeafOctree *octree; void RecursiveCreateLeafOctree(LeafOctree*, int deep); // this is called from CreateLeafNode void RecursiveFillOctreeWithLeaves(LeafOctree*); LeafOctree* CreateLeafOctree(int deep); // generates a new leaf octree and returns its root node size_t vertex_count; LeafOctree ** octree_owning_leaf; LeafOctree *GetMinOctreeNodeForLeaf(LeafOctree *start, const Leaf &leaf); bool PruneOctree(LeafOctree *); // erases one octree level and translates its leaves to the parent. Returns true if the node itself was pruned }; } #endif