- Timestamp:
- 09/28/06 17:49:37 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared
- Files:
-
- 17 added
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/GTGeometry.vcproj
r1090 r1526 20 20 Name="VCCLCompilerTool" 21 21 Optimization="0" 22 AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include "22 AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include;.\src\libs\ntl" 23 23 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;GLEW_STATIC" 24 24 MinimalRebuild="TRUE" … … 63 63 Name="VCCLCompilerTool" 64 64 Optimization="2" 65 AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include "65 AdditionalIncludeDirectories=".\src\libs;.\include;.\src\libs\vmi\include;.\src\libs\ntl" 66 66 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GLEW_STATIC" 67 67 MinimalRebuild="TRUE" … … 324 324 <File 325 325 RelativePath=".\src\libs\vmi\src\simplify.cpp"> 326 </File> 327 </Filter> 328 <Filter 329 Name="ntl" 330 Filter=""> 331 <File 332 RelativePath=".\src\libs\ntl\Cont.cpp"> 326 333 </File> 327 334 </Filter> -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoBase.h
r1070 r1526 15 15 { 16 16 // Basic types. 17 typedef float 18 typedef unsigned int 19 typedef int 20 typedef unsigned int 17 typedef float Real; 18 typedef unsigned int Index; 19 typedef int int32; 20 typedef unsigned int uint32; 21 21 typedef unsigned short uint16; 22 typedef std::string 22 typedef std::string String; 23 23 24 24 // Vertex Info. -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodManager.h
r1310 r1526 15 15 #include "GeoVector3.h" 16 16 #include "GeoLodObject.h" 17 #include <map>18 #include <vector>19 17 20 18 namespace Geometry 21 19 { 22 class lodobj_dist_node_t 23 { 24 public: 25 lodobj_dist_node_t(float dist, LodObject *o):dist2cam(dist),lodobj(o){ must_recalculate_distance=false; } 26 float dist2cam; 27 LodObject *lodobj; 28 bool must_recalculate_distance; 29 bool operator < (const lodobj_dist_node_t &o) const { return (dist2cam < o.dist2cam); } 30 }; 20 class NodeContainer; 21 class lodobj_node_t; 31 22 32 23 class LodManager 33 24 { 34 25 public: 35 LodManager(float near, float far, const Geometry::Vector3 &campos); 36 void AddLodObj(LodObject*, const Geometry::Vector3 &); 37 void UpdateLOD(void); 26 LodManager(Real near, Real far, const Geometry::Vector3 &campos, int numslots=10); 27 ~LodManager(void); 28 void AddLodObj(const std::string &name, LodObject*, const Geometry::Vector3 &); 29 void UpdateLOD(uint32 currFPS, uint32 targetFPS=30); 38 30 void UpdateCamera(const Geometry::Vector3 &); 39 31 void UpdateLODObjectPos(LodObject*,const Geometry::Vector3 &); 32 33 bool always_calculate_lod; // if true, there is no instant LOD changing 34 bool force_highest_lod; // if set to true, all objects will be set to their highest level of detail 35 40 36 private: 41 std::vector<lodobj_dist_node_t> lodobj_dists; // key: dist2cam for efficient distance finding 42 std::map<uint32,Geometry::Vector3> lodobj_pos; // map key: LodObject UniqueID for efficient ID-based finding 43 unsigned int targetFPS; 44 Vector3 camera_pos; 45 bool camera_changed; 37 NodeContainer *lodobj_container; 38 uint32 lasttime; 39 bool camera_changed, node_added; 46 40 float near_range, far_range; 47 float CalculateDistToCamera(const Geometry::Vector3 &) const;48 41 float SelectRandomDistance(void) const; 49 void RecalculateDist(lodobj_dist_node_t & node); 42 void ChangeLOD(lodobj_node_t*,Real); 43 void ReallyGoToLOD(lodobj_node_t*,Real); 44 45 lodobj_node_t * FindMostSimilarRealLOD(const std::string &, Real desired_lod); 46 47 void MakeDiscipleOf(lodobj_node_t *master, lodobj_node_t *disciple); 48 void MakeIndependent(lodobj_node_t*); 49 void RemoveDiscipleFrom(LodObject *master, LodObject *disciple); 50 void UpdateDisciples(lodobj_node_t *master); 51 void DeleteMeFromMyMastersDiscipleList(lodobj_node_t *); 52 void ChangeMaster(lodobj_node_t *orig, lodobj_node_t *newmaster); 50 53 }; 51 } ;54 } 52 55 53 56 #endif -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodObject.h
r1058 r1526 4 4 namespace Geometry 5 5 { 6 class IndexData; 7 6 8 class LodObject 7 9 { … … 13 15 uint32 GetUniqueID(void) const { return uniqueID; } 14 16 virtual void GoToLod(Real)=0; 17 virtual Real GetCurrentLodFactor(void) const =0; 18 virtual Geometry::IndexData * GetIndexDataInterface(void)=0; 15 19 16 20 private: -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsConstructor.h
r1078 r1526 124 124 // Sort submesh bones. 125 125 void sortBones(); 126 126 127 // Add new vertices to mesh. 128 void AddNewVertices(); 129 127 130 public: 128 131 -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsLibrary.h
r1090 r1526 34 34 typedef struct 35 35 { 36 unsigned long strip; 37 char position; 38 char vertexRepetition; 39 char edgeRepetition; 36 unsigned long strip; // change this to uint32 37 char position; 38 char vertexRepetition; 39 char edgeRepetition; 40 char obligatory; 40 41 } LODRegisterType; 41 42 42 43 typedef struct 43 44 { 44 float 45 float Vertex[3]; 45 46 SmallInt Next; 46 47 } VertexType; … … 130 131 131 132 // Copa STL vectors to C arrays. 132 void CopyVectors2Arrays( );133 void CopyVectors2Arrays(void); 133 134 134 135 // Loads Mesh. 135 136 void LoadStripMesh(const LodStripsLibraryData *, Mesh *geomesh); 136 137 137 Geometry::CREATEINDEXDATAFUNC create_index_data_func;138 // Geometry::CREATEINDEXDATAFUNC create_index_data_func; 138 139 139 140 // Strips vector. … … 146 147 //Number of strips in each submesh 147 148 int* mStripsSubmesh; 149 bool delete_indexdata; 150 int *submesh_x_strip; 151 Real lodFactor; 152 IndexData *dataRetrievalInterface; 153 uint32 current_triangle_count; 148 154 149 155 public: 150 156 151 IndexData * dataRetrievalInterface;157 IndexData *GetIndexDataInterface(void){ return dataRetrievalInterface; } 152 158 153 159 /** Constructor, receives as a parameter the name of the file 154 160 * including the multiresolution object. 155 161 */ 156 LodStripsLibrary(const LodStripsLibraryData *, Mesh *geomesh, CREATEINDEXDATAFUNC idfun=NULL);162 LodStripsLibrary(const LodStripsLibraryData *, Mesh *geomesh, IndexData * userindexdata = NULL); 157 163 158 164 /// Destructor. … … 182 188 uint32 GetTotalStripCount(void) const { return mTotalStrips; } 183 189 uint32 GetSubMeshtripCount(int submeshid) const { return mStripsSubmesh[submeshid]; } 190 uint32 GetCurrentTriangleCount(void) const { return current_triangle_count; } 191 192 virtual Real GetCurrentLodFactor(void) const { return lodFactor; } 184 193 }; 185 194 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h
r1090 r1526 20 20 { 21 21 public: 22 /* LodTreeLibrary( const LodTreeLibrary &);23 LodTreeLibrary(LodTreeLibrary*);*/24 22 LodTreeLibrary( const LodStripsLibraryData *, 25 23 const TreeSimplificationSequence *, 26 Geometry::Mesh *treeGeoMesh/*, 27 uint32 leafSubMeshID 28 /*std::string foliage_verts, 29 std::string foliage_leafs, 30 std::string foliage_simpl/*, 31 uint32 leafSubMeshID, 32 CREATEVERTEXDATAFUNC vdfun=NULL, 33 CREATEINDEXDATAFUNC idfun=NULL, 34 CREATEMULTIINDEXDATAFUNC midfun=NULL*/); // throws a FileNotFound exception 24 Geometry::Mesh *treeGeoMesh, 25 Geometry::IndexData *user_indexdata); 35 26 ~LodTreeLibrary(void); 36 27 … … 48 39 // changes the lod of the entire object (trunk and leaves) 49 40 virtual void GoToLod(Real); 41 virtual Real GetCurrentLodFactor(void) const { return (currentFoliageLodFactor+trunk->GetCurrentLodFactor())*0.5f; } 42 virtual Geometry::IndexData * GetIndexDataInterface(void){ return dataRetrievalInterface; } 50 43 51 44 // new proposed functions … … 71 64 Geometry::LodStripsLibrary *trunk; 72 65 uint32 mLeavesSubMesh; 66 IndexData *dataRetrievalInterface; 67 bool delete_indexdata; 68 float currentFoliageLodFactor; 73 69 }; 74 70 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshSimpSequence.h
r1007 r1526 28 28 \n 29 29 */ 30 31 // Vertex info. 32 struct GeoVertex 33 { 34 Index id; 35 Index bonefrom; 36 Vector3 position; 37 Vector2 texcoord; 38 Vector3 normal; 39 }; 30 40 31 41 class MeshSimplificationSequence: public Serializable … … 60 70 // Indicates the the step is obligatory to execute 61 71 // joined width the following step. 62 unsigned int obligator io;72 unsigned int obligatory; 63 73 }; 74 75 // Vertices added in simplification. 76 std::vector<GeoVertex> mNewVertices; 64 77 65 78 // Name of mesh. -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/VertexData.h
r1325 r1526 4 4 namespace Geometry 5 5 { 6 class VertexData7 {8 private:9 unsigned int numverts;10 public:11 VertexData(unsigned int numv):numverts(numv){}12 virtual ~VertexData(void){}13 14 virtual void Begin(void)=0;15 virtual void SetVertexCoord(unsigned int i, float x, float y, float z)=0;16 virtual void SetVertexNormal(unsigned int i, float x, float y, float z)=0;17 virtual void SetVertexTexCoord(unsigned int i, float x, float y)=0;18 virtual void End(void)=0;19 20 virtual void GetVertexCoord(unsigned int i, float &x, float &y, float &z) const = 0;21 virtual void GetVertexNormal(unsigned int i, float &x, float &y, float &z) const = 0;22 virtual void GetVertexTexCoord(unsigned int i, float &x, float &y) const =0;23 24 unsigned int GetNumVertices(void) const { return numverts; }25 };26 27 6 class IndexData 28 7 { 29 8 private: 30 unsigned int numinds, numvalidinds;31 unsigned int current_submesh;32 9 public: 33 IndexData( unsigned int numi):numinds(numi),numvalidinds(numi){ current_submesh=0;}10 IndexData(void){} 34 11 virtual ~IndexData(void){} 35 12 36 virtual void Begin( void)=0;13 virtual void Begin(unsigned int submesh, unsigned int numinds)=0; 37 14 virtual void SetIndex(unsigned int i, unsigned int index)=0; 38 15 virtual void End(void)=0; 39 16 40 virtual unsigned int GetIndex(unsigned int) const =0; 41 unsigned int GetNumMaxIndices(void) const { return numinds; } 42 unsigned int GetNumValidIndices(void) const { return numvalidinds; } 43 void SetNumValidIndices(unsigned int valid){ numvalidinds=valid; } // this should not be called from client applications 44 void SetCurrentSubmesh(unsigned int c){ current_submesh=c; } // this should not be called from client applications 45 unsigned int GetCurrentSubmesh(void) const { return current_submesh; } 17 virtual void BorrowIndexData(const IndexData *)=0; // tells the application to use this IndexData. If the app must use its own IndexData the param will be NULL 46 18 }; 47 19 48 /* class MultiIndexData49 {50 private:51 unsigned int num_prims, num_total_inds, *num_max_inds, *num_valid_inds;52 public:53 MultiIndexData(unsigned int numprims, unsigned int *maxinds){54 num_prims=numprims;55 num_total_inds=0;56 num_max_inds=new unsigned int[numprims];57 num_valid_inds=new unsigned int[numprims];58 for (unsigned int i=0; i<numprims; i++)59 {60 num_max_inds[i]=num_valid_inds[i]=maxinds[i];61 num_total_inds += maxinds[i];62 }63 }64 20 65 ~MultiIndexData(void){ 66 delete[] num_max_inds; 67 delete[] num_valid_inds; 68 } 69 70 virtual void Begin(void)=0; 71 virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index)=0; 72 virtual void End(void)=0; 73 74 virtual unsigned int GetIndex(unsigned int iprim, unsigned int index) const =0; 75 unsigned int GetNumMaxIndices(unsigned int iprim) const { return num_max_inds[iprim]; } 76 unsigned int GetNumValidIndices(unsigned int iprim) const { return num_valid_inds[iprim]; } 77 void SetNumValidIndices(unsigned int iprim, unsigned int valid){ num_valid_inds[iprim]=valid; } 78 unsigned int GetNumPrims(void) const { return num_prims; } 79 };*/ 80 81 typedef VertexData* CreateVertexDataFunc(unsigned int numv); 82 typedef CreateVertexDataFunc* CREATEVERTEXDATAFUNC; 83 typedef IndexData* CreateIndexDataFunc(unsigned int numi); 21 /* typedef IndexData* CreateIndexDataFunc(unsigned int numi); 84 22 typedef CreateIndexDataFunc* CREATEINDEXDATAFUNC; 85 /* typedef MultiIndexData* CreateMultiIndexDataFunc(unsigned int numprims, unsigned int *numi);86 typedef CreateMultiIndexDataFunc* CREATEMULTIINDEXDATAFUNC;*/87 88 class DefaultVertexData : public VertexData89 {90 private:91 float *v, *n, *t;92 public:93 DefaultVertexData(unsigned int numv);94 ~DefaultVertexData(void);95 96 virtual void Begin(void){}97 virtual void SetVertexCoord(unsigned int i, float x, float y, float z){98 v[i*3+0]=x; v[i*3+1]=y; v[i*3+2]=z; }99 virtual void SetVertexNormal(unsigned int i, float x, float y, float z){100 n[i*3+0]=x; n[i*3+1]=y; n[i*3+2]=z; }101 virtual void SetVertexTexCoord(unsigned int i, float x, float y){102 t[i*2+0]=x; t[i*2+1]=y; }103 104 virtual void End(void){}105 106 virtual void GetVertexCoord(unsigned int i, float &x, float &y, float &z) const {107 x=v[i*3+0];108 y=v[i*3+1];109 z=v[i*3+2];110 }111 virtual void GetVertexNormal(unsigned int i, float &x, float &y, float &z) const {x=n[i*3+0]; y=n[i*3+1]; z=n[i*3+2]; }112 virtual void GetVertexTexCoord(unsigned int i, float &x, float &y) const {x=t[i*2+0]; y=t[i*2+1]; }113 114 const float * GetVertexFloatBuffer(void) const { return v; }115 116 };117 VertexData *DefaultVertexDataCreator(unsigned int numv);118 119 23 120 24 class DefaultIndexData : public IndexData … … 123 27 unsigned int *indices; 124 28 public: 125 DefaultIndexData( unsigned int numi);29 DefaultIndexData(void){ indices=0; } 126 30 ~DefaultIndexData(void); 127 31 128 virtual void Begin(void){} 32 virtual void Init(unsigned int); 33 virtual void Begin(unsigned int submesh, unsigned int numinds){} 129 34 virtual void SetIndex(unsigned int i, unsigned int index){ 130 35 indices[i] = index; … … 135 40 return indices[i]; 136 41 } 137 42 virtual void BorrowIndexData(const IndexData *){} 138 43 }; 139 IndexData *DefaultIndexDataCreator(unsigned int numi); 140 141 /* class DefaultMultiIndexData : public MultiIndexData 142 { 143 private: 144 unsigned int **indices; 145 public: 146 DefaultMultiIndexData(unsigned int numprims, unsigned int *numi); 147 ~DefaultMultiIndexData(void); 148 149 virtual void Begin(void){} 150 virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index){ 151 indices[iprim][i] = index; 152 } 153 virtual void End(void){} 154 155 virtual unsigned int GetIndex(unsigned int iprim, unsigned int i) const { 156 return indices[iprim][i]; 157 } 158 159 }; 160 MultiIndexData *DefaultMultiIndexDataCreator(unsigned int numprims, unsigned int *numi); 161 */ 44 IndexData *DefaultIndexDataCreator(unsigned int numi);*/ 162 45 } 163 46 -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/auxiliar.h
r993 r1526 24 24 { 25 25 uint32 strip; 26 char 26 char nP,nL1,nL2,obligatory; 27 27 } LODData; 28 28 #pragma pack() … … 37 37 float Normal[3]; 38 38 float TexCoords[2]; 39 unsigned int obligator io;39 unsigned int obligatory; 40 40 int numMesh; 41 41 uint32 Next; … … 55 55 uint32 vLSNext; 56 56 uint32 vLS; 57 unsigned int obligator io;57 unsigned int obligatory; 58 58 float x; 59 59 char *cambio; -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/leaf.h
r1019 r1526 5 5 { 6 6 public : 7 int vertsLeaf[4]; // Array of pointers to vertices7 int vertsLeaf[4]; // the four indices of the leaf 8 8 float normal[3]; 9 9 float parentLeafCount; … … 30 30 Leaf (void); // default constructor 31 31 Leaf (const Leaf&); // Copy constructor 32 virtual ~Leaf (void); // Destructor32 // virtual ~Leaf (void); // Destructor 33 33 34 34 float Distance (Leaf&); … … 36 36 }; 37 37 38 // this class is used by the lodtreelibrary to represent a leaf 39 class RuntimeLeaf 40 { 41 public: 42 RuntimeLeaf(void); 43 RuntimeLeaf (const RuntimeLeaf&); // Copy constructor 44 45 int vertsLeaf[4]; // the four indices of the leaf 46 int childLeft; 47 int childRight; 48 int parent; 49 int root; 50 }; 51 38 52 #endif -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodManager.cpp
r1309 r1526 12 12 #include "GeoLodManager.h" 13 13 #include "GeoLodObject.h" 14 #include <algorithm> 15 /* 14 #include "VertexData.h" 15 #include <ntls.h> 16 #include <map> 17 18 using namespace Geometry; 19 20 //#define MINIMUM_VALID_LOD_SIMILARITY 0.1f 21 22 16 23 namespace Geometry 17 24 { 18 19 20 class lodobj_idpos_node_t 25 class lodobj_node_t : public Moveable<lodobj_node_t> 21 26 { 22 27 public: 23 lodobj_idpos_node_t(LodObject *o):lodobj(o),must_recalculate_distance(true),dist2cam(0.0f){} 28 lodobj_node_t(const std::string &nam, float dist, LodObject *o):dist2cam(dist),lodobj(o),name(nam){ must_recalculate_distance=false; to_update=0; master=NULL; lodfactor=o->GetCurrentLodFactor(); precalpos=-1; } 29 lodobj_node_t(const lodobj_node_t &n){ operator=(n); } 30 float dist2cam; 24 31 LodObject *lodobj; 25 float dist2cam; // used to index the lodobj in the other map 26 bool operator < (const lodobj_idpos_node_t &o) const { return (lodobj->GetUniqueID()<o.lodobj->GetUniqueID()); } 32 bool must_recalculate_distance; 33 uint32 to_update; 34 bool operator < (const lodobj_node_t &o) const { return (dist2cam < o.dist2cam); } 35 void operator = (const lodobj_node_t &n){ dist2cam=n.dist2cam; lodobj=n.lodobj; must_recalculate_distance=n.must_recalculate_distance; master=n.master; lodfactor=n.lodfactor; precalpos=-1; name=n.name; } 36 37 lodobj_node_t * master; 38 VectorMap<uint32,lodobj_node_t*> disciples; 39 float lodfactor; // virtual lod factor (the lodfactor it seems, not its real internal lodfactor) 40 int precalpos; 41 std::string name; 27 42 }; 28 }*/ 29 30 using namespace Geometry; 31 32 LodManager::LodManager(float near, float far, const Geometry::Vector3 &campos) 33 :targetFPS(30),camera_changed(true),camera_pos(campos), 34 near_range(near),far_range(far) 35 { 36 // make the lodobj_dists vector into a heap 37 make_heap(lodobj_dists.begin(),lodobj_dists.end()); 38 } 39 40 void Geometry::LodManager::AddLodObj(LodObject * o, const Geometry::Vector3 &p) 41 { 42 float dist = CalculateDistToCamera(p); 43 lodobj_dists.push_back(lodobj_dist_node_t(dist,o)); 44 push_heap(lodobj_dists.begin(),lodobj_dists.end()); 45 // lodobj_dists[dist] = lodobj_dist_node_t(o); 43 44 class NodeContainer 45 { 46 public: 47 Vector<lodobj_node_t> lodobj_dists; 48 std::map<uint32,Geometry::Vector3> lodobj_pos; // map key: LodObject UniqueID for efficient ID-based finding 49 Vector3 camera_pos; 50 51 int num_lod_sim; 52 53 NodeContainer(const Geometry::Vector3 &campos) 54 :camera_pos(campos){ 55 } 56 57 ~NodeContainer(void){ 58 for (VectorMap<std::string,lodobj_node_t**>::Iterator it = precalculated_lods.Begin(); 59 it != precalculated_lods.End(); it ++) 60 { 61 lodobj_node_t **nodes = *it; 62 delete[] nodes; 63 } 64 } 65 66 void RecalculateDist(lodobj_node_t & node){ 67 std::map<uint32,Vector3>::iterator posit = lodobj_pos.find(node.lodobj->GetUniqueID()); 68 assert(posit!=lodobj_pos.end()); 69 const Vector3 & pos = posit->second; 70 71 node.dist2cam = CalculateDistToCamera(pos); 72 } 73 74 float CalculateDistToCamera(const Geometry::Vector3 &p) const 75 { 76 Geometry::Vector3 v = camera_pos - p; 77 float distquad = v.length(); 78 return distquad; 79 } 80 81 lodobj_node_t * & GetPrecalculatedLOD(const std::string &name, int ipos){ 82 int foundpos = precalculated_lods.Find(name); 83 if (foundpos==-1) 84 { 85 lodobj_node_t **new_precalculated_lods=new lodobj_node_t*[num_lod_sim+1]; // +1 is done to include the highest lod (1.0) 86 for (int i=0; i<num_lod_sim+1; i++) 87 new_precalculated_lods[i]=NULL; 88 precalculated_lods.Add(name) = new_precalculated_lods; 89 return new_precalculated_lods[ipos]; 90 } 91 else 92 { 93 return precalculated_lods[foundpos][ipos]; 94 } 95 } 96 97 uint32 lod2precalpos(Real lodfactor){ 98 return (uint32)(num_lod_sim*lodfactor); 99 } 100 101 private: 102 // the following is an array of precalculated lods 103 // for 10 precalculated lods each element is in order [0.1, 0.2, 0.3, 0.4, 0.5, ...] 104 // for 100 precalculated lods each element is in order [0.01, 0.02, 0.03, 0.04, 0.05, ...] 105 // the funcion lod2precalpos translates a LOD factor to a position in the array 106 VectorMap<std::string,lodobj_node_t**> precalculated_lods; 107 108 }; 109 } 110 111 LodManager::LodManager(Real near, Real far, const Geometry::Vector3 &campos, int numslots) 112 :lasttime(0),camera_changed(true),node_added(false), 113 near_range(near),far_range(far), 114 always_calculate_lod(false),force_highest_lod(false) 115 { 116 lodobj_container=new NodeContainer(campos); 117 lodobj_container->num_lod_sim = numslots; 118 } 119 120 LodManager::~LodManager(void) 121 { 122 delete lodobj_container; 123 // delete[] precalculated_lods; 124 } 125 126 void Geometry::LodManager::AddLodObj(const std::string &name, LodObject * o, const Geometry::Vector3 &p) 127 { 128 float dist = lodobj_container->CalculateDistToCamera(p); 129 lodobj_node_t auxnode(name,dist,o); 130 131 lodobj_container->lodobj_dists.Add(auxnode); 132 Sort(lodobj_container->lodobj_dists); 133 46 134 UpdateLODObjectPos(o,p); 47 } 48 49 50 void Geometry::LodManager::UpdateLOD(void) 51 { 52 if (!lodobj_dists.empty()) 135 node_added=true; 136 } 137 138 139 void Geometry::LodManager::UpdateLOD(uint32 currFPS, uint32 targetFPS) 140 { 141 if (!lodobj_container->lodobj_dists.IsEmpty()) 53 142 { 54 143 // update distances to the camera 55 bool must_resort = false; 56 for (std::vector<lodobj_dist_node_t>::iterator it=lodobj_dists.begin(); it!=lodobj_dists.end(); it++) 57 { 58 lodobj_dist_node_t & node = *it; 59 if (camera_changed || node.must_recalculate_distance) 60 { 61 RecalculateDist(node); 62 must_resort=true; 63 } 64 } 65 if (must_resort) 66 sort_heap(lodobj_dists.begin(),lodobj_dists.end()); 67 68 // select a tree to change its LOD 69 // float random_dist = SelectRandomDistance(); 70 // std::map<float,Geometry::lodobj_dist_node_t>::iterator nearest = lodobj_dists.upper_bound(random_dist); 71 72 // the begining of the list is the greater element (greater dist) 73 lodobj_dist_node_t & node = lodobj_dists.front(); 144 if (camera_changed || node_added) 145 { 146 bool must_resort = false; 147 for (Vector<lodobj_node_t>::Iterator it=lodobj_container->lodobj_dists.Begin(); 148 it!=lodobj_container->lodobj_dists.End(); 149 it++) 150 { 151 lodobj_node_t & node = *it; 152 if (node.must_recalculate_distance || camera_changed || node_added) 153 { 154 lodobj_container->RecalculateDist(node); 155 must_resort=true; 156 } 157 } 158 /* if (must_resort) 159 Sort(lodobj_container->lodobj_dists);*/ 160 } 161 162 // the end of the list is the greater element (greater dist) 163 /* if (currFPS < targetFPS - 5) 164 { 165 Vector<lodobj_node_t>::Iterator selnode; 166 for (selnode=lodobj_container->lodobj_dists.End()-1; selnode!=lodobj_container->lodobj_dists.Begin()-1; selnode--) 167 { 168 // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 169 if (selnode->lodobj->GetCurrentLodFactor()>0.00001f) 170 { 171 if (selnode->to_update==0) 172 break; 173 else 174 selnode->to_update--; 175 } 176 } 177 178 if (selnode!=lodobj_container->lodobj_dists.Begin()-1) 179 { 180 // EL DECREMENTO O EL NUMERO DE DECREMENTOS TIENE QUE VENIR EN FUNCION DE LA DIFERENCIA DE FPS 181 // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 182 selnode->lodobj->GoToLod(selnode->lodobj->GetCurrentLodFactor()-0.02f); 183 selnode->to_update=10; // ESTO DEBE ASIGNARSE BASADO EN LA DISTANCIA A LA CAMARA! 184 } 185 } 186 if (currFPS > targetFPS + 5) 187 { 188 Vector<lodobj_node_t>::Iterator selnode; 189 for (selnode=lodobj_container->lodobj_dists.Begin(); selnode!=lodobj_container->lodobj_dists.End(); selnode++) 190 { 191 // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 192 if (selnode->lodobj->GetCurrentLodFactor()<0.99999f) 193 { 194 if (selnode->to_update==0) 195 break; 196 else 197 selnode->to_update--; 198 } 199 } 200 201 if (selnode!=lodobj_container->lodobj_dists.End()) 202 { 203 // NO HAY QUE USAR CURRENT LOD FACTOR SINO lodobj_container->lodobj_lodfactor 204 selnode->lodobj->GoToLod(selnode->lodobj->GetCurrentLodFactor()+0.02f); 205 selnode->to_update=10; // ESTO DEBE ASIGNARSE BASADO EN LA DISTANCIA A LA CAMARA! 206 } 207 }*/ 208 209 if (camera_changed) 210 { 211 // por ahora solo sacar el lod basado en la camara 212 for (Vector<lodobj_node_t>::Iterator it = lodobj_container->lodobj_dists.Begin(); 213 it != lodobj_container->lodobj_dists.End(); it ++) 214 { 215 float lodfactor = - ((it->dist2cam - near_range) / (far_range - near_range)); 216 if (lodfactor < 0.0f) 217 lodfactor = 0.0f; 218 if (lodfactor > 1.0f) 219 lodfactor = 1.0f; 220 221 if (force_highest_lod) 222 lodfactor = 1.0f; 223 224 ChangeLOD(it,lodfactor); 225 } 226 } 74 227 } 75 228 camera_changed=false; 76 } 77 78 void Geometry::LodManager::RecalculateDist(lodobj_dist_node_t & node) 79 { 80 std::map<uint32,Vector3>::iterator posit = lodobj_pos.find(node.lodobj->GetUniqueID()); 81 assert(posit!=lodobj_pos.end()); 82 const Vector3 & pos = posit->second; 83 84 node.dist2cam = CalculateDistToCamera(pos); 85 } 86 229 node_added=false; 230 } 231 232 void Geometry::LodManager::ChangeLOD(lodobj_node_t *lodobjnode, Real lodfactor) 233 { 234 LodObject *lodobj = lodobjnode->lodobj; 235 236 if (always_calculate_lod) 237 { 238 lodobj->GoToLod(lodfactor); 239 return; 240 } 241 242 // if the lodfactor is exactly 1.0 its level of detail must be always regenerated (for closeups) 243 if (lodfactor<1.0f) 244 { 245 // if the desired lod is very similar to the previous one, 246 // then there is no need to change the level of detail at all 247 // float sim = fabsf(lodfactor - lodobjnode->lodfactor); 248 // if (sim <= MINIMUM_VALID_LOD_SIMILARITY) 249 // return; // do not change anything if the lod is very similar! 250 int desiredpos = lodobj_container->lod2precalpos(lodfactor); 251 int mypos = lodobj_container->lod2precalpos(lodobjnode->lodfactor); 252 if (mypos==desiredpos) 253 return; 254 } 255 256 lodobj_node_t *found_node = FindMostSimilarRealLOD(lodobjnode->name,lodfactor); 257 258 if (found_node && found_node->lodobj->GetUniqueID()!=lodobj->GetUniqueID()) 259 { 260 // DEBUG 261 assert(found_node->master==NULL); 262 263 // float sim = fabsf(lodfactor - found_node->lodfactor); 264 // if (sim <= MINIMUM_VALID_LOD_SIMILARITY) 265 int desiredpos = lodobj_container->lod2precalpos(lodfactor); 266 int foundpos = lodobj_container->lod2precalpos(found_node->lodfactor); 267 if (foundpos==desiredpos) 268 { 269 lodobj->GetIndexDataInterface()->BorrowIndexData(found_node->lodobj->GetIndexDataInterface()); 270 MakeDiscipleOf(found_node,lodobjnode); 271 } 272 else 273 ReallyGoToLOD(lodobjnode,lodfactor); 274 } 275 else 276 ReallyGoToLOD(lodobjnode,lodfactor); 277 278 lodobjnode->lodfactor = lodfactor; 279 } 280 281 void Geometry::LodManager::DeleteMeFromMyMastersDiscipleList(lodobj_node_t *lodobjnode) 282 { 283 // if I have a master... 284 if (lodobjnode->master) 285 lodobjnode->master->disciples.RemoveKey(lodobjnode->lodobj->GetUniqueID()); 286 } 287 288 289 void Geometry::LodManager::MakeIndependent(lodobj_node_t *lodobjnode) 290 { 291 DeleteMeFromMyMastersDiscipleList(lodobjnode); 292 293 // next, delete my master 294 lodobjnode->master=NULL; 295 } 296 297 void Geometry::LodManager::MakeDiscipleOf(lodobj_node_t *master_node, lodobj_node_t *disciple_node) 298 { 299 ChangeMaster(disciple_node, master_node); 300 301 // delete my disciples 302 disciple_node->disciples.Clear(); 303 304 // first remove me from my master's disciple list 305 DeleteMeFromMyMastersDiscipleList(disciple_node); 306 307 master_node->disciples.GetAdd(disciple_node->lodobj->GetUniqueID()) = disciple_node; 308 309 // set master 310 disciple_node->master = master_node; 311 312 // no one must take me as a master! 313 if (disciple_node->precalpos!=-1) 314 { 315 // lodobj_container->precalculated_lods[disciple_node->precalpos] = NULL; 316 lodobj_container->GetPrecalculatedLOD(master_node->name,disciple_node->precalpos) = NULL; 317 disciple_node->precalpos = -1; 318 } 319 } 320 321 void Geometry::LodManager::ChangeMaster(lodobj_node_t *lodobj, lodobj_node_t *newmaster) 322 { 323 // delete me from my disciples' master list 324 for (VectorMap<uint32,lodobj_node_t*>::Iterator it = lodobj->disciples.Begin(); it != lodobj->disciples.End(); it++) 325 { 326 lodobj_node_t * auxnode = *it; 327 assert(auxnode->master->lodobj->GetUniqueID() == lodobj->lodobj->GetUniqueID()); 328 // auxnode->master = NULL; 329 // chanbge the master to the new one 330 auxnode->master = newmaster; 331 332 // add the new disciple to the new master 333 if (newmaster) 334 newmaster->disciples.GetAdd(auxnode->lodobj->GetUniqueID()) = auxnode; 335 } 336 } 337 338 339 void Geometry::LodManager::UpdateDisciples(lodobj_node_t *master_node) 340 { 341 for (VectorMap<uint32,lodobj_node_t*>::Iterator it= master_node->disciples.Begin(); it!= master_node->disciples.End(); it++) 342 { 343 lodobj_node_t *disciple_node = *it; 344 disciple_node->lodobj->GetIndexDataInterface()->BorrowIndexData(master_node->lodobj->GetIndexDataInterface()); 345 disciple_node->lodfactor = master_node->lodobj->GetCurrentLodFactor(); // we can use currentlodfactor here because the master is supposed to be at its REAL level of detail 346 } 347 } 348 349 void Geometry::LodManager::ReallyGoToLOD(lodobj_node_t *lodobjnode, Real lodfactor) 350 { 351 lodobjnode->lodobj->GoToLod(lodfactor); 352 353 MakeIndependent(lodobjnode); 354 UpdateDisciples(lodobjnode); 355 356 // store the precalculated lod in the table 357 int i = lodobj_container->lod2precalpos(lodfactor); 358 359 assert(i>=0 && i<=lodobj_container->num_lod_sim); // <= por lo del +1 360 361 if (lodobjnode->precalpos != -1) 362 //lodobj_container->precalculated_lods[lodobjnode->precalpos] = NULL; 363 lodobj_container->GetPrecalculatedLOD(lodobjnode->name,lodobjnode->precalpos) = NULL; 364 365 // lodobj_container->precalculated_lods[i] = lodobjnode; 366 lodobj_container->GetPrecalculatedLOD(lodobjnode->name,i) = lodobjnode; 367 368 lodobjnode->precalpos = i; 369 } 370 371 372 lodobj_node_t * Geometry::LodManager::FindMostSimilarRealLOD(const std::string &name, Real desired_lod) 373 { 374 uint32 i = lodobj_container->lod2precalpos(desired_lod); 375 assert(i>=0 && i<=lodobj_container->num_lod_sim); // <= por lo del +1 376 // lodobj_node_t *obj = lodobj_container->precalculated_lods[i]; 377 lodobj_node_t *obj = lodobj_container->GetPrecalculatedLOD(name,i); 378 379 return obj; 380 } 87 381 88 382 void Geometry::LodManager::UpdateCamera(const Geometry::Vector3 &p) 89 383 { 90 camera_pos = p;384 lodobj_container->camera_pos = p; 91 385 camera_changed = true; 92 386 } … … 94 388 void Geometry::LodManager::UpdateLODObjectPos(LodObject *o, const Geometry::Vector3 &p) 95 389 { 96 lodobj_pos[o->GetUniqueID()] = p; 97 } 98 99 100 float Geometry::LodManager::CalculateDistToCamera(const Geometry::Vector3 &p) const 101 { 102 return camera_pos.dotProduct(p); 103 } 390 lodobj_container->lodobj_pos[o->GetUniqueID()] = p; 391 } 392 104 393 105 394 float Geometry::LodManager::SelectRandomDistance(void) const -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp
r1136 r1526 27 27 void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb) 28 28 { 29 // LODPosition pos; 30 // vector <LODPosition> listaPos; 31 long int k; 32 long int i; 33 unsigned long int t; 34 long int r; 35 unsigned long int v; 36 long int p0; 37 long int lod = 0; 38 long int sigue; 39 long int ac[3] = {0,0,0}; 40 long int totalRegs = 0; 41 long int RegsCambios; 42 std::vector<std::vector<int> > TiraOriginal; 43 LODData regLOD; 44 //LODChanges listaCambios; 45 std::vector<LODData> listaCambios; 46 float percent; 47 float increment; 48 long int update; 29 long int k; 30 long int i; 31 unsigned long int t; 32 long int r; 33 unsigned long int v; 34 long int p0; 35 long int lod = 0; 36 long int sigue; 37 long int ac[3] = {0,0,0}; 38 long int totalRegs = 0; 39 long int RegsCambios; 40 std::vector<std::vector<int> > TiraOriginal; 41 LODData regLOD; 42 std::vector<LODData> listaCambios; 43 float percent; 44 float increment; 45 long int update; 49 46 50 47 // Saves original copy. … … 68 65 69 66 this->LodsDisp = this->TOTALCAMBIOS = lod; 70 pCambios 71 pCambios[0] 67 pCambios = new uint32[this->TOTALCAMBIOS]; 68 pCambios[0] = 0; 72 69 73 70 for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++) 74 71 { 75 /* if (update != (int)(increment * lod))76 {77 update = (int)(increment * lod);78 upb(percent);79 }*/80 81 72 tipoVertice & cVertsLOD = this->cVerts[lod]; 82 73 83 74 RegsCambios = 0; 84 regLOD.obligatory = this->Ordenacion[lod].obligator io;75 regLOD.obligatory = this->Ordenacion[lod].obligatory; 85 76 86 77 for(t = 0; t < this->cStrips.size(); t++) 87 78 { 88 89 79 std::vector<int> & cStripsT = this->cStrips[t]; 90 80 … … 101 91 // Strips. 102 92 if (regLOD.strip == this->MARCAVACIO) 103 { 104 regLOD.strip = t; 105 } 93 regLOD.strip = t; 106 94 107 95 ++totalRegs; … … 118 106 // Changes for simplification of level 1 to greater than 2. 119 107 totalRegs = 0; 120 i 121 r 122 sigue 123 k 108 i = 0; 109 r = 0; 110 sigue = 0; 111 k = long(cStripsT.size()-3); 124 112 125 113 while (i < k) … … 305 293 long int vSig; 306 294 long int k; 307 VECTORVERTEX 295 VECTORVERTEX Vertices; 308 296 std::vector<tipoVertice> NuevosVerts; 309 //vector <VECTORINT> NuevasTiras; 310 std::vector<std::vector<int> > NuevasTiras; 311 // VECTORINT tira; 312 std::vector<int> tira; 313 vector <Index> mV1Aux; 314 tipoOrden Orden; 315 tipoOrden *Ord; 316 bool bEncontrado; 317 long int c1; 318 long int c2; 297 std::vector<std::vector<int> > NuevasTiras; 298 std::vector<int> tira; 299 tipoOrden Orden; 300 tipoOrden *Ord; 301 bool bEncontrado; 302 303 319 304 // Progress bar 320 305 float percent; … … 326 311 size_t mStepsSize = mGeoMeshSQ->mSteps.size(); 327 312 328 c1 = 0;329 c2 = 0;330 331 313 update = -1; 332 314 percent = 1.0; … … 341 323 } 342 324 343 const Geometry::MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 344 345 mV1Aux.push_back(theStep.mV1); 325 const MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 346 326 347 327 Orden.vQslimNext = theStep.mV0; 348 Orden.vQslim 349 Orden.obligator io = theStep.obligatorio;350 Orden.vLS 351 352 Orden.x 353 Orden.vLSNext 354 Orden.cambio 328 Orden.vQslim = theStep.mV1; 329 Orden.obligatory = theStep.obligatory; 330 Orden.vLS = i; 331 332 Orden.x = theStep.x; 333 Orden.vLSNext = -1; 334 Orden.cambio = "n"; 355 335 356 336 Ordenacion.push_back(Orden); 357 337 } 358 338 359 this->NumVertsRepetidos = c2;360 339 361 340 update = -1; … … 363 342 percent = 1.0; 364 343 365 // Change all vertices that have x != 0.366 for(i = 0; i < Ordenacion.size(); i++)367 {368 if (update != (int)(i * increment))369 {370 update = (int)(i * increment);371 upb(percent);372 }373 374 Ord = &(Ordenacion[i]);375 376 if (Ord->x!=0)377 {378 // Change the simplification order.379 v = Ord->vQslim;380 Ord->vQslim = Ord->vQslimNext;381 Ord->vQslimNext = v;382 383 for (j = i+1; j < Ordenacion.size(); j++)384 {385 tipoOrden & ordJ = Ordenacion[j];386 if (ordJ.vQslim == Ord->vQslim)387 {388 ordJ.vQslim = Ord->vQslimNext;389 ordJ.cambio = "y";390 }391 else if (ordJ.vQslimNext == Ord->vQslim)392 {393 ordJ.vQslimNext = Ord->vQslimNext;394 ordJ.cambio = "y";395 }396 }397 }398 }399 400 344 update = -1; 401 345 increment = (float)(10.0) / (float)(Ordenacion.size()); … … 412 356 } 413 357 414 c1++; 415 NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]); 416 417 cVerts[Ordenacion[i].vQslim].Next = -1; 358 int OrdvQslim = Ordenacion[i].vQslim; 359 int OrdvQslimNext = Ordenacion[i].vQslimNext; 360 361 NuevosVerts.push_back(this->cVerts[OrdvQslim]); 362 363 cVerts[OrdvQslim].Next = -1; 418 364 419 365 } … … 421 367 // Añadir aquellos vertices que no estaban en NuevosVerts 422 368 // y no se simplificaban. 423 int cont 369 int cont = 0; 424 370 int contestaban = 0; 425 371 … … 431 377 cont++; 432 378 NuevosVerts.push_back(this->cVerts[i]); 433 Orden.vLS 434 Orden.obligator io= 0;435 Orden.vLSNext 436 Orden.vQslim 379 Orden.vLS = int(Ordenacion.size()); 380 Orden.obligatory = 0; 381 Orden.vLSNext = -1; 382 Orden.vQslim = i; 437 383 Orden.vQslimNext = -1; 438 384 … … 466 412 for (t = 0; t < Ordenacion.size() && !vSig;t++) 467 413 { 468 if (Ordenacion[t].vQslim ==v)469 { 470 vSig =Ordenacion[t].vLS;471 } 472 } 473 474 if (vSig !=0)414 if (Ordenacion[t].vQslim == v) 415 { 416 vSig = Ordenacion[t].vLS; 417 } 418 } 419 420 if (vSig != 0) 475 421 { 476 422 Ordenacion[i].vLSNext = vSig; … … 485 431 486 432 size_t cStripsSizeT = this->cStrips[t].size(); 433 487 434 for(i = 0; i < cStripsSizeT; i++) 435 { 488 436 tira.push_back(0); 437 } 489 438 490 439 NuevasTiras.push_back(tira); … … 499 448 // 2 min. 500 449 //Cambiar los vertices de las tiras 501 size_t NuevosVertsSize = NuevosVerts.size(); 450 size_t NuevosVertsSize = NuevosVerts.size(); 451 502 452 for(v = 0; v < NuevosVertsSize; v++) 503 453 { … … 515 465 std::vector<int> & NuevasTirasT = NuevasTiras[t]; 516 466 size_t cStripsSizeT = thisStrip.size(); 467 517 468 for(i = 0; i < cStripsSizeT; i++) 518 469 { … … 531 482 //NuevosVerts y Ordenacion = tamaño. 532 483 NuevosVertsSize = NuevosVerts.size(); 484 533 485 for(i = 0; i < NuevosVertsSize; i++) 534 486 { … … 563 515 564 516 this->mGeoMeshSQ = const_cast<MeshSimplificationSequence*>(ms); 517 518 // Add new vertices to mesh. 519 AddNewVertices(); 565 520 566 521 // Set the leaves submesh. … … 612 567 void LodStripsConstructor::Save(std::string filename) 613 568 { 614 //size_t i, j;615 int k = 0;616 char simp[256];617 618 569 int vertexCount = (int)this->cVerts.size(); 619 570 int changesCount = (int)this->cCambios.size(); 620 int dataCount 571 int dataCount = (int)this->cDatos.size(); 621 572 int cambiosCount = this->TOTALCAMBIOS; 622 int size 573 int size = changesCount*sizeof(LODData) + 623 574 (vertexCount + dataCount + cambiosCount + 4)*sizeof(int) + 624 575 CHUNK_OVERHEAD_SIZE; … … 630 581 fwrite(&size,sizeof(unsigned long),1,f); 631 582 583 // VERTICES 632 584 fwrite(&vertexCount, sizeof(int), 1, f); 633 585 for(size_t i = 0; i < this->cVerts.size(); i++) … … 636 588 fwrite(&auxv, sizeof(int), 1, f); 637 589 } 638 639 // VERTICES.640 /* for(i = 0; i < this->cVerts.size(); i++)641 {642 sprintf(simp,"v %d\n",cVerts[i].Next);643 oSerializer.WriteData(simp,sizeof(char),strlen(simp));644 }645 */646 590 647 591 // CSTRIPS. … … 649 593 650 594 for(size_t i = 0; i < this->cStrips.size(); i++) 651 {652 595 this->TOTALINDICES += int(this->cStrips[i].size()); 653 }654 596 655 597 // lines starting with a d. … … 662 604 } 663 605 664 665 /* for(i = 0; i < this->cCambios.size(); i++)666 {667 sprintf(simp,"c\n");668 oSerializer.WriteData(simp,sizeof(char),strlen(simp));669 670 sprintf(simp,671 "d %u %u %u %u %u\n",672 cCambios[i].strip,673 cCambios[i].nP,674 cCambios[i].nL1,675 cCambios[i].nL2,676 cCambios[i].obligatory);677 678 oSerializer.WriteData(simp,sizeof(char),strlen(simp));679 }680 */ // Lines starting with a b.681 606 // Data. 682 683 607 fwrite(&dataCount, sizeof(int), 1, f); 684 685 608 for(size_t i = 0; i < this->cDatos.size(); i++) 686 609 { … … 688 611 fwrite(&data, sizeof(int), 1, f); 689 612 } 690 691 sprintf(simp,"a\n");692 /* oSerializer.WriteData(simp,sizeof(char),strlen(simp));693 694 for(i = 0; i < this->cDatos.size(); i++)695 {696 sprintf(simp,"b %d\n",cDatos[i]);697 698 oSerializer.WriteData(simp,sizeof(char),strlen(simp));699 }700 */701 613 702 614 // lines starting with a p. … … 711 623 712 624 fclose(f); 713 714 /*715 // VERTICES.716 for(i = 0; i < this->cVerts.size(); i++)717 {718 sprintf(simp,"v %d\n",cVerts[i].Next);719 oSerializer.WriteData(simp,sizeof(char),strlen(simp));720 }721 722 // CSTRIPS.723 this->TOTALINDICES = 0;724 725 for(i = 0; i < this->cStrips.size(); i++)726 {727 this->TOTALINDICES += int(this->cStrips[i].size());728 }729 730 // lines starting with a d.731 // Changes732 for(i = 0; i < this->cCambios.size(); i++)733 {734 sprintf(simp,"c\n");735 oSerializer.WriteData(simp,sizeof(char),strlen(simp));736 737 sprintf(simp,738 "d %u %u %u %u %u\n",739 cCambios[i].strip,740 cCambios[i].nP,741 cCambios[i].nL1,742 cCambios[i].nL2,743 cCambios[i].obligatory);744 745 oSerializer.WriteData(simp,sizeof(char),strlen(simp));746 }747 // Lines starting with a b.748 // Data.749 sprintf(simp,"a\n");750 oSerializer.WriteData(simp,sizeof(char),strlen(simp));751 752 for(i = 0; i < this->cDatos.size(); i++)753 {754 sprintf(simp,"b %d\n",cDatos[i]);755 756 oSerializer.WriteData(simp,sizeof(char),strlen(simp));757 }758 759 // lines starting with a p.760 // Chages made in a LOD.761 for(i = 0; i < this->TOTALCAMBIOS; i++)762 {763 sprintf(simp,"p %d\n",this->pCambios[i]);764 765 oSerializer.WriteData(simp,sizeof(char),strlen(simp));766 }767 768 oSerializer.WriteData("\n",sizeof(char),1); */769 625 } 770 626 … … 815 671 for(i = 0; i < this->TOTALTIRAS; i++) 816 672 { 817 t =long(this->cStrips[i].size());673 t = long(this->cStrips[i].size()); 818 674 819 675 if (t > max) 820 { 821 max = t; 822 } 676 max = t; 823 677 } 824 678 … … 970 824 } 971 825 972 vAux.Next = -10; 973 vAux.numMesh = 0; 974 975 vAux.obligatorio = 0; 826 vAux.Next = -10; 827 vAux.numMesh = 0; 828 vAux.obligatory = 0; 976 829 977 830 this->cVerts.push_back(vAux); … … 1170 1023 { 1171 1024 assign.boneIndex = 0; 1172 assign.weight 1173 1174 for ( 1025 assign.weight = 1; 1026 1027 for (size_t m = copy_vb->mVertexCount; 1175 1028 m < mesh_vb->mVertexCount; 1176 1029 m++) 1177 1030 { 1178 1031 assign.vertexIndex = (unsigned int)m; 1179 1180 1032 mesh_bones->push_back(assign); 1181 1033 } … … 1185 1037 { 1186 1038 n = (*mesh_bones)[m].vertexIndex; 1187 1188 1039 o = 0; 1189 1040 1190 while (!( (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x) 1191 && 1192 (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y) 1193 && 1194 (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 1041 while (!( (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x) && 1042 (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y) && 1043 (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 1195 1044 { 1196 1045 o++; … … 1200 1049 1201 1050 while ((*copy_bones)[p].vertexIndex != o) 1202 {1203 1051 p++; 1204 }1205 1052 1206 1053 // Same bone for 'm' and 'p'. … … 1244 1091 } 1245 1092 1246 void Geometry::LodStripsConstructor::UpdateMesh(void)1093 void LodStripsConstructor::UpdateMesh(void) 1247 1094 { 1248 1095 int num_no = 0; … … 1303 1150 1304 1151 indice++; 1305 1306 1152 } 1307 1153 … … 1436 1282 } 1437 1283 } 1284 1285 //--------------------------------------------------------------------------- 1286 // Add new vertices to mesh. 1287 //--------------------------------------------------------------------------- 1288 void LodStripsConstructor::AddNewVertices() 1289 { 1290 int num_vertices; 1291 SubMesh *geosubmesh; 1292 VertexBuffer *vertex_buffer; 1293 VertexBuffer *new_vertex_buffer; 1294 1295 // Gets old vertex buffer. 1296 vertex_buffer = mGeoMesh->mVertexBuffer; 1297 1298 num_vertices = vertex_buffer->mVertexCount 1299 + 1300 mGeoMeshSQ->mNewVertices.size(); 1301 1302 // Initialize auxiliar vertex buffer. 1303 new_vertex_buffer = new VertexBuffer(); 1304 1305 new_vertex_buffer->mVertexCount = num_vertices; 1306 1307 new_vertex_buffer->mPosition = new Vector3[num_vertices]; 1308 new_vertex_buffer->mNormal = new Vector3[num_vertices]; 1309 new_vertex_buffer->mTexCoords = new Vector2[num_vertices]; 1310 1311 new_vertex_buffer->mVertexInfo = vertex_buffer->mVertexInfo; 1312 1313 // Num old vertices. 1314 num_vertices = vertex_buffer->mVertexCount; 1315 1316 // Copy the old vertex buffer. 1317 for (unsigned int i = 0; i < num_vertices; i++) 1318 { 1319 new_vertex_buffer->mPosition[i] = vertex_buffer->mPosition[i]; 1320 new_vertex_buffer->mNormal[i] = vertex_buffer->mNormal[i]; 1321 new_vertex_buffer->mTexCoords[i]= vertex_buffer->mTexCoords[i]; 1322 } 1323 1324 1325 // Copy new vertices. 1326 for (unsigned int i = 0; i < mGeoMeshSQ->mNewVertices.size(); i++) 1327 { 1328 new_vertex_buffer->mPosition[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].position; 1329 new_vertex_buffer->mTexCoords[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].texcoord; 1330 new_vertex_buffer->mNormal[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].normal; 1331 1332 // check if my twin-vertex-bone has a bone assignment 1333 // we check only the GeoMesh bones because the lodstrips only works for sharedvertex bones 1334 for (std::vector<VertexBoneAssignment>::iterator it = mGeoMesh->mBones.begin(); it != mGeoMesh->mBones.end(); it ++) 1335 { 1336 if (it->vertexIndex == mGeoMeshSQ->mNewVertices[i].bonefrom) 1337 { 1338 VertexBoneAssignment vba; 1339 vba.boneIndex = it->boneIndex; 1340 vba.vertexIndex = mGeoMeshSQ->mNewVertices[i].id; 1341 vba.weight = it->weight; 1342 mGeoMesh->mBones.push_back(vba); 1343 } 1344 } 1345 } 1346 1347 // For each submesh. 1348 for (unsigned int submesh = 0; submesh < mGeoMesh->mSubMeshCount; submesh++) 1349 { 1350 geosubmesh = &mGeoMesh->mSubMesh[submesh]; 1351 1352 geosubmesh->mVertexBuffer = new_vertex_buffer; 1353 } 1354 1355 delete vertex_buffer; 1356 1357 mGeoMesh->mVertexBuffer = new_vertex_buffer; 1358 } 1359 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp
r1325 r1526 15 15 16 16 //----------------------------------------------------------------------------- 17 // Constructor s.18 //----------------------------------------------------------------------------- 19 LodStripsLibrary::LodStripsLibrary(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh, CREATEINDEXDATAFUNC idfun)20 :create_index_data_func(idfun?idfun:DefaultIndexDataCreator)17 // Constructor. 18 //----------------------------------------------------------------------------- 19 LodStripsLibrary::LodStripsLibrary(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh, IndexData *userindexdata) 20 //:dataRetrievalInterface(idfun?idfun:DefaultIndexDataCreator) 21 21 { 22 22 // const char *name_of_file; … … 31 31 mGeoMesh = geomesh; 32 32 33 dataRetrievalInterface=NULL; 33 delete_indexdata=false; 34 dataRetrievalInterface=userindexdata; 35 34 36 indices_x_submesh = NULL; 35 37 offsets_x_submesh = NULL; 36 38 mStripsSubmesh = NULL; 39 submesh_x_strip = NULL; 40 lodFactor=1.0f; 41 current_triangle_count=0; 37 42 38 43 // Loads the Level Of Detail file. … … 51 56 52 57 //----------------------------------------------------------------------------- 53 // Destr oyer.58 // Destructor 54 59 //----------------------------------------------------------------------------- 55 60 LodStripsLibrary::~LodStripsLibrary() 56 61 { 57 62 delete [] mStrips; 58 if (d ataRetrievalInterface)63 if (delete_indexdata) 59 64 delete dataRetrievalInterface; 60 65 if (indices_x_submesh) … … 64 69 if (mStripsSubmesh) 65 70 delete[] mStripsSubmesh; 71 if (submesh_x_strip) 72 delete[] submesh_x_strip; 66 73 } 67 74 … … 75 82 void LodStripsLibrary::GoToLod(float lodfactor) 76 83 { 77 register int 78 register int 79 long int 80 long int 81 long int 82 unsigned long int 83 long int 84 long int 85 long int 86 long int 87 long int 88 long int 89 long int 90 SmallIntVector 84 register int j; 85 register int offset; 86 long int i; 87 long int k; 88 long int b_change_ok = 1; 89 unsigned long int lod; 90 long int t; 91 long int r; 92 long int next; 93 long int el1; 94 long int el2; 95 long int total_changes; 96 long int totalR; 97 SmallIntVector *strip; 91 98 SmallIntVector::iterator start; 92 uint32 return_value; 99 100 if (lodfactor<0.0f) lodfactor=0.0f; 101 if (lodfactor>1.0f) lodfactor=1.0f; 93 102 94 103 uint32 newLOD = (uint32)((1.0f - lodfactor) * mLods); 104 105 lodFactor=lodfactor; 106 LODRegisterType * lastLOD = mCurrentRegLOD; 95 107 96 // Initialize the return value to the current LOD.97 return_value = mCurrentLod;98 99 108 if (newLOD != mCurrentLod) 100 109 { … … 103 112 // Forwards. 104 113 // Increments LOD. 105 for (lod = mCurrentLod; lod < newLOD ; lod++)106 { 107 next 114 for (lod = mCurrentLod; lod < newLOD || lastLOD->obligatory==1; lod++) 115 { 116 next = mVertex[lod]; 108 117 total_changes = mPChanges[lod]; 109 118 … … 111 120 { 112 121 // Strip change. 113 t 122 t = mCurrentRegLOD->strip; 114 123 strip = &(mStrips[t]); 115 124 start = strip->begin(); 125 int stripsize_ini = strip->size(); 116 126 117 127 // Position. … … 120 130 for (j = totalR - 1; j >= 0; j--) 121 131 { 122 start[*mCurrentData] = next; 123 132 start[*mCurrentData] = next; 124 133 ++mCurrentData; 125 134 } … … 160 169 } 161 170 171 lastLOD = mCurrentRegLOD; 162 172 mCurrentRegLOD++; 163 173 164 174 mStripsChanges[t] = 1; 175 176 int stripsize_end = strip->size(); 177 indices_x_submesh[submesh_x_strip[t]] -= (stripsize_ini - stripsize_end); 165 178 166 179 } … … 177 190 178 191 // Decrements LOD. 179 for (lod = mCurrentLod; lod > newLOD ; lod--)192 for (lod = mCurrentLod; lod > newLOD || lastLOD->obligatory==1; lod--) 180 193 { 181 194 total_changes = mPChanges[lod - 1]; … … 186 199 strip = &(mStrips[t]); 187 200 start = mStrips[t].begin(); 201 int stripsize_ini = strip->size(); 188 202 189 203 // L2. … … 232 246 } 233 247 248 lastLOD = mCurrentRegLOD; 234 249 mCurrentRegLOD--; 235 250 mStripsChanges[t] = 1; 251 252 int stripsize_end = strip->size(); 253 indices_x_submesh[submesh_x_strip[t]] += (stripsize_end - stripsize_ini); 254 236 255 } 237 256 238 // Update LOD. 257 // Update LOD. 239 258 mCurrentLod = lod - 1; 240 259 } … … 359 378 // Copy a STL vector to a C array. 360 379 //----------------------------------------------------------------------------- 361 void LodStripsLibrary::CopyVectors2Arrays( )380 void LodStripsLibrary::CopyVectors2Arrays(void) 362 381 { 363 382 SmallInt max; … … 400 419 // Copy strips. 401 420 // unsigned int numDegenerated = 2*mTotalStrips - 2; 402 dataRetrievalInterface=create_index_data_func(total_strip_size/*+numDegenerated*/); // temporal! 403 dataRetrievalInterface->Begin(); 421 // dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal! 422 423 // dataRetrievalInterface->Init(total_strip_size); 424 /* dataRetrievalInterface->numinds=total_strip_size; 425 dataRetrievalInterface->numvalidinds=total_strip_size;*/ 426 // dataRetrievalInterface->Begin(); 404 427 405 428 unsigned int ii = 0; … … 410 433 { 411 434 mStrips[i].push_back(mFileStrips[i][j]); 412 dataRetrievalInterface->SetIndex(ii,mFileStrips[i][j]);435 // dataRetrievalInterface->SetIndex(ii,mFileStrips[i][j]); 413 436 } 414 437 … … 416 439 mStripsChanges[i] = 0; 417 440 } 418 dataRetrievalInterface->End();441 // dataRetrievalInterface->End(); 419 442 420 443 for (unsigned int i = 0; i < mData.size(); i++) … … 459 482 indices_x_submesh = new int[geomesh->mSubMeshCount]; 460 483 offsets_x_submesh = new int[geomesh->mSubMeshCount]; 484 485 int totaltiras = 0; 486 for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 487 for (unsigned int strip = 0; strip < geomesh->mSubMesh[submesh].mStripCount; strip++) 488 totaltiras++; 489 490 submesh_x_strip = new int[totaltiras]; 491 492 int istrip = 0; 461 493 for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 462 494 { 463 495 geoSubMesh = &geomesh->mSubMesh[submesh]; 496 indices_x_submesh[submesh] = 0; 464 497 465 498 // For each one of the strips. 466 for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++ )499 for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++, istrip++) 467 500 { 468 501 // Insert an empty strip. 502 submesh_x_strip[istrip] = submesh; 469 503 t++; 470 504 strip_aux.clear(); … … 499 533 int i; 500 534 i = 0; 501 indices_x_submesh[submesh] = 0;535 502 536 if (submesh==0) 503 537 offsets_x_submesh[submesh] = 0; … … 592 626 593 627 for (unsigned int i = 0; i < mLods; i++) 594 {595 628 mPChanges[i] = p_changes[i]; 596 }597 629 598 630 mTotalVertices = int(mFileVertices.size()); … … 603 635 //Copy the data to the structure we will use 604 636 CopyVectors2Arrays(); 605 // }606 637 } 607 638 … … 610 641 unsigned int ii = 0; 611 642 612 dataRetrievalInterface->Begin();613 614 643 int counter = 0; 615 644 int target_submesh = 0; 616 645 size_t strip_count = 0; 617 618 dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 646 unsigned int ii_submesh = 0; 647 648 dataRetrievalInterface->Begin(target_submesh, indices_x_submesh[target_submesh]); 649 650 // dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 619 651 620 652 for (unsigned int i = 0; i < mTotalStrips; i++, strip_count++) … … 622 654 if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount) 623 655 { 624 indices_x_submesh[target_submesh] = counter;656 // indices_x_submesh[target_submesh] = counter; 625 657 626 658 if (target_submesh==0) … … 634 666 635 667 target_submesh++; 636 dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 668 ii_submesh = 0; 669 // dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 670 dataRetrievalInterface->End(); 671 dataRetrievalInterface->Begin(target_submesh, indices_x_submesh[target_submesh]); 637 672 } 638 673 639 674 int lastindex = -1; 640 for (SmallIntVector::iterator it=mStrips[i].begin(); it!=mStrips[i].end(); it++, ii++ )675 for (SmallIntVector::iterator it=mStrips[i].begin(); it!=mStrips[i].end(); it++, ii++, ii_submesh++) 641 676 { 642 677 /* // repeat the first index of the strip: degenerate … … 649 684 }*/ 650 685 lastindex=*it; 651 dataRetrievalInterface->SetIndex(ii ,*it);686 dataRetrievalInterface->SetIndex(ii_submesh,*it); 652 687 counter++; 653 688 } … … 658 693 ii++;*/ 659 694 660 dataRetrievalInterface->SetNumValidIndices(ii);695 // dataRetrievalInterface->SetNumValidIndices(ii); 661 696 } 662 697 663 698 if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount) 664 699 { 665 indices_x_submesh[target_submesh] = counter;700 // indices_x_submesh[target_submesh] = counter; 666 701 if (target_submesh==0) 667 702 offsets_x_submesh[target_submesh] = 0; … … 673 708 strip_count = 0; 674 709 target_submesh++; 675 dataRetrievalInterface->SetCurrentSubmesh(target_submesh);710 // dataRetrievalInterface->SetCurrentSubmesh(target_submesh); 676 711 } 677 712 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp
r1136 r1526 7 7 Geometry::LodTreeLibrary::LodTreeLibrary(const LodStripsLibraryData *lodstripsdata, 8 8 const TreeSimplificationSequence *simpseq, 9 Geometry::Mesh *treeGeoMesh/*, 10 uint32 leafSubMeshID, 11 CREATEVERTEXDATAFUNC vdfun, 12 CREATEINDEXDATAFUNC idfun, 13 CREATEMULTIINDEXDATAFUNC midfun*/) 9 Geometry::Mesh *treeGeoMesh, 10 Geometry::IndexData *userindexdata) 14 11 { 15 12 // Cargar el tronco 16 trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh );13 trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh,userindexdata); 17 14 18 15 // select the first triangle-list submesh as leaves submesh … … 28 25 } 29 26 27 delete_indexdata=false; 28 dataRetrievalInterface=userindexdata; 29 30 30 // Cargar la copa del árbol 31 31 Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[mLeavesSubMesh]); 32 foliage = new Foliage( leafsSubMesh,simpseq);32 foliage = new Foliage(mLeavesSubMesh,leafsSubMesh,simpseq); 33 33 GoToFoliageLod(1.0f); 34 34 } … … 56 56 if (trunk) delete trunk; 57 57 if (foliage) delete foliage; 58 /* if (trunk_all_indices) delete trunk_all_indices; 59 if (indices_offsets) delete[] indices_offsets; 60 // if (current_foliage_indices) delete[] current_foliage_indices;*/ 58 if (delete_indexdata) delete dataRetrievalInterface; 61 59 } 62 60 /* … … 101 99 void LodTreeLibrary::GoToFoliageLod(float newlod) 102 100 { 103 uint32 targetLeaves = (uint32) 104 ( 105 (1.0f - newlod) 106 * 107 foliage->minLeaves 101 uint32 targetLeaves = (uint32) ( (1.0f - newlod) * foliage->minLeaves 108 102 + 109 newlod 110 * 111 foliage->leafCount 112 ); 103 newlod * foliage->leafCount ); 113 104 114 105 foliage->CalculateLOD(targetLeaves); 115 106 116 foliage->indexdata->Begin();117 foliage->vertexdata->Begin();118 107 int i = foliage->begin; 119 108 int auxnumleaves = 0; … … 124 113 } 125 114 126 assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices())); 127 foliage->indexdata->SetNumValidIndices(auxnumleaves*6); 115 // foliage->indexdata->Begin(GetLeavesSubMesh(),auxnumleaves*6); 116 dataRetrievalInterface->Begin(GetLeavesSubMesh(),auxnumleaves*6); 117 // foliage->vertexdata->Begin(); 118 128 119 i = foliage->begin; 129 120 int index=0; … … 136 127 v3 = foliage->Leaves[i].vertsLeaf[3]; 137 128 138 foliage->indexdata->SetIndex(index+0,v0);139 foliage->indexdata->SetIndex(index+1,v1);140 foliage->indexdata->SetIndex(index+2,v2);141 foliage->indexdata->SetIndex(index+3,v2);142 foliage->indexdata->SetIndex(index+4,v1);143 foliage->indexdata->SetIndex(index+5,v3);144 145 foliage->vertexdata->SetVertexTexCoord(v0,0,0);129 dataRetrievalInterface->SetIndex(index+0,v0); 130 dataRetrievalInterface->SetIndex(index+1,v1); 131 dataRetrievalInterface->SetIndex(index+2,v2); 132 dataRetrievalInterface->SetIndex(index+3,v2); 133 dataRetrievalInterface->SetIndex(index+4,v1); 134 dataRetrievalInterface->SetIndex(index+5,v3); 135 136 /* foliage->vertexdata->SetVertexTexCoord(v0,0,0); 146 137 foliage->vertexdata->SetVertexTexCoord(v1,0,1); 147 138 foliage->vertexdata->SetVertexTexCoord(v2,1,0); 148 foliage->vertexdata->SetVertexTexCoord(v3,1,1); 139 foliage->vertexdata->SetVertexTexCoord(v3,1,1); */ 149 140 150 141 index+=6; 151 142 i=foliage->Acth[i].next; 152 143 } 153 foliage->indexdata->End(); 154 foliage->vertexdata->End(); 144 dataRetrievalInterface->End(); 145 // foliage->vertexdata->End(); 146 currentFoliageLodFactor = newlod; 155 147 } 156 148 /* … … 170 162 const IndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const 171 163 { 172 return trunk-> dataRetrievalInterface;173 } 174 175 164 return trunk->GetIndexDataInterface(); 165 } 166 167 /* 176 168 const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const 177 169 { … … 181 173 const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const 182 174 { 183 return foliage->indexdata;184 } 185 186 187 /*void ThrowFileNotFoundError(const char *text)175 return currentLOD_foliageIndexCount; 176 } 177 178 179 void ThrowFileNotFoundError(const char *text) 188 180 { 189 181 throw Geometry::FileNotFound(text); … … 193 185 { 194 186 // return current_foliage_indexcount; 195 return foliage->indexdata->GetNumValidIndices(); 187 // return foliage->indexdata->GetNumValidIndices(); 188 return foliage->active_leaf_count*6; 196 189 } 197 190 /* … … 213 206 uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const 214 207 { 215 return foliage-> indexdata->GetNumMaxIndices();208 return foliage->leafTotal*6; 216 209 } 217 210 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshLoader.cpp
r1136 r1526 681 681 { 682 682 case 0xabcd: 683 684 // Debug. 683 685 cout << "LODSTRIPS_Chunk" << endl; 686 684 687 lodstripsdata = new Geometry::LodStripsLibraryData; 685 688 686 int aux,v,c;689 int aux,v,c; 687 690 LODRegisterType lod_register; 688 LODData dataaux;689 int tam;691 LODData dataaux; 692 int tam; 690 693 691 694 fread(&tam, sizeof(int), 1, f); 695 692 696 lodstripsdata->mFileVertices.clear(); 693 for (v=0; v<tam; v++) 697 698 for (v = 0; v < tam; v++) 694 699 { 695 700 fread(&aux, sizeof(int), 1, f); … … 698 703 699 704 lodstripsdata->mFileChangesLOD.clear(); 705 700 706 fread(&tam, sizeof(int), 1, f); 701 for (c=0; c<tam; c++) 707 708 for (c = 0; c < tam; c++) 702 709 { 703 710 fread(&dataaux, sizeof(LODData), 1, f); … … 706 713 lod_register.vertexRepetition= dataaux.nL1; 707 714 lod_register.edgeRepetition= dataaux.nL2; 708 //lod_register.obligatory=false; 709 //lod_register.obligatory= dataaux.obligatory; 715 lod_register.obligatory=dataaux.obligatory; 710 716 711 717 lodstripsdata->mFileChangesLOD.push_back(lod_register); … … 713 719 714 720 lodstripsdata->mData.clear(); 721 715 722 fread(&tam, sizeof(int), 1, f); 716 for (int b=0; b<tam; b++) 723 724 for (int b = 0; b < tam; b++) 717 725 { 718 726 fread(&aux, sizeof(int), 1, f); … … 721 729 722 730 lodstripsdata->p_changes.clear(); 731 723 732 fread(&tam, sizeof(int), 1, f); 724 for (int p=0; p<tam; p++) 733 734 for (int p = 0; p < tam; p++) 725 735 { 726 736 fread(&aux, sizeof(int), 1, f); 727 737 lodstripsdata->p_changes.push_back(aux); 728 } 738 } 729 739 730 740 break; … … 1146 1156 cout << version << endl; 1147 1157 1148 if (strcmp(version,"[MeshSerializer_v1.30]\n"))1158 /*if (strcmp(version,"[MeshSerializer_v1.30]\n")) 1149 1159 { 1150 1160 // Debug. … … 1156 1166 // Error. 1157 1167 mError = true; 1158 } 1168 }*/ 1159 1169 1160 1170 while(!feof(pFile)) … … 1423 1433 // Read bones of the submesh. 1424 1434 //--------------------------------------------------------------------------- 1425 void GeoMeshLoader::readSubMeshBoneAssignment(FILE *f,1426 SubMesh *geoSubMesh,1427 int 1435 void GeoMeshLoader::readSubMeshBoneAssignment(FILE *f, 1436 SubMesh *geoSubMesh, 1437 int option) 1428 1438 { 1429 1439 if (option == GEOMESH_BUILD) … … 1445 1455 // Read bones of the main mesh. 1446 1456 //--------------------------------------------------------------------------- 1447 void GeoMeshLoader::readMeshBoneAssignment(FILE * f, Mesh* geoMesh,int option)1457 void GeoMeshLoader::readMeshBoneAssignment(FILE *f, Mesh *geoMesh, int option) 1448 1458 { 1449 1459 if (option == GEOMESH_BUILD) … … 1465 1475 // Read skeleton link. 1466 1476 //--------------------------------------------------------------------------- 1467 void GeoMeshLoader::readSkeletonLink(FILE * f, Mesh* geoMesh,int option)1477 void GeoMeshLoader::readSkeletonLink(FILE *f, Mesh *geoMesh, int option) 1468 1478 { 1469 1479 if (option == GEOMESH_BUILD) … … 1829 1839 const std::vector<face_t> & vecfaces = faces[i]; 1830 1840 std::vector<Geometry::Index> aux_indices; 1841 1831 1842 submesh->mSharedVertexBuffer = true; 1832 1843 submesh->mIndexCount = vecfaces.size()*3; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSaver.cpp
r1136 r1526 878 878 } 879 879 } 880 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimpSequence.cpp
r1009 r1526 4 4 using namespace std; 5 5 6 MeshSimplificationSequence::MeshSimplificationSequence() 6 //--------------------------------------------------------------------------- 7 // Constructor. 8 //--------------------------------------------------------------------------- 9 MeshSimplificationSequence::MeshSimplificationSequence() 7 10 { 8 meshName ="";11 meshName = ""; 9 12 } 10 13 11 MeshSimplificationSequence::~MeshSimplificationSequence() 14 MeshSimplificationSequence::~MeshSimplificationSequence() 12 15 { 13 16 } 14 17 15 void MeshSimplificationSequence::Load(Serializer &s) 18 //--------------------------------------------------------------------------- 19 // Loads mesh simplification sequence. 20 //--------------------------------------------------------------------------- 21 void MeshSimplificationSequence::Load(Serializer &s) 16 22 { 17 // Loads a simplification sequence from a file18 char buffer[256];19 unsigned int 20 char 23 // Loads a simplification sequence from a file. 24 char buffer[256]; 25 unsigned int modVertex; 26 char name[256]; 21 27 28 // Read mesh name. 22 29 if (s.ReadData(buffer,256) != NULL) 23 30 { 24 31 sscanf(buffer,"%s",&name); 25 meshName=new char[strlen(name)]; 32 33 meshName = new char[strlen(name)]; 34 26 35 strcpy(meshName,name); 27 36 } 28 37 38 // Read steps data. 29 39 while (s.ReadData(buffer,256) != NULL) 30 40 { 31 41 Geometry::MeshSimplificationSequence::Step simplifstep; 32 //new step33 sscanf(buffer,"%u %u %u %u %u %f %f %f &",&simplifstep.mV1,&simplifstep.mV0, &simplifstep.mT0,&simplifstep.mT1, &simplifstep.obligatorio,&simplifstep.x, &simplifstep.y, &simplifstep.z);34 //sscanf(buffer,"%u %u %u %u %u &",&simplifstep.mV1,&simplifstep.mV0, &simplifstep.mT0,&simplifstep.mT1, &simplifstep.obligatorio);35 //sscanf(buffer + 3,"%u %u %f %f %f %u %u &",&simplifstep.mV0,&simplifstep.mV1,&simplifstep.x, &simplifstep.y, &simplifstep.z, &simplifstep.mT0,&simplifstep.mT1);36 //sscanf(buffer,"%u %u %u %u %u &",&simplifstep.mV0,&simplifstep.mV1,&simplifstep.mT0,&simplifstep.mT1, &simplifstep.obligatorio);37 42 38 buffer[strlen(buffer)-1]='\0'; 43 // New step. 44 sscanf( buffer, 45 "%u %u %u %u %u %f %f %f &", 46 &simplifstep.mV1, 47 &simplifstep.mV0, 48 &simplifstep.mT0, 49 &simplifstep.mT1, 50 &simplifstep.obligatory, 51 &simplifstep.x, 52 &simplifstep.y, 53 &simplifstep.z); 39 54 40 //if(!simplifstep.obligatorio)41 //{ 55 buffer[strlen(buffer)-1] = '\0'; 56 42 57 char *ptr1; 43 ptr1=strtok(buffer,"&");44 ptr1=strtok(NULL,"&");45 58 46 if (ptr1!=NULL) 59 ptr1 = strtok(buffer,"&"); 60 ptr1 = strtok(NULL,"&"); 61 62 if (ptr1 != NULL) 47 63 { 48 64 char *ptr; 49 ptr=strtok(ptr1," "); 65 66 ptr = strtok(ptr1," "); 50 67 51 while (ptr != NULL )68 while (ptr != NULL ) 52 69 { 53 modVertex = (unsigned int)atoi(ptr); 70 modVertex = (unsigned int)atoi(ptr); 71 54 72 simplifstep.mModfaces.push_back(modVertex); 55 ptr=strtok(NULL," "); 73 74 ptr = strtok(NULL," "); 56 75 } 57 76 } 77 58 78 mSteps.push_back(simplifstep); 59 //}60 61 79 } 62 63 80 } 64 81 82 //--------------------------------------------------------------------------- 83 // Saves simplification sequence. 84 //--------------------------------------------------------------------------- 65 85 void MeshSimplificationSequence::Save(Serializer &s) 66 86 { 67 // Stores the simplification sequence in a file87 // Stores the simplification sequence in a file. 68 88 char simp[256]; 69 89 70 // Name of the mesh90 // Name of the mesh. 71 91 sprintf(simp,"%s\n",meshName); 72 92 s.WriteData(simp,sizeof(char),strlen(simp)); 73 93 74 for(unsigned int i=0; i<mSteps.size(); i++) 94 // For each step. 95 for (unsigned int i = 0; i < mSteps.size(); i++) 75 96 { 76 97 Geometry::MeshSimplificationSequence::Step paso = mSteps.operator [](i); 77 //sprintf(simp,"%u %u %u %u %u &", paso.mV0, paso.mV1, paso.mT0, paso.mT1,paso.obligatorio); 78 sprintf(simp,"%u %u %u %u %u %f &", paso.mV0, paso.mV1, paso.mT0, paso.mT1,paso.obligatorio,paso.x); 98 99 sprintf(simp, 100 "%u %u %u %u %u %f &", 101 paso.mV0, 102 paso.mV1, 103 paso.mT0, 104 paso.mT1, 105 paso.obligatory, 106 paso.x); 107 108 // Write step. 79 109 s.WriteData(simp,sizeof(char),strlen(simp)); 80 for (unsigned int j=0; j<paso.mModfaces.size(); j++) 110 111 // Triangles modified. 112 for (unsigned int j = 0; j < paso.mModfaces.size(); j++) 81 113 { 82 114 sprintf(simp," %u",paso.mModfaces.operator [](j)); 83 115 s.WriteData(simp,sizeof(char),strlen(simp)); 84 116 } 117 118 // New line. 85 119 s.WriteData("\n",sizeof(char),1); 86 120 } 87 121 } 88 122 89 void MeshSimplificationSequence::putMeshName(char *name) 123 //--------------------------------------------------------------------------- 124 // Puts mesh name. 125 //--------------------------------------------------------------------------- 126 void MeshSimplificationSequence::putMeshName(char *name) 90 127 { 91 meshName =name;128 meshName = name; 92 129 } 93 130 94 char *MeshSimplificationSequence::getMeshName(void) 131 //--------------------------------------------------------------------------- 132 // Gets mesh name. 133 //--------------------------------------------------------------------------- 134 char *MeshSimplificationSequence::getMeshName(void) 95 135 { 96 136 return meshName; 97 137 } 138 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r1070 r1526 413 413 current_step.z = VMI::mVMISteps[i].z; 414 414 415 current_step.obligator io= VMI::mVMISteps[i].obligatory;415 current_step.obligatory = VMI::mVMISteps[i].obligatory; 416 416 417 417 // For each face modificated. -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjModel.cxx
r1025 r1526 17 17 int Model::in_Vertex(const Vec3& p) 18 18 { 19 20 21 19 Vertex *v = newVertex(p[X], p[Y], p[Z]); 20 bounds.addPoint(p); 21 return vertCount() - 1; 22 22 } 23 23 … … 36 36 int Model::in_Face(int a, int b, int c, int n1, int n2, int n3, int t1, int t2, int t3) 37 37 { 38 39 40 41 42 38 Vertex *v1 = vertices(a-1); 39 Vertex *v2 = vertices(b-1); 40 Vertex *v3 = vertices(c-1); 41 42 Face *t = newFace(v1, v2, v3); 43 43 44 44 t->normals[0] = n1; … … 55 55 int Model::miin_Face(int a, int b, int c) 56 56 { 57 Vertex *v1 = vertices(a-1);58 Vertex *v2 = vertices(b-1);59 Vertex *v3 = vertices(c-1);60 61 57 Vertex *v1 = vertices(a); 58 Vertex *v2 = vertices(b); 59 Vertex *v3 = vertices(c); 60 61 Face *t = newFace(v1, v2, v3); 62 62 63 63 t->normals[0] = a; … … 75 75 int Model::in_FColor(const Vec3& c) 76 76 { 77 Face *f = faces(faces.length()-1); 78 79 if( !f->props ) 80 f->props = new FProp; 81 82 f->props->color = c; 83 return 0; 77 Face *f = faces(faces.length()-1); 78 79 if( !f->props ) 80 { 81 f->props = new FProp; 82 } 83 84 f->props->color = c; 85 86 return 0; 84 87 } 85 88 #endif … … 88 91 int Model::in_VColor(const Vec3& c) 89 92 { 90 Vertex *v = vertices(vertices.length()-1); 91 92 if( !v->props ) 93 v->props = new VProp; 94 95 v->props->color = c; 96 return 0; 93 Vertex *v = vertices(vertices.length()-1); 94 95 if( !v->props ) 96 { 97 v->props = new VProp; 98 } 99 100 v->props->color = c; 101 return 0; 97 102 } 98 103 #endif … … 100 105 Vec3 Model::synthesizeNormal(Vertex *v) 101 106 { 102 Vec3 n(0,0,0); 103 int n_count = 0; 104 105 edge_buffer& edges = v->edgeUses(); 106 for(int i=0; i<edges.length(); i++) 107 { 108 face_buffer& faces = edges(i)->faceUses(); 109 110 for(int j=0; j<faces.length(); j++) 111 { 112 n += faces(j)->plane().normal(); 113 n_count++; 114 } 115 } 116 117 if( n_count ) 118 n /= (real)n_count; 119 else 120 { 107 Vec3 n(0,0,0); 108 int n_count = 0; 109 110 edge_buffer& edges = v->edgeUses(); 111 for(int i=0; i<edges.length(); i++) 112 { 113 face_buffer& faces = edges(i)->faceUses(); 114 115 for(int j=0; j<faces.length(); j++) 116 { 117 n += faces(j)->plane().normal(); 118 n_count++; 119 } 120 } 121 122 if( n_count ) 123 { 124 n /= (real)n_count; 125 } 126 else 127 { 121 128 std::cerr << "Vertex with no normals!!: " << v->uniqID; 122 129 std::cerr << " / " << v->tempID << std::endl; 123 124 130 } 131 return n; 125 132 } 126 133 … … 138 145 Vertex *Model::newVertex(real x, real y, real z) 139 146 { 140 141 142 143 144 /* if( logfile && selected_output&OUTPUT_MODEL_DEFN )145 146 */147 148 149 147 Vertex *v = new Vertex(x, y, z); 148 149 v->vID = v->uniqID = vertices.add(v); 150 151 /* if( logfile && selected_output&OUTPUT_MODEL_DEFN ) 152 *logfile << "v " << x << " " << y << " " << z << std::endl; 153 */ 154 validVertCount++; 155 156 return v; 150 157 } 151 158 152 159 Edge *Model::newEdge(Vertex *a, Vertex *b) 153 160 { 154 155 156 157 158 159 160 161 161 Edge *e = new Edge(a, b); 162 163 e->uniqID = edges.add(e); 164 e->sym()->uniqID = e->uniqID; 165 166 validEdgeCount++; 167 168 return e; 162 169 } 163 170 164 171 static Edge *get_edge(Model *m, Vertex *org, Vertex *v) 165 172 { 166 edge_buffer& edge_uses = org->edgeUses(); 167 168 for(int i=0; i<edge_uses.length(); i++) 169 if( edge_uses(i)->dest() == v ) 170 return edge_uses(i); 171 172 Edge *e = m->newEdge(org, v); 173 174 return e; 175 } 176 173 edge_buffer& edge_uses = org->edgeUses(); 174 175 for (int i=0; i<edge_uses.length(); i++) 176 { 177 if ( edge_uses(i)->dest() == v ) 178 { 179 return edge_uses(i); 180 } 181 } 182 183 Edge *e = m->newEdge(org, v); 184 185 return e; 186 } 177 187 178 188 Face *Model::newFace(Vertex *v1, Vertex *v2, Vertex *v3) 179 189 { 180 181 182 183 184 185 186 187 188 /* if( logfile && selected_output&OUTPUT_MODEL_DEFN )189 *logfile << "f " << v1->uniqID+1 << " "190 << v2->uniqID+1 << " " << v3->uniqID+1 << std::endl;191 */192 193 194 190 Edge *e0 = get_edge(this, v1, v2); // v1->edgeTo(m, v2); 191 Edge *e1 = get_edge(this, v2, v3); // v2->edgeTo(m, v3); 192 Edge *e2 = get_edge(this, v3, v1); // v3->edgeTo(m, v1); 193 194 Face *t = new Face(e0, e1, e2); 195 196 t->uniqID = faces.add(t); 197 198 /* if( logfile && selected_output&OUTPUT_MODEL_DEFN ) 199 *logfile << "f " << v1->uniqID+1 << " " 200 << v2->uniqID+1 << " " << v3->uniqID+1 << std::endl; 201 */ 202 validFaceCount++; 203 204 return t; 195 205 } 196 206 … … 198 208 void Model::killVertex(Vertex *v) 199 209 { 200 201 202 /* if( logfile && selected_output&OUTPUT_CONTRACTIONS )203 *logfile << "v- " << v->uniqID+1 << std::endl;204 */205 v->kill();206 validVertCount--;207 210 if( v->isValid() ) 211 { 212 /* if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 213 *logfile << "v- " << v->uniqID+1 << std::endl; 214 */ 215 v->kill(); 216 validVertCount--; 217 } 208 218 } 209 219 210 220 void Model::killEdge(Edge *e) 211 221 { 212 213 214 e->kill();215 validEdgeCount--;216 222 if( e->isValid() ) 223 { 224 e->kill(); 225 validEdgeCount--; 226 } 217 227 } 218 228 219 229 void Model::killFace(Face *f) 220 230 { 221 222 223 /* if( logfile && selected_output&OUTPUT_CONTRACTIONS )224 *logfile << "f- " << f->uniqID+1 << std::endl;225 */226 f->kill();227 validFaceCount--;228 231 if( f->isValid() ) 232 { 233 /* if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 234 *logfile << "f- " << f->uniqID+1 << std::endl; 235 */ 236 f->kill(); 237 validFaceCount--; 238 } 229 239 } 230 240 231 241 void Model::reshapeVertex(Vertex *v, real x, real y, real z) 232 242 { 233 243 v->set(x, y, z); 234 244 235 245 #ifdef LOG_LOWLEVEL_OPS 236 if( logfile ) 237 *logfile << "v! " << v->uniqID+1 << " " 238 << x << " " << y << " " << z << endl; 246 if( logfile ) 247 { 248 *logfile << "v! " << v->uniqID+1 << " " 249 << x << " " << y << " " << z << endl; 250 } 239 251 #endif 240 252 } … … 242 254 void Model::remapVertex(Vertex *from, Vertex *to) 243 255 { 244 256 from->remapTo(to); 245 257 246 258 #ifdef LOG_LOWLEVEL_OPS 247 248 *logfile << "v> " << from->uniqID+1 << " " << to->uniqID+1 << endl;249 #endif 250 }251 252 259 if( logfile ) 260 { 261 *logfile << "v> " << from->uniqID+1 << " " << to->uniqID+1 << endl; 262 } 263 #endif 264 } 253 265 254 266 void Model::contract(Vertex *v1, … … 257 269 face_buffer& changed) 258 270 { 259 int i; 260 261 /* if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 262 { 263 *logfile << "v% (" << v1->uniqID+1; 271 int i; 272 273 /* if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 274 { 275 *logfile << "v% (" << v1->uniqID+1; 276 for(i=0; i<rest.length(); i++) 277 *logfile << " " << rest(i)->uniqID+1; 278 279 *logfile << ") " << to[X] << " " << to[Y] << " " << to[Z] << std::endl; 280 } 281 */ 282 283 // 284 // Collect all the faces that are going to be changed 285 // 286 contractionRegion(v1, rest, changed); 287 288 reshapeVertex(v1, to[X], to[Y], to[Z]); 289 264 290 for(i=0; i<rest.length(); i++) 265 *logfile << " " << rest(i)->uniqID+1; 266 267 *logfile << ") " << to[X] << " " << to[Y] << " " << to[Z] << std::endl; 268 } 269 */ 270 271 // 272 // Collect all the faces that are going to be changed 273 // 274 contractionRegion(v1, rest, changed); 275 276 reshapeVertex(v1, to[X], to[Y], to[Z]); 277 278 for(i=0; i<rest.length(); i++) 291 { 279 292 rest(i)->remapTo(v1); 280 281 removeDegeneracy(changed); 293 } 294 295 removeDegeneracy(changed); 282 296 } 283 297 284 298 void Model::maybeFixFace(Face *F) 285 299 { 286 287 300 // 301 // Invalid faces do not need to be fixed. 288 302 #ifdef SAFETY 289 290 #endif 291 292 293 294 295 296 297 298 299 // This triangle has been reduced to a point300 killEdge(e0);301 killEdge(e1);302 killEdge(e2);303 304 killFace(F);305 306 307 308 309 310 killEdge(e0);311 e1->remapTo(e2->sym());312 killFace(F);313 314 315 316 killEdge(e2);317 e0->remapTo(e1->sym());318 killFace(F);319 320 321 322 killEdge(e1);323 e0->remapTo(e2->sym());324 killFace(F);325 326 327 328 // This triangle remains non-degenerate329 /* // SUS: recalcular la normal en los triangulos cambiados no degenerados330 331 simplif::Vertex * auxv0 = F->vertex(0);332 simplif::Vertex * auxv1 = F->vertex(1);333 simplif::Vertex * auxv2 = F->vertex(2);334 simplif::Vec3 vd1(auxv1->operator[](simplif::X) - auxv0->operator[](simplif::X),335 336 337 simplif::Vec3 vd2(auxv2->operator[](simplif::X) - auxv0->operator[](simplif::X),338 339 340 341 simplif::unitize(vd1);342 simplif::unitize(vd2);343 344 simplif::Vec3 vn = vd1 ^ vd2;345 simplif::unitize(vn);346 303 assert( F->isValid() ); 304 #endif 305 306 Vertex *v0=F->vertex(0); Vertex *v1=F->vertex(1); Vertex *v2=F->vertex(2); 307 Edge *e0 = F->edge(0); Edge *e1 = F->edge(1); Edge *e2 = F->edge(2); 308 309 bool a=(v0 == v1), b=(v0 == v2), c=(v1 == v2); 310 311 if( a && c ) 312 { 313 // This triangle has been reduced to a point 314 killEdge(e0); 315 killEdge(e1); 316 killEdge(e2); 317 318 killFace(F); 319 } 320 // 321 // In the following 3 cases, the triangle has become an edge 322 else if( a ) 323 { 324 killEdge(e0); 325 e1->remapTo(e2->sym()); 326 killFace(F); 327 } 328 else if( b ) 329 { 330 killEdge(e2); 331 e0->remapTo(e1->sym()); 332 killFace(F); 333 } 334 else if( c ) 335 { 336 killEdge(e1); 337 e0->remapTo(e2->sym()); 338 killFace(F); 339 } 340 else 341 { 342 // This triangle remains non-degenerate 343 /* // SUS: recalcular la normal en los triangulos cambiados no degenerados 344 345 simplif::Vertex * auxv0 = F->vertex(0); 346 simplif::Vertex * auxv1 = F->vertex(1); 347 simplif::Vertex * auxv2 = F->vertex(2); 348 simplif::Vec3 vd1(auxv1->operator[](simplif::X) - auxv0->operator[](simplif::X), 349 auxv1->operator[](simplif::Y) - auxv0->operator[](simplif::Y), 350 auxv1->operator[](simplif::Z) - auxv0->operator[](simplif::Z)); 351 simplif::Vec3 vd2(auxv2->operator[](simplif::X) - auxv0->operator[](simplif::X), 352 auxv2->operator[](simplif::Y) - auxv0->operator[](simplif::Y), 353 auxv2->operator[](simplif::Z) - auxv0->operator[](simplif::Z)); 354 355 simplif::unitize(vd1); 356 simplif::unitize(vd2); 357 358 simplif::Vec3 vn = vd1 ^ vd2; 359 simplif::unitize(vn); 360 347 361 //auxf->vertex_normals[0] = vn; 348 362 //auxf->vertex_normals[1] = vn; … … 358 372 F->vertex_normals[2][simplif::Z] = vn[simplif::Z];*/ 359 373 360 374 } 361 375 } 362 376 363 377 void Model::removeDegeneracy(face_buffer& changed) 364 378 { 365 for(int i=0; i<changed.length(); i++) 379 for(int i=0; i<changed.length(); i++) 380 { 366 381 maybeFixFace(changed(i)); 382 } 367 383 } 368 384 369 385 void Model::contractionRegion(Vertex *v1, 370 const vert_buffer& vertices, 371 face_buffer& changed) 372 { 373 changed.reset(); 374 375 // 376 // First, reset the marks on all reachable vertices 377 int i; 378 379 untagFaceLoop(v1); 380 for(i=0; i<vertices.length(); i++) 386 const vert_buffer& vertices, 387 face_buffer& changed) 388 { 389 changed.reset(); 390 391 // First, reset the marks on all reachable vertices 392 int i; 393 394 untagFaceLoop(v1); 395 396 for(i = 0; i < vertices.length(); i++) 397 { 381 398 untagFaceLoop(vertices(i)); 382 383 // 384 // Now, pick out all the unique reachable faces 385 collectFaceLoop(v1, changed); 386 for(i=0; i<vertices.length(); i++) 399 } 400 401 // Now, pick out all the unique reachable faces 402 collectFaceLoop(v1, changed); 403 404 for(i = 0; i < vertices.length(); i++) 405 { 387 406 collectFaceLoop(vertices(i), changed); 407 } 388 408 } 389 409 … … 391 411 void Model::contractionRegion(Vertex *v1, Vertex *v2, face_buffer& changed) 392 412 { 393 394 395 396 397 398 399 400 401 402 403 413 changed.reset(); 414 415 // 416 // Clear marks on all reachable faces 417 untagFaceLoop(v1); 418 untagFaceLoop(v2); 419 420 // 421 // Collect all the unique reachable faces 422 collectFaceLoop(v1, changed); 423 collectFaceLoop(v2, changed); 404 424 } 405 425 … … 408 428 { 409 429 #ifdef SAFETY 410 assert( v1 != v2); 411 #endif 412 413 /* if( logfile && selected_output&OUTPUT_CONTRACTIONS ) 414 *logfile << "v% (" << v1->uniqID+1 << " " << v2->uniqID+1 << ") " 415 << to[X] << " " 416 << to[Y] << " " 417 << to[Z] << std::endl; 418 */ 419 // 420 // Collect all the faces that are going to be changed 421 // 422 contractionRegion(v1, v2, changed); 423 424 reshapeVertex(v1, to[X], to[Y], to[Z]); 425 426 // 427 // Map v2 ---> v1. This accomplishes the topological change that we want. 428 v2->remapTo(v1); 429 430 removeDegeneracy(changed); 431 } 432 430 assert( v1 != v2); 431 #endif 432 // 433 // Collect all the faces that are going to be changed 434 // 435 contractionRegion(v1, v2, changed); 436 437 reshapeVertex(v1, to[X], to[Y], to[Z]); 438 439 // Map v2 ---> v1. This accomplishes the topological change that we want. 440 v2->remapTo(v1); 441 442 // std::cout << "Contract(QslimInds): " << v2->validID() << " --> " << v1->validID() << std::endl; 443 444 removeDegeneracy(changed); 445 } 433 446 434 447 /* … … 494 507 } 495 508 */ 509 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjModel.h
r1025 r1526 22 22 class Model : public SMF_Model 23 23 { 24 protected: 25 vert_buffer vertices; 26 edge_buffer edges; 27 face_buffer faces; 28 vec3_buffer normals; // SUS 29 vec2_buffer texcoords; 24 protected: 25 26 vert_buffer vertices; 27 edge_buffer edges; 28 face_buffer faces; 29 vec3_buffer normals; // SUS 30 vec2_buffer texcoords; 30 31 31 private:32 private: 32 33 33 void maybeFixFace(Face *);34 void maybeFixFace(Face *); 34 35 35 public: 36 Model() { 37 validVertCount = 0; 38 validEdgeCount = 0; 39 validFaceCount = 0; 40 } 36 public: 37 38 Model() 39 { 40 validVertCount = 0; 41 validEdgeCount = 0; 42 validFaceCount = 0; 43 } 41 44 42 ~Model(){ 43 for (int i=0; i<vertices.length(); i++) 44 delete vertices[i]; 45 for (int i=0; i<edges.length(); i++) 46 delete edges[i]; 47 for (int i=0; i<faces.length(); i++) 48 delete faces[i]; 49 } 45 ~Model() 46 { 47 for (int i=0; i<vertices.length(); i++) 48 { 49 delete vertices[i]; 50 } 50 51 51 Bounds bounds; 52 for (int i=0; i<edges.length(); i++) 53 { 54 delete edges[i]; 55 } 52 56 53 int validVertCount; 54 int validEdgeCount; 55 int validFaceCount; 57 for (int i=0; i<faces.length(); i++) 58 { 59 delete faces[i]; 60 } 61 } 56 62 57 // 58 // Basic model accessor functions 59 // 60 simplif::Vertex *vertex(int i) { return vertices(i); } 61 simplif::Vec3 & normal(int i){ return normals(i); } 62 simplif::Vec2 & texcoord(int i){ return texcoords(i); } 63 simplif::Edge *edge(int i) { return edges(i); } 64 simplif::Face *face(int i) { return faces(i); } 63 Bounds bounds; 65 64 66 int vertCount() { return vertices.length(); } 67 int normCount() { return normals.length(); } 68 int texcoordCount() { return texcoords.length(); } 69 int edgeCount() { return edges.length(); } 70 int faceCount() { return faces.length(); } 65 int validVertCount; 66 int validEdgeCount; 67 int validFaceCount; 71 68 72 vert_buffer& allVertices() { return vertices; } 73 edge_buffer& allEdges() { return edges; } 74 face_buffer& allFaces() { return faces; } 69 // 70 // Basic model accessor functions 71 // 72 simplif::Vertex *vertex(int i) { return vertices(i); } 73 simplif::Vec3 & normal(int i){ return normals(i); } 74 simplif::Vec2 & texcoord(int i){ return texcoords(i); } 75 simplif::Edge *edge(int i) { return edges(i); } 76 simplif::Face *face(int i) { return faces(i); } 75 77 76 // 77 // Simplification primitives 78 // 79 Vertex *newVertex(real x=0.0, real y=0.0, real z=0.0); 80 Edge *newEdge(Vertex *,Vertex *); 81 Face *newFace(Vertex *, Vertex *, Vertex *); 78 int vertCount() { return vertices.length(); } 79 int normCount() { return normals.length(); } 80 int texcoordCount() { return texcoords.length(); } 81 int edgeCount() { return edges.length(); } 82 int faceCount() { return faces.length(); } 82 83 83 void killVertex(Vertex *);84 void killEdge(Edge *);85 void killFace(Face *);84 vert_buffer& allVertices() { return vertices; } 85 edge_buffer& allEdges() { return edges; } 86 face_buffer& allFaces() { return faces; } 86 87 87 void reshapeVertex(Vertex *, real, real, real); 88 void remapVertex(Vertex *from, Vertex *to); 88 // 89 // Simplification primitives 90 // 91 Vertex *newVertex(real x=0.0, real y=0.0, real z=0.0); 92 Edge *newEdge(Vertex *,Vertex *); 93 Face *newFace(Vertex *, Vertex *, Vertex *); 89 94 90 void contract(Vertex *v1, Vertex *v2, const Vec3& to, 91 face_buffer& changed); 95 void killVertex(Vertex *); 96 void killEdge(Edge *); 97 void killFace(Face *); 92 98 93 void contract(Vertex *v1, 94 const vert_buffer& others, 95 const Vec3& to, 96 face_buffer& changed); 99 void reshapeVertex(Vertex *, real, real, real); 100 void remapVertex(Vertex *from, Vertex *to); 97 101 102 void contract(Vertex *v1, Vertex *v2, const Vec3& to, 103 face_buffer& changed); 98 104 99 // 100 // Simplification convenience procedures 101 // 102 void removeDegeneracy(face_buffer& changed); 103 void contractionRegion(Vertex *v1, Vertex *v2, face_buffer& changed); 104 void contractionRegion(Vertex *v1, 105 const vert_buffer& vertices, 106 face_buffer& changed); 105 void contract(Vertex *v1, 106 const vert_buffer& others, 107 const Vec3& to, 108 face_buffer& changed); 107 109 108 //109 // SMF reader functions110 //111 int in_Vertex(const Vec3&);112 int in_Normal(const Vec3&);113 int in_TexCoord(const Vec2&);114 int in_Face(int v1, int v2, int v3, int n1, int n2, int n3, int t1, int t2, int t3);115 int miin_Face(int v1, int v2, int v3);110 // 111 // Simplification convenience procedures 112 // 113 void removeDegeneracy(face_buffer& changed); 114 void contractionRegion(Vertex *v1, Vertex *v2, face_buffer& changed); 115 void contractionRegion(Vertex *v1, 116 const vert_buffer& vertices, 117 face_buffer& changed); 116 118 117 /* #ifdef SUPPORT_VCOLOR 118 int in_VColor(const Vec3&); 119 #endif 120 #ifdef SUPPORT_FCOLOR 121 int in_FColor(const Vec3&); 122 #endif 119 // 120 // SMF reader functions 121 // 122 int in_Vertex(const Vec3&); 123 int in_Normal(const Vec3&); 124 int in_TexCoord(const Vec2&); 125 126 int in_Face(int v1, int v2, int v3, 127 int n1, int n2, int n3, 128 int t1, int t2, int t3); 129 130 int miin_Face(int v1, int v2, int v3); 131 132 /* #ifdef SUPPORT_VCOLOR 133 int in_VColor(const Vec3&); 134 #endif 135 #ifdef SUPPORT_FCOLOR 136 int in_FColor(const Vec3&); 137 #endif 123 138 */ 124 //125 // Some random functions that are mostly temporary126 //139 // 140 // Some random functions that are mostly temporary 141 // 127 142 128 Vec3 synthesizeNormal(Vertex *);143 Vec3 synthesizeNormal(Vertex *); 129 144 }; 130 145 } 131 146 132 133 147 // NAUTILUS_ADJMODEL_INCLUDED 134 148 #endif 149 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjPrims.cxx
r1025 r1526 18 18 { 19 19 #ifdef SAFETY 20 21 #endif 22 23 20 assert( edge_uses.length() == 0 ); 21 #endif 22 markInvalid(); 23 edge_uses.reset(); 24 24 } 25 25 26 26 void Vertex::linkEdge(Edge *e) 27 27 { 28 28 edge_uses.add(e); 29 29 } 30 30 31 31 void Vertex::unlinkEdge(Edge *e) 32 32 { 33 34 35 #ifdef SAFETY 36 37 #endif 38 39 40 kill();33 int index = edge_uses.find(e); 34 35 #ifdef SAFETY 36 assert( index >= 0 ); 37 #endif 38 edge_uses.remove(index); 39 if( edge_uses.length() <= 0 ) 40 kill(); 41 41 } 42 42 … … 45 45 void Vertex::remapTo(Vertex *v) 46 46 { 47 if( v != this )48 49 for (int i=0; i<edge_uses.length(); i++)47 if ( v != this ) 48 { 49 for (int i=0; i<edge_uses.length(); i++) 50 50 { 51 51 assert( edge_uses(i)->org() == this ); … … 54 54 55 55 kill(); 56 } 57 } 58 56 } 57 } 59 58 60 59 Edge::Edge(Vertex *a, Vertex *b) 61 60 { 62 63 64 65 66 67 61 v1 = a; 62 v1->linkEdge(this); 63 64 face_uses = new buffer<Face *>(2); 65 66 twin = new Edge(this, b); 68 67 } 69 68 70 69 Edge::Edge(Edge *sibling, Vertex *org) 71 70 { 72 73 74 75 76 71 v1 = org; 72 v1->linkEdge(this); 73 74 face_uses = sibling->face_uses; 75 twin = sibling; 77 76 } 78 77 79 78 Edge::~Edge() 80 79 { 81 if( twin )82 83 face_uses->f_r_e_e();84 delete face_uses;85 86 twin->twin = NULL;87 delete twin;88 80 if ( twin ) 81 { 82 face_uses->f_r_e_e(); 83 delete face_uses; 84 85 twin->twin = NULL; 86 delete twin; 87 } 89 88 } 90 89 … … 92 91 { 93 92 #ifdef SAFETY 94 95 #endif 96 if( isValid() )97 98 org()->unlinkEdge(this);99 dest()->unlinkEdge(sym());100 markInvalid();101 twin->markInvalid();102 face_uses->reset();103 93 assert( face_uses->length() == 0 ); 94 #endif 95 if ( isValid() ) 96 { 97 org()->unlinkEdge(this); 98 dest()->unlinkEdge(sym()); 99 markInvalid(); 100 twin->markInvalid(); 101 face_uses->reset(); 102 } 104 103 } 105 104 106 105 void Edge::linkFace(Face *face) 107 106 { 108 107 face_uses->add(face); 109 108 } 110 109 111 110 void Edge::unlinkFace(Face *face) 112 111 { 113 114 115 #ifdef SAFETY 116 117 #endif 118 119 120 kill();112 int index = face_uses->find(face); 113 114 #ifdef SAFETY 115 assert( index>=0 ); 116 #endif 117 face_uses->remove(index); 118 if( face_uses->length() == 0 ) 119 kill(); 121 120 } 122 121 123 122 void Edge::remapTo(Edge *e) 124 123 { 125 if( e != this )126 127 for(int i=0; i<face_uses->length(); i++)128 {129 130 }131 132 // Disconnect from all faces and vertices133 kill();134 124 if ( e != this ) 125 { 126 for (int i=0; i<face_uses->length(); i++) 127 { 128 (*face_uses)(i)->remapEdge(this, e); 129 } 130 131 // Disconnect from all faces and vertices 132 kill(); 133 } 135 134 } 136 135 137 136 void Edge::remapEndpoint(Vertex *from, Vertex *to) 138 137 { 139 if( org()==from )140 138 if ( org() == from ) 139 { 141 140 v1 = to; 142 141 to->linkEdge(this); 143 144 else if( dest()==from )145 142 } 143 else if ( dest() == from ) 144 { 146 145 twin->v1 = to; 147 146 to->linkEdge(twin); 148 149 150 147 } 148 else 149 { 151 150 std::cerr << "WARNING remapEndpoint: Illegal endpoint." << std::endl; 152 153 154 155 156 157 for(int i=0; i<face_uses->length(); i++)158 151 } 152 153 // 154 // The cached Plane equations for the faces attached to us may 155 // no longer be valid (in general, chances are pretty slim that they're OK) 156 for (int i = 0; i < face_uses->length(); i++) 157 { 159 158 face_uses->ref(i)->invalidatePlane(); 160 } 161 } 162 159 } 160 } 163 161 164 162 Face::Face(Edge *e0, Edge *e1, Edge *e2) 165 163 : Face3(*e0->org(), *e1->org(), *e2->org()) 166 164 { 167 168 169 170 171 172 173 165 edges[0] = e0; 166 edges[1] = e1; 167 edges[2] = e2; 168 169 edges[0]->linkFace(this); 170 edges[1]->linkFace(this); 171 edges[2]->linkFace(this); 174 172 175 173 #ifdef SUPPORT_FCOLOR 176 174 props = NULL; 177 175 #endif 178 176 } … … 180 178 void Face::kill() 181 179 { 182 183 184 if( edge(0)->isValid() )185 186 187 if( edge(1)->isValid() )188 189 190 if( edge(2)->isValid() )191 192 193 markInvalid();194 180 if( isValid() ) 181 { 182 if( edge(0)->isValid() ) 183 edge(0)->unlinkFace(this); 184 185 if( edge(1)->isValid() ) 186 edge(1)->unlinkFace(this); 187 188 if( edge(2)->isValid() ) 189 edge(2)->unlinkFace(this); 190 191 markInvalid(); 192 } 195 193 } 196 194 197 195 void Face::remapEdge(Edge *from, Edge *to) 198 196 { 199 for(int i=0; i<3; i++) 200 { 201 if( edges[i] == from ) 202 { 203 edges[i] = to; 204 to->linkFace(this); 205 } 206 else if( edges[i] == from->sym() ) 207 { 208 edges[i] = to->sym(); 209 to->sym()->linkFace(this); 210 } 211 } 212 213 invalidatePlane(); 214 } 215 197 for (int i=0; i<3; i++) 198 { 199 if ( edges[i] == from ) 200 { 201 edges[i] = to; 202 to->linkFace(this); 203 } 204 else if ( edges[i] == from->sym() ) 205 { 206 edges[i] = to->sym(); 207 to->sym()->linkFace(this); 208 } 209 } 210 211 invalidatePlane(); 212 } 216 213 217 214 void simplif::untagFaceLoop(Vertex *v) 218 215 { 219 edge_buffer& edges = v->edgeUses(); 220 221 for(int j=0; j<edges.length(); j++) 222 { 223 face_buffer& faces = edges(j)->faceUses(); 224 for(int k=0; k<faces.length(); k++) 225 faces(k)->untag(); 226 } 216 edge_buffer& edges = v->edgeUses(); 217 218 for (int j = 0; j < edges.length(); j++) 219 { 220 face_buffer& faces = edges(j)->faceUses(); 221 222 for (int k = 0; k < faces.length(); k++) 223 { 224 faces(k)->untag(); 225 } 226 } 227 227 } 228 228 229 229 void simplif::collectFaceLoop(Vertex *v, face_buffer& loop) 230 230 { 231 232 233 234 235 face_buffer& faces = edges(j)->faceUses();236 for(int k=0; k<faces.length(); k++)237 238 239 loop.add(faces(k));240 faces(k)->tag();241 242 231 edge_buffer& edges = v->edgeUses(); 232 233 for(int j=0; j<edges.length(); j++) 234 { 235 face_buffer& faces = edges(j)->faceUses(); 236 for(int k=0; k<faces.length(); k++) 237 if( !faces(k)->isTagged() ) 238 { 239 loop.add(faces(k)); 240 faces(k)->tag(); 241 } 242 } 243 243 } 244 244 245 245 int simplif::classifyEdge(Edge *e) 246 246 { 247 248 249 250 251 247 int cls = e->faceUses().length(); 248 249 if( cls>3 ) cls=3; 250 251 return cls; 252 252 } 253 253 254 254 int simplif::classifyVertex(Vertex *v) 255 255 { 256 int border_count = 0; 257 const edge_buffer& edges = v->edgeUses(); 258 259 for(int i=0; i<edges.length(); i++) 260 if( classifyEdge(edges(i)) == 1 ) 261 border_count++; 262 263 if( border_count == edges.length() ) 264 return VERTEX_BORDER_ONLY; 265 else 266 return (border_count > 0); 267 } 256 int border_count = 0; 257 const edge_buffer& edges = v->edgeUses(); 258 259 for(int i=0; i<edges.length(); i++) 260 if( classifyEdge(edges(i)) == 1 ) 261 border_count++; 262 263 if( border_count == edges.length() ) 264 return VERTEX_BORDER_ONLY; 265 else 266 return (border_count > 0); 267 } 268 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/AdjPrims.h
r1025 r1526 27 27 class Face; 28 28 29 30 29 typedef buffer<Vertex *> vert_buffer; 31 30 typedef buffer<Edge *> edge_buffer; … … 37 36 extern void collectFaceLoop(Vertex *v, face_buffer& faces); 38 37 39 40 41 42 38 #define EDGE_BOGUS 0 39 #define EDGE_BORDER 1 40 #define EDGE_MANIFOLD 2 41 #define EDGE_NONMANIFOLD 3 43 42 extern int classifyEdge(Edge *); 44 43 45 46 47 44 #define VERTEX_INTERIOR 0 45 #define VERTEX_BORDER 1 46 #define VERTEX_BORDER_ONLY 2 48 47 extern int classifyVertex(Vertex *); 49 48 … … 52 51 // The actual class definitions 53 52 // 53 //////////////////////////////////////////////////////////////////////// 54 54 55 55 class VProp 56 56 { 57 public:58 Vec3 color;57 public: 58 Vec3 color; 59 59 }; 60 60 61 61 class FProp 62 62 { 63 public:64 Vec3 color;63 public: 64 Vec3 color; 65 65 }; 66 66 … … 68 68 { 69 69 edge_buffer edge_uses; 70 71 public:72 70 71 public: 72 #ifdef SUPPORT_VCOLOR 73 73 VProp *props; 74 74 #endif 75 75 76 76 Vertex(real x, real y, real z) : Vec3(x, y, z), edge_uses(6) { 77 78 props = NULL;79 #endif 77 #ifdef SUPPORT_VCOLOR 78 props = NULL; 79 #endif 80 80 } 81 81 // … … 92 92 void remapTo(Vertex *v); 93 93 94 unsigned int vID; 94 // SUS 95 int vID; // this can be -1 when the vertex becomes non-valid 95 96 }; 96 97 97 98 98 class Edge : public NPrim 99 99 { 100 private:100 private: 101 101 102 Vertex *v1;102 Vertex *v1; 103 103 104 face_buffer *face_uses;105 Edge *twin;104 face_buffer *face_uses; 105 Edge *twin; 106 106 107 Edge(Edge *twin, Vertex *org); // the twin constructor107 Edge(Edge *twin, Vertex *org); // the twin constructor 108 108 109 public: 110 Edge(Vertex *, Vertex *); 111 ~Edge(); 109 public: 112 110 113 // 114 // Fundamental Edge accessors 115 // 116 Vertex *org() { return v1; } 117 Vertex *dest() { return twin->v1; } 118 Edge *sym() { return twin; } 111 Edge(Vertex *, Vertex *); 112 ~Edge(); 119 113 120 // 121 // Standard methods for all objects 122 // 123 void kill(); 124 face_buffer& faceUses() { return *face_uses; } 114 // 115 // Fundamental Edge accessors 116 // 117 Vertex *org() { return v1; } 118 Vertex *dest() { return twin->v1; } 119 Edge *sym() { return twin; } 125 120 126 // 127 // Basic primitives for manipulating model topology 128 // 129 void linkFace(Face *); 130 void unlinkFace(Face *); 131 void remapEndpoint(Vertex *from, Vertex *to); 132 void remapTo(Edge *); 121 // 122 // Standard methods for all objects 123 // 124 void kill(); 125 face_buffer& faceUses() { return *face_uses; } 126 127 // 128 // Basic primitives for manipulating model topology 129 // 130 void linkFace(Face *); 131 void unlinkFace(Face *); 132 void remapEndpoint(Vertex *from, Vertex *to); 133 void remapTo(Edge *); 133 134 }; 134 135 … … 137 138 Edge *edges[3]; 138 139 139 140 public: 141 #ifdef SUPPORT_FCOLOR 140 public: 141 #ifdef SUPPORT_FCOLOR 142 142 FProp *props; 143 143 #endif 144 144 145 145 Face(Edge *, Edge *, Edge *); … … 148 148 // Basic Face accessors 149 149 // 150 const Vec3& vertexPos(int i) const { return *edges[i]->org(); } 151 void vertexPos(int, const Vec3&) { 150 const Vec3& vertexPos(int i) const{return *edges[i]->org();} 151 152 void vertexPos(int, const Vec3&) 153 { 152 154 fatal_error("Face: can't directly set vertex position."); 153 155 } 154 156 155 Vertex *vertex(int i) { return edges[i]->org(); } 156 const Vertex *vertex(int i) const { return edges[i]->org(); } 157 Edge *edge(int i) { return edges[i]; } 158 157 Vertex *vertex(int i){return edges[i]->org();} 158 const Vertex *vertex(int i) const{return edges[i]->org();} 159 Edge *edge(int i){return edges[i];} 159 160 160 161 // … … 173 174 } 174 175 175 176 176 // NAUTILUS_ADJPRIMS_INCLUDED 177 177 #endif 178 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.cpp
r1025 r1526 6 6 using namespace std; 7 7 using namespace Geometry; 8 using namespace simplif; 8 9 9 10 #include <gfx/geom/ProxGrid.h> … … 13 14 // Constructor 14 15 //--------------------------------------------------------------------------- 15 SimplificationMethod::SimplificationMethod(const Mesh *m) 16 SimplificationMethod::SimplificationMethod(const Mesh *m) 16 17 { 17 18 objmesh = m; … … 19 20 first_index_submesh = new unsigned int[objmesh->mSubMeshCount]; 20 21 indexMeshLeaves = -1; 22 23 // Create simplification sequence. 24 msimpseq = new MeshSimplificationSequence(); 21 25 } 22 26 … … 41 45 simplif::vert_info& v1_info = vertex_info(v1); 42 46 43 simplif::Mat4 Q =v0_info.Q + v1_info.Q;44 simplif::real norm =v0_info.norm + v1_info.norm;47 simplif::Mat4 Q = v0_info.Q + v1_info.Q; 48 simplif::real norm = v0_info.norm + v1_info.norm; 45 49 46 50 auxpair->cost = simplif::quadrix_pair_target(Q, v0, v1, auxpair->candidate); 47 51 48 if( simplif::will_weight_by_area ) 52 if ( simplif::will_weight_by_area ) 53 { 49 54 auxpair->cost /= norm; 50 51 if( simplif::will_preserve_mesh_quality ) 55 } 56 57 if ( simplif::will_preserve_mesh_quality ) 58 { 52 59 auxpair->cost += pair_mesh_penalty(M0, v0, v1, auxpair->candidate); 53 60 } 54 61 55 62 // … … 57 64 // the heap is implemented as a MAX heap. 58 65 // 59 if ( auxpair->isInHeap() )66 if ( auxpair->isInHeap() ) 60 67 { 61 68 heap->update(auxpair, (float)-auxpair->cost); … … 70 77 // Reasign the new vertex to the adequate face 71 78 //--------------------------------------------------------------------------- 72 int SimplificationMethod::predict_face(simplif::Face& F, simplif::Vertex *v1, simplif::Vertex *v2, simplif::Vec3& vnew, simplif::Vec3& f1, simplif::Vec3& f2, simplif::Vec3& f3) 79 int SimplificationMethod::predict_face( simplif::Face& F, 80 simplif::Vertex *v1, 81 simplif::Vertex *v2, 82 simplif::Vec3& vnew, 83 simplif::Vec3& f1, 84 simplif::Vec3& f2, 85 simplif::Vec3& f3) 73 86 { 74 87 int nmapped = 0; 75 88 76 89 if( F.vertex(0) == v1 || F.vertex(0) == v2 ) 77 { f1 = vnew; nmapped++; } 78 else f1 = *F.vertex(0); 90 { 91 f1 = vnew; nmapped++; 92 } 93 else 94 { 95 f1 = *F.vertex(0); 96 } 79 97 80 98 if( F.vertex(1) == v1 || F.vertex(1) == v2 ) 81 { f2 = vnew; nmapped++; } 82 else f2 = *F.vertex(1); 99 { 100 f2 = vnew; nmapped++; 101 } 102 else 103 { 104 f2 = *F.vertex(1); 105 } 83 106 84 107 if( F.vertex(2) == v1 || F.vertex(2) == v2 ) 85 { f3 = vnew; nmapped++; } 86 else f3 = *F.vertex(2); 108 { 109 f3 = vnew; nmapped++; 110 } 111 else 112 { 113 f3 = *F.vertex(2); 114 } 87 115 88 116 return nmapped; … … 93 121 //--------------------------------------------------------------------------- 94 122 //--------------------------------------------------------------------------- 95 simplif::real SimplificationMethod::pair_mesh_penalty(simplif::Model& M, simplif::Vertex *v1, simplif::Vertex *v2, simplif::Vec3& vnew) 123 simplif::real SimplificationMethod::pair_mesh_penalty(simplif::Model& M, simplif::Vertex *v1, 124 simplif::Vertex *v2, 125 simplif::Vec3& vnew) 96 126 { 97 127 static simplif::face_buffer changed; 128 98 129 changed.reset(); 99 130 … … 103 134 simplif::real Nmin = 0; 104 135 105 for (int i=0; i<changed.length(); i++)136 for (int i = 0; i < changed.length(); i++) 106 137 { 107 138 simplif::Face& F = *changed(i); … … 114 145 { 115 146 simplif::Plane Pnew(f1, f2, f3); 147 116 148 simplif::real delta = Pnew.normal() * F.plane().normal(); 117 149 118 if( Nmin > delta ) Nmin = delta; 150 if( Nmin > delta ) 151 { 152 Nmin = delta; 153 } 119 154 } 120 155 } … … 122 157 //return (-Nmin) * MESH_INVERSION_PENALTY; 123 158 if( Nmin < 0.0 ) 159 { 124 160 return MESH_INVERSION_PENALTY; 161 } 125 162 else 163 { 126 164 return 0.0; 165 } 127 166 } 128 167 … … 130 169 // Returns true if the givens vertices are a valid pair 131 170 //--------------------------------------------------------------------------- 132 bool SimplificationMethod::check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1) 171 bool SimplificationMethod::check_for_pair(simplif::Vertex *v0, 172 simplif::Vertex *v1) 133 173 { 134 174 const simplif::pair_buffer& pairs = vertex_info(v0).pairs; … … 137 177 { 138 178 if( pairs(i)->v0==v1 || pairs(i)->v1==v1 ) 179 { 139 180 return true; 181 } 140 182 } 141 183 … … 146 188 // Create a new pair with two given vertices 147 189 //--------------------------------------------------------------------------- 148 simplif::pair_info *SimplificationMethod::new_pair(simplif::Vertex *v0, simplif::Vertex *v1) 190 simplif::pair_info *SimplificationMethod::new_pair( simplif::Vertex *v0, 191 simplif::Vertex *v1) 149 192 { 150 193 simplif::vert_info& v0_info = vertex_info(v0); … … 152 195 153 196 simplif::pair_info *pair = new simplif::pair_info(v0,v1); 197 154 198 v0_info.pairs.add(pair); 155 199 v1_info.pairs.add(pair); … … 169 213 v1_info.pairs.remove(v1_info.pairs.find(auxpair)); 170 214 171 if( auxpair->isInHeap() ) 215 if ( auxpair->isInHeap() ) 216 { 172 217 heap->kill(auxpair->getHeapPos()); 218 } 173 219 174 220 delete auxpair; … … 178 224 // Contract a given pair 179 225 //--------------------------------------------------------------------------- 180 void SimplificationMethod::do_contract(simplif::Model& m, simplif::pair_info *auxpair) 181 { 182 simplif::Vertex *v0 = auxpair->v0; simplif::Vertex *v1 = auxpair->v1; 226 void SimplificationMethod::do_contract( simplif::Model& m, 227 simplif::pair_info *auxpair) 228 { 229 simplif::Vertex *v0 = auxpair->v0; 230 simplif::Vertex *v1 = auxpair->v1; 183 231 simplif::vert_info& v0_info = vertex_info(v0); 184 232 simplif::vert_info& v1_info = vertex_info(v1); 185 simplif::Vec3 vnew = auxpair->candidate; 233 simplif::Vec3 vnew = auxpair->candidate; 234 186 235 int i; 236 237 // V0 must be always the alive vertex 238 // V1 must be always the removed vertex 239 if (vnew == (*v0)) 240 { 241 // Simplification step. 242 simplifstep.mV0 = v0->vID; 243 simplifstep.mV1 = v1->vID; 244 } 245 else 246 { 247 // Simplification step. 248 simplifstep.mV0 = v1->vID; 249 simplifstep.mV1 = v0->vID; 250 v0->vID = v1->vID; 251 } 187 252 188 253 // Make v0 be the new vertex 189 v0_info.Q 190 v0_info.norm 254 v0_info.Q += v1_info.Q; 255 v0_info.norm += v1_info.norm; 191 256 192 257 simplif::Vec3 p(vnew); 193 simplif::Vec3 v0antes(v0->operator[](simplif::X),v0->operator[](simplif::Y),v0->operator[](simplif::Z)); 194 195 // Find the edge to remove (before remove it (contract())) 196 simplif::Edge *econ=NULL; 197 bool finded = false; 198 for (i=0; i<v0->edgeUses().length(); i++) 199 { 200 econ = v0->edgeUses()(i); 201 if (v1->vID == econ->org()->vID || v1->vID == econ->dest()->vID) 202 { 203 finded = true; 204 break; 205 } 206 } 207 208 assert(finded); 209 210 211 // Perform the actual contraction 258 /* simplif::Vec3 v0antes(v0->operator[](simplif::X), 259 v0->operator[](simplif::Y), 260 v0->operator[](simplif::Z));*/ 261 262 // Perform the actual contraction. 212 263 static simplif::face_buffer changed; 264 213 265 changed.reset(); 214 266 m.contract(v0, v1, vnew, changed); 215 267 216 // Stores the simplification step 217 MeshSimplificationSequence::Step simplifstep; 218 simplif::Vec3 vdesp = p - v0antes; 219 220 // Stores the displacement in the simplification step 221 simplifstep.x=(float)vdesp[simplif::X]; 222 simplifstep.y = (float)vdesp[simplif::Y]; 223 simplifstep.z = (float)vdesp[simplif::Z]; 224 225 // Submeshes which pertains each vertex 226 simplifstep.mV1 = v0->validID(); 227 228 // The simplification method returns as v1 the dead vertex. 229 simplifstep.mV0 = v1->validID(); 268 std::cout << "Simp seq: " << simplifstep.mV1 << " --> " << simplifstep.mV0 << std::endl; 269 270 /* simplif::Vec3 vdesp = p - v0antes; 271 272 // Stores the displacement in the simplification step. 273 simplifstep.x = (float)vdesp[X]; 274 simplifstep.y = (float)vdesp[Y]; 275 simplifstep.z = (float)vdesp[Z];*/ 276 277 // Stores the displacement in the simplification step. 278 simplifstep.x = (float)0.0f; 279 simplifstep.y = (float)0.0f; 280 simplifstep.z = (float)0.0f; 230 281 231 282 // Number of triangles that are removed in this simplification step. … … 242 293 int del_index = 0; 243 294 244 // mModfaces y mT0, mT1 of simplifstep stores the triangles id's -> geomesh has not triangles id's 245 for (i=0; i<changed.length(); i++) 246 { 247 simplif::Face *auxface = changed(i); 295 // Clears faces list. 296 simplifstep.mModfaces.clear(); 297 298 // mModfaces y mT0, mT1 of simplifstep stores 299 // the triangles id's -> geomesh has not triangles id's. 300 for (i = 0; i < changed.length(); i++) 301 { 302 simplif::Face *auxface = changed(i); 248 303 249 304 if (auxface->isValid()) 250 305 { 251 // Modified triangles306 // Modified triangles. 252 307 simplifstep.mModfaces.push_back(auxface->validID()); 253 308 } 254 309 else 255 310 { 256 // Removed triangles257 if (_numDelTris ==1)258 { 259 simplifstep.mT0 =auxface->validID();260 simplifstep.mT1 =auxface->validID();311 // Removed triangles. 312 if (_numDelTris == 1) 313 { 314 simplifstep.mT0 = auxface->validID(); 315 simplifstep.mT1 = auxface->validID(); 261 316 } 262 317 else 263 318 { 264 if(del_index ==0)319 if(del_index == 0) 265 320 { 266 simplifstep.mT0 =auxface->validID();321 simplifstep.mT0 = auxface->validID(); 267 322 del_index++; 268 323 } 269 324 else 270 325 { 271 simplifstep.mT1 =auxface->validID();326 simplifstep.mT1 = auxface->validID(); 272 327 } 273 328 } … … 275 330 } 276 331 277 decim_data.push_back(simplifstep); // Simplification sequence that make reference to the simplification method sequence 332 // Simplification sequence that make reference to the 333 // simplification method sequence. 334 //decim_data.push_back(simplifstep); 335 336 // Adds new simplification step. 337 msimpseq->mSteps.push_back(simplifstep); 278 338 279 339 #ifdef SUPPORT_VCOLOR 280 // 281 // If the vertices are colored, color the new vertex 282 // using the average of the old colors. 340 // If the vertices are colored, color the new vertex 341 // using the average of the old colors. 283 342 v0->props->color += v1->props->color; 284 343 v0->props->color /= 2; 285 344 #endif 286 345 287 // Remove the pair that we just contracted346 // Remove the pair that we just contracted. 288 347 delete_pair(auxpair); 289 348 290 // Recalculate pairs associated with v0291 for (i=0; i<v0_info.pairs.length();i++)349 // Recalculate pairs associated with v0. 350 for (i = 0; i < v0_info.pairs.length(); i++) 292 351 { 293 352 simplif::pair_info *p = v0_info.pairs(i); … … 295 354 } 296 355 297 // Process pairs associated with now dead vertex 298 static simplif::pair_buffer condemned(6); // collect condemned pairs for execution 356 // Process pairs associated with now dead vertex. 357 // Collect condemned pairs for execution. 358 static simplif::pair_buffer condemned(6); 359 299 360 condemned.reset(); 300 361 301 for (i=0; i<v1_info.pairs.length(); i++)362 for (i = 0; i < v1_info.pairs.length(); i++) 302 363 { 303 364 simplif::pair_info *p = v1_info.pairs(i); 304 365 305 366 simplif::Vertex *u; 306 if( p->v0 == v1 ) 367 368 if( p->v0 == v1 ) 369 { 307 370 u = p->v1; 308 else 309 if( p->v1 == v1) 371 } 372 else 373 { 374 if( p->v1 == v1) 375 { 310 376 u = p->v0; 377 } 311 378 else 379 { 312 380 std::cerr << "YOW! This is a bogus pair." << endl; 313 314 if( !check_for_pair(u, v0) ) 315 { 316 p->v0 = v0; 317 p->v1 = u; 381 } 382 } 383 384 if ( !check_for_pair(u, v0) ) 385 { 386 p->v0 = v0; 387 p->v1 = u; 388 318 389 v0_info.pairs.add(p); 319 390 compute_pair_info(p); 320 391 } 321 392 else 393 { 322 394 condemned.add(p); 323 } 324 325 for(i=0; i<condemned.length(); i++) 395 } 396 } 397 398 for (i = 0; i < condemned.length(); i++) 399 { 326 400 // Do you have any last requests? 327 401 delete_pair(condemned(i)); 328 v1_info.pairs.reset(); // safety precaution 329 330 } 331 332 //--------------------------------------------------------------------------- 333 //--------------------------------------------------------------------------- 334 bool SimplificationMethod::decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q) 402 } 403 404 // Safety precaution. 405 v1_info.pairs.reset(); 406 } 407 408 //--------------------------------------------------------------------------- 409 //--------------------------------------------------------------------------- 410 bool SimplificationMethod::decimate_quadric(simplif::Vertex *v, 411 simplif::Mat4& Q) 335 412 { 336 413 if( vinfo.length() > 0 ) … … 340 417 } 341 418 else 419 { 342 420 return false; 421 } 343 422 } 344 423 … … 347 426 //--------------------------------------------------------------------------- 348 427 void SimplificationMethod::decimate_contract(simplif::Model& m) 428 { 429 simplif::heap_node *top; 430 simplif::pair_info *pair; 431 simplif::Vertex *v0; 432 simplif::Vertex *v1; 433 simplif::Vec3 candidate; 434 435 for (;;) 436 { 437 top = heap->extract(); 438 439 if (!top) 440 { 441 return; 442 } 443 444 pair = (simplif::pair_info *)top->obj; 445 446 // Remove all the vertices of the removed edges. 447 bool sharededge = false; 448 449 for (int i = 0; i < pair->v0->edgeUses().length(); i++) 450 { 451 simplif::Edge *econ = pair->v0->edgeUses()(i); 452 453 if (pair->v1->vID == econ->org()->vID 454 || 455 pair->v1->vID == econ->dest()->vID) 456 { 457 sharededge = true; 458 break; 459 } 460 } 461 462 if (pair->isValid() && sharededge) 463 { 464 break; 465 } 466 467 // Deletes repetitions of pair in heap. 468 delete_pair(pair); 469 } 470 471 // Copy pair. 472 v0 = new Vertex( pair->v0->operator[](0), 473 pair->v0->operator[](1), 474 pair->v0->operator[](2)); 475 v0->uniqID = pair->v0->uniqID; 476 477 v1 = new Vertex( pair->v1->operator[](0), 478 pair->v1->operator[](1), 479 pair->v1->operator[](2)); 480 481 v1->uniqID = pair->v1->uniqID; 482 483 candidate = pair->candidate; 484 485 // First contract. 486 simplifstep.obligatory = 0; 487 488 // Debug. 489 cout << "Contracting..." << endl; 490 491 // Contract main pair. 492 do_contract(m, pair); 493 494 // Twin contract and lonely vertex contract. 495 simplifstep.obligatory = 1; 496 497 // Attempt to maintain valid vertex information. 498 M0.validVertCount--; 499 500 // Find an edge of the same coordinates and different vertex identifiers. 501 removeTwinEdges(m,v0,v1,candidate); 502 503 // Move vertex of non twin edges. 504 contractLonelyVertices(m,v0,v1,candidate); 505 506 // Free Memory. 507 delete v0; 508 delete v1; 509 } 510 511 //--------------------------------------------------------------------------- 512 // Contract lonely vertex that has the same coords that the contracted one. 513 //--------------------------------------------------------------------------- 514 void SimplificationMethod::contractLonelyVertices( simplif::Model &m, simplif::Vertex *v0, 515 simplif::Vertex *v1, 516 simplif::Vec3 candidate) 517 { 518 bool lonely_vertex_found; 519 simplif::Vertex *vert; 520 simplif::Vertex *new_vert; 521 simplif::Vertex *lonely_vert; 522 simplif::Edge *edge; 523 simplif::heap_node *top; 524 simplif::pair_info *pair; 525 simplif::vert_info new_vert_info; 526 Geometry::GeoVertex vertex_added; 527 simplif::Vertex *take_bone_from_vert; 528 529 // Gets the vertex that is not the candidate. 530 if ((*v0) == candidate) 531 { 532 vert = v1; 533 take_bone_from_vert = v0; 534 } 535 else if ((*v1) == candidate) 536 { 537 vert = v0; 538 take_bone_from_vert = v1; 539 } 540 541 // For all vertex. 542 for (int i = 0; i < heap->getSize(); i++) 543 { 544 // Initialize lonely vertex flag. 545 lonely_vertex_found = false; 546 547 // Gets the current pair. 548 top = heap->getElement(i); 549 pair = (simplif::pair_info *)top->obj; 550 551 if (pair->v0->isValid() && (*vert) == (*pair->v0)) 552 { 553 lonely_vert = pair->v0; 554 lonely_vertex_found = true; 555 } 556 else if (pair->v1->isValid() && (*vert) == (*pair->v1)) 557 { 558 lonely_vert = pair->v1; 559 lonely_vertex_found = true; 560 } 561 562 // If a lonely vertex is found. Creates new vertex and contract. 563 if (lonely_vertex_found) 564 { 565 new_vert = m.newVertex(candidate[X],candidate[Y],candidate[Z]); 566 edge = m.newEdge(new_vert,lonely_vert); 567 568 // We assume here the there are the same number of vertices and texture coordinates and normals 569 570 // assign a texture coordinate for the vbertex 571 simplif::Vec2 newtexcoord = m.texcoord(lonely_vert->validID()); 572 m.in_TexCoord(newtexcoord); 573 574 // assign a normal coordinate for the vbertex 575 simplif::Vec3 newnormal = m.normal(lonely_vert->validID()); 576 m.in_Normal(newnormal); 577 578 // Adds new vertex information to simplification sequence. 579 vertex_added.id = new_vert->vID; 580 vertex_added.bonefrom = take_bone_from_vert->vID; 581 vertex_added.position = Vector3(candidate[X],candidate[Y],candidate[Z]); 582 583 simplif::Vec2 tc = m.texcoord(new_vert->validID()); 584 vertex_added.texcoord = Vector2(tc[X],tc[Y]); 585 586 simplif::Vec3 vn = m.normal(new_vert->validID()); 587 vertex_added.normal = Vector3(vn[X],vn[Y],vn[Z]); 588 589 msimpseq->mNewVertices.push_back(vertex_added); 590 591 pair = new_pair(new_vert,lonely_vert); 592 pair->candidate = candidate; 593 594 pair->notInHeap(); 595 /* vinfo(new_vert->validID()).Q = vinfo(lonely_vert->validID()).Q; 596 vinfo(new_vert->validID()).norm = vinfo(lonely_vert->validID()).norm;*/ 597 598 // Debug. 599 cout << "Contracting new pair..." << endl; 600 601 // Contract twin pair. 602 do_contract(m, pair); 603 M0.validVertCount--; 604 } 605 } 606 } 607 608 //--------------------------------------------------------------------------- 609 // Find a twin edge of the given one. 610 //--------------------------------------------------------------------------- 611 void SimplificationMethod::removeTwinEdges( simplif::Model &m, 612 simplif::Vertex *v0, 613 simplif::Vertex *v1, 614 simplif::Vec3 candidate) 615 { 616 bool twin_found; 617 simplif::heap_node *top; 618 simplif::pair_info *pair; 619 simplif::Vertex *aux_vert; 620 621 // Find a twin edge in heap. 622 for (int i = 0; i < heap->getSize(); i++) 623 { 624 // Initialize twin flag. 625 twin_found = false; 626 627 // Gets the current pair. 628 top = heap->getElement(i); 629 pair = (simplif::pair_info *)top->obj; 630 631 if (pair->v0->isValid()==false || pair->v1->isValid()==false) 632 continue; 633 634 if (v0->operator[](0) == pair->v0->operator[](0) 635 && 636 v0->operator[](1) == pair->v0->operator[](1) 637 && 638 v0->operator[](2) == pair->v0->operator[](2)) 639 { 640 if (v1->operator[](0) == pair->v1->operator[](0) 641 && 642 v1->operator[](1) == pair->v1->operator[](1) 643 && 644 v1->operator[](2) == pair->v1->operator[](2)) 645 { 646 // Debug. 647 cout << "Twin contracted (NO Swap)..." << endl; 648 649 // Active twin flag. 650 twin_found = true; 651 } 652 } 653 else 654 { 655 // If there is a twin edge in reverse order. 656 if (v0->operator[](0) == pair->v1->operator[](0) 657 && 658 v0->operator[](1) == pair->v1->operator[](1) 659 && 660 v0->operator[](2) == pair->v1->operator[](2)) 661 { 662 if (v1->operator[](0) == pair->v0->operator[](0) 663 && 664 v1->operator[](1) == pair->v0->operator[](1) 665 && 666 v1->operator[](2) == pair->v0->operator[](2)) 667 { 668 // Debug. 669 cout << "Twin contracted (Swap)..." << endl; 670 671 // Swap. 672 aux_vert = pair->v0; 673 pair->v0 = pair->v1; 674 pair->v1 = aux_vert; 675 676 // Active twin flag. 677 twin_found = true; 678 } 679 } 680 } 681 682 // If a twin edge has been found. 683 if (twin_found) 684 { 685 // Extract twin edge from heap. 686 top = heap->extract(i); 687 pair = (simplif::pair_info *)top->obj; 688 689 // Copy candidate. 690 pair->candidate = candidate; 691 692 // Contract twin pair. 693 do_contract(m, pair); 694 i--; 695 M0.validVertCount--; 696 } 697 } 698 } 699 700 //--------------------------------------------------------------------------- 701 //--------------------------------------------------------------------------- 702 simplif::real SimplificationMethod::decimate_error(simplif::Vertex *v) 703 { 704 simplif::vert_info& info = vertex_info(v); 705 706 simplif::real err = simplif::quadrix_evaluate_vertex(*v, info.Q); 707 708 if( simplif::will_weight_by_area ) 709 { 710 err /= info.norm; 711 } 712 713 return err; 714 } 715 716 //--------------------------------------------------------------------------- 717 // Extract the minimum cost of the the valid nodes (not simplified) 718 //--------------------------------------------------------------------------- 719 simplif::real SimplificationMethod::decimate_min_error() 349 720 { 350 721 simplif::heap_node *top; … … 353 724 for(;;) 354 725 { 355 top = heap->extract(); 356 if( !top ) return; 726 top = heap->top(); 727 728 if( !top ) 729 { 730 return -1.0; 731 } 732 357 733 pair = (simplif::pair_info *)top->obj; 358 734 359 //Remove all the vertices of the removed edges 360 bool sharededge= false; 361 for (int i=0; i<pair->v0->edgeUses().length(); i++) 362 { 363 simplif::Edge *econ = pair->v0->edgeUses()(i); 364 if (pair->v1->vID == econ->org()->vID || pair->v1->vID == econ->dest()->vID) 365 { 366 sharededge= true; 367 break; 368 } 369 370 } 371 372 if( pair->isValid() && sharededge) 735 if( pair->isValid() ) 736 { 373 737 break; 374 375 delete_pair(pair); 376 } 377 378 do_contract(m, pair); 379 380 M0.validVertCount--; // Attempt to maintain valid vertex information 381 } 382 383 //--------------------------------------------------------------------------- 384 //--------------------------------------------------------------------------- 385 simplif::real SimplificationMethod::decimate_error(simplif::Vertex *v) 386 { 387 simplif::vert_info& info = vertex_info(v); 388 389 simplif::real err = simplif::quadrix_evaluate_vertex(*v, info.Q); 390 391 if( simplif::will_weight_by_area ) 392 err /= info.norm; 393 394 return err; 395 } 396 397 //--------------------------------------------------------------------------- 398 // Extract the minimum cost of the the valid nodes (not simplified) 399 //--------------------------------------------------------------------------- 400 simplif::real SimplificationMethod::decimate_min_error() 401 { 402 simplif::heap_node *top; 403 simplif::pair_info *pair; 404 405 for(;;) 406 { 407 top = heap->top(); 408 if( !top ) return -1.0; 409 pair = (simplif::pair_info *)top->obj; 410 411 if( pair->isValid() ) 412 break; 738 } 413 739 414 740 top = heap->extract(); … … 442 768 int i,j; 443 769 444 vinfo.init(m.vertCount()); 445 446 if( simplif::will_use_vertex_constraint ) 447 for(i=0; i<m.vertCount(); i++) 448 { 449 simplif::Vertex *v = m.vertex(i); 450 if( v->isValid() ) 770 // Reserve memory for vert_info array. 771 vinfo.init(m.vertCount()*10); 772 773 if (simplif::will_use_vertex_constraint) 774 { 775 // For each vertex, calculate contraints. 776 for (i = 0; i < m.vertCount(); i++) 777 { 778 simplif::Vertex *v = m.vertex(i); 779 780 if (v->isValid()) 781 { 451 782 vertex_info(v).Q = simplif::quadrix_vertex_constraint(*v); 452 } 453 454 for(i=0; i<m.faceCount(); i++) 455 if( m.face(i)->isValid() ) 456 { 457 if( simplif::will_use_plane_constraint ) 783 } 784 } 785 } 786 787 // Sets the fill value of the vinfo buffer. 788 //vinfo.setFill(m.vertCount()); 789 790 // For each face, recalculate constraints. 791 for (i = 0; i < m.faceCount(); i++) 792 { 793 if (m.face(i)->isValid()) 794 { 795 if (simplif::will_use_plane_constraint) 458 796 { 459 797 simplif::Mat4 Q = simplif::quadrix_plane_constraint(*m.face(i)); 460 798 simplif::real norm = 0.0; 461 799 462 if ( simplif::will_weight_by_area)800 if (simplif::will_weight_by_area) 463 801 { 464 norm =m.face(i)->area();465 Q *=norm;802 norm = m.face(i)->area(); 803 Q *= norm; 466 804 } 467 805 468 for (j=0; j<3;j++)806 for (j = 0; j < 3; j++) 469 807 { 470 vertex_info(m.face(i)->vertex(j)).Q += Q; 471 vertex_info(m.face(i)->vertex(j)).norm += norm; 472 808 vertex_info(m.face(i)->vertex(j)).Q += Q; 809 vertex_info(m.face(i)->vertex(j)).norm += norm; 473 810 } 474 811 } 475 812 } 476 477 if( simplif::will_constrain_boundaries ) 478 { 479 for(i=0; i<m.edgeCount(); i++) 480 if( m.edge(i)->isValid() && simplif::check_for_discontinuity(m.edge(i)) ) 813 } 814 815 if (simplif::will_constrain_boundaries) 816 { 817 // For each edge, recalculate constraints. 818 for (i = 0; i < m.edgeCount(); i++) 819 { 820 if (m.edge(i)->isValid() && simplif::check_for_discontinuity(m.edge(i))) 481 821 { 482 822 simplif::Mat4 B = simplif::quadrix_discontinuity_constraint(m.edge(i)); 483 823 simplif::real norm = 0.0; 484 824 485 if ( simplif::will_weight_by_area)825 if (simplif::will_weight_by_area) 486 826 { 487 norm =simplif::norm2(*m.edge(i)->org() - *m.edge(i)->dest());488 B *=norm;827 norm = simplif::norm2(*m.edge(i)->org() - *m.edge(i)->dest()); 828 B *= norm; 489 829 } 490 830 … … 495 835 vertex_info(m.edge(i)->dest()).norm += norm; 496 836 } 497 } 498 837 } 838 } 839 840 // Create heap. 499 841 heap = new simplif::Heap(m.validEdgeCount); 500 842 501 843 int pair_count = 0; 502 844 503 for(i=0; i<m.edgeCount(); i++) 504 if( m.edge(i)->isValid() ) 845 // For each edge, add pairs to heap. 846 for (i = 0; i < m.edgeCount(); i++) 847 { 848 if (m.edge(i)->isValid()) 505 849 { 506 850 simplif::pair_info *pair = new_pair(m.edge(i)->org(), m.edge(i)->dest()); … … 509 853 pair_count++; 510 854 } 511 512 if( limit<0 ) 513 { 514 limit = m.bounds.radius * 0.05; 515 } 516 proximity_limit = limit * limit; 517 if( proximity_limit > 0 ) 855 } 856 857 if (limit < 0) 858 { 859 limit = m.bounds.radius * 0.05; 860 } 861 862 proximity_limit = limit * limit; 863 864 if (proximity_limit > 0) 518 865 { 519 866 simplif::ProxGrid grid(m.bounds.min, m.bounds.max, limit); 520 for(i=0; i<m.vertCount(); i++) 867 868 // Add points to grid. 869 for (i = 0; i < m.vertCount(); i++) 870 { 521 871 grid.addPoint(m.vertex(i)); 872 } 522 873 523 874 simplif::buffer<simplif::Vec3 *> nearby(32); 524 for(i=0; i<m.vertCount(); i++) 875 876 // For each vertex. 877 for (i = 0; i < m.vertCount(); i++) 525 878 { 526 879 nearby.reset(); 527 880 grid.proximalPoints(m.vertex(i), nearby); 528 881 529 for (j=0; j<nearby.length();j++)882 for (j = 0; j < nearby.length(); j++) 530 883 { 531 884 simplif::Vertex *v1 = m.vertex(i); 532 885 simplif::Vertex *v2 = (simplif::Vertex *)nearby(j); 533 886 534 if ( v1->isValid() && v2->isValid())887 if (v1->isValid() && v2->isValid()) 535 888 { 536 889 #ifdef SAFETY 537 890 assert(pair_is_valid(v1,v2)); 538 891 #endif 539 if ( !check_for_pair(v1,v2))892 if (!check_for_pair(v1,v2)) 540 893 { 541 894 simplif::pair_info *pair = new_pair(v1,v2); … … 544 897 } 545 898 } 546 547 899 } 548 900 } … … 555 907 void SimplificationMethod::simplifmethod_init(void) 556 908 { 557 int i;558 559 909 // Change mesh structure. 560 ge omesh2simplifModel();561 910 generateSimplifModel(); 911 562 912 M0.bounds.complete(); 563 913 … … 566 916 initialFaceCount = M0.faceCount(); 567 917 568 // Get rid of degenerate faces 569 for(i=0; i<M0.faceCount(); i++) 570 if( !M0.face(i)->plane().isValid() ) 918 // Get rid of degenerate faces. 919 for (int i = 0; i < M0.faceCount(); i++) 920 { 921 if (!M0.face(i)->plane().isValid()) 922 { 571 923 M0.killFace(M0.face(i)); 924 } 925 } 572 926 573 927 M0.removeDegeneracy(M0.allFaces()); 574 928 575 // Get rid of unused vertices 576 for(i=0; i<M0.vertCount(); i++) 577 { 578 if( M0.vertex(i)->edgeUses().length() == 0 ) 929 // Get rid of unused vertices. 930 for (int i = 0; i < M0.vertCount(); i++) 931 { 932 if (M0.vertex(i)->edgeUses().length() == 0) 933 { 579 934 M0.vertex(i)->kill(); 935 } 580 936 } 581 937 } … … 598 954 } 599 955 600 for (std::vector<MeshSimplificationSequence::Step>::iterator it= decim_data.begin(); it!=decim_data.end(); it++) 956 /* 957 for ( std::vector<MeshSimplificationSequence::Step>::iterator 958 it = decim_data.begin(); 959 it != decim_data.end(); 960 it++) 601 961 { 602 962 it->mModfaces.clear(); 603 963 } 964 604 965 decim_data.clear(); 605 606 while( M0.validFaceCount > finalfaces/*simplif::face_target*/ 607 && M0.validFaceCount > 1 608 && decimate_min_error() < simplif::error_tolerance ) 966 */ 967 968 // Debug. 969 cout << "M0.validFaceCount: " << M0.validFaceCount << endl; 970 cout << "finalfaces: " << finalfaces << endl; 971 972 while ( M0.validFaceCount > finalfaces/*simplif::face_target*/ 973 && M0.validFaceCount > 1 974 && decimate_min_error() < simplif::error_tolerance ) 609 975 { 610 976 decimate_contract(M0); … … 636 1002 previousValidVertCount = 0; 637 1003 638 percent = (float)(2.0 * 100.0) /(float)((M0.validFaceCount - numvertices / 3.0)); 1004 percent = (float)(2.0 * 100.0) 1005 / 1006 (float)((M0.validFaceCount - numvertices / 3.0)); 639 1007 640 1008 // Update progress bar. … … 644 1012 } 645 1013 646 for (std::vector<MeshSimplificationSequence::Step>::iterator it= decim_data.begin(); it!=decim_data.end(); it++) 1014 /* 1015 for ( std::vector<MeshSimplificationSequence::Step>::iterator 1016 it = decim_data.begin(); 1017 it != decim_data.end(); 1018 it++) 647 1019 { 648 1020 it->mModfaces.clear(); 649 1021 } 1022 650 1023 decim_data.clear(); 1024 */ 1025 1026 // Debug. 1027 cout << "M0.validVertCount: " << M0.validVertCount << endl; 1028 cout << "numvertices: " << numvertices << endl; 651 1029 652 1030 while( M0.validVertCount > numvertices /*simplif::face_target*/ … … 680 1058 { 681 1059 public: 1060 682 1061 float x,y,z; 683 _float3_(float x=0.0f, float y=0.0f, float z=0.0f){ this->x = x; this->y = y; this->z = z; } 684 _float3_(const _float3_ &f){ x=f.x; y=f.y; z=f.z; } 685 _float3_ & operator=(const _float3_ &f){ x=f.x; y=f.y; z=f.z; return *this; } 1062 1063 _float3_(float x=0.0f, float y=0.0f, float z=0.0f) 1064 { 1065 this->x = x; this->y = y; this->z = z; 1066 } 1067 1068 _float3_(const _float3_ &f) 1069 { 1070 x=f.x; y=f.y; z=f.z; 1071 } 1072 1073 _float3_ & operator=(const _float3_ &f) 1074 { 1075 x=f.x; y=f.y; z=f.z; return *this; 1076 } 1077 686 1078 bool operator<(const _float3_ &f) const 687 1079 { … … 696 1088 }; 697 1089 698 699 //--------------------------------------------------------------------------- 700 //Unify the model to work with it 701 //The vertices that have the same space coordinates are stored as an unique vertex 702 //in order to avoid holes in the simplification 703 //The necessary information to store correctly the decimation data is stored 704 //--------------------------------------------------------------------------- 705 void SimplificationMethod::geomesh2simplifModel(void) 706 { 707 std::map<_float3_,int> vertices_map; //Unique vertices (without repetitions) from all the submeshes 708 unsigned int num_final_verts = 0; //Number of unique vertices from all the submeshes 709 710 int num_final_verts2=0; 711 int num_repeated_verts=0; 712 713 int simplifindex; 714 for (size_t i=0; i<objmesh->mSubMeshCount; i++) //For all the submeshes 715 { 716 if (i != indexMeshLeaves) 717 { 718 //If the model has texture information 719 if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 720 { 721 //For all the vertices of each submesh 722 for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++) 723 { 724 _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 1090 //--------------------------------------------------------------------------- 1091 // Generate simplification model. 1092 //--------------------------------------------------------------------------- 1093 void SimplificationMethod::generateSimplifModel(void) 1094 { 1095 int face_index = 0; 1096 1097 // For each submesh. 1098 bool added_vertices = false; 1099 for (size_t i = 0; i < objmesh->mSubMeshCount; i++) 1100 { 1101 // If is not a tree leaves submesh. 1102 if (i != indexMeshLeaves) 1103 { 1104 // For all the vertices of each submesh. 1105 for ( size_t j = 0; 1106 j < objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 1107 j++) 1108 { 1109 // If the vertex is not in vertices_map, then is added. 1110 M0.in_Vertex(simplif::Vec3( 1111 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 725 1112 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 726 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 727 728 std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 729 if (mit==vertices_map.end()) 730 { 731 //If the vertex is not in vertices_map, then is added 732 simplifindex=M0.in_Vertex(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 733 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 734 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 735 M0.in_Normal(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x, 736 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 737 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 738 739 M0.in_TexCoord(simplif::Vec2(objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x, 740 objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 741 vertices_map[auxvert] = num_final_verts; 742 num_final_verts ++; 743 744 std::vector<int> v; 745 submeshmap[simplifindex]=v; 746 submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 747 std::vector<int> v2; 748 vertexbuffermap[simplifindex]=v2; 749 vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 750 751 // Debug 752 num_final_verts2++; 753 } 754 else 755 { 756 //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 757 simplifindex = mit->second; 758 submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 759 vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 760 761 // Debug 762 num_repeated_verts++; 763 } 764 } 765 } 766 else //the model has not texture information 767 { 768 //For all the vertices of each submesh 769 for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++) 770 { 771 _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 772 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 773 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 774 775 std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 776 if (mit==vertices_map.end()) 777 { 778 //If the vertex is not in vertices_map, then is added 779 simplifindex=M0.in_Vertex(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 780 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 781 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 782 M0.in_Normal(simplif::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x, 783 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 784 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 785 M0.in_TexCoord(simplif::Vec2(0.0,0.0)); 786 vertices_map[auxvert] = num_final_verts; 787 num_final_verts ++; 788 789 std::vector<int> v; 790 submeshmap[simplifindex]=v; 791 submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 792 std::vector<int> v2; 793 vertexbuffermap[simplifindex]=v2; 794 vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 795 } 796 else 797 { 798 //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 799 simplifindex = mit->second; 800 submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 801 vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 802 } 803 } 804 } 805 if (objmesh->mSubMesh[i].mSharedVertexBuffer) 806 { 807 printf("Shared break"); 808 break; 809 } 810 } 811 } 812 813 //Create the faces 814 unsigned int base_index=0; 815 816 number_of_triangles=0; //Number of triangles of the model 817 int face_index=0; 818 819 int index_in_vertices_map0,index_in_vertices_map1,index_in_vertices_map2; 820 for (size_t i=0; i<objmesh->mSubMeshCount; i++) //For all the submeshes 821 { 822 if (i!=indexMeshLeaves) 823 { 824 for (Index j=0; j<objmesh->mSubMesh[i].mIndexCount; j+=3) 825 { 826 //+1 is required because the first index in the simplification method is 1 827 //Index of the vertex in vertices_map 828 Index indice0=objmesh->mSubMesh[i].mIndex[j]; 829 _float3_ auxvert0(objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice0].x, 830 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice0].y, 831 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice0].z); 832 index_in_vertices_map0=vertices_map[auxvert0] + 1; 833 834 Index indice1=objmesh->mSubMesh[i].mIndex[j+1]; 835 _float3_ auxvert1(objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice1].x, 836 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice1].y, 837 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice1].z); 838 index_in_vertices_map1=vertices_map[auxvert1] + 1; 839 840 Index indice2=objmesh->mSubMesh[i].mIndex[j+2]; 841 _float3_ auxvert2(objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice2].x, 842 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice2].y, 843 objmesh->mSubMesh[i].mVertexBuffer->mPosition[indice2].z); 844 index_in_vertices_map2=vertices_map[auxvert2] + 1; 845 846 //Create a triangle with its indices in vertices_map 847 face_index=M0.miin_Face(index_in_vertices_map0,index_in_vertices_map1,index_in_vertices_map2); 848 849 //igeo allows to identify the submesh that contains the triangle 850 M0.face(face_index)->igeo=(int)i; 851 } 852 } 853 } 854 number_of_triangles=face_index; 855 } 856 857 858 //--------------------------------------------------------------------------- 859 //Wrties a file with the vertices, triangles and the simplification sequence 860 //--------------------------------------------------------------------------- 861 void SimplificationMethod::WriteOBJ(void) 862 { 863 MeshSimplificationSequence::Step stepaux; 864 vector<int> v0,v1,submesh0,submesh1; 865 std::ofstream obj("salida.lod"); 866 obj << "begin" << std::endl; 867 //vertices 868 for (size_t i=0; i<objmesh->mSubMeshCount; i++) 869 { 870 for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++) 871 { 872 obj << "v " << objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x << " " << 873 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y << " " << 874 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z << " " << std::endl; 875 } 876 } 877 878 879 //faces 880 for (size_t i=0; i<objmesh->mSubMeshCount; i++) 881 { 882 for (size_t j=0; j<objmesh->mSubMesh[i].mIndexCount; j=j+3) 883 { 884 obj << "f " << objmesh->mSubMesh[i].mIndex[j]+1 << " " << 885 objmesh->mSubMesh[i].mIndex[j+1]+1 << " " << 886 objmesh->mSubMesh[i].mIndex[j+2]+1 << std::endl; 887 } 888 } 889 890 obj << "end" << std::endl; 891 892 for (unsigned i=0; i<decim_data.size(); i++) 893 { 894 stepaux = decim_data.operator [](i); 895 v0=vertexbuffermap[stepaux.mV0]; //vertexbuffer index 896 submesh0=submeshmap[stepaux.mV0]; //displacement for each submesh 897 v1=vertexbuffermap[stepaux.mV1]; 898 submesh1=submeshmap[stepaux.mV1]; 899 for (unsigned j=0; j<v0.size(); j++) 900 { 901 for (unsigned k=0; k<v1.size(); k++) 902 { 903 //obtain the index of the VertexBuffer of each submesh and the displacemente by submesh 904 obj << "v% " << v1.operator [](k)+first_index_submesh[submesh1.operator [](k)] << 905 " " << v0.operator [](j)+first_index_submesh[submesh0.operator [](j)] << " " << 906 stepaux.x << " " << stepaux.y << " " << stepaux.z << " " << stepaux.mT0 << " " << 907 stepaux.mT1 << " & "; 908 if (stepaux.mModfaces.size()>0) 909 { 910 unsigned int ii=0; 911 for (ii=0; ii<stepaux.mModfaces.size()-1; ii++) 912 { 913 obj << stepaux.mModfaces.operator [](ii) << " "; 914 } 915 obj << stepaux.mModfaces.operator [](ii) << std::endl; 916 } 917 else 918 { 919 obj << std::endl; 920 } 921 } 922 } 923 } 924 obj.close(); 925 } 926 927 //--------------------------------------------------------------------------- 928 //simplifmethod_init is executed to do some initalizations 929 //simplifmethod_run is executed to do the decimation 930 //Then, the simpified model is created and the decimation information is returned 1113 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 1114 1115 M0.in_Normal(simplif::Vec3( 1116 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x, 1117 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 1118 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 1119 1120 M0.in_TexCoord(simplif::Vec2( 1121 objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x, 1122 objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 1123 1124 added_vertices = true; 1125 } 1126 } 1127 1128 // If is shared vertex buffer object. 1129 if (objmesh->mSubMesh[i].mSharedVertexBuffer && added_vertices) 1130 { 1131 printf("Shared break"); 1132 break; 1133 } 1134 } 1135 1136 // For each submesh. 1137 for (size_t i = 0; i < objmesh->mSubMeshCount; i++) 1138 { 1139 if (i != indexMeshLeaves) 1140 { 1141 for (Index j = 0; j < objmesh->mSubMesh[i].mIndexCount; j += 3) 1142 { 1143 // +1 is required because the first index in the 1144 // simplification method is 1 1145 // Index of the vertex in vertices_map. 1146 Index index0 = objmesh->mSubMesh[i].mIndex[j]; 1147 1148 Index index1 = objmesh->mSubMesh[i].mIndex[j + 1]; 1149 1150 Index index2 = objmesh->mSubMesh[i].mIndex[j + 2]; 1151 1152 // Create a triangle with its indices in vertices_map. 1153 face_index = M0.miin_Face( 1154 index0, 1155 index1, 1156 index2); 1157 1158 // igeo allows to identify the submesh that contains the triangle. 1159 M0.face(face_index)->igeo = (int)i; 1160 } 1161 } 1162 } 1163 number_of_triangles = face_index; 1164 } 1165 1166 //--------------------------------------------------------------------------- 1167 // simplifmethod_init is executed to do some initalizations 1168 // simplifmethod_run is executed to do the decimation 1169 // Then, the simpified model is created and the decimation 1170 // information is returned. 931 1171 //--------------------------------------------------------------------------- 932 1172 MeshSimplificationSequence *SimplificationMethod::Decimate( float lod, … … 938 1178 if (simpliftype == 0) 939 1179 { 940 // Percentage option1180 // Percentage option. 941 1181 simplifmethod_run((int)(number_of_triangles*lod),upb); 942 1182 } 943 1183 else 944 1184 { 945 // Number of vertices option1185 // Number of vertices option. 946 1186 simplifmethod_runv((int)lod,upb); 947 1187 } … … 953 1193 typedef std::vector<int> REPINDLIST; 954 1194 955 MAPAINDIND *unique_verts_inds_by_geo = new MAPAINDIND[objmesh->mSubMeshCount]; 956 REPINDLIST *ver_inds_rep_by_geo = new REPINDLIST[objmesh->mSubMeshCount]; 1195 MAPAINDIND *unique_verts_inds_by_geo = 1196 new MAPAINDIND[objmesh->mSubMeshCount]; 1197 1198 REPINDLIST *ver_inds_rep_by_geo = new REPINDLIST[objmesh->mSubMeshCount]; 957 1199 958 1200 // Index counter by submesh. … … 964 1206 } 965 1207 966 967 1208 // Construct the model. 1209 std::cout << "M0.faceCount(): " << M0.faceCount() << std::endl; 968 1210 for (int i = 0; i < M0.faceCount(); i++) 969 1211 { … … 976 1218 977 1219 // Insert to each submesh its triangles. 978 std::map<int,int>::iterator findit = unique_verts_inds_by_geo[igeo].find(auxface->vertex(0)->validID()); 1220 std::map<int,int>::iterator findit = 1221 unique_verts_inds_by_geo[igeo].find(auxface->vertex(0)->validID()); 1222 979 1223 if (findit == unique_verts_inds_by_geo[igeo].end()) 980 1224 { 981 1225 // If it is not added... add and map it. 982 unique_verts_inds_by_geo[igeo][auxface->vertex(0)->validID()] = inextvert[igeo]; 1226 unique_verts_inds_by_geo[igeo][auxface->vertex(0)->validID()] = 1227 inextvert[igeo]; 1228 983 1229 inextvert[igeo]++; 984 } 985 findit = unique_verts_inds_by_geo[igeo].find(auxface->vertex(1)->validID()); 1230 } 1231 1232 findit = 1233 unique_verts_inds_by_geo[igeo].find(auxface->vertex(1)->validID()); 1234 986 1235 if (findit == unique_verts_inds_by_geo[igeo].end()) 987 1236 { 988 1237 // If it is not added... add and map it. 989 unique_verts_inds_by_geo[igeo][auxface->vertex(1)->validID()] = inextvert[igeo]; 1238 unique_verts_inds_by_geo[igeo][auxface->vertex(1)->validID()] = 1239 inextvert[igeo]; 990 1240 inextvert[igeo]++; 991 } 992 findit = unique_verts_inds_by_geo[igeo].find(auxface->vertex(2)->validID()); 1241 } 1242 1243 findit = 1244 unique_verts_inds_by_geo[igeo].find(auxface->vertex(2)->validID()); 1245 993 1246 if (findit == unique_verts_inds_by_geo[igeo].end()) 994 1247 { 995 1248 // If it is not added... add and map it. 996 unique_verts_inds_by_geo[igeo][auxface->vertex(2)->validID()] = inextvert[igeo]; 1249 unique_verts_inds_by_geo[igeo][auxface->vertex(2)->validID()] = 1250 inextvert[igeo]; 997 1251 inextvert[igeo]++; 998 } 1252 } 999 1253 1000 1254 // Total number of indices by submesh. … … 1043 1297 bool copiedShared = false; 1044 1298 1299 // For each submesh. 1045 1300 for (size_t i = 0; i < objmesh->mSubMeshCount; i++) 1046 1301 { 1047 mGeoMesh->mSubMesh[i].mStripCount 1048 mGeoMesh->mSubMesh[i].mStrip 1302 mGeoMesh->mSubMesh[i].mStripCount = 0; 1303 mGeoMesh->mSubMesh[i].mStrip = NULL; 1049 1304 1050 1305 mGeoMesh-> … … 1060 1315 { 1061 1316 mGeoMesh->mSubMesh[i].mBones.push_back(objmesh-> 1062 mSubMesh[i].mBones[j]);1317 mSubMesh[i].mBones[j]); 1063 1318 } 1064 1319 } … … 1068 1323 // Indices vectors. 1069 1324 mGeoMesh->mSubMesh[i].mIndexCount = ver_inds_rep_by_geo[i].size(); 1325 1070 1326 mGeoMesh->mSubMesh[i].mIndex = new Index[mGeoMesh-> 1071 mSubMesh[i].mIndexCount];1327 mSubMesh[i].mIndexCount]; 1072 1328 1073 1329 // Store the indices. … … 1075 1331 { 1076 1332 // Obtain the indices that point at VertexBuffer. 1077 mGeoMesh->mSubMesh[i].mIndex[j] = unique_verts_inds_by_geo[i].operator [](ver_inds_rep_by_geo[i].operator [](j)); 1333 mGeoMesh->mSubMesh[i].mIndex[j] = 1334 unique_verts_inds_by_geo[i]. 1335 operator [](ver_inds_rep_by_geo[i]. 1336 operator [](j)); 1078 1337 } 1079 1338 … … 1096 1355 } 1097 1356 1098 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount = unique_verts_inds_by_geo[i].size(); 1099 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo = objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 1357 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount = 1358 unique_verts_inds_by_geo[i].size(); 1359 1360 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo = 1361 objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 1100 1362 1101 1363 // Allocate memory for position, normal and texutre coordinates. 1102 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition = new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1103 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal = new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1104 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords = new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1364 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition = 1365 new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1366 1367 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal = 1368 new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1369 1370 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords = 1371 new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1105 1372 1106 1373 for ( MAPAINDIND::iterator mapit = unique_verts_inds_by_geo[i].begin(); … … 1114 1381 // Vertex coordinate. 1115 1382 // Construction of the submeshes. 1116 Vector3 v3((Real)M0.vertex(isrc)->operator [](0), 1117 (Real)M0.vertex(isrc)->operator [](1), 1118 (Real)M0.vertex(isrc)->operator [](2)); 1119 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[idst]=v3; 1383 Vector3 v3( (Real)M0.vertex(isrc)->operator [](0), 1384 (Real)M0.vertex(isrc)->operator [](1), 1385 (Real)M0.vertex(isrc)->operator [](2)); 1386 1387 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[idst] = v3; 1120 1388 1121 1389 // Normal coordinates. 1122 Vector3 v3n((Real)M0.normal(isrc)(0), (Real)M0.normal(isrc)(1), (Real)M0.normal(isrc)(2)); 1123 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[idst]=v3n; 1390 Vector3 v3n( (Real)M0.normal(isrc)(0), 1391 (Real)M0.normal(isrc)(1), 1392 (Real)M0.normal(isrc)(2)); 1393 1394 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[idst] = v3n; 1124 1395 1125 1396 // Texture coordinates. 1126 Vector2 v2((Real)M0.texcoord(isrc)(0), (Real)M0.texcoord(isrc)(1)); 1127 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[idst]=v2; 1397 Vector2 v2( (Real)M0.texcoord(isrc)(0), 1398 (Real)M0.texcoord(isrc)(1)); 1399 1400 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[idst] = v2; 1128 1401 } 1129 1402 } … … 1131 1404 { 1132 1405 // Leaves mesh. 1133 mGeoMesh->mSubMesh[i].mIndexCount=objmesh->mSubMesh[i].mIndexCount; 1134 mGeoMesh->mSubMesh[i].mIndex=new Index[mGeoMesh->mSubMesh[i].mIndexCount]; 1406 mGeoMesh->mSubMesh[i].mIndexCount = objmesh->mSubMesh[i].mIndexCount; 1407 1408 mGeoMesh->mSubMesh[i].mIndex = new Index[mGeoMesh->mSubMesh[i].mIndexCount]; 1135 1409 1136 1410 // Copy the leaves submesh indexes. 1137 for (unsigned int j=0; j<mGeoMesh->mSubMesh[i].mIndexCount;j++)1411 for (unsigned int j = 0; j < mGeoMesh->mSubMesh[i].mIndexCount; j++) 1138 1412 { 1139 mGeoMesh->mSubMesh[i].mIndex[j] =objmesh->mSubMesh[i].mIndex[j];1413 mGeoMesh->mSubMesh[i].mIndex[j] = objmesh->mSubMesh[i].mIndex[j]; 1140 1414 } 1141 1415 1142 1416 // Copy the leaves submesh vertices. 1143 mGeoMesh->mSubMesh[i].mVertexBuffer=new VertexBuffer(); 1144 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount=objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 1145 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo=objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 1417 mGeoMesh->mSubMesh[i].mVertexBuffer = new VertexBuffer(); 1418 1419 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount = 1420 objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 1421 1422 mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo = 1423 objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 1146 1424 1147 1425 // Allocate memory for position, normal and texture coordinates. 1148 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition=new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1149 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal=new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1150 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords=new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1426 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition = 1427 new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1428 1429 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal = 1430 new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1431 1432 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords = 1433 new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 1151 1434 1152 1435 for ( unsigned int j = 0; … … 1155 1438 { 1156 1439 // Position. 1157 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x=objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; 1158 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y=objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; 1159 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z=objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; 1440 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x = 1441 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; 1442 1443 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y = 1444 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; 1445 1446 mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z = 1447 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; 1160 1448 1161 1449 // Normals. 1162 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].x=objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x; 1163 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].y=objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y; 1164 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].z=objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z; 1450 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].x = 1451 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x; 1452 1453 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].y = 1454 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y; 1455 1456 mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].z = 1457 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z; 1165 1458 1166 1459 // Textures. 1167 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x=objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x; 1168 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y=objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y; 1460 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x = 1461 objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x; 1462 1463 mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y = 1464 objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y; 1169 1465 } 1170 1466 } … … 1176 1472 1177 1473 // Store the simplification steps in MeshSimplificationSequence. 1178 int 1474 int acum = 0; 1179 1475 1180 1476 for (size_t i = 0; i < objmesh->mSubMeshCount; i++) … … 1192 1488 } 1193 1489 1194 MeshSimplificationSequence::Step stepaux, newstep; 1195 vector<int> v0,v1,submesh0,submesh1; 1196 MeshSimplificationSequence *msimpseq; 1197 1198 msimpseq = new MeshSimplificationSequence(); 1199 1200 for (unsigned i = 0; i < decim_data.size(); i++) 1201 { 1202 stepaux = decim_data.operator [](i); 1203 v0 = vertexbuffermap[stepaux.mV0]; // vertexbuffer index 1204 submesh0 = submeshmap[stepaux.mV0]; // displacement by submesh 1205 v1 = vertexbuffermap[stepaux.mV1]; 1206 submesh1 = submeshmap[stepaux.mV1]; 1207 1208 for (unsigned j = 0; j < v0.size(); j++) 1209 { 1210 for (unsigned k = 0; k < v1.size(); k++) 1211 { 1212 // Obtain the submesh index in VertexBuffer 1213 // and the displacement by submesh 1214 newstep.mV0 = v0.operator [](j)+first_index_submesh[submesh0.operator [](j)]; 1215 newstep.mV1 = v1.operator [](k)+first_index_submesh[submesh1.operator [](k)]; 1216 newstep.x = stepaux.x; 1217 newstep.y = stepaux.y; 1218 newstep.z = stepaux.z; 1219 1220 // mT0 y mT1 are unique triangles identifiers 1221 // returned by the simplification method 1222 newstep.mT0 = stepaux.mT0; 1223 newstep.mT1 = stepaux.mT1; 1224 1225 if (j == v0.size() - 1 && k == v1.size() - 1) 1226 { 1227 newstep.obligatorio = 0; 1228 } 1229 else 1230 { 1231 newstep.obligatorio = 1; 1232 } 1233 1234 if (j == 0 && k == 0) 1235 { 1236 // First simplification step. 1237 // unique triangle identifiers 1238 // returned by the simplification method. 1239 newstep.mModfaces = stepaux.mModfaces; 1240 } 1241 else 1242 { 1243 std::vector<Index> vvacio; 1244 1245 newstep.mModfaces = vvacio; 1246 } 1247 1248 msimpseq->mSteps.push_back(newstep); 1249 } 1250 } 1251 } 1252 1253 // WriteOBJ(); 1490 vector<int> v0; 1491 vector<int> v1; 1492 vector<int> submesh0; 1493 vector<int> submesh1; 1494 1254 1495 return msimpseq; 1255 1496 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/SimplificationMethod.h
r1025 r1526 9 9 #include <GeoMeshSimplifier.h> 10 10 11 using namespace Geometry; 12 11 13 class SimplificationMethod 12 14 { 13 private: 14 Geometry::Mesh *mGeoMesh; 15 void compute_pair_info(simplif::pair_info*); 16 simplif::Model M0; 17 simplif::array<simplif::vert_info> vinfo; 18 simplif::Heap *heap; 19 simplif::real proximity_limit; // distance threshold squared 20 int initialVertCount; 21 int initialEdgeCount; 22 int initialFaceCount; 15 private: 23 16 24 inline simplif::vert_info& vertex_info(simplif::Vertex *v) 25 { 26 return vinfo(v->validID()); 27 } 28 29 simplif::real pair_mesh_penalty(simplif::Model& M, 30 simplif::Vertex *v1, 31 simplif::Vertex *v2, 32 simplif::Vec3& vnew); 33 34 int predict_face(simplif::Face& F, 35 simplif::Vertex *v1, 36 simplif::Vertex *v2, 37 simplif::Vec3& vnew, 38 simplif::Vec3& f1, 39 simplif::Vec3& f2, 40 simplif::Vec3& f3); 41 42 bool check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1); 43 44 simplif::pair_info *new_pair(simplif::Vertex *v0, simplif::Vertex *v1); 45 46 void delete_pair(simplif::pair_info *pair); 47 48 void do_contract(simplif::Model& m, simplif::pair_info *pair); 49 50 bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q); 51 52 void decimate_contract(simplif::Model& m); 53 54 simplif::real decimate_error(simplif::Vertex *v); 55 56 simplif::real decimate_min_error(); 57 58 simplif::real decimate_max_error(simplif::Model& m); 59 60 void decimate_init(simplif::Model& m, simplif::real limit); 61 62 bool pair_is_valid(simplif::Vertex *u, simplif::Vertex *v); 63 64 void simplifmethod_run(int, Geometry::TIPOFUNC upb=0); 65 66 void simplifmethod_runv(int, Geometry::TIPOFUNC upb=0); 67 68 void simplifmethod_init(void); 17 Geometry::Mesh *mGeoMesh; 69 18 70 // To map the mesh with de simplification method structure. 71 // Submeshes which pertains each vertex. 72 std::map<int,std::vector<int> > submeshmap; 73 74 // Vertices of the VertexBuffer that point 75 // at this vertex of the simplification method. 76 std::map<int,std::vector<int> > vertexbuffermap; 19 void compute_pair_info(simplif::pair_info*); 77 20 78 // Simplification sequence of the simplification method. 79 std::vector<Geometry::MeshSimplificationSequence::Step> decim_data; 80 81 std::string meshName; 82 83 void WriteOBJ(void); 84 85 unsigned int *first_index_submesh; 86 87 //std::vector<simplif::pair_info *> pointers_to_remove; 21 simplif::Model M0; 88 22 89 int indexMeshLeaves; 90 91 public: 92 93 const Geometry::Mesh *objmesh; 94 95 // Total number of triangles of all the submeshes. 96 int number_of_triangles; 97 98 SimplificationMethod(const Geometry::Mesh *m); 99 100 void geomesh2simplifModel(void); 101 102 Geometry::MeshSimplificationSequence *Decimate( float lod, 103 int simpliftype, 104 Geometry::TIPOFUNC upb=0); 105 106 void setMeshLeaves(int meshLeaves); 23 simplif::array<simplif::vert_info> vinfo; 107 24 108 /// Gets mesh simplified. 109 Geometry::Mesh * GetMesh(); 110 111 ///Destructor 112 ~SimplificationMethod(); 25 simplif::Heap *heap; 26 simplif::real proximity_limit; // distance threshold squared 27 28 int initialVertCount; 29 int initialEdgeCount; 30 int initialFaceCount; 31 32 // Simplification sequence. 33 MeshSimplificationSequence *msimpseq; 34 35 // Stores the simplification step. 36 MeshSimplificationSequence::Step simplifstep; 37 38 inline simplif::vert_info& vertex_info(simplif::Vertex *v) 39 { 40 return vinfo(v->validID()); 41 } 42 43 simplif::real pair_mesh_penalty(simplif::Model& M, 44 simplif::Vertex *v1, 45 simplif::Vertex *v2, 46 simplif::Vec3& vnew); 47 48 int predict_face(simplif::Face& F, 49 simplif::Vertex *v1, 50 simplif::Vertex *v2, 51 simplif::Vec3& vnew, 52 simplif::Vec3& f1, 53 simplif::Vec3& f2, 54 simplif::Vec3& f3); 55 56 bool check_for_pair(simplif::Vertex *v0, simplif::Vertex *v1); 57 58 simplif::pair_info *new_pair(simplif::Vertex *v0, simplif::Vertex *v1); 59 60 void delete_pair(simplif::pair_info *pair); 61 62 void do_contract(simplif::Model& m, simplif::pair_info *pair); 63 64 bool decimate_quadric(simplif::Vertex *v, simplif::Mat4& Q); 65 66 void decimate_contract(simplif::Model& m); 67 68 simplif::real decimate_error(simplif::Vertex *v); 69 70 simplif::real decimate_min_error(); 71 72 simplif::real decimate_max_error(simplif::Model& m); 73 74 void decimate_init(simplif::Model& m, simplif::real limit); 75 76 bool pair_is_valid(simplif::Vertex *u, simplif::Vertex *v); 77 78 void simplifmethod_run(int, Geometry::TIPOFUNC upb=0); 79 80 void simplifmethod_runv(int, Geometry::TIPOFUNC upb=0); 81 82 void simplifmethod_init(void); 83 84 // To map the mesh with de simplification method structure. 85 // Submeshes which pertains each vertex. 86 std::map< int, std::vector<int> > submeshmap; 87 88 // Vertices of the VertexBuffer that point 89 // at this vertex of the simplification method. 90 std::map< int, std::vector<int> > vertexbuffermap; 91 92 // Simplification sequence of the simplification method. 93 std::vector<Geometry::MeshSimplificationSequence::Step> decim_data; 94 95 std::string meshName; 96 97 unsigned int *first_index_submesh; 98 99 //std::vector<simplif::pair_info *> pointers_to_remove; 100 101 int indexMeshLeaves; 102 103 // Contract lonely vertices that have same coords than the contracted one. 104 void contractLonelyVertices( simplif::Model &m, 105 simplif::Vertex *v0, 106 simplif::Vertex *v1, 107 simplif::Vec3 candidate); 108 109 // Remove twin edges. 110 void removeTwinEdges(simplif::Model &m, 111 simplif::Vertex *v0, 112 simplif::Vertex *v1, 113 simplif::Vec3 candidate); 114 115 public: 116 117 const Geometry::Mesh *objmesh; 118 119 // Total number of triangles of all the submeshes. 120 int number_of_triangles; 121 122 SimplificationMethod(const Geometry::Mesh *m); 123 124 void generateSimplifModel(void); 125 126 Geometry::MeshSimplificationSequence *Decimate( float lod, 127 int simpliftype, 128 Geometry::TIPOFUNC upb=0); 129 130 void setMeshLeaves(int meshLeaves); 131 132 /// Gets mesh simplified. 133 Geometry::Mesh * GetMesh(); 134 135 /// Destructor. 136 ~SimplificationMethod(); 113 137 }; 114 138 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/avars.cxx
r1025 r1526 19 19 bool simplif::will_preserve_mesh_quality = true; 20 20 bool simplif::will_constrain_boundaries = true; 21 simplif::real simplif::boundary_constraint_weight = 1 .0;21 simplif::real simplif::boundary_constraint_weight = 10.0; 22 22 23 23 bool simplif::will_weight_by_area = false; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/geom/3D.cxx
r1025 r1526 85 85 } 86 86 87 88 89 90 87 //////////////////////////////////////////////////////////////////////// 91 88 // -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/geom/3D.h
r1025 r1526 63 63 }; 64 64 65 66 65 // 67 66 // A triangular face in 3D (ie. a 2-simplex in E3) … … 94 93 } 95 94 96 97 98 95 // GFXGEOM_3D_INCLUDED 99 96 #endif -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Array.h
r1025 r1526 8 8 { 9 9 template<class T> 10 class array { 11 protected: 12 T *data; 13 int len; 14 public: 15 array() { data=NULL; len=0; } 16 array(int l) { init(l); } 17 ~array() { f_r_e_e(); } 10 class array 11 { 12 protected: 13 T *data; 14 int len; 15 public: 16 array() { data=NULL; len=0; } 17 array(int l) { init(l); } 18 ~array() { f_r_e_e(); } 18 19 20 inline void init(int l); 21 inline void f_r_e_e(); 22 inline void resize(int l); 19 23 20 inline void init(int l);21 inline void f_r_e_e();22 inline void resize(int l);24 inline T& ref(int i); 25 inline T& operator[](int i) { return data[i]; } 26 inline T& operator()(int i) { return ref(i); } 23 27 24 inline T& ref(int i);25 inline T& operator[](int i){ return data[i]; }26 inline T& operator()(int i){ return ref(i); }28 inline const T& ref(int i) const; 29 inline const T& operator[](int i) const { return data[i]; } 30 inline const T& operator()(int i) const { return ref(i); } 27 31 28 inline const T& ref(int i) const; 29 inline const T& operator[](int i) const { return data[i]; } 30 inline const T& operator()(int i) const { return ref(i); } 31 32 33 inline int length() const { return len; } 34 inline int maxLength() const { return len; } 35 }; 32 inline int length() const { return len; } 33 inline int maxLength() const { return len; } 34 }; 36 35 37 36 template<class T> 38 inline void array<T>::init(int l)39 {40 data = new T[l];41 len = l;42 }37 inline void array<T>::init(int l) 38 { 39 data = new T[l]; 40 len = l; 41 } 43 42 44 43 template<class T> 45 inline void array<T>::f_r_e_e() 46 { 47 if( data ) 44 inline void array<T>::f_r_e_e() 48 45 { 49 delete[] data; 50 data = NULL; 46 if( data ) 47 { 48 delete[] data; 49 data = NULL; 50 } 51 51 } 52 }53 52 54 53 template<class T> 55 inline T& array<T>::ref(int i)56 {57 58 assert( data );59 assert( i>=0 && i<len );60 61 return data[i];62 }54 inline T& array<T>::ref(int i) 55 { 56 #ifdef SAFETY 57 assert( data ); 58 assert( i>=0 && i<len ); 59 #endif 60 return data[i]; 61 } 63 62 64 63 template<class T> 65 inline const T& array<T>::ref(int i) const66 {67 68 assert( data );69 assert( i>=0 && i<len );70 71 return data[i];72 }64 inline const T& array<T>::ref(int i) const 65 { 66 #ifdef SAFETY 67 assert( data ); 68 assert( i>=0 && i<len ); 69 #endif 70 return data[i]; 71 } 73 72 74 73 template<class T> 75 inline void array<T>::resize(int l)76 {77 T *old = data;78 data = new T[l];79 data = (T *)memcpy(data,old,MIN(len,l)*sizeof(T));80 len = l;81 delete[] old;82 }74 inline void array<T>::resize(int l) 75 { 76 T *old = data; 77 data = new T[l]; 78 data = (T *)memcpy(data,old,MIN(len,l)*sizeof(T)); 79 len = l; 80 delete[] old; 81 } 83 82 } 84 83 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Buffer.h
r1025 r1526 25 25 inline int length() const { return fill; } 26 26 inline int maxLength() const { return len; } 27 inline void setFill(int l){fill = l;} 27 28 }; 28 29 29 30 30 template<class T> -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Heap.h
r1025 r1526 16 16 class Heapable 17 17 { 18 private: 19 int token; 18 private: 20 19 21 public: 22 Heapable() { notInHeap(); } 20 int token; 23 21 24 inline int isInHeap() { return token!=NOT_IN_HEAP; } 25 inline void notInHeap() { token = NOT_IN_HEAP; } 26 inline int getHeapPos() { return token; } 27 inline void setHeapPos(int t) { token=t; } 22 public: 23 24 Heapable() { notInHeap(); } 25 26 inline int isInHeap() { return token!=NOT_IN_HEAP; } 27 inline void notInHeap() { token = NOT_IN_HEAP; } 28 inline int getHeapPos() { return token; } 29 inline void setHeapPos(int t) { token=t; } 28 30 }; 29 31 32 class heap_node 33 { 34 public: 35 float import; 36 Heapable *obj; 30 37 31 class heap_node { 32 public: 33 float import; 34 Heapable *obj; 35 36 heap_node() { obj=NULL; import=0.0; } 37 heap_node(Heapable *t, float i=0.0) { obj=t; import=i; } 38 heap_node(const heap_node& h) { import=h.import; obj=h.obj; } 38 heap_node() { obj=NULL; import=0.0; } 39 heap_node(Heapable *t, float i=0.0) { obj=t; import=i; } 40 heap_node(const heap_node& h) { import=h.import; obj=h.obj; } 39 41 }; 40 42 41 42 43 class Heap : public array<heap_node> { 44 43 class Heap : public array<heap_node> 44 { 45 45 // 46 46 // The actual size of the heap. array::length() … … 57 57 void downheap(int i); 58 58 59 public:59 public: 60 60 61 61 Heap() { size=0; } 62 62 Heap(int s) : array<heap_node>(s) { size=0; } 63 64 63 65 64 void insert(Heapable *, float); … … 67 66 68 67 heap_node *extract(); 68 69 // Overhead method. 70 heap_node *extract(int i); 71 69 72 heap_node *top() { return size<1 ? (heap_node *)NULL : &ref(0); } 70 73 heap_node *kill(int i); 74 75 // Gets heap size. 76 int getSize(){return size;} 77 78 // Gets element at position i. 79 heap_node *getElement(int i){return &ref(i);} 80 71 81 }; 72 82 73 83 } 74 84 75 76 85 // GFXTOOLS_HEAP_INCLUDED 77 86 #endif 87 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/heap.cxx
r1025 r1526 7 7 void Heap::swap(int i,int j) 8 8 { 9 9 heap_node tmp = ref(i); 10 10 11 12 11 ref(i) = ref(j); 12 ref(j) = tmp; 13 13 14 15 14 ref(i).obj->setHeapPos(i); 15 ref(j).obj->setHeapPos(j); 16 16 } 17 17 18 18 void Heap::upheap(int i) 19 19 { 20 20 if( i==0 ) return; 21 21 22 if( ref(i).import > ref(parent(i)).import ) { 23 swap(i,parent(i)); 24 upheap(parent(i)); 25 } 22 if( ref(i).import > ref(parent(i)).import ) 23 { 24 swap(i,parent(i)); 25 upheap(parent(i)); 26 } 26 27 } 27 28 28 29 void Heap::downheap(int i) 29 30 { 30 31 if (i>=size) return; // perhaps just extracted the last 31 32 32 33 34 33 int largest = i, 34 l = left(i), 35 r = right(i); 35 36 36 37 37 if( l<size && ref(l).import > ref(largest).import ) largest = l; 38 if( r<size && ref(r).import > ref(largest).import ) largest = r; 38 39 39 40 41 42 40 if( largest != i ) { 41 swap(i,largest); 42 downheap(largest); 43 } 43 44 } 44 45 46 45 47 46 void Heap::insert(Heapable *t,float v) 48 47 { 49 50 51 std::cerr << "NOTE: Growing heap from " << size << " to " << 2*size << std::endl;52 resize(2*size);53 48 if( size == maxLength() ) 49 { 50 std::cerr << "NOTE: Growing heap from " << size << " to " << 2*size << std::endl; 51 resize(2*size); 52 } 54 53 55 54 int i = size++; 56 55 57 58 56 ref(i).obj = t; 57 ref(i).import = v; 59 58 60 59 ref(i).obj->setHeapPos(i); 61 60 62 61 upheap(i); 63 62 } 64 63 65 64 void Heap::update(Heapable *t,float v) 66 65 { 67 66 int i = t->getHeapPos(); 68 67 69 70 68 if( i >= size ) 69 { 71 70 std::cerr << "WARNING: Attempting to update past end of heap!" << std::endl; 72 71 return; 73 74 75 72 } 73 else if( i == NOT_IN_HEAP ) 74 { 76 75 std::cerr << "WARNING: Attempting to update object not in heap!" << std::endl; 77 76 return; 78 77 } 79 78 80 81 79 float old=ref(i).import; 80 ref(i).import = v; 82 81 83 84 85 86 82 if( v<old ) 83 downheap(i); 84 else 85 upheap(i); 87 86 } 88 89 90 87 91 88 heap_node *Heap::extract() 92 89 { 93 90 if( size<1 ) return 0; 94 91 95 96 92 swap(0,size-1); 93 size--; 97 94 98 95 downheap(0); 99 96 100 97 ref(size).obj->notInHeap(); 101 98 102 return &ref(size); 99 return &ref(size); 100 } 101 102 // Overhead method. 103 heap_node *Heap::extract(int i) 104 { 105 if( size<1 ) return 0; 106 107 swap(i,size-1); 108 size--; 109 110 downheap(i); 111 112 ref(size).obj->notInHeap(); 113 114 return &ref(size); 103 115 } 104 116 105 117 heap_node *Heap::kill(int i) 106 118 { 107 119 if( i>=size ) 108 120 std::cerr << "WARNING: Attempt to delete invalid heap node." << std::endl; 109 121 110 111 112 122 swap(i, size-1); 123 size--; 124 ref(size).obj->notInHeap(); 113 125 114 126 if( ref(i).import < ref(size).import ) 115 127 downheap(i); 116 128 else 117 129 upheap(i); 118 130 131 return &ref(size); 132 } 119 133 120 return &ref(size);121 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Leaf.cpp
r1026 r1526 10 10 vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] =0; 11 11 center[0] = center[1] = center[2] = 0; 12 normal[0] = normal[1] = normal[2] = 0;12 // normal[0] = normal[1] = normal[2] = 0; 13 13 leafNear=-1; 14 14 parentLeafCount = 1; … … 40 40 for ( int i=0;i<3;i++){ 41 41 center[i] = aLeaf.center[i]; 42 normal[i] = aLeaf.normal[i];42 // normal[i] = aLeaf.normal[i]; 43 43 } 44 44 for (i = 0L; i < 4; i++) … … 53 53 54 54 55 RuntimeLeaf::RuntimeLeaf(void) 56 { 57 vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] = 0; 58 parent = root = childLeft = childRight = -1; 59 } 55 60 56 61 //-------------------------------------------------------------------------------------------------------------------------------- 57 // Destructor. We must deallocate the memory allocated for pointers to vertices and edges62 // Copy constructor 58 63 //-------------------------------------------------------------------------------------------------------------------------------- 59 Leaf::~Leaf (void)64 RuntimeLeaf::RuntimeLeaf (const RuntimeLeaf& aLeaf) 60 65 { 66 for (int i = 0L; i < 4; i++) 67 vertsLeaf[i] = aLeaf.vertsLeaf[i]; 68 parent = aLeaf.parent; 69 childLeft = aLeaf.childLeft; 70 childRight = aLeaf.childRight; 71 root = aLeaf.root; 61 72 } 62 73 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/VertexData.cpp
r1105 r1526 1 1 #include "VertexData.h" 2 2 3 Geometry::DefaultVertexData::DefaultVertexData(unsigned int numv):Geometry::VertexData(numv) 3 /* 4 void Geometry::DefaultIndexData::Init(unsigned int numi) 4 5 { 5 v = new float[numv*3]; 6 n = new float[numv*3]; 7 t = new float[numv*2]; 8 } 9 Geometry::DefaultVertexData::~DefaultVertexData(void) 10 { 11 /* delete[] v; 12 delete[] n; 13 delete[] t;*/ 14 } 15 16 Geometry::VertexData *Geometry::DefaultVertexDataCreator(unsigned int numv) 17 { 18 return new DefaultVertexData(numv); 19 } 20 21 22 Geometry::DefaultIndexData::DefaultIndexData(unsigned int numi):Geometry::IndexData(numi) 23 { 24 indices = new unsigned int[numi]; 6 indices = new unsigned int[numi]; 25 7 } 26 8 Geometry::DefaultIndexData::~DefaultIndexData(void) 27 9 { 28 /* delete[] indices;*/29 10 } 30 11 31 12 Geometry::IndexData *Geometry::DefaultIndexDataCreator(unsigned int numi) 32 13 { 33 return new DefaultIndexData(numi); 14 IndexData *ret = new DefaultIndexData(); 15 // ret->Init(numi); 16 return ret; 34 17 } 35 18 36 37 /*Geometry::DefaultMultiIndexData::DefaultMultiIndexData(unsigned int numprims, unsigned int *numi):Geometry::MultiIndexData(numprims,numi)38 {39 indices = new unsigned int*[numprims];40 for (unsigned int i=0; i<numprims; i++)41 indices[i]=new unsigned int[numi[i]];42 }43 Geometry::DefaultMultiIndexData::~DefaultMultiIndexData(void)44 {45 for (unsigned int i=0; i<GetNumPrims(); i++)46 delete[] indices[i];47 delete[] indices;48 }49 50 Geometry::MultiIndexData *Geometry::DefaultMultiIndexDataCreator(unsigned int numprims, unsigned int *numi)51 {52 return new DefaultMultiIndexData(numprims,numi);53 }54 19 */ -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp
r1083 r1526 10 10 // Parameters --> None 11 11 //-------------------------------------------------------------------------------------------------------------------------------- 12 Foliage::Foliage(const Geometry::SubMesh *leavesSubMesh, const Geometry::TreeSimplificationSequence * simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun): 12 Foliage::Foliage(int leavessubmeshID, 13 const Geometry::SubMesh *leavesSubMesh, 14 const Geometry::TreeSimplificationSequence * simpSeq/*, 15 Geometry::CREATEVERTEXDATAFUNC vdfun*/): 13 16 Acth(NULL), 14 create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun),15 create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun),16 vertexdata(NULL),Leaves(NULL), MinDet(NULL)17 //create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun), 18 //create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun), 19 /*vertexdata(NULL),*/ Leaves(NULL), MinDet(NULL) 17 20 { 18 21 begin = final = -1; 19 20 ReadVertices(leavesSubMesh); 22 // indexdata=NULL; 23 24 // ReadVertices(leavesSubMesh); 25 int countv= int(leavesSubMesh->mVertexBuffer->mVertexCount); 26 Leaves = new RuntimeLeaf[countv*2]; 27 TotalVerts = countv; 28 21 29 ReadLeafs(leavesSubMesh); 22 30 if (!ReadSimpSeq(simpSeq)) exit(1); 23 31 FillRoot(); 24 CalculateTexCoordsAndNorms();25 26 indexdata->SetNumValidIndices(0);32 // CalculateTexCoordsAndNorms(); 33 34 // indexdata->SetNumValidIndices(0); 27 35 28 36 int h=0; … … 44 52 final = leafCount-1; 45 53 active_leaf_count = leafCount; 54 leavesSubMeshID=leavessubmeshID; 46 55 } 47 56 … … 51 60 Foliage::~Foliage (void) 52 61 { 53 if (vertexdata) delete vertexdata;54 if (indexdata) delete indexdata;62 // if (vertexdata) delete vertexdata; 63 // if (indexdata) delete indexdata; 55 64 delete[] Leaves; 56 65 delete MinDet; … … 222 231 223 232 } 224 233 /* 225 234 void Foliage::ReadVertices(const Geometry::SubMesh *submesh) 226 235 { … … 228 237 vertexdata = create_vertex_data_func(2*countv); 229 238 Leaves = new Leaf[countv*2]; 230 indexdata = create_index_data_func(countv*2*3); // 3 indices x 2 triangulos x hoja239 //indexdata = create_index_data_func(countv*2*3); // 3 indices x 2 triangulos x hoja 231 240 232 241 vertexdata->Begin(); … … 249 258 float twox, twoy, twoz; 250 259 float threex, threey, threez; 251 252 /* Vertices[aHoja.vertsLeaf[0]].GetCoordinates (onex, oney, onez);253 Vertices[aHoja.vertsLeaf[1]].GetCoordinates(twox, twoy, twoz);254 Vertices[aHoja.vertsLeaf[2]].GetCoordinates (threex, threey, threez);*/255 260 256 261 vertexdata->GetVertexCoord(aleaf.vertsLeaf[0],onex,oney,onez); … … 286 291 res[2]=v[2]/module; 287 292 } 288 293 */ 289 294 void Foliage::ReadLeafs(const Geometry::SubMesh *submesh) 290 295 { … … 297 302 Leaves[h].vertsLeaf[2] = submesh->mIndex[h*6+2]; 298 303 Leaves[h].vertsLeaf[3] = submesh->mIndex[h*6+5]; 299 Leaves[h].visible = 0;300 301 GetNormalH ( Leaves[h]);304 // Leaves[h].visible = 0; 305 306 // GetNormalH ( Leaves[h]); 302 307 } 303 308 } … … 316 321 Leaves[tn].vertsLeaf[3] = it->mNewQuad[3]; 317 322 318 Leaves[tn].visible = 0;319 320 GetNormalH (Leaves[tn]);323 // Leaves[tn].visible = 0; 324 325 // GetNormalH (Leaves[tn]); 321 326 322 327 tv1 = it->mV0/2; … … 433 438 } 434 439 435 void Foliage::CalculateTexCoordsAndNorms(void)440 /*void Foliage::CalculateTexCoordsAndNorms(void) 436 441 { 437 442 vertexdata->Begin(); … … 453 458 vertexdata->End(); 454 459 } 455 460 */ 456 461 Foliage::Foliage(const Foliage *ar) 457 462 { … … 465 470 TotalVerts=ar->TotalVerts; 466 471 467 create_vertex_data_func=ar->create_vertex_data_func;468 create_index_data_func=ar->create_index_data_func;472 /* create_vertex_data_func=ar->create_vertex_data_func; 473 // create_index_data_func=ar->create_index_data_func; 469 474 vertexdata=create_vertex_data_func(ar->vertexdata->GetNumVertices()); 470 475 vertexdata->Begin(); … … 477 482 vertexdata->SetVertexNormal(i,va,vb,vc); 478 483 } 479 vertexdata->End(); 480 indexdata=create_index_data_func(ar->indexdata->GetNumMaxIndices());481 indexdata->Begin( );484 vertexdata->End();*/ 485 /* indexdata=create_index_data_func(ar->indexdata->GetNumMaxIndices()); 486 indexdata->Begin(ar->leavesSubMeshID,indexdata->GetNumMaxIndices()); 482 487 for (unsigned int i=0; i<indexdata->GetNumMaxIndices(); i++) 483 488 indexdata->SetIndex(i,ar->indexdata->GetIndex(i)); 484 indexdata->End(); 485 486 Leaves=new Leaf[vertexdata->GetNumVertices()];489 indexdata->End();*/ 490 491 Leaves=new RuntimeLeaf[TotalVerts]; 487 492 // for (unsigned int i=0; i<vertexdata->GetNumVertices(); i++) 488 493 // Leaves[i]=ar->Leaves[i]; 489 memcpy(Leaves,ar->Leaves,sizeof(Leaf)* vertexdata->GetNumVertices());494 memcpy(Leaves,ar->Leaves,sizeof(Leaf)*TotalVerts); 490 495 491 496 // esto no sé si devería haber akí 492 indexdata->SetNumValidIndices(0);497 // indexdata->SetNumValidIndices(0); 493 498 494 499 int h=0; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.h
r1083 r1526 26 26 int begin, final; 27 27 int active_leaf_count; 28 int leavesSubMeshID; 28 29 29 Foliage (const Geometry::SubMesh *, const Geometry::TreeSimplificationSequence *, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); 30 Foliage ( int leavesSubMeshID, 31 const Geometry::SubMesh *, 32 const Geometry::TreeSimplificationSequence * ); 33 30 34 Foliage (const Foliage *); 31 35 virtual ~Foliage (void); // Destructor … … 33 37 void CalculateLOD(int nhojas); 34 38 35 Geometry::VertexData *vertexdata; 36 Geometry::IndexData *indexdata; 37 38 Leaf *Leaves; 39 RuntimeLeaf *Leaves; 39 40 ActiveLeafNode *MinDet; // first active leaf 40 41 int leafCount; … … 45 46 46 47 private: 47 Geometry::CREATEVERTEXDATAFUNC create_vertex_data_func;48 Geometry::CREATEINDEXDATAFUNC create_index_data_func;49 48 50 49 bool IsActive( int num) const; … … 59 58 bool ReadSimpSeq(const Geometry::TreeSimplificationSequence *); /// returns true when successful 60 59 void FillRoot(void); 61 62 void GetNormalH (Leaf&);63 64 void CrossProduct(const float *v1, const float *v2, float *res);65 void Normalize(const float *v, float *res);66 // void CalculaNormalesVertice(void);67 void CalculateTexCoordsAndNorms(void);68 69 60 }; 70 61 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/simplif.h
r1025 r1526 12 12 class pair_info : public Heapable 13 13 { 14 public:15 Vertex *v0, *v1;14 public: 15 Vertex *v0, *v1; 16 16 17 Vec3 candidate;18 real cost;17 Vec3 candidate; 18 real cost; 19 19 20 pair_info(Vertex *a,Vertex *b) { v0=a; v1=b; cost=HUGE; }20 pair_info(Vertex *a,Vertex *b) { v0=a; v1=b; cost=HUGE; } 21 21 22 bool isValid() { return v0->isValid() && v1->isValid(); }22 bool isValid() { return v0->isValid() && v1->isValid(); } 23 23 }; 24 24 … … 27 27 class vert_info 28 28 { 29 public:29 public: 30 30 31 pair_buffer pairs;31 pair_buffer pairs; 32 32 33 Mat4 Q;34 real norm;33 Mat4 Q; 34 real norm; 35 35 36 vert_info() : Q(Mat4::zero) { pairs.init(2); norm=0.0; }36 vert_info() : Q(Mat4::zero) { pairs.init(2); norm=0.0; } 37 37 }; 38 38 } 39 -
GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h
r1090 r1526 87 87 using namespace Geometry; 88 88 89 class GeoToolIndexData : public Geometry::IndexData 90 { 91 public: 92 GeoToolIndexData(unsigned int submeshes):Geometry::IndexData(){ 93 submeshcount = submeshes; 94 indices=new unsigned int*[submeshcount]; 95 indexCount=new unsigned int[submeshcount]; 96 for (int i=0; i<submeshcount; i++) 97 { 98 indices[i]=NULL; 99 indexCount[i]=0; 100 } 101 } 102 virtual ~GeoToolIndexData(void){ 103 for (int i=0; i<submeshcount; i++) 104 if (indices[i]) 105 delete[] indices[i]; 106 delete[] indices; 107 delete[] indexCount; 108 } 109 110 virtual void Begin(unsigned int submesh, unsigned int numinds){ 111 if (indices[submesh]) 112 delete[] indices[submesh]; 113 indices[submesh] = new unsigned int[numinds]; 114 indexCount[submesh] = numinds; 115 modifySubmesh=submesh; 116 } 117 118 virtual void SetIndex(unsigned int i, unsigned int index){ 119 indices[modifySubmesh][i] = index; 120 } 121 122 virtual void End(void){} 123 virtual void BorrowIndexData(const IndexData *){} 124 125 unsigned int submeshcount; 126 unsigned int **indices; 127 unsigned int *indexCount; 128 unsigned int modifySubmesh; 129 }; 130 89 131 class GeoMeshViewUI 90 132 { … … 109 151 // Lod tree object. 110 152 LodTreeLibrary *lodTreeLib; 111 153 112 154 MeshSimplifier *mMeshSimplifier; 113 155 TreeSimplifier *mTreeSimplifier; … … 117 159 118 160 MeshSimplificationSequence *oMeshSimpSequence; 119 LodStripsConstructor *oLodStrip;120 GeoMeshLoader *geoMeshLoader;161 LodStripsConstructor *oLodStrip; 162 GeoMeshLoader *geoMeshLoader; 121 163 122 164 inline void cb_menuFileOpen_i(fltk::Item*, void*); … … 288 330 289 331 public: 332 333 // the indexdata for the LOD models 334 GeoToolIndexData *lod_index_data; 290 335 291 336 GeoMeshView *geoMeshView; -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
r1090 r1526 594 594 // For each strip. 595 595 // MultiIndexData *dataInterface = lodStripsLib->dataRetrievalInterface; 596 IndexData *dataInterface = lodStripsLib->dataRetrievalInterface;596 /* IndexData *dataInterface = lodStripsLib->dataRetrievalInterface; 597 597 size_t triangle_count = dataInterface->GetNumValidIndices() - 2; 598 /* for (int strip = 0; strip < dataInterface->GetNumPrims(); strip++) 599 { 600 // triangle_count += lodStripsLib->mStrips[strip].size() - 2; 601 triangle_count += dataInterface->GetNumValidIndices(strip) - 2; 602 }*/ 603 604 return triangle_count; 598 599 return triangle_count;*/ 600 601 return lodStripsLib->GetCurrentTriangleCount(); 605 602 } 606 603 … … 716 713 i = 0; 717 714 718 /*if (getColorStrips())715 if (getColorStrips()) 719 716 { 720 717 // Gets the color of the strip. … … 728 725 // Paint a new color. 729 726 glColor3f(r,g,b); 730 }*/ 727 GLfloat color[] = {r,g,b,1.0f}; 728 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color); 729 } 731 730 732 731 … … 904 903 905 904 // For each one of the strips. 906 /* for (int strip = 0; strip < geosubmesh->mStripCount; strip++)907 {908 // Paint the current strip.909 glBegin(GL_TRIANGLE_STRIP);910 911 if (getColorStrips())912 {913 // Gets the color of the strip.914 r = mStripColors[submesh][color_index].r;915 g = mStripColors[submesh][color_index].g;916 b = mStripColors[submesh][color_index].b;917 918 // Change to the next color.919 color_index++;920 921 // Paint a new color.922 glColor3f(r,g,b);923 }924 925 // For each index of the strip.926 for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(current_strip); index++)927 {928 position = lodStripsLib->dataRetrievalInterface->GetIndex(current_strip,index);929 930 // Gets the vertex normal.931 vector3 = geosubmesh->mVertexBuffer->mNormal[position];932 933 x = vector3[0];934 y = vector3[1];935 z = vector3[2];936 937 // Sets the vertex normal.938 glNormal3f(x,y,z);939 940 // set the texture coordinates if needed941 if (usetex)942 {943 vector2 = geosubmesh->mVertexBuffer->mTexCoords[position];944 x = vector2[0];945 y = vector2[1];946 glTexCoord2f(x,y);947 }948 949 // Gets the vertex coordinates.950 vector3 = geosubmesh->mVertexBuffer->mPosition[position];951 952 x = vector3[0];953 y = vector3[1];954 z = vector3[2];955 956 // Sets the vertex position.957 glVertex3f(x,y,z);958 }959 960 // Increments current strip.961 current_strip++;962 963 // A strip is generated.964 glEnd();965 966 }*/967 968 905 int indices_to_render = lodStripsLib->GetValidIndexCount(submesh); 969 906 int offset = lodStripsLib->GetValidOffset(submesh); 970 907 971 908 glBegin(GL_TRIANGLE_STRIP); 972 //for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(); index ++) 973 for (int index = offset; index < indices_to_render+offset; index ++) 974 { 975 position = lodStripsLib->dataRetrievalInterface->GetIndex(index); 909 // for (int index = offset; index < indices_to_render+offset; index ++) 910 for (int index = 0; index < mGeoMeshViewUI->lod_index_data->indexCount[submesh]; index ++) 911 { 912 // position = lodStripsLib->dataRetrievalInterface->GetIndex(index); 913 position = mGeoMeshViewUI->lod_index_data->indices[submesh][index]; 976 914 977 915 // Gets the vertex normal. … … 1045 983 1046 984 // For each one of the strips. 1047 /* for (int strip = 0; strip < geosubmesh->mStripCount; strip++)1048 {1049 // Paint the current strip.1050 glBegin(GL_TRIANGLE_STRIP);1051 1052 if (getColorStrips())1053 {1054 // Gets the color of the strip.1055 r = mStripColors[submesh][color_index].r;1056 g = mStripColors[submesh][color_index].g;1057 b = mStripColors[submesh][color_index].b;1058 1059 // Change to the next color.1060 color_index++;1061 1062 // Paint a new color.1063 glColor3f(r,g,b);1064 }1065 1066 // For each index of the strip.1067 for (int index = 0; index < lodTreeLib->CurrentLOD_Trunk_IndexCountByStrip(current_strip); index++)1068 {1069 position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(current_strip,index);1070 1071 // Gets the vertex normal.1072 vector3 = geosubmesh->mVertexBuffer->mNormal[position];1073 1074 x = vector3[0];1075 y = vector3[1];1076 z = vector3[2];1077 1078 // Sets the vertex normal.1079 glNormal3f(x,y,z);1080 1081 // set the texture coordinates if needed1082 if (usetex)1083 {1084 vector2 = geosubmesh->mVertexBuffer->mTexCoords[position];1085 x = vector2[0];1086 y = vector2[1];1087 glTexCoord2f(x,y);1088 }1089 1090 // Gets the vertex coordinates.1091 vector3 = geosubmesh->mVertexBuffer->mPosition[position];1092 1093 x = vector3[0];1094 y = vector3[1];1095 z = vector3[2];1096 1097 // Sets the vertex position.1098 glVertex3f(x,y,z);1099 }1100 1101 // Increments current strip.1102 current_strip++;1103 1104 // A strip is generated.1105 glEnd();1106 1107 }*/1108 1109 // int indices_to_render = lodTreeLib->trunk->GetValidIndexCount(submesh);1110 985 int indices_to_render = lodTreeLib->GetValidTrunkIndexCount(submesh); 1111 986 int begin_index = lodTreeLib->GetValidTrunkOffset(submesh); 1112 987 1113 988 glBegin(GL_TRIANGLE_STRIP); 1114 for (int index = begin_index; index < indices_to_render+begin_index; index ++) 1115 { 1116 position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(index); 989 // for (int index = begin_index; index < indices_to_render+begin_index; index ++) 990 for (int index = 0; index < mGeoMeshViewUI->lod_index_data->indexCount[submesh]; index ++) 991 { 992 // position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(index); 993 position = mGeoMeshViewUI->lod_index_data->indices[submesh][index]; 1117 994 1118 995 // Gets the vertex normal. … … 1157 1034 1158 1035 glBegin(GL_TRIANGLES); 1159 const Geometry::VertexData *foliage_verts = lodTreeLib->Get_Foliage_VertexData();1160 const Geometry::IndexData *foliage_inds = lodTreeLib->CurrentLOD_Foliage_Indices();1161 for (int j=0; j< lodTreeLib->CurrentLOD_Foliage_IndexCount(); j++)1162 { 1163 float vx,vy,vz;1036 Geometry::SubMesh & foliageSubMesh = geoMesh->mSubMesh[lodTreeLib->GetLeavesSubMesh()]; 1037 Geometry::Vector3 auxv; 1038 for (int j=0; j<mGeoMeshViewUI->lod_index_data->indexCount[lodTreeLib->GetLeavesSubMesh()]; j++) 1039 { 1040 int k = mGeoMeshViewUI->lod_index_data->indices[lodTreeLib->GetLeavesSubMesh()][j]; 1164 1041 if (usetex) 1165 1042 { 1166 foliage_verts->GetVertexTexCoord(foliage_inds->GetIndex(j),vx,vy);1167 glTexCoord2f( vx,vy);1168 } 1169 foliage_verts->GetVertexNormal(foliage_inds->GetIndex(j),vx,vy,vz);1170 glNormal3f( vx,vy,vz);1171 foliage_verts->GetVertexCoord(foliage_inds->GetIndex(j),vx,vy,vz);1172 glVertex3f( vx,vy,vz);1043 Geometry::Vector2 tc = foliageSubMesh.mVertexBuffer->mTexCoords[k]; 1044 glTexCoord2f(tc.x,tc.y); 1045 } 1046 auxv = foliageSubMesh.mVertexBuffer->mNormal[k]; 1047 glNormal3f(auxv.x,auxv.y,auxv.z); 1048 auxv = foliageSubMesh.mVertexBuffer->mPosition[k]; 1049 glVertex3f(auxv.x,auxv.y,auxv.z); 1173 1050 } 1174 1051 glEnd(); … … 1253 1130 1254 1131 glEnable (GL_POLYGON_OFFSET_LINE); 1255 glPolygonOffset(- 1,-1);1132 glPolygonOffset(-0.5,1); 1256 1133 glEnable(GL_DEPTH_TEST); 1257 1134 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 1269 1146 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco); 1270 1147 1271 glClearColor(0 ,0,0,0);1148 glClearColor(0.3,0.3,0.3,0); 1272 1149 1273 1150 if (mCW) … … 1292 1169 { 1293 1170 enableColorStrips(); 1294 glDisable(GL_LIGHTING);1171 //glDisable(GL_LIGHTING); 1295 1172 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 1296 1173 drawGeoMesh(false); … … 1304 1181 { 1305 1182 disableColorStrips(); 1306 glDisable(GL_LIGHTING); 1307 glColor3d(0.0, 0.0, 1.0); 1183 //glDisable(GL_LIGHTING); 1184 glColor3d(0.0, 0.0, 0.0); 1185 GLfloat color[] = {0.0f,0.0f,0.0f,1.0f}; 1186 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color); 1187 1308 1188 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 1309 1189 drawGeoMesh(true); … … 1313 1193 if (!mSolid) 1314 1194 { 1315 enableColorStrips();1316 glEnable(GL_LIGHTING);1195 disableColorStrips(); 1196 //glEnable(GL_LIGHTING); 1317 1197 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 1318 1198 drawGeoMesh(false); -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
r1098 r1526 1075 1075 { 1076 1076 // Create the simplification sequence. 1077 createSimplificationSequence();1077 //createSimplificationSequence(); 1078 1078 1079 1079 // Show build process. … … 1120 1120 { 1121 1121 // Create the simplification sequence. 1122 createSimplificationSequence();1122 //createSimplificationSequence(); 1123 1123 1124 delete mMeshSimplifier;1124 //delete mMeshSimplifier; 1125 1125 geoMeshView->restoreContext(); 1126 1126 … … 1211 1211 1212 1212 // Simplification sequence. 1213 oMeshSimpSequence = new MeshSimplificationSequence();1213 //oMeshSimpSequence = new MeshSimplificationSequence(); 1214 1214 1215 1215 // Loads a simplification sequence file. 1216 oMeshSimpSequence->Load(Serializer("SimplifSequence.txt",Serializer::READ)); 1216 //oMeshSimpSequence->Load(Serializer("SimplifSequence.txt",Serializer::READ)); 1217 1218 // Simplification sequence. 1219 oMeshSimpSequence = mMeshSimplifier->GetSimplificationSequence(); 1217 1220 1218 1221 // If the simplification sequence and the mesh exist. … … 1224 1227 progress_function); 1225 1228 1226 // oSerializer = new Serializer(file_name,Serializer::Mode::WRITE); 1227 1228 oLodStrip->UpdateMesh(); 1229 oLodStrip->UpdateMesh(); 1229 1230 1230 1231 // Deletes the previous mesh. … … 1243 1244 1244 1245 mesh_saver = new GeoMeshSaver(); 1245 // file_name[strlen(file_name) - 4] = '\0';1246 1246 // file_name[strlen(file_name) - 4] = '\0'; 1247 1247 1248 mesh_saver->leavesSubMesh=idMeshLeaves; 1248 1249 mesh_saver->leavesVB=origSubMeshVB; … … 1252 1253 delete mesh_saver; 1253 1254 oLodStrip->Save(file_name); 1255 1256 // Delete simplified mesh. 1257 delete mMeshSimplifier; 1254 1258 // Close file. 1255 // delete oSerializer;1259 // delete oSerializer; 1256 1260 } 1257 1261 else … … 1262 1266 1263 1267 // Deletes the siplification sequence object. 1264 delete oMeshSimpSequence;1268 //delete oMeshSimpSequence; 1265 1269 1266 1270 if (mApplicationState==LODTREES_AUTO) … … 2145 2149 2146 2150 secsimpl = mMeshSimplifier->GetSimplificationSequence(); 2147 2148 secsimpl->putMeshName(nombremesh); // Nombre del mesh para guardar la secuencia de simplificación 2151 2152 // Nombre del mesh para guardar la secuencia de simplificación. 2153 secsimpl->putMeshName(nombremesh); 2149 2154 secsimpl->Save(Geometry::Serializer("SimplifSequence.txt",Serializer::WRITE)); 2150 2151 //delete secsimpl;2152 2155 } 2153 2156 … … 2325 2328 { 2326 2329 delete lodStripsLib; 2330 delete lod_index_data; 2327 2331 } 2328 2332 2329 2333 // New lod strips object. 2330 lodStripsLib = new LodStripsLibrary(loddata, geomesh); 2334 lod_index_data = new GeoToolIndexData(geomesh->mSubMeshCount); 2335 lodStripsLib = new LodStripsLibrary(loddata, geomesh, lod_index_data); 2331 2336 2332 2337 // Sets the slider range. … … 2348 2353 // If there is no lod strips object. 2349 2354 if (lodTreeLib) 2355 { 2350 2356 delete lodTreeLib; 2357 delete lod_index_data; 2358 } 2351 2359 2352 2360 // New lod strips object. 2353 2361 2354 lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh/*,ileafSubMesh*/); 2362 lod_index_data = new GeoToolIndexData(geomesh->mSubMeshCount); 2363 lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh,lod_index_data); 2355 2364 2356 2365 // Sets the slider range. … … 2669 2678 2670 2679 { 2671 mMetricLabel = new fltk::Output(26, 28, 5, 25, "Metric");2680 mMetricLabel = new fltk::Output(26, 28, 0, 25, "Metric"); 2672 2681 fltk::Output* o = mMetricLabel; 2673 2682 o->set_vertical(); … … 2715 2724 2716 2725 { 2717 mMeshReductionLabel = new fltk::Output(26, 124, 5, 25, "Mesh Reduction");2726 mMeshReductionLabel = new fltk::Output(26, 124, 0, 25, "Mesh Reduction"); 2718 2727 fltk::Output* o = mMeshReductionLabel; 2719 2728 o->set_vertical();
Note: See TracChangeset
for help on using the changeset viewer.