#ifndef __GEO_MESH_SIMPLIFIER__ #define __GEO_MESH_SIMPLIFIER__ #include #include #include "GeoMesh.h" #include "GeoMeshSimpSequence.h" #include "vmi_simplifier.h" #include "change.h" //#include "SimplificationMethod.h" using namespace Geometry; namespace Geometry { //----------------------------------------------------------------------- // Class for join triangle holes. //----------------------------------------------------------------------- class _coord_ { public: float x,y,z; inline _coord_( float x = 0.0f, float y = 0.0f, float z = 0.0f) { this->x = x; this->y = y; this->z = z; } inline _coord_(const _coord_ &f) { x = f.x; y=f.y; z=f.z; } inline _coord_ & operator=(const _coord_ &f) { x = f.x; y = f.y; z = f.z; return *this; } inline bool operator<(const _coord_ &f) const { if (xf.x+0.0001) return false; if (yf.y+0.0001) return false; if (zf.z+0.0001) return false; return false; } }; //----------------------------------------------------------------------- // Class tha implements a double-linked map. //----------------------------------------------------------------------- class EdgesMultimap { private: multimap edges; public: EdgesMultimap(); ~EdgesMultimap(); void insert(int v1,int v2); void remove(int v1,int v2); void contract(int v1,int v2); bool exists(int v1,int v2); }; //----------------------------------------------------------------------- // Class that conserves textures adding new vertices to mesh. //----------------------------------------------------------------------- class TextureConserver { private: EdgesMultimap *mEdges; Mesh *mGeoMesh; public: multimap mVertices; TextureConserver(); ~TextureConserver(); void JoinVertices(Mesh *mesh); Mesh *GetMesh(); }; /// Mesh simplificator interface. /** This module is used by both models, general mesh models and the plant and tree models for the trunk and the branches. It contains functions that generate simplified versions of 3D objects made out of triangles. Given a 3D object, this module computes a sequence of geometric transformations that reduce the object’s geometric detail while preserving its appearance. For each simplification step, returns a simplification sequence containing the edge to be collapse, the two triangles being removed and the new triangles remapped to the model.\n\n Inputs:\n - A pointer to the Geometry::Mesh object containing the 3D model to be simplified. . Outputs:\n -# The simplified mesh, contained in a Geometry::Mesh object. -# Simplification sequence, represented by a Geometry::MeshSimplificationSequence object. */ class MeshSimplifier { public: /// Class constructor. Retrieves a pointer to a valid Geometry::Mesh object to simplify. MeshSimplifier( const Geometry::Mesh *, Geometry::TIPOFUNC upb=0); /// Virtual class destructor. virtual ~MeshSimplifier (void); /// Copy constructor //MeshSimplifier(const MeshSimplifier&); /// Assignment operator //MeshSimplifier& operator =(const MeshSimplifier&); /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm. virtual void Simplify(Geometry::Real)=0; /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. This is a pure virtual method and must be overloaded in a derived class that implements a simplification algorithm. virtual void Simplify(Geometry::uint32)=0; /// Returns the simplified mesh. Mesh *GetMesh(); /// Returns the simplification sequence for general meshes. MeshSimplificationSequence *GetSimplificationSequence(); // Sets what is the mesh that stores the leaves void setMeshLeaves(Geometry::Index); protected: //private: // fer protected Mesh *mGeoMesh; Mesh *mInitialMesh; MeshSimplificationSequence *msimpsequence; const Mesh *objmesh; Geometry::Index indexMeshLeaves; // Progress bar function. Geometry::TIPOFUNC mUPB; // Sort mesh bones. void sortBones(); }; /// Implementation of a simplification algorithm based on viewpoint. /** This class implements a simplification algorithm based on a viewpoint evaluation technique. */ class ViewPointDrivenSimplifier : public MeshSimplifier { private: // Vectors of positions, normals and texture coordinates. vector vPositions; vector vNormals; vector vTexCoords; // Auxiliar vertex buffer. Geometry::VertexBuffer *mVB; // Set of indices. map mIndexMap; // Join and split vertices to matain texture aspect. TextureConserver *mTexConserver; // Loads a vmi mesh with a given geometry mesh. VMI::Mesh * initMeshStructure(Geometry::Mesh *geoMesh); // Loads a geometry mesh with a given vmi mesh. void loadMesh(); // Find vertex in auxiliar vertex buffer. void findVertex(size_t submesh, size_t index); // Gets the VMI mesh simplification sequence. void GetMeshSimpSequence(); // Fill up vectors of positions, normals and texture coordinates. void fillUpPosNorTC(Mesh *geoMesh); // Reassigns bones. void bonesReassignament(); public: /// Class constructor. Will call Simplifier class constructor. ViewPointDrivenSimplifier( const Geometry::Mesh *geoMesh, Geometry::TIPOFUNC upb=0); /// Class destructor. ~ViewPointDrivenSimplifier(void); /// Copy constructor //ViewPointDrivenSimplifier(const ViewPointDrivenSimplifier&); /// Assignment operator //ViewPointDrivenSimplifier& operator =(const ViewPointDrivenSimplifier&); /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. void Simplify(Geometry::Real); /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. void Simplify(Geometry::uint32); // Returns the simplified mesh. //Mesh *GetMesh(); }; /// Implementation of a simplification algorithm based on geometry information. /** This class implements a simplification algorithm based on a classic geometry evaluation technique. */ class GeometryBasedSimplifier : public MeshSimplifier { public: /// Class constructor. Will call Simplifier class constructor. GeometryBasedSimplifier( const Geometry::Mesh *geoMesh, Geometry::TIPOFUNC upb=0); /// Class destructor. ~GeometryBasedSimplifier(void); /// Copy constructor //GeometryBasedSimplifier(const GeometryBasedSimplifier&); /// Assignment operator //GeometryBasedSimplifier& operator =(const GeometryBasedSimplifier&); /// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1]. Implements the Simplifier::Simplify method to perform an image based simplification. void Simplify(Geometry::Real); /// Starts the simplification process. Receives as a parameter the number of vertices of the resulting mesh. Implements the Simplifier::Simplify method to perform an image based simplification. void Simplify(Geometry::uint32); }; } // end of Geometry namespace; #endif