Changeset 1019 for GTP/trunk/Lib/Geom/shared/GTGeometry
- Timestamp:
- 06/16/06 16:56:05 (19 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry
- Files:
-
- 2 deleted
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/GTGeometry.vcproj
r1014 r1019 260 260 </File> 261 261 <File 262 RelativePath=".\src\libs\leaves\Arbol.cpp">263 </File>264 <File265 262 RelativePath=".\src\libs\leaves\foliage.cpp"> 266 263 </File> … … 360 357 </File> 361 358 <File 362 RelativePath=".\src\libs\leaves\arbol.h">363 </File>364 <File365 359 RelativePath=".\include\auxiliar.h"> 366 360 </File> -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h
r1018 r1019 44 44 uint32 MaxFoliageLod(void) const; 45 45 46 // funciones nuevas propuestas46 // new proposed functions 47 47 // uint32 Get_Trunk_VertexCount(void) const; 48 48 // uint32 Get_Trunk_MaxIndexCount(uint32 istrip) const; -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoTreeSimplifier.h
r1007 r1019 4 4 #include "GeoMesh.h" 5 5 #include "GeoTreeSimpSequence.h" 6 #include "Hoja.h"7 6 8 7 #define K1 0.8f //distance factor … … 10 9 11 10 class LeafOctree; 11 class Leaf; 12 12 13 13 namespace Geometry … … 51 51 52 52 private: 53 void CalculateLeafCenter( Hoja&);54 void CalculateLeafNormal( Hoja&);55 float CalculateLeafArea( Hoja&) const;53 void CalculateLeafCenter(Leaf &); 54 void CalculateLeafNormal(Leaf &); 55 float CalculateLeafArea(Leaf &) const; 56 56 void CoplanarBetweenLeaves(void); 57 57 float BoundingSphereDiameter() const; … … 64 64 long int Collapse(float); 65 65 void TwoGreater(float*, int* ); 66 void ChooseVertices( Hoja& , Hoja& , long int);67 float HausdorffOptimized(const Hoja &, const Hoja&) const;68 float DistanceFromCenters(const Hoja &, const Hoja&) const;66 void ChooseVertices(Leaf& , Leaf& , long int); 67 float HausdorffOptimized(const Leaf &, const Leaf&) const; 68 float DistanceFromCenters(const Leaf &, const Leaf &) const; 69 69 float distan(float, float, float, float, float, float) const; 70 70 long int MinDistance(void); … … 82 82 const Mesh *objmesh; 83 83 float (*Vertex)[3]; 84 Hoja*Leaves;84 Leaf *Leaves; 85 85 long int activeLeaves, countLeaves; 86 86 TreeSimplificationSequence *mtreesimpsequence; … … 96 96 int vertex_count; 97 97 LeafOctree ** octree_owning_leaf; 98 LeafOctree *GetMinOctreeNodeForLeaf(LeafOctree *start, const Hoja&leaf);98 LeafOctree *GetMinOctreeNodeForLeaf(LeafOctree *start, const Leaf &leaf); 99 99 bool PruneOctree(LeafOctree *); // erases one octree level and translates its leaves to the parent. Returns true if the node itself was pruned 100 100 }; -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/VertexData.h
r831 r1019 36 36 virtual void SetIndex(unsigned int i, unsigned int index)=0; 37 37 virtual void End(void)=0; 38 39 // virtual void UpdateData(int*,int)=0; 38 40 39 41 virtual unsigned int GetIndex(unsigned int) const =0; -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/leaf.h
r834 r1019 1 #ifndef HOJA_H2 #define HOJA_H1 #ifndef LEAF_H 2 #define LEAF_H 3 3 4 5 class Hoja 4 class Leaf 6 5 { 7 6 public : 8 // Variable members 9 int Vert_Hoja[4];// Array of pointers to vertices 10 float Normal[3]; 11 float Cuantas_hojas; 12 float Centro[3]; 13 int padre; 14 int hijoi; 15 int hijod; 7 int vertsLeaf[4];// Array of pointers to vertices 8 float normal[3]; 9 float parentLeafCount; 10 float center[3]; 11 int parent; 12 int childLeft; 13 int childRight; 16 14 int visible; 17 int r aiz;15 int root; 18 16 19 bool exist e;20 int hoja_cerca;17 bool exists; 18 int leafNear; 21 19 float dist; 22 long int hoja_cop;20 long int leafCop; 23 21 float coplanar; 24 float criterio; 25 long int hoja_crit; 26 22 float criteria; 23 long int leafCrit; 27 24 28 // Identifi cadores de los triángulos que forman la hoja29 long int id _triangulo[2];25 // Identifiers of the triangles forming this leaf 26 long int idTriangle[2]; 30 27 31 28 public : 32 29 // Constructors 33 Hoja (void); // Voidconstructor34 Hoja (const Hoja& aHoja); // Copy constructor35 virtual ~ Hoja(void); // Destructor30 Leaf (void); // default constructor 31 Leaf (const Leaf&); // Copy constructor 32 virtual ~Leaf (void); // Destructor 36 33 37 float Distanc ia (Hoja&);38 float Coplanari dad (Hoja&);34 float Distance (Leaf&); 35 float Coplanarity (Leaf&); 39 36 }; 40 37 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp
r1018 r1019 2 2 #include <assert.h> 3 3 #include "GeoLodTreeLibrary.h" 4 #include "libs/leaves/arbol.h"5 4 #include "libs/leaves/Foliage.h" 6 5 … … 29 28 // arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/); 30 29 Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]); 31 arbol = new Arbol(leafsSubMesh,leafSimpSeqFile.c_str()); 32 foliage = new Foliage(arbol); 30 foliage = new Foliage(leafsSubMesh,leafSimpSeqFile.c_str()); 33 31 } 34 32 /* … … 54 52 { 55 53 if (trunk) delete trunk; 56 if (arbol) delete arbol;57 54 if (foliage) delete foliage; 58 55 /* if (trunk_all_indices) delete trunk_all_indices; … … 111 108 foliage->AjusteHojas(newlod); 112 109 113 arbol->indexdata->Begin();114 arbol->vertexdata->Begin();110 foliage->indexdata->Begin(); 111 foliage->vertexdata->Begin(); 115 112 int i = foliage->ppio; 116 113 int auxnumhojas = 0; … … 121 118 } 122 119 123 assert(auxnumhojas*6<=int( arbol->indexdata->GetNumMaxIndices()));124 arbol->indexdata->SetNumValidIndices(auxnumhojas*6);120 assert(auxnumhojas*6<=int(foliage->indexdata->GetNumMaxIndices())); 121 foliage->indexdata->SetNumValidIndices(auxnumhojas*6); 125 122 i = foliage->ppio; 126 123 int kkkk=0; … … 128 125 { 129 126 unsigned int v0,v1,v2,v3; 130 v0 = arbol->Hojas[i].Vert_Hoja[0];131 v1 = arbol->Hojas[i].Vert_Hoja[1];132 v2 = arbol->Hojas[i].Vert_Hoja[2];133 v3 = arbol->Hojas[i].Vert_Hoja[3];134 135 arbol->indexdata->SetIndex(kkkk+0,v0);136 arbol->indexdata->SetIndex(kkkk+1,v1);137 arbol->indexdata->SetIndex(kkkk+2,v2);138 arbol->indexdata->SetIndex(kkkk+3,v2);139 arbol->indexdata->SetIndex(kkkk+4,v1);140 arbol->indexdata->SetIndex(kkkk+5,v3);141 142 arbol->vertexdata->SetVertexTexCoord(v0,0,0);143 arbol->vertexdata->SetVertexTexCoord(v1,0,1);144 arbol->vertexdata->SetVertexTexCoord(v2,1,0);145 arbol->vertexdata->SetVertexTexCoord(v3,1,1);127 v0 = foliage->Leaves[i].vertsLeaf[0]; 128 v1 = foliage->Leaves[i].vertsLeaf[1]; 129 v2 = foliage->Leaves[i].vertsLeaf[2]; 130 v3 = foliage->Leaves[i].vertsLeaf[3]; 131 132 foliage->indexdata->SetIndex(kkkk+0,v0); 133 foliage->indexdata->SetIndex(kkkk+1,v1); 134 foliage->indexdata->SetIndex(kkkk+2,v2); 135 foliage->indexdata->SetIndex(kkkk+3,v2); 136 foliage->indexdata->SetIndex(kkkk+4,v1); 137 foliage->indexdata->SetIndex(kkkk+5,v3); 138 139 foliage->vertexdata->SetVertexTexCoord(v0,0,0); 140 foliage->vertexdata->SetVertexTexCoord(v1,0,1); 141 foliage->vertexdata->SetVertexTexCoord(v2,1,0); 142 foliage->vertexdata->SetVertexTexCoord(v3,1,1); 146 143 147 144 kkkk+=6; 148 145 i=foliage->Acth[i].next; 149 146 } 150 arbol->indexdata->End();151 arbol->vertexdata->End();147 foliage->indexdata->End(); 148 foliage->vertexdata->End(); 152 149 153 150 return 0; … … 157 154 { 158 155 // return arbol->minHojas; 159 return arbol->nHojas;156 return foliage->nHojas; 160 157 } 161 158 uint32 LodTreeLibrary::MaxFoliageLod(void) const … … 163 160 // return arbol->TotHojas; 164 161 //return arbol->nHojas; 165 return arbol->minHojas;162 return foliage->minHojas; 166 163 } 167 164 … … 180 177 const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const 181 178 { 182 return arbol->vertexdata;179 return foliage->vertexdata; 183 180 } 184 181 … … 186 183 { 187 184 // return current_foliage_indices; 188 return arbol->indexdata;185 return foliage->indexdata; 189 186 } 190 187 … … 198 195 { 199 196 // return current_foliage_indexcount; 200 return arbol->indexdata->GetNumValidIndices();197 return foliage->indexdata->GetNumValidIndices(); 201 198 } 202 199 /* … … 218 215 uint32 LodTreeLibrary::Get_Foliage_MaxIndexCount(void) const 219 216 { 220 return arbol->indexdata->GetNumMaxIndices();221 } 217 return foliage->indexdata->GetNumMaxIndices(); 218 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimplifier.cpp
r1014 r1019 1 1 #include "GeoTreeSimplifier.h" 2 #include " Hoja.h"2 #include "Leaf.h" 3 3 4 4 #include <iostream> … … 87 87 /* std::map<float,int> hojas_x_crit; 88 88 for (int i=0; i<countLeaves; i++) 89 hojas_x_crit[Leaves[i].criteri o] = i;89 hojas_x_crit[Leaves[i].criteria] = i; 90 90 91 91 int *leaf_order = new int[countLeaves]; … … 167 167 168 168 if (countLeaves > 0) 169 Leaves = new Hoja[2*countLeaves];169 Leaves = new Leaf[2*countLeaves]; 170 170 171 171 activeLeaves = countLeaves; … … 191 191 v2=mesh->mSubMesh[meshLeaves].mIndex[j+1]; 192 192 v3=mesh->mSubMesh[meshLeaves].mIndex[j+2]; 193 Leaves[pos]. Vert_Hoja[0]=v1;194 Leaves[pos]. Vert_Hoja[1]=v2;195 Leaves[pos]. Vert_Hoja[2]=v3;196 Leaves[pos].id _triangulo[0]=triangleID;197 Leaves[pos].exist e=true;193 Leaves[pos].vertsLeaf[0]=v1; 194 Leaves[pos].vertsLeaf[1]=v2; 195 Leaves[pos].vertsLeaf[2]=v3; 196 Leaves[pos].idTriangle[0]=triangleID; 197 Leaves[pos].exists=true; 198 198 triangleID++; 199 199 200 200 // second triangle 201 201 v3=mesh->mSubMesh[meshLeaves].mIndex[j+5]; 202 Leaves[pos]. Vert_Hoja[3]=v3;203 Leaves[pos].id _triangulo[1]=triangleID;202 Leaves[pos].vertsLeaf[3]=v3; 203 Leaves[pos].idTriangle[1]=triangleID; 204 204 triangleID++; 205 205 … … 228 228 229 229 // Calculates the center of a leaf 230 void TreeSimplifier::CalculateLeafCenter( Hoja&auxleaf)230 void TreeSimplifier::CalculateLeafCenter(Leaf &auxleaf) 231 231 { 232 232 float max_x; … … 238 238 239 239 //x1 240 max_x = max(max(Vertex[auxleaf. Vert_Hoja[0]][0],Vertex[auxleaf.Vert_Hoja[1]][0]),241 max(Vertex[auxleaf. Vert_Hoja[2]][0],Vertex[auxleaf.Vert_Hoja[3]][0]));242 243 min_x = min(min(Vertex[auxleaf. Vert_Hoja[0]][0],Vertex[auxleaf.Vert_Hoja[1]][0]),244 min(Vertex[auxleaf. Vert_Hoja[2]][0],Vertex[auxleaf.Vert_Hoja[3]][0]));245 246 auxleaf. Centro[0] = (max_x + min_x)/2;240 max_x = max(max(Vertex[auxleaf.vertsLeaf[0]][0],Vertex[auxleaf.vertsLeaf[1]][0]), 241 max(Vertex[auxleaf.vertsLeaf[2]][0],Vertex[auxleaf.vertsLeaf[3]][0])); 242 243 min_x = min(min(Vertex[auxleaf.vertsLeaf[0]][0],Vertex[auxleaf.vertsLeaf[1]][0]), 244 min(Vertex[auxleaf.vertsLeaf[2]][0],Vertex[auxleaf.vertsLeaf[3]][0])); 245 246 auxleaf.center[0] = (max_x + min_x)/2; 247 247 248 248 //y1 249 max_y = max(max(Vertex[auxleaf. Vert_Hoja[0]][1],Vertex[auxleaf.Vert_Hoja[1]][1]),250 max(Vertex[auxleaf. Vert_Hoja[2]][1],Vertex[auxleaf.Vert_Hoja[3]][1]));251 252 min_y = min(min(Vertex[auxleaf. Vert_Hoja[0]][1],Vertex[auxleaf.Vert_Hoja[1]][1]),253 min(Vertex[auxleaf. Vert_Hoja[2]][1],Vertex[auxleaf.Vert_Hoja[3]][1]));254 255 auxleaf. Centro[1] = (max_y + min_y) / 2;249 max_y = max(max(Vertex[auxleaf.vertsLeaf[0]][1],Vertex[auxleaf.vertsLeaf[1]][1]), 250 max(Vertex[auxleaf.vertsLeaf[2]][1],Vertex[auxleaf.vertsLeaf[3]][1])); 251 252 min_y = min(min(Vertex[auxleaf.vertsLeaf[0]][1],Vertex[auxleaf.vertsLeaf[1]][1]), 253 min(Vertex[auxleaf.vertsLeaf[2]][1],Vertex[auxleaf.vertsLeaf[3]][1])); 254 255 auxleaf.center[1] = (max_y + min_y) / 2; 256 256 257 257 //z1 258 max_z = max(max(Vertex[auxleaf. Vert_Hoja[0]][2],Vertex[auxleaf.Vert_Hoja[1]][2]),259 max(Vertex[auxleaf. Vert_Hoja[2]][2],Vertex[auxleaf.Vert_Hoja[3]][2]));260 261 min_z = min(min(Vertex[auxleaf. Vert_Hoja[0]][2],Vertex[auxleaf.Vert_Hoja[1]][2]),262 min(Vertex[auxleaf. Vert_Hoja[2]][2],Vertex[auxleaf.Vert_Hoja[3]][2]));263 264 auxleaf. Centro[2] = (max_z + min_z) / 2;258 max_z = max(max(Vertex[auxleaf.vertsLeaf[0]][2],Vertex[auxleaf.vertsLeaf[1]][2]), 259 max(Vertex[auxleaf.vertsLeaf[2]][2],Vertex[auxleaf.vertsLeaf[3]][2])); 260 261 min_z = min(min(Vertex[auxleaf.vertsLeaf[0]][2],Vertex[auxleaf.vertsLeaf[1]][2]), 262 min(Vertex[auxleaf.vertsLeaf[2]][2],Vertex[auxleaf.vertsLeaf[3]][2])); 263 264 auxleaf.center[2] = (max_z + min_z) / 2; 265 265 } 266 266 267 267 268 268 // calculate the normal vector of a leaf 269 void TreeSimplifier::CalculateLeafNormal( Hoja&auxleaf)269 void TreeSimplifier::CalculateLeafNormal(Leaf &auxleaf) 270 270 { 271 271 float onex, oney, onez; … … 273 273 float threex, threey, threez; 274 274 275 onex = Vertex[auxleaf. Vert_Hoja[0]][0]; oney = Vertex[auxleaf.Vert_Hoja[0]][1]; onez = Vertex[auxleaf.Vert_Hoja[0]][2];276 twox = Vertex[auxleaf. Vert_Hoja[1]][0]; twoy = Vertex[auxleaf.Vert_Hoja[1]][1]; twoz = Vertex[auxleaf.Vert_Hoja[1]][2];277 threex = Vertex[auxleaf. Vert_Hoja[2]][0]; threey = Vertex[auxleaf.Vert_Hoja[2]][1]; threez = Vertex[auxleaf.Vert_Hoja[2]][2];278 279 auxleaf. Normal[0] = ((twoz-onez)*(threey-oney)) - ((twoy-oney)*(threez-onez));280 auxleaf. Normal[1] = ((twox-onex)*(threez-onez)) - ((threex-onex)*(twoz-onez));281 auxleaf. Normal[2] = ((threex-onex)*(twoy-oney)) - ((twox-onex)*(threey-oney));275 onex = Vertex[auxleaf.vertsLeaf[0]][0]; oney = Vertex[auxleaf.vertsLeaf[0]][1]; onez = Vertex[auxleaf.vertsLeaf[0]][2]; 276 twox = Vertex[auxleaf.vertsLeaf[1]][0]; twoy = Vertex[auxleaf.vertsLeaf[1]][1]; twoz = Vertex[auxleaf.vertsLeaf[1]][2]; 277 threex = Vertex[auxleaf.vertsLeaf[2]][0]; threey = Vertex[auxleaf.vertsLeaf[2]][1]; threez = Vertex[auxleaf.vertsLeaf[2]][2]; 278 279 auxleaf.normal[0] = ((twoz-onez)*(threey-oney)) - ((twoy-oney)*(threez-onez)); 280 auxleaf.normal[1] = ((twox-onex)*(threez-onez)) - ((threex-onex)*(twoz-onez)); 281 auxleaf.normal[2] = ((threex-onex)*(twoy-oney)) - ((twox-onex)*(threey-oney)); 282 282 } 283 283 … … 296 296 float dist1, dist2, dist3, dist4, distmp, dista, distb, dist; 297 297 298 onex=Vertex[leaf1. Vert_Hoja[0]][0]; oney= Vertex[leaf1.Vert_Hoja[0]][1]; onez = Vertex[leaf1.Vert_Hoja[0]][2];299 twox = Vertex[leaf1. Vert_Hoja[1]][0]; twoy = Vertex[leaf1.Vert_Hoja[1]][1]; twoz = Vertex[leaf1.Vert_Hoja[1]][2];300 threex = Vertex[leaf1. Vert_Hoja[2]][0]; threey = Vertex[leaf1.Vert_Hoja[2]][1]; threez = Vertex[leaf1.Vert_Hoja[2]][2];301 fourx = Vertex[leaf1. Vert_Hoja[3]][0]; foury = Vertex[leaf1.Vert_Hoja[3]][1]; fourz = Vertex[leaf1.Vert_Hoja[3]][2];302 303 304 x1 = Vertex[leaf2. Vert_Hoja[0]][0]; y1 = Vertex[leaf2.Vert_Hoja[0]][1]; z1 = Vertex[leaf2.Vert_Hoja[0]][2];305 x2 = Vertex[leaf2. Vert_Hoja[1]][0]; y2 = Vertex[leaf2.Vert_Hoja[1]][1]; z2 = Vertex[leaf2.Vert_Hoja[1]][2];306 x3 = Vertex[leaf2. Vert_Hoja[2]][0]; y3 = Vertex[leaf2.Vert_Hoja[2]][1]; z3 = Vertex[leaf2.Vert_Hoja[2]][2];307 x4 = Vertex[leaf2. Vert_Hoja[3]][0]; y4 = Vertex[leaf2.Vert_Hoja[3]][1]; z4 = Vertex[leaf2.Vert_Hoja[3]][2];298 onex=Vertex[leaf1.vertsLeaf[0]][0]; oney= Vertex[leaf1.vertsLeaf[0]][1]; onez = Vertex[leaf1.vertsLeaf[0]][2]; 299 twox = Vertex[leaf1.vertsLeaf[1]][0]; twoy = Vertex[leaf1.vertsLeaf[1]][1]; twoz = Vertex[leaf1.vertsLeaf[1]][2]; 300 threex = Vertex[leaf1.vertsLeaf[2]][0]; threey = Vertex[leaf1.vertsLeaf[2]][1]; threez = Vertex[leaf1.vertsLeaf[2]][2]; 301 fourx = Vertex[leaf1.vertsLeaf[3]][0]; foury = Vertex[leaf1.vertsLeaf[3]][1]; fourz = Vertex[leaf1.vertsLeaf[3]][2]; 302 303 304 x1 = Vertex[leaf2.vertsLeaf[0]][0]; y1 = Vertex[leaf2.vertsLeaf[0]][1]; z1 = Vertex[leaf2.vertsLeaf[0]][2]; 305 x2 = Vertex[leaf2.vertsLeaf[1]][0]; y2 = Vertex[leaf2.vertsLeaf[1]][1]; z2 = Vertex[leaf2.vertsLeaf[1]][2]; 306 x3 = Vertex[leaf2.vertsLeaf[2]][0]; y3 = Vertex[leaf2.vertsLeaf[2]][1]; z3 = Vertex[leaf2.vertsLeaf[2]][2]; 307 x4 = Vertex[leaf2.vertsLeaf[3]][0]; y4 = Vertex[leaf2.vertsLeaf[3]][1]; z4 = Vertex[leaf2.vertsLeaf[3]][2]; 308 308 309 309 dist1 = distan ( onex, oney,onez,x1,y1,z1); … … 414 414 415 415 // Calculate the Hausdorff distance (distance between point clouds) (Optimized) 416 float TreeSimplifier::HausdorffOptimized(const Hoja &leaf1, const Hoja& leaf2) const416 float TreeSimplifier::HausdorffOptimized(const Leaf &leaf1, const Leaf& leaf2) const 417 417 { 418 418 float onex, oney, onez; … … 426 426 float dist1, dist2, dist3, dist4, distmp, dista, distb, dist; 427 427 428 onex = Vertex[leaf1. Vert_Hoja[0]][0]; oney = Vertex[leaf1.Vert_Hoja[0]][1]; onez = Vertex[leaf1.Vert_Hoja[0]][2];429 twox = Vertex[leaf1. Vert_Hoja[1]][0]; twoy = Vertex[leaf1.Vert_Hoja[1]][1]; twoz = Vertex[leaf1.Vert_Hoja[1]][2];430 threex = Vertex[leaf1. Vert_Hoja[2]][0]; threey = Vertex[leaf1.Vert_Hoja[2]][1]; threez = Vertex[leaf1.Vert_Hoja[2]][2];431 fourx = Vertex[leaf1. Vert_Hoja[3]][0]; foury = Vertex[leaf1.Vert_Hoja[3]][1]; fourz = Vertex[leaf1.Vert_Hoja[3]][2];432 433 x1 = Vertex[leaf2. Vert_Hoja[0]][0]; y1 = Vertex[leaf2.Vert_Hoja[0]][1]; z1 = Vertex[leaf2.Vert_Hoja[0]][2];434 x2 = Vertex[leaf2. Vert_Hoja[1]][0]; y2 = Vertex[leaf2.Vert_Hoja[1]][1]; z2 = Vertex[leaf2.Vert_Hoja[1]][2];435 x3 = Vertex[leaf2. Vert_Hoja[2]][0]; y3 = Vertex[leaf2.Vert_Hoja[2]][1]; z3 = Vertex[leaf2.Vert_Hoja[2]][2];436 x4 = Vertex[leaf2. Vert_Hoja[3]][0]; y4 = Vertex[leaf2.Vert_Hoja[3]][1]; z4 = Vertex[leaf2.Vert_Hoja[3]][2];428 onex = Vertex[leaf1.vertsLeaf[0]][0]; oney = Vertex[leaf1.vertsLeaf[0]][1]; onez = Vertex[leaf1.vertsLeaf[0]][2]; 429 twox = Vertex[leaf1.vertsLeaf[1]][0]; twoy = Vertex[leaf1.vertsLeaf[1]][1]; twoz = Vertex[leaf1.vertsLeaf[1]][2]; 430 threex = Vertex[leaf1.vertsLeaf[2]][0]; threey = Vertex[leaf1.vertsLeaf[2]][1]; threez = Vertex[leaf1.vertsLeaf[2]][2]; 431 fourx = Vertex[leaf1.vertsLeaf[3]][0]; foury = Vertex[leaf1.vertsLeaf[3]][1]; fourz = Vertex[leaf1.vertsLeaf[3]][2]; 432 433 x1 = Vertex[leaf2.vertsLeaf[0]][0]; y1 = Vertex[leaf2.vertsLeaf[0]][1]; z1 = Vertex[leaf2.vertsLeaf[0]][2]; 434 x2 = Vertex[leaf2.vertsLeaf[1]][0]; y2 = Vertex[leaf2.vertsLeaf[1]][1]; z2 = Vertex[leaf2.vertsLeaf[1]][2]; 435 x3 = Vertex[leaf2.vertsLeaf[2]][0]; y3 = Vertex[leaf2.vertsLeaf[2]][1]; z3 = Vertex[leaf2.vertsLeaf[2]][2]; 436 x4 = Vertex[leaf2.vertsLeaf[3]][0]; y4 = Vertex[leaf2.vertsLeaf[3]][1]; z4 = Vertex[leaf2.vertsLeaf[3]][2]; 437 437 438 438 // variables used to cache distances … … 608 608 for (i = 0; i < countLeaves; i++) 609 609 { 610 if (Leaves[i].exist e)610 if (Leaves[i].exists) 611 611 { 612 612 if (mindist > Leaves[i].dist || which==-1) … … 631 631 for (i=0;i<countLeaves;i++) 632 632 { 633 if (Leaves[i].exist e)633 if (Leaves[i].exists) 634 634 { 635 635 if (i == countLeaves-1) … … 638 638 j = i + 1; 639 639 640 while (Leaves[j].exist e== false)640 while (Leaves[j].exists == false) 641 641 j++; 642 642 643 cop = Leaves[i].Coplanari dad(Leaves[j]);644 Leaves[i]. hoja_cop = j;643 cop = Leaves[i].Coplanarity(Leaves[j]); 644 Leaves[i].leafCop = j; 645 645 646 646 for (j=0; j<countLeaves-1; j++) 647 647 { 648 if (( j != i) && (Leaves[j].exist e))648 if (( j != i) && (Leaves[j].exists)) 649 649 { 650 coptmp = Leaves[i].Coplanari dad(Leaves[j]);650 coptmp = Leaves[i].Coplanarity(Leaves[j]); 651 651 652 652 // Take the most coplanar: close to 1 … … 654 654 { 655 655 cop = coptmp; 656 Leaves[i]. hoja_cop = j;656 Leaves[i].leafCop = j; 657 657 } 658 658 } … … 729 729 730 730 // initialize all vertices to the first 731 xmax = Vertex[Leaves[0]. Vert_Hoja[0]][0];731 xmax = Vertex[Leaves[0].vertsLeaf[0]][0]; 732 732 xmin = xmax; 733 733 734 ymax = Vertex[Leaves[0]. Vert_Hoja[0]][1];734 ymax = Vertex[Leaves[0].vertsLeaf[0]][1]; 735 735 ymin = ymax; 736 736 737 zmax = Vertex[Leaves[0]. Vert_Hoja[0]][2];737 zmax = Vertex[Leaves[0].vertsLeaf[0]][2]; 738 738 zmin = zmax; 739 739 … … 753 753 for (j=0;j<4;j++) 754 754 { 755 if ( xmax < Vertex[Leaves[i]. Vert_Hoja[j]][0]) xmax = Vertex[Leaves[i].Vert_Hoja[j]][0];756 if ( xmin > Vertex[Leaves[i]. Vert_Hoja[j]][0]) xmin = Vertex[Leaves[i].Vert_Hoja[j]][0];757 758 if ( ymax < Vertex[Leaves[i]. Vert_Hoja[j]][1]) ymax = Vertex[Leaves[i].Vert_Hoja[j]][1];759 if ( ymin > Vertex[Leaves[i]. Vert_Hoja[j]][1]) ymin = Vertex[Leaves[i].Vert_Hoja[j]][1];755 if ( xmax < Vertex[Leaves[i].vertsLeaf[j]][0]) xmax = Vertex[Leaves[i].vertsLeaf[j]][0]; 756 if ( xmin > Vertex[Leaves[i].vertsLeaf[j]][0]) xmin = Vertex[Leaves[i].vertsLeaf[j]][0]; 757 758 if ( ymax < Vertex[Leaves[i].vertsLeaf[j]][1]) ymax = Vertex[Leaves[i].vertsLeaf[j]][1]; 759 if ( ymin > Vertex[Leaves[i].vertsLeaf[j]][1]) ymin = Vertex[Leaves[i].vertsLeaf[j]][1]; 760 760 761 if ( zmax < Vertex[Leaves[i]. Vert_Hoja[j]][2]) zmax = Vertex[Leaves[i].Vert_Hoja[j]][2];762 if ( zmin > Vertex[Leaves[i]. Vert_Hoja[j]][2]) zmin = Vertex[Leaves[i].Vert_Hoja[j]][2];761 if ( zmax < Vertex[Leaves[i].vertsLeaf[j]][2]) zmax = Vertex[Leaves[i].vertsLeaf[j]][2]; 762 if ( zmin > Vertex[Leaves[i].vertsLeaf[j]][2]) zmin = Vertex[Leaves[i].vertsLeaf[j]][2]; 763 763 } 764 764 } … … 802 802 { 803 803 //incializo criterio a un numero elevado 804 Leaves[i].criteri o= 1000;805 nhojasi = int(Leaves[i]. Cuantas_hojas);804 Leaves[i].criteria = 1000; 805 nhojasi = int(Leaves[i].parentLeafCount); 806 806 //coplanaridad 807 807 for ( j =0; j<countLeaves;j++) … … 813 813 // ES COMO MÁXIMO 1 814 814 815 nhojasj = int(Leaves[j]. Cuantas_hojas);815 nhojasj = int(Leaves[j].parentLeafCount); 816 816 817 817 if ( abs((nhojasi - nhojasj)) < 2) … … 826 826 criteriotmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); 827 827 //selecciono el criterio menor 828 if (Leaves[i].criteri o> criteriotmp)828 if (Leaves[i].criteria > criteriotmp) 829 829 { 830 Leaves[i].criteri o= criteriotmp;830 Leaves[i].criteria = criteriotmp; 831 831 Leaves[i].hoja_crit = j; 832 832 } … … 854 854 if ((Leaves[i].existe == true) && (i != hojanueva)) 855 855 { 856 nhojasi = int(Leaves[i]. Cuantas_hojas);856 nhojasi = int(Leaves[i].parentLeafCount); 857 857 //¿ SE HA DESACTIVADO LA HOJA_CRIT QUE GUARDABA LA HOJA? 858 858 if ( Leaves[Leaves[i].hoja_crit].existe == false) 859 859 { 860 Leaves[i].criteri o= 1000;860 Leaves[i].criteria = 1000; 861 861 862 862 //coplanaridad … … 869 869 // ES COMO MÁXIMO 1 870 870 871 nhojasj = int(Leaves[j]. Cuantas_hojas);871 nhojasj = int(Leaves[j].parentLeafCount); 872 872 873 873 if ( abs((nhojasi - nhojasj)) < 2) … … 884 884 criteriotmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); 885 885 //selecciono el criterio menor 886 if (Leaves[i].criteri o> criteriotmp)886 if (Leaves[i].criteria > criteriotmp) 887 887 { 888 Leaves[i].criteri o= criteriotmp;888 Leaves[i].criteria = criteriotmp; 889 889 Leaves[i].hoja_crit = j; 890 890 } … … 895 895 else 896 896 { // CALCULARE SI EL CRITERIO CON ESTA HOJA ES MENOR QUE EL ANTERIOR 897 nhojasj = int(Leaves[hojanueva]. Cuantas_hojas);897 nhojasj = int(Leaves[hojanueva].parentLeafCount); 898 898 899 899 if ( abs((nhojasi - nhojasj)) < 2) … … 909 909 criteriotmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); 910 910 //selecciono el criterio menor 911 if (Leaves[i].criteri o> criteriotmp)911 if (Leaves[i].criteria > criteriotmp) 912 912 { 913 Leaves[i].criteri o= criteriotmp;913 Leaves[i].criteria = criteriotmp; 914 914 Leaves[i].hoja_crit = hojanueva; 915 915 } … … 929 929 930 930 /* while (Leaves[i].existe != true) i++; 931 mincrit = Leaves[i].criteri o;931 mincrit = Leaves[i].criteria; 932 932 which =i; 933 933 */ 934 934 for (int i=0;i<countLeaves;i++) 935 935 { 936 if (Leaves[i].exist e)937 { 938 if (mincrit>Leaves[i].criteri o|| which==-1)936 if (Leaves[i].exists) 937 { 938 if (mincrit>Leaves[i].criteria || which==-1) 939 939 { 940 mincrit = Leaves[i].criteri o;940 mincrit = Leaves[i].criteria; 941 941 which = i; 942 942 } … … 948 948 949 949 950 void TreeSimplifier::ChooseVertices( Hoja& leaf1, Hoja& leaf2, long int count)950 void TreeSimplifier::ChooseVertices(Leaf& leaf1, Leaf& leaf2, long int count) 951 951 { 952 952 float a,b,c; … … 954 954 int indices[4]; 955 955 956 a = Vertex[leaf1. Vert_Hoja[0]][0];957 b = Vertex[leaf1. Vert_Hoja[0]][1];958 c = Vertex[leaf1. Vert_Hoja[0]][2];959 960 dist[0] = ((leaf2. Centro[0]-a)*(leaf2.Centro[0]-a)) + ((leaf2.Centro[1]-b)*(leaf2.Centro[1]-b)) +961 ((leaf2. Centro[2]-c)*(leaf2.Centro[2]-c));962 963 964 a = Vertex[leaf1. Vert_Hoja[1]][0];965 b = Vertex[leaf1. Vert_Hoja[1]][1];966 c = Vertex[leaf1. Vert_Hoja[1]][2];967 968 dist[1] = ((leaf2. Centro[0]-a)*(leaf2.Centro[0]-a)) + ((leaf2.Centro[1]-b)*(leaf2.Centro[1]-b)) +969 ((leaf2. Centro[2]-c)*(leaf2.Centro[2]-c));970 971 a = Vertex[leaf1. Vert_Hoja[2]][0];972 b = Vertex[leaf1. Vert_Hoja[2]][1];973 c = Vertex[leaf1. Vert_Hoja[2]][2];974 975 dist[2] = ((leaf2. Centro[0]-a)*(leaf2.Centro[0]-a)) + ((leaf2.Centro[1]-b)*(leaf2.Centro[1]-b)) +976 ((leaf2. Centro[2]-c)*(leaf2.Centro[2]-c));977 978 979 a = Vertex[leaf1. Vert_Hoja[3]][0];980 b = Vertex[leaf1. Vert_Hoja[3]][1];981 c = Vertex[leaf1. Vert_Hoja[3]][2];982 983 dist[3] = ((leaf2. Centro[0]-a)*(leaf2.Centro[0]-a)) + ((leaf2.Centro[1]-b)*(leaf2.Centro[1]-b)) +984 ((leaf2. Centro[2]-c)*(leaf2.Centro[2]-c));956 a = Vertex[leaf1.vertsLeaf[0]][0]; 957 b = Vertex[leaf1.vertsLeaf[0]][1]; 958 c = Vertex[leaf1.vertsLeaf[0]][2]; 959 960 dist[0] = ((leaf2.center[0]-a)*(leaf2.center[0]-a)) + ((leaf2.center[1]-b)*(leaf2.center[1]-b)) + 961 ((leaf2.center[2]-c)*(leaf2.center[2]-c)); 962 963 964 a = Vertex[leaf1.vertsLeaf[1]][0]; 965 b = Vertex[leaf1.vertsLeaf[1]][1]; 966 c = Vertex[leaf1.vertsLeaf[1]][2]; 967 968 dist[1] = ((leaf2.center[0]-a)*(leaf2.center[0]-a)) + ((leaf2.center[1]-b)*(leaf2.center[1]-b)) + 969 ((leaf2.center[2]-c)*(leaf2.center[2]-c)); 970 971 a = Vertex[leaf1.vertsLeaf[2]][0]; 972 b = Vertex[leaf1.vertsLeaf[2]][1]; 973 c = Vertex[leaf1.vertsLeaf[2]][2]; 974 975 dist[2] = ((leaf2.center[0]-a)*(leaf2.center[0]-a)) + ((leaf2.center[1]-b)*(leaf2.center[1]-b)) + 976 ((leaf2.center[2]-c)*(leaf2.center[2]-c)); 977 978 979 a = Vertex[leaf1.vertsLeaf[3]][0]; 980 b = Vertex[leaf1.vertsLeaf[3]][1]; 981 c = Vertex[leaf1.vertsLeaf[3]][2]; 982 983 dist[3] = ((leaf2.center[0]-a)*(leaf2.center[0]-a)) + ((leaf2.center[1]-b)*(leaf2.center[1]-b)) + 984 ((leaf2.center[2]-c)*(leaf2.center[2]-c)); 985 985 986 986 for ( int i=0;i<4;i++) indices[i]=i; … … 988 988 TwoGreater(dist, indices); 989 989 990 Leaves[countLeaves]. Vert_Hoja[0] = leaf1.Vert_Hoja[indices[0]];991 Leaves[countLeaves]. Vert_Hoja[1] = leaf1.Vert_Hoja[indices[1]];992 993 994 995 a = Vertex[leaf2. Vert_Hoja[0]][0];996 b = Vertex[leaf2. Vert_Hoja[0]][1];997 c = Vertex[leaf2. Vert_Hoja[0]][2];998 999 dist[0] = ((leaf1. Centro[0]-a)*(leaf1.Centro[0]-a)) + ((leaf1.Centro[1]-b)*(leaf1.Centro[1]-b)) +1000 ((leaf1. Centro[2]-c)*(leaf1.Centro[2]-c));1001 1002 1003 a = Vertex[leaf2. Vert_Hoja[1]][0];1004 b = Vertex[leaf2. Vert_Hoja[1]][1];1005 c = Vertex[leaf2. Vert_Hoja[1]][2];1006 1007 dist[1] = ((leaf2. Centro[0]-a)*(leaf2.Centro[0]-a)) + ((leaf1.Centro[1]-b)*(leaf1.Centro[1]-b)) +1008 ((leaf2. Centro[2]-c)*(leaf2.Centro[2]-c));1009 1010 a = Vertex[leaf2. Vert_Hoja[2]][0];1011 b = Vertex[leaf2. Vert_Hoja[2]][1];1012 c = Vertex[leaf2. Vert_Hoja[2]][2];1013 1014 dist[2] = ((leaf1. Centro[0]-a)*(leaf1.Centro[0]-a)) + ((leaf1.Centro[1]-b)*(leaf1.Centro[1]-b)) +1015 ((leaf1. Centro[2]-c)*(leaf1.Centro[2]-c));1016 1017 1018 a = Vertex[leaf2. Vert_Hoja[3]][0];1019 b = Vertex[leaf2. Vert_Hoja[3]][1];1020 c = Vertex[leaf2. Vert_Hoja[3]][2];1021 1022 dist[3] = ((leaf1. Centro[0]-a)*(leaf1.Centro[0]-a)) + ((leaf1.Centro[1]-b)*(leaf1.Centro[1]-b)) +1023 ((leaf1. Centro[2]-c)*(leaf1.Centro[2]-c));990 Leaves[countLeaves].vertsLeaf[0] = leaf1.vertsLeaf[indices[0]]; 991 Leaves[countLeaves].vertsLeaf[1] = leaf1.vertsLeaf[indices[1]]; 992 993 994 995 a = Vertex[leaf2.vertsLeaf[0]][0]; 996 b = Vertex[leaf2.vertsLeaf[0]][1]; 997 c = Vertex[leaf2.vertsLeaf[0]][2]; 998 999 dist[0] = ((leaf1.center[0]-a)*(leaf1.center[0]-a)) + ((leaf1.center[1]-b)*(leaf1.center[1]-b)) + 1000 ((leaf1.center[2]-c)*(leaf1.center[2]-c)); 1001 1002 1003 a = Vertex[leaf2.vertsLeaf[1]][0]; 1004 b = Vertex[leaf2.vertsLeaf[1]][1]; 1005 c = Vertex[leaf2.vertsLeaf[1]][2]; 1006 1007 dist[1] = ((leaf2.center[0]-a)*(leaf2.center[0]-a)) + ((leaf1.center[1]-b)*(leaf1.center[1]-b)) + 1008 ((leaf2.center[2]-c)*(leaf2.center[2]-c)); 1009 1010 a = Vertex[leaf2.vertsLeaf[2]][0]; 1011 b = Vertex[leaf2.vertsLeaf[2]][1]; 1012 c = Vertex[leaf2.vertsLeaf[2]][2]; 1013 1014 dist[2] = ((leaf1.center[0]-a)*(leaf1.center[0]-a)) + ((leaf1.center[1]-b)*(leaf1.center[1]-b)) + 1015 ((leaf1.center[2]-c)*(leaf1.center[2]-c)); 1016 1017 1018 a = Vertex[leaf2.vertsLeaf[3]][0]; 1019 b = Vertex[leaf2.vertsLeaf[3]][1]; 1020 c = Vertex[leaf2.vertsLeaf[3]][2]; 1021 1022 dist[3] = ((leaf1.center[0]-a)*(leaf1.center[0]-a)) + ((leaf1.center[1]-b)*(leaf1.center[1]-b)) + 1023 ((leaf1.center[2]-c)*(leaf1.center[2]-c)); 1024 1024 1025 1025 for ( int i=0;i<4;i++) indices[i]=i; … … 1027 1027 TwoGreater(dist, indices); 1028 1028 1029 Leaves[countLeaves]. Vert_Hoja[2] = leaf2.Vert_Hoja[indices[0]];1030 Leaves[countLeaves]. Vert_Hoja[3] = leaf2.Vert_Hoja[indices[1]];1029 Leaves[countLeaves].vertsLeaf[2] = leaf2.vertsLeaf[indices[0]]; 1030 Leaves[countLeaves].vertsLeaf[3] = leaf2.vertsLeaf[indices[1]]; 1031 1031 1032 1032 … … 1043 1043 1044 1044 which=MinCriteria(); 1045 other = Leaves[which]. hoja_crit;1045 other = Leaves[which].leafCrit; 1046 1046 1047 1047 //desactivo las hojas cercanas 1048 Leaves[which].exist e= false;1049 Leaves[other].exist e= false;1048 Leaves[which].exists = false; 1049 Leaves[other].exists = false; 1050 1050 //creo la hoja nueva 1051 1051 1052 Leaves[countLeaves]. hoja_cerca= -1;1052 Leaves[countLeaves].leafNear = -1; 1053 1053 Leaves[countLeaves].dist = 0; 1054 Leaves[countLeaves]. hoja_cop = -1;1054 Leaves[countLeaves].leafCop = -1; 1055 1055 Leaves[countLeaves].coplanar = 0; 1056 1056 1057 Leaves[countLeaves]. Cuantas_hojas = Leaves[which].Cuantas_hojas + Leaves[other].Cuantas_hojas;1058 // Leaves[countLeaves]. Cuantas_hojas= 10;1057 Leaves[countLeaves].parentLeafCount = Leaves[which].parentLeafCount + Leaves[other].parentLeafCount; 1058 // Leaves[countLeaves].parentLeafCount = 10; 1059 1059 ChooseVertices(Leaves[which], Leaves[other], countLeaves); 1060 1060 CalculateLeafCenter (Leaves[countLeaves]); … … 1066 1066 onode->leaves.push_back(countLeaves); 1067 1067 1068 /* if (Leaves[countLeaves]. Cuantas_hojas> 60 )1068 /* if (Leaves[countLeaves].parentLeafCount > 60 ) 1069 1069 { 1070 1070 Leaves[countLeaves].existe = false; … … 1073 1073 else 1074 1074 { */ 1075 Leaves[countLeaves].exist e= true;1076 Leaves[countLeaves].criteri o= 1000000.0f;1077 Leaves[countLeaves].id _triangulo[0] = countLeaves*2;1078 Leaves[countLeaves].id _triangulo[1] = countLeaves*2+1;1075 Leaves[countLeaves].exists = true; 1076 Leaves[countLeaves].criteria = 1000000.0f; 1077 Leaves[countLeaves].idTriangle[0] = countLeaves*2; 1078 Leaves[countLeaves].idTriangle[1] = countLeaves*2+1; 1079 1079 1080 1080 float area_leaf_i = CalculateLeafArea(Leaves[i])/diam; … … 1088 1088 int j = *it;*/ 1089 1089 1090 if (j != countLeaves && Leaves[j].exist e)1090 if (j != countLeaves && Leaves[j].exists) 1091 1091 { 1092 coptmp2 = Leaves[countLeaves].Coplanari dad(Leaves[j]);1092 coptmp2 = Leaves[countLeaves].Coplanarity(Leaves[j]); 1093 1093 coptmp = 1 - coptmp2; 1094 1094 //distmp2 = HausdorffOptimized(Leaves[countLeaves], Leaves[j]); … … 1098 1098 criteriatmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); 1099 1099 criteriatmp *= CalculateLeafArea(Leaves[j])/diam + area_leaf_i; 1100 criteriatmp *= Leaves[j]. Cuantas_hojas + Leaves[i].Cuantas_hojas;1100 criteriatmp *= Leaves[j].parentLeafCount + Leaves[i].parentLeafCount; 1101 1101 1102 if (Leaves[countLeaves].criteri o> criteriatmp)1102 if (Leaves[countLeaves].criteria > criteriatmp) 1103 1103 { 1104 Leaves[countLeaves].criteri o= criteriatmp;1105 Leaves[countLeaves]. hoja_crit = j;1104 Leaves[countLeaves].criteria = criteriatmp; 1105 Leaves[countLeaves].leafCrit = j; 1106 1106 } 1107 1107 } … … 1112 1112 // Crear el paso de simplificación 1113 1113 Geometry::TreeSimplificationSequence::Step pasosimp; 1114 pasosimp.mV0=Leaves[which].id _triangulo[0];1115 pasosimp.mV1=Leaves[which].id _triangulo[1];1116 pasosimp.mT0=Leaves[other].id _triangulo[0];1117 pasosimp.mT1=Leaves[other].id _triangulo[1];1114 pasosimp.mV0=Leaves[which].idTriangle[0]; 1115 pasosimp.mV1=Leaves[which].idTriangle[1]; 1116 pasosimp.mT0=Leaves[other].idTriangle[0]; 1117 pasosimp.mT1=Leaves[other].idTriangle[1]; 1118 1118 1119 1119 // Nuevos vértices 1120 pasosimp.mNewQuad[0]=Leaves[countLeaves]. Vert_Hoja[0];1121 pasosimp.mNewQuad[1]=Leaves[countLeaves]. Vert_Hoja[1];1122 pasosimp.mNewQuad[2]=Leaves[countLeaves]. Vert_Hoja[2];1123 pasosimp.mNewQuad[3]=Leaves[countLeaves]. Vert_Hoja[3];1120 pasosimp.mNewQuad[0]=Leaves[countLeaves].vertsLeaf[0]; 1121 pasosimp.mNewQuad[1]=Leaves[countLeaves].vertsLeaf[1]; 1122 pasosimp.mNewQuad[2]=Leaves[countLeaves].vertsLeaf[2]; 1123 pasosimp.mNewQuad[3]=Leaves[countLeaves].vertsLeaf[3]; 1124 1124 1125 1125 // Insertar el paso de simplificación … … 1156 1156 ticks_since_last_update++; 1157 1157 1158 if (Leaves[j].exist e)1158 if (Leaves[j].exists) 1159 1159 { 1160 1160 // if (index<6) 1161 1161 // { 1162 mesh->mSubMesh[idMeshLeaves].mIndex[index]=Leaves[j]. Vert_Hoja[0];1163 mesh->mSubMesh[idMeshLeaves].mIndex[index+1]=Leaves[j]. Vert_Hoja[1];1164 mesh->mSubMesh[idMeshLeaves].mIndex[index+2]=Leaves[j]. Vert_Hoja[2];1165 mesh->mSubMesh[idMeshLeaves].mIndex[index+3]=Leaves[j]. Vert_Hoja[2];1166 mesh->mSubMesh[idMeshLeaves].mIndex[index+4]=Leaves[j]. Vert_Hoja[1];1167 mesh->mSubMesh[idMeshLeaves].mIndex[index+5]=Leaves[j]. Vert_Hoja[3];1162 mesh->mSubMesh[idMeshLeaves].mIndex[index]=Leaves[j].vertsLeaf[0]; 1163 mesh->mSubMesh[idMeshLeaves].mIndex[index+1]=Leaves[j].vertsLeaf[1]; 1164 mesh->mSubMesh[idMeshLeaves].mIndex[index+2]=Leaves[j].vertsLeaf[2]; 1165 mesh->mSubMesh[idMeshLeaves].mIndex[index+3]=Leaves[j].vertsLeaf[2]; 1166 mesh->mSubMesh[idMeshLeaves].mIndex[index+4]=Leaves[j].vertsLeaf[1]; 1167 mesh->mSubMesh[idMeshLeaves].mIndex[index+5]=Leaves[j].vertsLeaf[3]; 1168 1168 /* } 1169 1169 else … … 1312 1312 { 1313 1313 int idleaf = *it; 1314 int idv0 = Leaves[idleaf]. Vert_Hoja[0];1315 int idv1 = Leaves[idleaf]. Vert_Hoja[1];1316 int idv2 = Leaves[idleaf]. Vert_Hoja[2];1317 int idv3 = Leaves[idleaf]. Vert_Hoja[3];1314 int idv0 = Leaves[idleaf].vertsLeaf[0]; 1315 int idv1 = Leaves[idleaf].vertsLeaf[1]; 1316 int idv2 = Leaves[idleaf].vertsLeaf[2]; 1317 int idv3 = Leaves[idleaf].vertsLeaf[3]; 1318 1318 1319 1319 float * v0 = Vertex[idv0]; … … 1358 1358 ticks_since_last_update++; 1359 1359 1360 if (Leaves[i].exist e== true)1361 { 1362 Leaves[i].criteri o= 1000000.0f;1363 nleavesi = int(Leaves[i]. Cuantas_hojas);1360 if (Leaves[i].exists == true) 1361 { 1362 Leaves[i].criteria = 1000000.0f; 1363 nleavesi = int(Leaves[i].parentLeafCount); 1364 1364 float area_leaf_i = CalculateLeafArea(Leaves[i])/diam; 1365 1365 … … 1373 1373 // for (j=0; j<countLeaves; j++) 1374 1374 // { 1375 if (j!=i && Leaves[j].exist e)1375 if (j!=i && Leaves[j].exists) 1376 1376 { 1377 nleavesj = int(Leaves[j]. Cuantas_hojas);1377 nleavesj = int(Leaves[j].parentLeafCount); 1378 1378 1379 1379 // if ( abs((nleavesi - nleavesj)) < 2) 1380 1380 // { 1381 coptmp2 = Leaves[i].Coplanari dad(Leaves[j]);1381 coptmp2 = Leaves[i].Coplanarity(Leaves[j]); 1382 1382 coptmp = 1 - coptmp2; 1383 1383 … … 1390 1390 // select the lowest 1391 1391 criteriatmp *= CalculateLeafArea(Leaves[j])/diam + area_leaf_i; 1392 criteriatmp *= Leaves[j]. Cuantas_hojas + Leaves[i].Cuantas_hojas;1393 if (Leaves[i].criteri o> criteriatmp)1392 criteriatmp *= Leaves[j].parentLeafCount + Leaves[i].parentLeafCount; 1393 if (Leaves[i].criteria > criteriatmp) 1394 1394 { 1395 Leaves[i].criteri o= criteriatmp;1396 Leaves[i]. hoja_crit = j;1395 Leaves[i].criteria = criteriatmp; 1396 Leaves[i].leafCrit = j; 1397 1397 } 1398 1398 // } … … 1412 1412 for (i = 0; i < countLeaves; i++) 1413 1413 { 1414 if (Leaves[i].exist e&& i!=newleaf)1414 if (Leaves[i].exists && i!=newleaf) 1415 1415 { 1416 1416 float area_leaf_i = CalculateLeafArea(Leaves[i])/diam; 1417 nleavesi = int(Leaves[i]. Cuantas_hojas);1418 if ( Leaves[Leaves[i]. hoja_crit].existe== false)1417 nleavesi = int(Leaves[i].parentLeafCount); 1418 if ( Leaves[Leaves[i].leafCrit].exists == false) 1419 1419 { 1420 Leaves[i].criteri o= 1000000.0f;1420 Leaves[i].criteria = 1000000.0f; 1421 1421 1422 1422 int visit_parents = VISIT_PARENTS_DEEP; … … 1428 1428 // for (j=0; j<countLeaves; j++) 1429 1429 // { 1430 if (j!=i && Leaves[j].exist e)1430 if (j!=i && Leaves[j].exists) 1431 1431 { 1432 nleavesj = int(Leaves[j]. Cuantas_hojas);1432 nleavesj = int(Leaves[j].parentLeafCount); 1433 1433 1434 1434 // if ( abs((nleavesi - nleavesj)) < 2) 1435 1435 // { 1436 coptmp2 = Leaves[i].Coplanari dad(Leaves[j]);1436 coptmp2 = Leaves[i].Coplanarity(Leaves[j]); 1437 1437 coptmp = 1 - coptmp2; 1438 1438 … … 1444 1444 criteriatmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); 1445 1445 criteriatmp *= CalculateLeafArea(Leaves[j])/diam + area_leaf_i; 1446 criteriatmp *= Leaves[j]. Cuantas_hojas + Leaves[i].Cuantas_hojas;1446 criteriatmp *= Leaves[j].parentLeafCount + Leaves[i].parentLeafCount; 1447 1447 1448 1448 // select the leaf with the lowest criteria 1449 if (Leaves[i].criteri o> criteriatmp)1449 if (Leaves[i].criteria > criteriatmp) 1450 1450 { 1451 Leaves[i].criteri o= criteriatmp;1452 Leaves[i]. hoja_crit = j;1451 Leaves[i].criteria = criteriatmp; 1452 Leaves[i].leafCrit = j; 1453 1453 } 1454 1454 // } … … 1459 1459 else 1460 1460 { 1461 nleavesj = int(Leaves[newleaf]. Cuantas_hojas);1461 nleavesj = int(Leaves[newleaf].parentLeafCount); 1462 1462 1463 1463 // if ( abs((nleavesi - nleavesj)) < 2) 1464 1464 // { 1465 coptmp2 = Leaves[i].Coplanari dad(Leaves[newleaf]);1465 coptmp2 = Leaves[i].Coplanarity(Leaves[newleaf]); 1466 1466 coptmp = 1 - coptmp2; 1467 1467 … … 1472 1472 criteriatmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); 1473 1473 criteriatmp *= CalculateLeafArea(Leaves[newleaf])/diam + area_leaf_i; 1474 criteriatmp *= Leaves[newleaf]. Cuantas_hojas + Leaves[i].Cuantas_hojas;1474 criteriatmp *= Leaves[newleaf].parentLeafCount + Leaves[i].parentLeafCount; 1475 1475 1476 if (Leaves[i].criteri o> criteriatmp)1476 if (Leaves[i].criteria > criteriatmp) 1477 1477 { 1478 Leaves[i].criteri o= criteriatmp;1479 Leaves[i]. hoja_crit = newleaf;1478 Leaves[i].criteria = criteriatmp; 1479 Leaves[i].leafCrit = newleaf; 1480 1480 } 1481 1481 // } … … 1486 1486 1487 1487 1488 LeafOctree *TreeSimplifier::GetMinOctreeNodeForLeaf(LeafOctree *start, const Hoja&leaf)1489 { 1490 int idv0 = leaf. Vert_Hoja[0];1491 int idv1 = leaf. Vert_Hoja[1];1492 int idv2 = leaf. Vert_Hoja[2];1493 int idv3 = leaf. Vert_Hoja[3];1488 LeafOctree *TreeSimplifier::GetMinOctreeNodeForLeaf(LeafOctree *start, const Leaf &leaf) 1489 { 1490 int idv0 = leaf.vertsLeaf[0]; 1491 int idv1 = leaf.vertsLeaf[1]; 1492 int idv2 = leaf.vertsLeaf[2]; 1493 int idv3 = leaf.vertsLeaf[3]; 1494 1494 1495 1495 float * v0 = Vertex[idv0]; … … 1517 1517 } 1518 1518 1519 float TreeSimplifier::DistanceFromCenters(const Hoja &leaf1, const Hoja&leaf2) const1519 float TreeSimplifier::DistanceFromCenters(const Leaf &leaf1, const Leaf &leaf2) const 1520 1520 { 1521 1521 float onex, oney, onez; … … 1528 1528 float x4, y4, z4; 1529 1529 1530 onex = Vertex[leaf1. Vert_Hoja[0]][0]; oney = Vertex[leaf1.Vert_Hoja[0]][1]; onez = Vertex[leaf1.Vert_Hoja[0]][2];1531 twox = Vertex[leaf1. Vert_Hoja[1]][0]; twoy = Vertex[leaf1.Vert_Hoja[1]][1]; twoz = Vertex[leaf1.Vert_Hoja[1]][2];1532 threex = Vertex[leaf1. Vert_Hoja[2]][0]; threey = Vertex[leaf1.Vert_Hoja[2]][1]; threez = Vertex[leaf1.Vert_Hoja[2]][2];1533 fourx = Vertex[leaf1. Vert_Hoja[3]][0]; foury = Vertex[leaf1.Vert_Hoja[3]][1]; fourz = Vertex[leaf1.Vert_Hoja[3]][2];1530 onex = Vertex[leaf1.vertsLeaf[0]][0]; oney = Vertex[leaf1.vertsLeaf[0]][1]; onez = Vertex[leaf1.vertsLeaf[0]][2]; 1531 twox = Vertex[leaf1.vertsLeaf[1]][0]; twoy = Vertex[leaf1.vertsLeaf[1]][1]; twoz = Vertex[leaf1.vertsLeaf[1]][2]; 1532 threex = Vertex[leaf1.vertsLeaf[2]][0]; threey = Vertex[leaf1.vertsLeaf[2]][1]; threez = Vertex[leaf1.vertsLeaf[2]][2]; 1533 fourx = Vertex[leaf1.vertsLeaf[3]][0]; foury = Vertex[leaf1.vertsLeaf[3]][1]; fourz = Vertex[leaf1.vertsLeaf[3]][2]; 1534 1534 1535 1535 float center1x = (onex + twox + threex + fourx)*0.25f; … … 1537 1537 float center1z = (onez + twoz + threez + fourz)*0.25f; 1538 1538 1539 x1 = Vertex[leaf2. Vert_Hoja[0]][0]; y1 = Vertex[leaf2.Vert_Hoja[0]][1]; z1 = Vertex[leaf2.Vert_Hoja[0]][2];1540 x2 = Vertex[leaf2. Vert_Hoja[1]][0]; y2 = Vertex[leaf2.Vert_Hoja[1]][1]; z2 = Vertex[leaf2.Vert_Hoja[1]][2];1541 x3 = Vertex[leaf2. Vert_Hoja[2]][0]; y3 = Vertex[leaf2.Vert_Hoja[2]][1]; z3 = Vertex[leaf2.Vert_Hoja[2]][2];1542 x4 = Vertex[leaf2. Vert_Hoja[3]][0]; y4 = Vertex[leaf2.Vert_Hoja[3]][1]; z4 = Vertex[leaf2.Vert_Hoja[3]][2];1539 x1 = Vertex[leaf2.vertsLeaf[0]][0]; y1 = Vertex[leaf2.vertsLeaf[0]][1]; z1 = Vertex[leaf2.vertsLeaf[0]][2]; 1540 x2 = Vertex[leaf2.vertsLeaf[1]][0]; y2 = Vertex[leaf2.vertsLeaf[1]][1]; z2 = Vertex[leaf2.vertsLeaf[1]][2]; 1541 x3 = Vertex[leaf2.vertsLeaf[2]][0]; y3 = Vertex[leaf2.vertsLeaf[2]][1]; z3 = Vertex[leaf2.vertsLeaf[2]][2]; 1542 x4 = Vertex[leaf2.vertsLeaf[3]][0]; y4 = Vertex[leaf2.vertsLeaf[3]][1]; z4 = Vertex[leaf2.vertsLeaf[3]][2]; 1543 1543 1544 1544 float center2x = (x1 + x2 + x3 + x4)*0.25f; … … 1588 1588 1589 1589 1590 float TreeSimplifier::CalculateLeafArea( Hoja&leaf) const1591 { 1592 int idv0 = leaf. Vert_Hoja[0];1593 int idv1 = leaf. Vert_Hoja[1];1594 int idv2 = leaf. Vert_Hoja[2];1595 int idv3 = leaf. Vert_Hoja[3];1590 float TreeSimplifier::CalculateLeafArea(Leaf &leaf) const 1591 { 1592 int idv0 = leaf.vertsLeaf[0]; 1593 int idv1 = leaf.vertsLeaf[1]; 1594 int idv2 = leaf.vertsLeaf[2]; 1595 int idv3 = leaf.vertsLeaf[3]; 1596 1596 1597 1597 float * v0 = Vertex[idv0]; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Hoja.cpp
r985 r1019 1 1 #include <math.h> 2 #include " Hoja.h"2 #include "Leaf.h" 3 3 4 4 //-------------------------------------------------------------------------------------------------------------------------------- … … 6 6 // Parameters --> None 7 7 //-------------------------------------------------------------------------------------------------------------------------------- 8 Hoja::Hoja(void)8 Leaf::Leaf(void) 9 9 { 10 Vert_Hoja[0] = Vert_Hoja[1] = Vert_Hoja[2] = Vert_Hoja[3] =0;11 Centro[0] = Centro[1] = Centro[2] = 0;12 Normal[0] = Normal[1] = Normal[2] = 0;13 hoja_cerca=-1;14 Cuantas_hojas= 1;10 vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] =0; 11 center[0] = center[1] = center[2] = 0; 12 normal[0] = normal[1] = normal[2] = 0; 13 leafNear=-1; 14 parentLeafCount = 1; 15 15 dist = -1; 16 16 coplanar = -1; 17 criteri o= -1;18 hoja_cop = -1;19 hoja_crit =-1;20 exist e= false;21 pa dre=-1;22 hijoi = hijod= -1;23 r aiz= visible= -1;17 criteria = -1; 18 leafCop = -1; 19 leafCrit =-1; 20 exists = false; 21 parent=-1; 22 childLeft = childRight = -1; 23 root = visible= -1; 24 24 } 25 25 … … 27 27 //-------------------------------------------------------------------------------------------------------------------------------- 28 28 // Copy constructor 29 // Parameters --> const Hoja& aHoja : The Hoja to copy30 29 //-------------------------------------------------------------------------------------------------------------------------------- 31 Hoja::Hoja (const Hoja& aHoja)30 Leaf::Leaf (const Leaf& aLeaf) 32 31 { 33 Cuantas_hojas = aHoja.Cuantas_hojas;;34 hoja_cerca = aHoja.hoja_cerca;35 hoja_crit = aHoja.hoja_crit;36 dist = a Hoja.dist;37 exist e = aHoja.existe;38 coplanar = a Hoja.coplanar;39 hoja_cop = aHoja.hoja_cop;40 criteri o = aHoja.criterio;32 parentLeafCount = aLeaf.parentLeafCount;; 33 leafNear = aLeaf.leafNear; 34 leafCrit = aLeaf.leafCrit; 35 dist = aLeaf.dist; 36 exists = aLeaf.exists; 37 coplanar = aLeaf.coplanar; 38 leafCop = aLeaf.leafCop; 39 criteria = aLeaf.criteria; 41 40 for ( int i=0;i<3;i++){ 42 Centro[i] = aHoja.Centro[i];43 Normal[i] = aHoja.Normal[i];41 center[i] = aLeaf.center[i]; 42 normal[i] = aLeaf.normal[i]; 44 43 } 45 44 for (i = 0L; i < 4; i++) 46 Vert_Hoja[i] = aHoja.Vert_Hoja[i];45 vertsLeaf[i] = aLeaf.vertsLeaf[i]; 47 46 48 pa dre = aHoja.padre;49 hijoi = aHoja.hijoi;50 hijod = aHoja.hijod;51 visible = a Hoja.visible;52 r aiz = aHoja.raiz;47 parent = aLeaf.parent; 48 childLeft = aLeaf.childLeft; 49 childRight = aLeaf.childRight; 50 visible = aLeaf.visible; 51 root = aLeaf.root; 53 52 } 54 53 … … 58 57 // Destructor. We must deallocate the memory allocated for pointers to vertices and edges 59 58 //-------------------------------------------------------------------------------------------------------------------------------- 60 Hoja::~Hoja(void)59 Leaf::~Leaf (void) 61 60 { 62 61 } … … 67 66 //-------------------------------------------------------------------------------------------------------------------------------- 68 67 69 float Hoja::Distancia (Hoja& Hoja1)68 float Leaf::Distance (Leaf& leaf) 70 69 { 71 70 float dist =0; 72 71 float x1,y1,z1; 73 72 74 x1 = Hoja1.Centro[0]; y1 = Hoja1.Centro[1] ; z1 = Hoja1.Centro[2];73 x1 = leaf.center[0]; y1 = leaf.center[1] ; z1 = leaf.center[2]; 75 74 76 75 77 //DISTANCIA ENTRE CENTROS76 //DISTANCIA BETWEEN CENTERS 78 77 79 dist = (( Centro[0]-x1)*(Centro[0]-x1)) + ((Centro[1]-y1)*(Centro[1]-y1)) + ((Centro[2]-z1)*(Centro[2]-z1));78 dist = ((center[0]-x1)*(center[0]-x1)) + ((center[1]-y1)*(center[1]-y1)) + ((center[2]-z1)*(center[2]-z1)); 80 79 81 return (dist);80 return dist; 82 81 } 83 82 … … 87 86 //-------------------------------------------------------------------------------------------------------------------------------- 88 87 89 float Hoja::Coplanaridad (Hoja& Hoja1)88 float Leaf::Coplanarity (Leaf& leaf) 90 89 { 91 90 float cop =0; … … 95 94 96 95 //hoja pasada como parametro, normalizo las componentes 97 x1 = Hoja1.Normal[0]; y1 = Hoja1.Normal[1] ; z1 = Hoja1.Normal[2];96 x1 = leaf.normal[0]; y1 = leaf.normal[1] ; z1 = leaf.normal[2]; 98 97 modulo1 = sqrt ( (x1*x1) + (y1*y1) + (z1*z1)); 99 98 nx1 = x1 / modulo1; … … 103 102 // hoja desde la que llamo 104 103 105 modulo2 = sqrt ( ( Normal[0]*Normal[0]) + (Normal[1]*Normal[1]) + (Normal[2]*Normal[2]));106 nx = Normal[0] / modulo2;107 ny = Normal[1] / modulo2;108 nz = Normal[2] / modulo2;104 modulo2 = sqrt ( (normal[0]*normal[0]) + (normal[1]*normal[1]) + (normal[2]*normal[2])); 105 nx = normal[0] / modulo2; 106 ny = normal[1] / modulo2; 107 nz = normal[2] / modulo2; 109 108 110 109 // producto escalar : si es proximo a 0, perpendiculares, a 1, coplanares -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp
r985 r1019 1 //#include <GL\glut.h>2 1 #include <stdio.h> 3 2 #include <string.h> 4 3 #include <math.h> 5 //#include <vl\VLf.h>6 4 7 5 #include "Foliage.h" … … 13 11 // Parameters --> None 14 12 //-------------------------------------------------------------------------------------------------------------------------------- 15 Foliage::Foliage(void): MiArbol(NULL), Acth(NULL) 16 { 17 ppio= final = -1; 18 } 19 20 21 //-------------------------------------------------------------------------------------------------------------------------------- 22 // Constructor with the name of a file cotaining the data 23 //-------------------------------------------------------------------------------------------------------------------------------- 24 Foliage::Foliage ( Arbol *Arbol1) 25 { 13 Foliage::Foliage(const Geometry::SubMesh *leavesSubMesh, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun): 14 Acth(NULL), 15 create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun), 16 create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun), 17 vertexdata(NULL), Leaves(NULL), MinDet(NULL) 18 { 19 cx = cy= cz= 0; 20 ppio= final = -1; 21 22 ReadVertices(leavesSubMesh); 23 ReadLeafs(leavesSubMesh); 24 if (!ReadSimpSeq(simpSeq)) exit(1); 25 RellenoRaiz(); 26 CalculaTexCoordsYNorms(); 27 28 29 // esto no sé si devería haber akí 30 indexdata->SetNumValidIndices(0); 31 26 32 int h=0; 27 33 28 34 29 MiArbol = Arbol1; 30 31 Acth = new Activas[(MiArbol->nHojas)*8]; 32 33 for ( h=0; h < MiArbol->nHojas; h++) { 35 Acth = new Activas[nHojas*8]; 36 37 for ( h=0; h < nHojas; h++) { 34 38 35 39 Acth[h].indice = h; … … 43 47 44 48 ppio = 0; 49 final = nHojas-1; 50 nhactivas = nHojas; 51 52 } 53 54 /* 55 //-------------------------------------------------------------------------------------------------------------------------------- 56 // Constructor with the name of a file cotaining the data 57 //-------------------------------------------------------------------------------------------------------------------------------- 58 Foliage::Foliage ( Arbol *Arbol1) 59 { 60 int h=0; 61 62 63 MiArbol = Arbol1; 64 65 Acth = new Activas[(MiArbol->nHojas)*8]; 66 67 for ( h=0; h < MiArbol->nHojas; h++) { 68 69 Acth[h].indice = h; 70 if ( h != 0) 71 { 72 Acth[h].prev = (h-1); 73 Acth[h-1].next = h; 74 } 75 76 } 77 78 ppio = 0; 45 79 final = (MiArbol->nHojas)-1; 46 80 nhactivas = MiArbol->nHojas; … … 48 82 49 83 50 } 84 }*/ 51 85 52 86 //-------------------------------------------------------------------------------------------------------------------------------- … … 55 89 Foliage::~Foliage (void) 56 90 { 57 delete MiArbol; 91 if (vertexdata) delete vertexdata; 92 if (indexdata) delete indexdata; 93 delete[] Leaves; 94 delete MinDet; 58 95 delete Acth; 59 96 } … … 71 108 glBegin (GL_TRIANGLE_STRIP); 72 109 glNormal3fv (aHoja.Normal); 73 MiArbol->Vertices[aHoja. Vert_Hoja[0]].GetCoordinates (a,b,c);110 MiArbol->Vertices[aHoja.vertsLeaf[0]].GetCoordinates (a,b,c); 74 111 glTexCoord2f ( 0.0, 0.0); 75 112 76 113 glVertex3f (a,b,c); 77 114 78 MiArbol->Vertices[aHoja. Vert_Hoja[1]].GetCoordinates (a,b,c);115 MiArbol->Vertices[aHoja.vertsLeaf[1]].GetCoordinates (a,b,c); 79 116 glTexCoord2f ( 0.0, 1.0); 80 117 glVertex3f (a,b,c); 81 118 82 MiArbol->Vertices[aHoja. Vert_Hoja[2]].GetCoordinates (a,b,c);119 MiArbol->Vertices[aHoja.vertsLeaf[2]].GetCoordinates (a,b,c); 83 120 glTexCoord2f ( 1.0, 0.0); 84 121 glVertex3f (a,b,c); 85 122 86 MiArbol->Vertices[aHoja. Vert_Hoja[3]].GetCoordinates (a,b,c);123 MiArbol->Vertices[aHoja.vertsLeaf[3]].GetCoordinates (a,b,c); 87 124 glTexCoord2f ( 1.0, 1.0); 88 125 glVertex3f (a,b,c); … … 236 273 237 274 i = 0; 238 while ( Mi Arbol->MinDet[i].indice != -1)239 { 240 j = Mi Arbol->MinDet[i].indice;275 while ( MinDet[i].indice != -1) 276 { 277 j = MinDet[i].indice; 241 278 if (LeafinFrustum ( j, frustum) == true) { 242 // printf("dentro %i y el padre es %i\n", j, MiArbol->Hojas[MiArbol->MinDet[i].indice].pa dre);243 MiArbol->Hojas[j].visible = 1;279 // printf("dentro %i y el padre es %i\n", j, MiArbol->Hojas[MiArbol->MinDet[i].indice].parent); 280 Leaves[j].visible = 1; 244 281 } 245 282 else 246 283 { 247 284 // printf("fuera %i\n", j); 248 MiArbol->Hojas[j].visible = 0;285 Leaves[j].visible = 0; 249 286 } 250 287 … … 269 306 for (j =0; j<4; j++) 270 307 { 271 // MiArbol->Vertices[MiArbol->Hojas[i]. Vert_Hoja[j]].GetCoordinates (a,b,c);272 MiArbol->vertexdata->GetVertexCoord(MiArbol->Hojas[i].Vert_Hoja[j],a,b,c);308 // MiArbol->Vertices[MiArbol->Hojas[i].vertsLeaf[j]].GetCoordinates (a,b,c); 309 vertexdata->GetVertexCoord(Leaves[i].vertsLeaf[j],a,b,c); 273 310 v[0]=a; v[1]=b; v[2]=c; v[3]=1; 274 311 … … 336 373 337 374 338 bool Foliage::Criterio ( Hoja &aHoja, char ch, float rva, float rvb,float rvc, float rvd, float radio)375 bool Foliage::Criterio ( Leaf &aLeaf, char ch, float rva, float rvb,float rvc, float rvd, float radio) 339 376 { 340 377 float a,b,c; // coordenadas del primero de los vertices en la hoja … … 346 383 float ccx, ccy, ccz; 347 384 348 349 350 // MiArbol->Vertices[aHoja.Vert_Hoja[0]].GetCoordinates (a,b,c); 351 MiArbol->vertexdata->GetVertexCoord(aHoja.Vert_Hoja[0],a,b,c); 352 353 ccx = MiArbol->cx; 354 ccy = MiArbol->cy; 355 ccz = MiArbol->cz; 356 385 vertexdata->GetVertexCoord(aLeaf.vertsLeaf[0],a,b,c); 386 387 ccx = cx; 388 ccy = cy; 389 ccz = cz; 357 390 358 391 if ( (ch == 'p') || (ch == 'd')) … … 361 394 if (DondeEsta (a,b,c, rva,rvb,rvc,rvd) == 1) 362 395 { 363 // MiArbol->Vertices[aHoja. Vert_Hoja[1]].GetCoordinates (d,e,f);364 MiArbol->vertexdata->GetVertexCoord(aHoja.Vert_Hoja[1],d,e,f);396 // MiArbol->Vertices[aHoja.vertsLeaf[1]].GetCoordinates (d,e,f); 397 vertexdata->GetVertexCoord(aLeaf.vertsLeaf[1],d,e,f); 365 398 if (DondeEsta (d,e,f, rva,rvb,rvc,rvd) == 1) 366 399 { 367 // MiArbol->Vertices[aHoja. Vert_Hoja[2]].GetCoordinates (g,h,i);368 MiArbol->vertexdata->GetVertexCoord(aHoja.Vert_Hoja[2],g,h,i);400 // MiArbol->Vertices[aHoja.vertsLeaf[2]].GetCoordinates (g,h,i); 401 vertexdata->GetVertexCoord(aLeaf.vertsLeaf[2],g,h,i); 369 402 if (DondeEsta (g,h,i, rva,rvb,rvc,rvd) == 1) 370 403 { 371 // MiArbol->Vertices[aHoja.Vert_Hoja[3]].GetCoordinates (j,k,l);372 MiArbol->vertexdata->GetVertexCoord(aHoja.Vert_Hoja[3],j,k,l);404 // Vertices[aHoja.vertsLeaf[3]].GetCoordinates (j,k,l); 405 vertexdata->GetVertexCoord(aLeaf.vertsLeaf[3],j,k,l); 373 406 if (DondeEsta (j,k,l, rva,rvb,rvc,rvd) == 1) inter = true; 374 407 } … … 388 421 389 422 { 390 // MiArbol->Vertices[aHoja. Vert_Hoja[1]].GetCoordinates (a,b,c);391 MiArbol->vertexdata->GetVertexCoord(aHoja.Vert_Hoja[1],a,b,c);423 // MiArbol->Vertices[aHoja.vertsLeaf[1]].GetCoordinates (a,b,c); 424 vertexdata->GetVertexCoord(aLeaf.vertsLeaf[1],a,b,c); 392 425 dist =(float)sqrt ((a-ccx)*(a-ccx)+ (b-ccy)*(b-ccy)+ (c-ccz)*(c-ccz)); 393 426 394 427 if (dist > radio) 395 428 { 396 // MiArbol->Vertices[aHoja. Vert_Hoja[2]].GetCoordinates (a,b,c);397 MiArbol->vertexdata->GetVertexCoord(aHoja.Vert_Hoja[2],a,b,c);429 // MiArbol->Vertices[aHoja.vertsLeaf[2]].GetCoordinates (a,b,c); 430 vertexdata->GetVertexCoord(aLeaf.vertsLeaf[2],a,b,c); 398 431 dist =(float)sqrt ((a-ccx)*(a-ccx)+ (b-ccy)*(b-ccy)+ (c-ccz)*(c-ccz)); 399 432 400 433 if (dist > radio) 401 434 { 402 // MiArbol->Vertices[aHoja. Vert_Hoja[3]].GetCoordinates (a,b,c);403 MiArbol->vertexdata->GetVertexCoord(aHoja.Vert_Hoja[3],a,b,c);435 // MiArbol->Vertices[aHoja.vertsLeaf[3]].GetCoordinates (a,b,c); 436 vertexdata->GetVertexCoord(aLeaf.vertsLeaf[3],a,b,c); 404 437 dist =(float)sqrt ((a-ccx)*(a-ccx)+ (b-ccy)*(b-ccy)+ (c-ccz)*(c-ccz)); 405 438 … … 442 475 spli = -1; 443 476 444 renvol = MiArbol->rad;445 centroz = MiArbol->cz;477 renvol = rad; 478 centroz = cz; 446 479 // printf (" el centro en %f y el radio es de %f\n", centroz, renvol); 447 480 … … 473 506 //COLAPSAR 474 507 475 if (( Criterio ( MiArbol->Hojas[i], ch, rva,rvb,rvc,rvd, radio )== false) && (MiArbol->Hojas[i].padre!= -1))508 if (( Criterio ( Leaves[i], ch, rva,rvb,rvc,rvd, radio )== false) && (Leaves[i].parent != -1)) 476 509 { 477 510 // SI ESTA FUESE LA HOJA IZQUIERDA Y LA DERECHA NO CUMPLE TAMPOCO EL CRITERIO 478 if (( MiArbol->Hojas[MiArbol->Hojas[i].padre].hijoi== i) &&479 ( Criterio ( MiArbol->Hojas[MiArbol->Hojas[MiArbol->Hojas[i].padre].hijod] , ch, rva,rvb,rvc,rvd, radio )== false))511 if ((Leaves[Leaves[i].parent].childLeft == i) && 512 ( Criterio (Leaves[Leaves[Leaves[i].parent].childRight] , ch, rva,rvb,rvc,rvd, radio )== false)) 480 513 { //hay que colapsar 481 if (EsActivo( MiArbol->Hojas[MiArbol->Hojas[i].padre].hijod) == false)482 lista = Forzar_Colapse ( MiArbol->Hojas[MiArbol->Hojas[i].padre].hijod, hpost, ch, rva,rvb,rvc,rvd, radio); // para activarla514 if (EsActivo(Leaves[Leaves[i].parent].childRight) == false) 515 lista = Forzar_Colapse (Leaves[Leaves[i].parent].childRight, hpost, ch, rva,rvb,rvc,rvd, radio); // para activarla 483 516 else lista = true; 484 517 … … 486 519 else 487 520 // SI ESTA FUESE LA HOJA DERECHA Y LA IZQUIERDA NO CUMPLE TAMPOCO EL CRITERIO 488 if (( MiArbol->Hojas[MiArbol->Hojas[i].padre].hijod== i) &&489 ( Criterio ( MiArbol->Hojas[MiArbol->Hojas[MiArbol->Hojas[i].padre].hijoi] , ch, rva,rvb,rvc,rvd, radio )== false))521 if ((Leaves[Leaves[i].parent].childRight == i) && 522 ( Criterio (Leaves[Leaves[Leaves[i].parent].childLeft] , ch, rva,rvb,rvc,rvd, radio )== false)) 490 523 {//hay que colapsar 491 if (EsActivo( MiArbol->Hojas[MiArbol->Hojas[i].padre].hijoi) == false)492 lista = Forzar_Colapse ( MiArbol->Hojas[MiArbol->Hojas[i].padre].hijoi, hpost, ch, rva,rvb,rvc,rvd, radio); // para activarla524 if (EsActivo(Leaves[Leaves[i].parent].childLeft) == false) 525 lista = Forzar_Colapse (Leaves[Leaves[i].parent].childLeft, hpost, ch, rva,rvb,rvc,rvd, radio); // para activarla 493 526 else lista = true; 494 527 … … 501 534 lista = false; 502 535 503 ColapsaHoja ( MiArbol->Hojas[i].padre, hpost);536 ColapsaHoja ( Leaves[i].parent, hpost); 504 537 } 505 538 … … 535 568 536 569 //actualizo los punteros del ppio y del final, y post 537 while (( ppio == MiArbol->Hojas[h].hijoi) || ( ppio == MiArbol->Hojas[h].hijod))570 while (( ppio == Leaves[h].childLeft) || ( ppio == Leaves[h].childRight)) 538 571 ppio = Acth[ppio].next; 539 while (( final == MiArbol->Hojas[h].hijoi) || ( final == MiArbol->Hojas[h].hijod))572 while (( final == Leaves[h].childLeft) || ( final == Leaves[h].childRight)) 540 573 final = Acth[final].prev; 541 574 542 while (( post == MiArbol->Hojas[h].hijoi) || ( post == MiArbol->Hojas[h].hijod))575 while (( post == Leaves[h].childLeft) || ( post == Leaves[h].childRight)) 543 576 post = Acth[post].next; 544 577 … … 547 580 //COLAPSAR = QUITO DOS DE ACTIVOS PONGO UNO A ACTIVO 548 581 549 if (Acth[ MiArbol->Hojas[h].hijoi].next != -1)550 Acth[Acth[ MiArbol->Hojas[h].hijoi].next].prev = Acth[MiArbol->Hojas[h].hijoi].prev;551 if (Acth[ MiArbol->Hojas[h].hijoi].prev != -1)552 Acth[Acth[ MiArbol->Hojas[h].hijoi].prev].next = Acth[MiArbol->Hojas[h].hijoi].next;553 554 if (Acth[ MiArbol->Hojas[h].hijod].next != -1)555 Acth[Acth[ MiArbol->Hojas[h].hijod].next].prev = Acth[MiArbol->Hojas[h].hijod].prev;556 if (Acth[ MiArbol->Hojas[h].hijod].prev != -1)557 Acth[Acth[ MiArbol->Hojas[h].hijod].prev].next = Acth[MiArbol->Hojas[h].hijod].next;582 if (Acth[Leaves[h].childLeft].next != -1) 583 Acth[Acth[Leaves[h].childLeft].next].prev = Acth[Leaves[h].childLeft].prev; 584 if (Acth[Leaves[h].childLeft].prev != -1) 585 Acth[Acth[Leaves[h].childLeft].prev].next = Acth[Leaves[h].childLeft].next; 586 587 if (Acth[Leaves[h].childRight].next != -1) 588 Acth[Acth[Leaves[h].childRight].next].prev = Acth[Leaves[h].childRight].prev; 589 if (Acth[Leaves[h].childRight].prev != -1) 590 Acth[Acth[Leaves[h].childRight].prev].next = Acth[Leaves[h].childRight].next; 558 591 559 592 560 593 // desconecto a los hijos 561 Acth[ MiArbol->Hojas[h].hijoi].prev = -1;562 Acth[ MiArbol->Hojas[h].hijoi].next = -1;563 Acth[ MiArbol->Hojas[h].hijod].prev = -1;564 Acth[ MiArbol->Hojas[h].hijod].next = -1;594 Acth[Leaves[h].childLeft].prev = -1; 595 Acth[Leaves[h].childLeft].next = -1; 596 Acth[Leaves[h].childRight].prev = -1; 597 Acth[Leaves[h].childRight].next = -1; 565 598 566 599 //añado al final … … 596 629 597 630 h = listah.GetCola ();//coger la cola 598 if ( MiArbol->Hojas[h].hijoi!= -1)599 600 { if (!EsActivo ( MiArbol->Hojas[h].hijoi))601 listah.Inserta ( MiArbol->Hojas[h].hijoi);631 if (Leaves[h].childLeft != -1) 632 633 { if (!EsActivo (Leaves[h].childLeft )) 634 listah.Inserta (Leaves[h].childLeft); 602 635 603 if ( (!EsActivo ( MiArbol->Hojas[h].hijod)) )604 listah.Inserta ( MiArbol->Hojas[h].hijod);605 606 if (EsActivo ( MiArbol->Hojas[h].hijoi) && EsActivo (MiArbol->Hojas[h].hijod))607 if((Criterio ( MiArbol->Hojas[MiArbol->Hojas[h].hijoi] ,ch, rva,rvb,rvc,rvd, radio )== false) &&608 (Criterio ( MiArbol->Hojas[MiArbol->Hojas[h].hijod], ch, rva,rvb,rvc,rvd, radio ) == false))636 if ( (!EsActivo (Leaves[h].childRight)) ) 637 listah.Inserta (Leaves[h].childRight); 638 639 if (EsActivo (Leaves[h].childLeft) && EsActivo (Leaves[h].childRight )) 640 if((Criterio ( Leaves[Leaves[h].childLeft] ,ch, rva,rvb,rvc,rvd, radio )== false) && 641 (Criterio ( Leaves[Leaves[h].childRight], ch, rva,rvb,rvc,rvd, radio ) == false)) 609 642 { 610 643 ColapsaHoja ( h, hpost); … … 642 675 643 676 // 1 enlazo los hijos 644 Acth[ MiArbol->Hojas[h].hijoi].next = MiArbol->Hojas[h].hijod;645 Acth[ MiArbol->Hojas[h].hijod].prev = MiArbol->Hojas[h].hijoi;646 Acth[ MiArbol->Hojas[h].hijod].next = -1;677 Acth[Leaves[h].childLeft].next = Leaves[h].childRight; 678 Acth[Leaves[h].childRight].prev = Leaves[h].childLeft; 679 Acth[Leaves[h].childRight].next = -1; 647 680 648 681 //y desconecto al padre … … 655 688 656 689 //añado al final los hijos 657 Acth[ MiArbol->Hojas[h].hijoi].prev = final;658 Acth[final].next = MiArbol->Hojas[h].hijoi;659 final = MiArbol->Hojas[h].hijod;690 Acth[Leaves[h].childLeft].prev = final; 691 Acth[final].next = Leaves[h].childLeft; 692 final = Leaves[h].childRight; 660 693 661 694 } … … 676 709 nodo = -1; 677 710 678 if ( MiArbol->Hojas[h].hijoi!= -1)711 if (Leaves[h].childLeft != -1) 679 712 680 713 { // si el hijo derecho o el izquierdo están en la zona de máximo detalle, haré que estos se activen 681 if ( (Criterio ( MiArbol->Hojas[MiArbol->Hojas[h].hijoi], ch, rva,rvb,rvc,rvd, radio ) == true) ||682 (Criterio ( MiArbol->Hojas[MiArbol->Hojas[h].hijod], ch, rva,rvb,rvc,rvd, radio ) == true))714 if ( (Criterio (Leaves[Leaves[h].childLeft], ch, rva,rvb,rvc,rvd, radio ) == true) || 715 (Criterio (Leaves[Leaves[h].childRight], ch, rva,rvb,rvc,rvd, radio ) == true)) 683 716 684 nodo = MiArbol->Hojas[h].hijoi;717 nodo = Leaves[h].childLeft; 685 718 686 719 else // si no, bajo un nivel más hasta encontrar algún descendiente que se encuentre en la zona de + detalle 687 720 { 688 nodo = Chequea_Split ( MiArbol->Hojas[h].hijoi, ch, rva,rvb,rvc,rvd, radio);689 if ( nodo == -1 ) nodo = Chequea_Split ( MiArbol->Hojas[h].hijod, ch, rva,rvb,rvc,rvd, radio);721 nodo = Chequea_Split (Leaves[h].childLeft, ch, rva,rvb,rvc,rvd, radio); 722 if ( nodo == -1 ) nodo = Chequea_Split (Leaves[h].childRight, ch, rva,rvb,rvc,rvd, radio); 690 723 } 691 724 … … 711 744 712 745 bien = false; 713 h = MiArbol->Hojas[hoja].padre;746 h = Leaves[hoja].parent; 714 747 listah.Inserta (h); // Inserta un dato en la lista 715 748 716 749 while ( h != padre) 717 750 { 718 h = MiArbol->Hojas[h].padre;751 h = Leaves[h].parent; 719 752 listah.Inserta (h); // Inserta un dato en la lista 720 753 } … … 750 783 { 751 784 difdist = dmax - dmin; 752 difhojas = MiArbol->nHojas - MiArbol->minHojas;785 difhojas = nHojas - minHojas; 753 786 754 787 d = dist - dmin; … … 758 791 nhojas = int(abs(d*difhojas /difdist)); 759 792 760 AjusteHojas (( MiArbol->nHojas)-nhojas);793 AjusteHojas ((nHojas)-nhojas); 761 794 762 795 } 763 796 else if (dist > dmax) { 764 AjusteHojas ( MiArbol->minHojas);797 AjusteHojas (minHojas); 765 798 } 766 799 else if (dist < dmin) { 767 AjusteHojas ( MiArbol->nHojas);800 AjusteHojas (nHojas); 768 801 } 769 802 … … 775 808 void Foliage::AjusteHojas( int nhojas) 776 809 { 777 if ((nhojas <= MiArbol->nHojas) && (nhojas >= MiArbol->minHojas))810 if ((nhojas <= nHojas) && (nhojas >= minHojas)) 778 811 { 779 812 if ( nhojas < nhactivas) { … … 810 843 hpost = Acth[i].next; 811 844 812 if ( MiArbol->Hojas[i].pa dre!= -1)813 if ( MiArbol->Hojas[MiArbol->Hojas[i].pa dre].hijoi== i)814 {if ( EsActivo (MiArbol->Hojas[MiArbol->Hojas[i].pa dre].hijod) )845 if ( MiArbol->Hojas[i].parent != -1) 846 if ( MiArbol->Hojas[MiArbol->Hojas[i].parent].childLeft == i) 847 {if ( EsActivo (MiArbol->Hojas[MiArbol->Hojas[i].parent].childRight ) ) 815 848 { 816 ColapsaHoja ( MiArbol->Hojas[i].pa dre, hpost);849 ColapsaHoja ( MiArbol->Hojas[i].parent, hpost); 817 850 nhojas --; } 818 851 } 819 852 else 820 {if ( EsActivo (MiArbol->Hojas[MiArbol->Hojas[i].pa dre].hijoi) )853 {if ( EsActivo (MiArbol->Hojas[MiArbol->Hojas[i].parent].childLeft ) ) 821 854 { 822 ColapsaHoja ( MiArbol->Hojas[i].pa dre, hpost);855 ColapsaHoja ( MiArbol->Hojas[i].parent, hpost); 823 856 nhojas --; } 824 857 } … … 838 871 j = num; 839 872 h = final+1; 840 while ((h<= MiArbol->TotHojas) && (j>0))873 while ((h<=TotHojas) && (j>0)) 841 874 { 842 while (( ppio == MiArbol->Hojas[h].hijoi) || ( ppio == MiArbol->Hojas[h].hijod))875 while (( ppio == Leaves[h].childLeft) || ( ppio == Leaves[h].childRight)) 843 876 ppio = Acth[ppio].next; 844 877 845 while (( final == MiArbol->Hojas[h].hijoi) || ( final == MiArbol->Hojas[h].hijod))878 while (( final == Leaves[h].childLeft) || ( final == Leaves[h].childRight)) 846 879 final = Acth[final].prev; 847 880 … … 849 882 //COLAPSAR = QUITO DOS DE ACTIVOS PONGO UNO A ACTIVO 850 883 851 if (Acth[ MiArbol->Hojas[h].hijoi].next != -1)852 Acth[Acth[ MiArbol->Hojas[h].hijoi].next].prev = Acth[MiArbol->Hojas[h].hijoi].prev;853 if (Acth[ MiArbol->Hojas[h].hijoi].prev != -1)854 Acth[Acth[ MiArbol->Hojas[h].hijoi].prev].next = Acth[MiArbol->Hojas[h].hijoi].next;855 856 if (Acth[ MiArbol->Hojas[h].hijod].next != -1)857 Acth[Acth[ MiArbol->Hojas[h].hijod].next].prev = Acth[MiArbol->Hojas[h].hijod].prev;858 if (Acth[ MiArbol->Hojas[h].hijod].prev != -1)859 Acth[Acth[ MiArbol->Hojas[h].hijod].prev].next = Acth[MiArbol->Hojas[h].hijod].next;884 if (Acth[Leaves[h].childLeft].next != -1) 885 Acth[Acth[Leaves[h].childLeft].next].prev = Acth[Leaves[h].childLeft].prev; 886 if (Acth[Leaves[h].childLeft].prev != -1) 887 Acth[Acth[Leaves[h].childLeft].prev].next = Acth[Leaves[h].childLeft].next; 888 889 if (Acth[Leaves[h].childRight].next != -1) 890 Acth[Acth[Leaves[h].childRight].next].prev = Acth[Leaves[h].childRight].prev; 891 if (Acth[Leaves[h].childRight].prev != -1) 892 Acth[Acth[Leaves[h].childRight].prev].next = Acth[Leaves[h].childRight].next; 860 893 861 894 862 895 // desconecto a los hijos 863 Acth[ MiArbol->Hojas[h].hijoi].prev = -1;864 Acth[ MiArbol->Hojas[h].hijoi].next = -1;865 Acth[ MiArbol->Hojas[h].hijod].prev = -1;866 Acth[ MiArbol->Hojas[h].hijod].next = -1;896 Acth[Leaves[h].childLeft].prev = -1; 897 Acth[Leaves[h].childLeft].next = -1; 898 Acth[Leaves[h].childRight].prev = -1; 899 Acth[Leaves[h].childRight].next = -1; 867 900 868 901 //añado al final … … 893 926 hpost = Acth[i].next; 894 927 895 if (MiArbol-> Hojas[i].hijoi!= -1){928 if (MiArbol->Leaves[i].childLeft != -1){ 896 929 SplitHoja(i, hpost); 897 930 nhojas --; … … 927 960 i = h++; 928 961 929 while ((EsActivo (i) == false) || (i> MiArbol->TotHojas))962 while ((EsActivo (i) == false) || (i> TotHojas)) 930 963 i++; 931 964 932 if (i > MiArbol->TotHojas) i=-1;965 if (i > TotHojas) i=-1; 933 966 934 967 … … 943 976 j = num; 944 977 h = final; 945 while ((h > MiArbol->nHojas) && (j>0))978 while ((h > nHojas) && (j>0)) 946 979 { 947 980 948 981 ///////////// insertar a los hijos en orden segun su indice 949 982 //hijo izquierdo 950 ant = AnteriorActivo ( MiArbol->Hojas[h].hijoi);951 post = PosteriorActivo ( MiArbol->Hojas[h].hijoi);952 953 954 Acth[ MiArbol->Hojas[h].hijoi].next = post;955 Acth[ MiArbol->Hojas[h].hijoi].prev = ant;956 if (ant != -1) Acth[ant].next = MiArbol->Hojas[h].hijoi;957 else ppio = MiArbol->Hojas[h].hijoi;958 if (post != -1) Acth[post].prev = MiArbol->Hojas[h].hijoi;983 ant = AnteriorActivo (Leaves[h].childLeft); 984 post = PosteriorActivo (Leaves[h].childLeft); 985 986 987 Acth[Leaves[h].childLeft].next = post; 988 Acth[Leaves[h].childLeft].prev = ant; 989 if (ant != -1) Acth[ant].next = Leaves[h].childLeft; 990 else ppio = Leaves[h].childLeft; 991 if (post != -1) Acth[post].prev = Leaves[h].childLeft; 959 992 960 993 961 994 //hijo derecho 962 ant = AnteriorActivo ( MiArbol->Hojas[h].hijod);963 post = PosteriorActivo ( MiArbol->Hojas[h].hijod);964 965 966 Acth[ MiArbol->Hojas[h].hijod].next = post;967 Acth[ MiArbol->Hojas[h].hijod].prev = ant;968 if (ant != -1) Acth[ant].next = MiArbol->Hojas[h].hijod;969 else ppio = MiArbol->Hojas[h].hijod;970 if (post != -1) Acth[post].prev = MiArbol->Hojas[h].hijod;995 ant = AnteriorActivo (Leaves[h].childRight); 996 post = PosteriorActivo (Leaves[h].childRight); 997 998 999 Acth[Leaves[h].childRight].next = post; 1000 Acth[Leaves[h].childRight].prev = ant; 1001 if (ant != -1) Acth[ant].next = Leaves[h].childRight; 1002 else ppio = Leaves[h].childRight; 1003 if (post != -1) Acth[post].prev = Leaves[h].childRight; 971 1004 972 1005 … … 992 1025 993 1026 } 1027 1028 void Foliage::ReadVertices(const Geometry::SubMesh *submesh) 1029 { 1030 int countv= int(submesh->mVertexBuffer->mVertexCount); 1031 vertexdata = create_vertex_data_func(2*countv); 1032 Leaves = new Leaf[countv*2]; 1033 indexdata = create_index_data_func(countv*2*3); // 3 indices x 2 triangulos x hoja 1034 1035 vertexdata->Begin(); 1036 for (int i=0; i<countv; i++) 1037 { 1038 vertexdata->SetVertexCoord( i, submesh->mVertexBuffer->mPosition[i].x, 1039 submesh->mVertexBuffer->mPosition[i].y, 1040 submesh->mVertexBuffer->mPosition[i].z ); 1041 } 1042 vertexdata->End(); 1043 1044 TotVerts = countv; 1045 } 1046 1047 1048 void Foliage::GetNormalH (Leaf &aleaf) 1049 { 1050 1051 float onex, oney, onez; 1052 float twox, twoy, twoz; 1053 float threex, threey, threez; 1054 1055 /* Vertices[aHoja.vertsLeaf[0]].GetCoordinates (onex, oney, onez); 1056 Vertices[aHoja.vertsLeaf[1]].GetCoordinates(twox, twoy, twoz); 1057 Vertices[aHoja.vertsLeaf[2]].GetCoordinates (threex, threey, threez);*/ 1058 1059 vertexdata->GetVertexCoord(aleaf.vertsLeaf[0],onex,oney,onez); 1060 vertexdata->GetVertexCoord(aleaf.vertsLeaf[1],twox,twoy,twoz); 1061 vertexdata->GetVertexCoord(aleaf.vertsLeaf[2],threex,threey,threez); 1062 1063 float v1[3]={twox-onex,twoy-oney,twoz-onez}; 1064 float v2[3]={threex-onex,threey-oney,threez-onez}; 1065 1066 Normalize(v1,v1); 1067 Normalize(v2,v2); 1068 1069 // aleaf.Normal[0] = (twoz-onez)*(threey-oney) - (twoy-oney)*(threez-onez); 1070 // aleaf.Normal[1] = (twox-onex)*(threez-onez) - (threex-onex)*(twoz-onez); 1071 // aleaf.Normal[2] = (threex-onex)*(twoy-oney) - (twox-onex)*(threey-oney); 1072 1073 CrossProduct(v1,v2,aleaf.normal); 1074 1075 } 1076 1077 void Foliage::CrossProduct(const float *v1, const float *v2, float *res) 1078 { 1079 res[0] = v1[1]*v2[2] - v1[2]*v2[1]; 1080 res[1] = v1[2]*v2[0] - v1[0]*v2[2]; 1081 res[2] = v1[0]*v2[1] - v1[1]*v2[0]; 1082 } 1083 1084 void Foliage::Normalize(const float *v, float *res) 1085 { 1086 float module=sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); 1087 res[0]=v[0]/module; 1088 res[1]=v[1]/module; 1089 res[2]=v[2]/module; 1090 } 1091 1092 void Foliage::ReadLeafs(const Geometry::SubMesh *submesh) 1093 { 1094 int numtris = int(submesh->mIndexCount / 3); 1095 nHojas = numtris / 2; 1096 for (int h=0; h<nHojas; h++) 1097 { 1098 Leaves[h].vertsLeaf[0] = submesh->mIndex[h*6+0]; 1099 Leaves[h].vertsLeaf[1] = submesh->mIndex[h*6+1]; 1100 Leaves[h].vertsLeaf[2] = submesh->mIndex[h*6+2]; 1101 Leaves[h].vertsLeaf[3] = submesh->mIndex[h*6+5]; 1102 Leaves[h].visible = 0; 1103 1104 GetNormalH ( Leaves[h]); 1105 } 1106 } 1107 1108 /// returns the number of total leafs 1109 bool Foliage::ReadSimpSeq(const char *simpSeqFile) 1110 { 1111 FILE* fp_simpli; 1112 char linea[256]; 1113 int v0, v1, v2, v3, tn, tv1,tv2, e=0; 1114 1115 if ((fp_simpli = fopen (simpSeqFile, "r")) == NULL) 1116 { 1117 printf ("No he podido abrir el fichero %s\n", simpSeqFile); 1118 return false; 1119 } 1120 else 1121 { 1122 tn = nHojas; 1123 while (fgets (linea, 255, fp_simpli) != NULL) 1124 { 1125 if (linea[0]<'0' || linea[0]>'9') 1126 continue; 1127 1128 //N 446 Ver 10176 10178 10169 10171 Tv 156 154 E 2 1129 1130 // sscanf(linea, "%s %lu %s %lu %lu %lu %lu %s %lu %lu %s %i", 1131 // &str, &tn, &str, &v0, &v1, &v2, &v3, &str, &tv1, &tv2, &str, &e ); 1132 long int triviej00=-1, triviej01=-1; 1133 long int triviej10=-1, triviej11=-1; 1134 sscanf(linea, "%lu %lu %lu %lu & %lu %lu %lu %lu", &triviej00,&triviej01,&triviej10,&triviej11, &v0,&v1,&v2,&v3); 1135 1136 Leaves[tn].vertsLeaf[0] = v0; 1137 Leaves[tn].vertsLeaf[1] = v1; 1138 Leaves[tn].vertsLeaf[2] = v2; 1139 Leaves[tn].vertsLeaf[3] = v3; 1140 1141 Leaves[tn].visible = 0; 1142 1143 GetNormalH (Leaves[tn]); 1144 1145 tv1 = triviej00/2; 1146 tv2 = triviej10/2; 1147 1148 Leaves[tn].childLeft= tv1; 1149 Leaves[tn].childRight= tv2; 1150 1151 Leaves[tv1].parent = tn; 1152 Leaves[tv2].parent = tn; 1153 1154 tn++; 1155 } 1156 1157 } 1158 1159 fclose(fp_simpli); 1160 1161 TotHojas=tn; 1162 1163 return true; 1164 } 1165 1166 void Foliage::RellenoRaiz (void) 1167 { 1168 int i,j, k, t, cont; 1169 bool esta, fin; 1170 1171 i=0; 1172 k=-1; 1173 cont =-1; 1174 1175 MinDet = new Activas[nHojas*2]; 1176 1177 while (i<TotHojas) 1178 { 1179 j=i; 1180 while (Leaves[j].parent > -1) j= Leaves[j].parent; 1181 Leaves[i].root = j; 1182 1183 1184 // para la estructura MinDet 1185 if ( k == -1){ 1186 k++; 1187 MinDet[k].indice = j; 1188 cont =k; 1189 } 1190 else 1191 { 1192 t = 0; 1193 esta = false; 1194 fin = false; 1195 1196 while (( fin == false) && (esta == false)) 1197 { if ( MinDet[t].indice == j) esta = true; 1198 else t++; 1199 if (MinDet[t].indice == -1) fin = true; 1200 } 1201 1202 if ( esta == false) //añado al final 1203 { 1204 cont++; 1205 MinDet[cont].indice = j; 1206 } 1207 } 1208 1209 i++; 1210 } 1211 1212 minHojas = cont; 1213 1214 } 1215 1216 void Foliage::CalculaTexCoordsYNorms(void) 1217 { 1218 vertexdata->Begin(); 1219 for (int i=0; i<nHojas; i++) 1220 { 1221 const float* lanormal = Leaves[i].normal; 1222 vertexdata->SetVertexNormal(Leaves[i].vertsLeaf[0], lanormal[0], lanormal[1], lanormal[2]); 1223 vertexdata->SetVertexTexCoord(Leaves[i].vertsLeaf[0], 0.0f, 1.0f); 1224 1225 vertexdata->SetVertexNormal(Leaves[i].vertsLeaf[1], lanormal[0], lanormal[1], lanormal[2]); 1226 vertexdata->SetVertexTexCoord(Leaves[i].vertsLeaf[1], 0.0f, 0.0f); 1227 1228 vertexdata->SetVertexNormal(Leaves[i].vertsLeaf[2], lanormal[0], lanormal[1], lanormal[2]); 1229 vertexdata->SetVertexTexCoord(Leaves[i].vertsLeaf[2], 1.0f, 1.0f); 1230 1231 vertexdata->SetVertexNormal(Leaves[i].vertsLeaf[3], lanormal[0], lanormal[1], lanormal[2]); 1232 vertexdata->SetVertexTexCoord(Leaves[i].vertsLeaf[3], 1.0f, 0.0f); 1233 1234 1235 /* MiArbol->Vertices[aHoja.vertsLeaf[1]].GetCoordinates (a,b,c); 1236 glTexCoord2f ( 0.0, 1.0); 1237 glVertex3f (a,b,c); 1238 1239 MiArbol->Vertices[aHoja.vertsLeaf[2]].GetCoordinates (a,b,c); 1240 glTexCoord2f ( 1.0, 0.0); 1241 glVertex3f (a,b,c); 1242 1243 MiArbol->Vertices[aHoja.vertsLeaf[3]].GetCoordinates (a,b,c); 1244 glTexCoord2f ( 1.0, 1.0); 1245 glVertex3f (a,b,c);*/ 1246 } 1247 vertexdata->End(); 1248 } 1249 1250 Foliage::Foliage(const Foliage *ar) 1251 { 1252 nHojas=ar->nHojas; 1253 MinDet = new Activas[nHojas*2]; 1254 // for (unsigned int i=0; i<nHojas*2; i++) 1255 // MinDet[i]=ar->MinDet[i]; 1256 memcpy(MinDet,ar->MinDet,sizeof(Activas)*nHojas*2); 1257 TotHojas=ar->TotHojas; 1258 cx=ar->cx; 1259 cy=ar->cy; 1260 cz=ar->cz; 1261 rad=ar->rad; 1262 minHojas=ar->minHojas; 1263 TotVerts=ar->TotVerts; 1264 1265 create_vertex_data_func=ar->create_vertex_data_func; 1266 create_index_data_func=ar->create_index_data_func; 1267 vertexdata=create_vertex_data_func(ar->vertexdata->GetNumVertices()); 1268 vertexdata->Begin(); 1269 for (unsigned int i=0; i<vertexdata->GetNumVertices(); i++) 1270 { 1271 float va,vb,vc; 1272 ar->vertexdata->GetVertexCoord(i,va,vb,vc); 1273 vertexdata->SetVertexCoord(i,va,vb,vc); 1274 ar->vertexdata->GetVertexNormal(i,va,vb,vc); 1275 vertexdata->SetVertexNormal(i,va,vb,vc); 1276 } 1277 vertexdata->End(); 1278 indexdata=create_index_data_func(ar->indexdata->GetNumMaxIndices()); 1279 indexdata->Begin(); 1280 for (unsigned int i=0; i<indexdata->GetNumMaxIndices(); i++) 1281 indexdata->SetIndex(i,ar->indexdata->GetIndex(i)); 1282 indexdata->End(); 1283 1284 Leaves=new Leaf[vertexdata->GetNumVertices()]; 1285 // for (unsigned int i=0; i<vertexdata->GetNumVertices(); i++) 1286 // Leaves[i]=ar->Leaves[i]; 1287 memcpy(Leaves,ar->Leaves,sizeof(Leaf)*vertexdata->GetNumVertices()); 1288 1289 // esto no sé si devería haber akí 1290 indexdata->SetNumValidIndices(0); 1291 1292 int h=0; 1293 1294 Acth = new Activas[nHojas*8]; 1295 1296 for ( h=0; h < nHojas; h++) { 1297 1298 Acth[h].indice = h; 1299 if ( h != 0) 1300 { 1301 Acth[h].prev = (h-1); 1302 Acth[h-1].next = h; 1303 } 1304 1305 } 1306 1307 ppio = 0; 1308 final = nHojas-1; 1309 nhactivas = nHojas; 1310 1311 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.h
r830 r1019 3 3 4 4 5 #include "arbol.h"6 5 #include "Activas.h" 7 //#include "material.h"6 #include "GeoSubMesh.h" 8 7 #include "tlista.h" 9 //#include <vl\VLf.h>10 8 #include "TMatrix.h" 11 12 9 #include "VertexData.h" 10 #include "Leaf.h" 13 11 14 12 class Foliage … … 16 14 public : 17 15 18 Arbol *MiArbol; 19 Activas *Acth; // primera hoja activa 20 int ppio, final; 21 int nhactivas; 22 TMatrix mat_aux; 16 Activas *Acth; // primera hoja activa 17 int ppio, final; 18 int nhactivas; 19 TMatrix mat_aux; 23 20 24 public : 25 Foliage (void); // Void constructor 26 Foliage ( Arbol* Arbol1 ); // Constructor with the name of a file cotaining the data 21 Foliage (const Geometry::SubMesh *, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); 22 Foliage (const Foliage *); 27 23 virtual ~Foliage (void); // Destructor 28 24 29 // sacar por pantalla30 /* void Dibuja_Hoja ( Hoja&);31 int DibujarHojas (float frustum[6][4], float zoom);32 void DibujaEsfera (float);*/33 34 25 //culling 35 26 void Culling (float frustum[6][4]); … … 39 30 bool EsActivo ( int num); 40 31 int DondeEsta ( float x, float y, float z, float rva, float rvb,float rvc, float rvd); 41 bool Criterio ( Hoja &aHoja, char ch, float rva, float rvb,float rvc, float rvd, float radio);32 bool Criterio ( Leaf &, char ch, float rva, float rvb,float rvc, float rvd, float radio); 42 33 int ResolucionV ( char c, float rva, float rvb,float rvc, float rvd, float radio); 43 34 void ColapsaHoja (int, int&); … … 56 47 void RCsplit ( int nhojas); 57 48 58 //impostores 59 // void DibujaCaja (float alfa, float d); 60 // int DibujaMediaCopa ( char c, float rva, float rvb,float rvc, float rvd, float radio); 49 Geometry::VertexData *vertexdata; 50 Geometry::IndexData *indexdata; 51 52 Leaf *Leaves; 53 Activas *MinDet; // primera hoja activa 54 int nHojas; 55 int TotHojas; 61 56 57 float cx,cy,cz; //centro de la copa// para los impostores y resolucion variable 58 float rad; //radio de la esfera envolvente 59 int minHojas; 60 int TotVerts; 61 62 private: 63 Geometry::CREATEVERTEXDATAFUNC create_vertex_data_func; 64 Geometry::CREATEINDEXDATAFUNC create_index_data_func; 65 66 void ReadLeafs(const Geometry::SubMesh *); 67 void ReadVertices(const Geometry::SubMesh *); 68 bool ReadSimpSeq(const char*); /// returns true when successful 69 void RellenoRaiz (void); 70 71 void GetNormalH (Leaf&); 72 // void GetNormalT(Tronco&); 73 74 void CrossProduct(const float *v1, const float *v2, float *res); 75 void Normalize(const float *v, float *res); 76 // void CalculaNormalesVertice(void); 77 void CalculaTexCoordsYNorms(void); 78 62 79 }; 63 80
Note: See TracChangeset
for help on using the changeset viewer.