11# if defined(__GNUC__) && (__GNUC__ >= 3)
44 list<IndexedVertex> indexedVertices;
46 for (i = 0; i < iVSize; i += 3) {
47 indexedVertices.emplace_back(
Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2]), i / 3);
51 indexedVertices.sort();
54 uint *mapIndices =
new uint[iVSize / 3];
55 *oVertices =
new float[iVSize];
56 list<IndexedVertex>::iterator iv;
59 for (iv = indexedVertices.begin(); iv != indexedVertices.end(); iv++) {
61 (*oVertices)[vIndex] = iv->x();
62 (*oVertices)[vIndex + 1] = iv->y();
63 (*oVertices)[vIndex + 2] = iv->z();
65 mapIndices[iv->index()] = newIndex;
71 *oIndices =
new uint[iISize];
72 for (i = 0; i < iISize; i++) {
73 (*oIndices)[i] = 3 * mapIndices[iIndices[i] / 3];
88 vector<Vec3f> vertices;
90 for (i = 0; i < iVSize; i += 3) {
91 vertices.emplace_back(iVertices[i], iVertices[i + 1], iVertices[i + 2]);
95 vector<Vec3f>::iterator
v = vertices.begin();
97 vector<Vec3f> compressedVertices;
100 compressedVertices.push_back(vertices.front());
105 for (;
v != vertices.end();
v++) {
107 if (current == previous) {
108 mapVertex[i] = compressedVertices.size() - 1;
111 compressedVertices.push_back(current);
112 mapVertex[i] = compressedVertices.size() - 1;
119 *oVSize = 3 * compressedVertices.size();
120 *oVertices =
new float[*oVSize];
122 for (
v = compressedVertices.begin();
v != compressedVertices.end();
v++) {
123 (*oVertices)[i] = (*v)[0];
124 (*oVertices)[i + 1] = (*v)[1];
125 (*oVertices)[i + 2] = (*v)[2];
130 *oIndices =
new uint[iISize];
131 for (i = 0; i < iISize; i++) {
132 (*oIndices)[i] = 3 * mapVertex[iIndices[i] / 3];
140 const uint *iIndices,
154 iVertices, iVSize, iIndices, iISize, &tmpVertices, &tmpIndices);
162 tmpVertices, iVSize, tmpIndices, iISize, oVertices, oVSize, oIndices);
165 printf(
"Merging: %lf sec.\n", duration);
169 delete[] tmpVertices;
175#define _MUL 950706376UL
176#define _MOD 2147483647UL
189 const uint *iIndices,
195 using cleanHashTable = map<Vec3f, uint>;
196 vector<Vec3f> vertices;
198 for (i = 0; i < iVSize; i += 3) {
199 vertices.emplace_back(iVertices[i], iVertices[i + 1], iVertices[i + 2]);
203 vector<uint> newIndices;
204 vector<Vec3f> newVertices;
207 uint currentIndex = 0;
208 vector<Vec3f>::const_iterator
v = vertices.begin();
209 vector<Vec3f>::const_iterator end = vertices.end();
210 cleanHashTable::const_iterator found;
211 for (;
v != end;
v++) {
213 if (found != ht.end()) {
215 newIndices.push_back((*found).second);
218 newVertices.push_back(*
v);
219 newIndices.push_back(currentIndex);
220 ht[*
v] = currentIndex;
226 *oVSize = 3 * newVertices.size();
227 *oVertices =
new float[*oVSize];
229 end = newVertices.end();
230 for (
v = newVertices.begin();
v != end;
v++) {
231 (*oVertices)[currentIndex++] = (*v)[0];
232 (*oVertices)[currentIndex++] = (*v)[1];
233 (*oVertices)[currentIndex++] = (*v)[2];
237 *oIndices =
new uint[iISize];
238 for (i = 0; i < iISize; i++) {
239 (*oIndices)[i] = 3 * newIndices[iIndices[i] / 3];
Class to define a cleaner of geometry providing a set of useful tools.
Class to measure elapsed time.
ATTR_WARN_UNUSED_RESULT const BMVert * v
static void SortIndexedVertexArray(const float *iVertices, uint iVSize, const uint *iIndices, uint iISize, float **oVertices, uint **oIndices)
static void CompressIndexedVertexArray(const float *iVertices, uint iVSize, const uint *iIndices, uint iISize, float **oVertices, uint *oVSize, uint **oIndices)
static void SortAndCompressIndexedVertexArray(const float *iVertices, uint iVSize, const uint *iIndices, uint iISize, float **oVertices, uint *oVSize, uint **oIndices)
static void CleanIndexedVertexArray(const float *iVertices, uint iVSize, const uint *iIndices, uint iISize, float **oVertices, uint *oVSize, uint **oIndices)
VecMat::Vec3< float > Vec3f
size_t operator()(const Vec3r &p) const