1 | #include "GeoMeshSimpSequence.h"
|
---|
2 |
|
---|
3 | using namespace Geometry;
|
---|
4 | using namespace std;
|
---|
5 |
|
---|
6 | //---------------------------------------------------------------------------
|
---|
7 | // Constructor.
|
---|
8 | //---------------------------------------------------------------------------
|
---|
9 | MeshSimplificationSequence::MeshSimplificationSequence()
|
---|
10 | {
|
---|
11 | meshName = "";
|
---|
12 | }
|
---|
13 |
|
---|
14 | MeshSimplificationSequence::~MeshSimplificationSequence()
|
---|
15 | {
|
---|
16 | }
|
---|
17 |
|
---|
18 | //---------------------------------------------------------------------------
|
---|
19 | // Loads mesh simplification sequence.
|
---|
20 | //---------------------------------------------------------------------------
|
---|
21 | void MeshSimplificationSequence::Load(Serializer &s)
|
---|
22 | {
|
---|
23 | // Loads a simplification sequence from a file.
|
---|
24 | char buffer[256];
|
---|
25 | unsigned int modVertex;
|
---|
26 | char name[256];
|
---|
27 |
|
---|
28 | // Read mesh name.
|
---|
29 | if (s.ReadData(buffer,256) != NULL)
|
---|
30 | {
|
---|
31 | sscanf(buffer,"%s",&name);
|
---|
32 |
|
---|
33 | meshName = new char[strlen(name)];
|
---|
34 |
|
---|
35 | strcpy(meshName,name);
|
---|
36 | }
|
---|
37 |
|
---|
38 | // Read steps data.
|
---|
39 | while (s.ReadData(buffer,256) != NULL)
|
---|
40 | {
|
---|
41 | Geometry::MeshSimplificationSequence::Step simplifstep;
|
---|
42 |
|
---|
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);
|
---|
54 |
|
---|
55 | buffer[strlen(buffer)-1] = '\0';
|
---|
56 |
|
---|
57 | char *ptr1;
|
---|
58 |
|
---|
59 | ptr1 = strtok(buffer,"&");
|
---|
60 | ptr1 = strtok(NULL,"&");
|
---|
61 |
|
---|
62 | if (ptr1 != NULL)
|
---|
63 | {
|
---|
64 | char *ptr;
|
---|
65 |
|
---|
66 | ptr = strtok(ptr1," ");
|
---|
67 |
|
---|
68 | while (ptr != NULL )
|
---|
69 | {
|
---|
70 | modVertex = (unsigned int)atoi(ptr);
|
---|
71 |
|
---|
72 | simplifstep.mModfaces.push_back(modVertex);
|
---|
73 |
|
---|
74 | ptr = strtok(NULL," ");
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | mSteps.push_back(simplifstep);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | //---------------------------------------------------------------------------
|
---|
83 | // Saves simplification sequence.
|
---|
84 | //---------------------------------------------------------------------------
|
---|
85 | void MeshSimplificationSequence::Save(Serializer &s)
|
---|
86 | {
|
---|
87 | // Stores the simplification sequence in a file.
|
---|
88 | char simp[256];
|
---|
89 |
|
---|
90 | // Name of the mesh.
|
---|
91 | sprintf(simp,"%s\n",meshName);
|
---|
92 | s.WriteData(simp,sizeof(char),strlen(simp));
|
---|
93 |
|
---|
94 | // For each step.
|
---|
95 | for (unsigned int i = 0; i < mSteps.size(); i++)
|
---|
96 | {
|
---|
97 | Geometry::MeshSimplificationSequence::Step paso = mSteps.operator [](i);
|
---|
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.
|
---|
109 | s.WriteData(simp,sizeof(char),strlen(simp));
|
---|
110 |
|
---|
111 | // Triangles modified.
|
---|
112 | for (unsigned int j = 0; j < paso.mModfaces.size(); j++)
|
---|
113 | {
|
---|
114 | sprintf(simp," %u",paso.mModfaces.operator [](j));
|
---|
115 | s.WriteData(simp,sizeof(char),strlen(simp));
|
---|
116 | }
|
---|
117 |
|
---|
118 | // New line.
|
---|
119 | s.WriteData("\n",sizeof(char),1);
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | //---------------------------------------------------------------------------
|
---|
124 | // Puts mesh name.
|
---|
125 | //---------------------------------------------------------------------------
|
---|
126 | void MeshSimplificationSequence::putMeshName(char *name)
|
---|
127 | {
|
---|
128 | meshName = name;
|
---|
129 | }
|
---|
130 |
|
---|
131 | //---------------------------------------------------------------------------
|
---|
132 | // Gets mesh name.
|
---|
133 | //---------------------------------------------------------------------------
|
---|
134 | char *MeshSimplificationSequence::getMeshName(void)
|
---|
135 | {
|
---|
136 | return meshName;
|
---|
137 | }
|
---|
138 |
|
---|