1 | #include "GeoTreeSimpSequence.h"
|
---|
2 | #include <iostream>
|
---|
3 | #include <fstream>
|
---|
4 | #include "GeoMeshLoader.h"
|
---|
5 |
|
---|
6 | using namespace Geometry;
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | TreeSimplificationSequence::TreeSimplificationSequence()
|
---|
10 | {
|
---|
11 | meshName="";
|
---|
12 | }
|
---|
13 |
|
---|
14 | TreeSimplificationSequence::~TreeSimplificationSequence()
|
---|
15 | {
|
---|
16 | }
|
---|
17 |
|
---|
18 | void TreeSimplificationSequence::Load(Serializer &s)
|
---|
19 | {
|
---|
20 | // Carga una secuencia de simplificación desde un fichero
|
---|
21 | char buffer[256];
|
---|
22 | char nombre[256];
|
---|
23 | Geometry::Index quad;
|
---|
24 | int cont;
|
---|
25 |
|
---|
26 | if (s.ReadData(buffer,256) != NULL)
|
---|
27 | {
|
---|
28 | sscanf(buffer,"%s",&nombre);
|
---|
29 | meshName=new char[strlen(nombre)];
|
---|
30 | strcpy(meshName,nombre);
|
---|
31 | }
|
---|
32 |
|
---|
33 | while (s.ReadData(buffer,256) != NULL)
|
---|
34 | {
|
---|
35 | Geometry::TreeSimplificationSequence::Step pasosimp;
|
---|
36 | sscanf(buffer,"%u %u %u %u &",&pasosimp.mV0,&pasosimp.mV1,&pasosimp.mT0,&pasosimp.mT1);
|
---|
37 | // Quitar el salto de línea del final.
|
---|
38 | buffer[strlen(buffer)-1]='\0';
|
---|
39 |
|
---|
40 | char *ptr1;
|
---|
41 | ptr1=strtok(buffer,"&");
|
---|
42 | ptr1=strtok(NULL,"&");
|
---|
43 | if (ptr1!=NULL)
|
---|
44 | {
|
---|
45 | char *ptr;
|
---|
46 | ptr=strtok(ptr1," ");
|
---|
47 | cont=0;
|
---|
48 | while(ptr != NULL )
|
---|
49 | {
|
---|
50 | quad = (Index)atoi(ptr);
|
---|
51 | pasosimp.mNewQuad[cont]=quad;
|
---|
52 | ptr=strtok(NULL," ");
|
---|
53 | cont++;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | mSteps.push_back(pasosimp);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | void TreeSimplificationSequence::Save(Serializer &s)
|
---|
61 | {
|
---|
62 | // Stores simplification sequence.
|
---|
63 | unsigned short chunkid = 0xdcba;
|
---|
64 | s.WriteData(&chunkid,sizeof(unsigned short),1);
|
---|
65 |
|
---|
66 | unsigned long size = (unsigned long)
|
---|
67 | (
|
---|
68 | mSteps.size()*8*sizeof(int)
|
---|
69 | +
|
---|
70 | CHUNK_OVERHEAD_SIZE
|
---|
71 | );
|
---|
72 |
|
---|
73 | s.WriteData(&size,sizeof(unsigned long),1);
|
---|
74 |
|
---|
75 | int tam = (int)mSteps.size();
|
---|
76 |
|
---|
77 | s.WriteData(&tam,sizeof(int),1);
|
---|
78 |
|
---|
79 | for(int i=0; i<tam; i++)
|
---|
80 | {
|
---|
81 | Geometry::TreeSimplificationSequence::Step paso = mSteps.operator [](i);
|
---|
82 |
|
---|
83 | s.WriteData(&paso.mV0,sizeof(int),1);
|
---|
84 | s.WriteData(&paso.mV1,sizeof(int),1);
|
---|
85 | s.WriteData(&paso.mT0,sizeof(int),1);
|
---|
86 | s.WriteData(&paso.mT1,sizeof(int),1);
|
---|
87 |
|
---|
88 | s.WriteData(paso.mNewQuad,sizeof(int),4);
|
---|
89 |
|
---|
90 | // El último %u que recibe el sprintf es para indicar si un paso es dependiente del anterior. REVISAR
|
---|
91 | // ------------------------------------------------------------------------
|
---|
92 | /* sprintf(simp,"%u %u %u %u &", paso.mV0, paso.mV1, paso.mT0, paso.mT1);
|
---|
93 | s.WriteData(simp,sizeof(char),strlen(simp));
|
---|
94 |
|
---|
95 | // los quads
|
---|
96 | sprintf(simp," %u %u %u %u\n",paso.mNewQuad[0],paso.mNewQuad[1],paso.mNewQuad[2],paso.mNewQuad[3]);
|
---|
97 | s.WriteData(simp,sizeof(char),strlen(simp));*/
|
---|
98 | //s.WriteData("\n",sizeof(char),1);
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | void TreeSimplificationSequence::putMeshName(char *name)
|
---|
103 | {
|
---|
104 | meshName=name;
|
---|
105 | }
|
---|
106 |
|
---|
107 | char *TreeSimplificationSequence::getMeshName(void)
|
---|
108 | {
|
---|
109 | return meshName;
|
---|
110 | } |
---|