Debian Codegraph @

src/vcglib/wrap/io_trimesh/import_off.h

raw symbols SCIP
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23 #ifndef __VCGLIB_IMPORT_OFF
24 #define __VCGLIB_IMPORT_OFF
25
26 #include <fstream>
27 #include<vcg/complex/algorithms/bitquad_support.h>
28 #include <wrap/io_trimesh/io_mask.h>
29 #include <wrap/io_trimesh/io_fan_tessellator.h>
30
31 namespace vcg {
32 namespace tri {
33 namespace io {
34
35 // /** \addtogroup */
36 // /* @{ */
37 /**
38 This class encapsulate a filter for importing OFF meshes.
39 A basic description of the OFF file format can be found at http://www.geomview.org/docs/html/geomview_41.html
40 */
41 template<class MESH_TYPE>
42 class ImporterOFF
43 {
44 public:
45
46 typedef typename MESH_TYPE::VertexType VertexType;
47 typedef typename MESH_TYPE::VertexIterator VertexIterator;
48 typedef typename MESH_TYPE::VertexPointer VertexPointer;
49 typedef typename MESH_TYPE::FaceType FaceType;
50 typedef typename MESH_TYPE::FaceIterator FaceIterator;
51 typedef typename MESH_TYPE::FacePointer FacePointer;
52 typedef typename MESH_TYPE::CoordType CoordType;
53 typedef typename MESH_TYPE::ScalarType ScalarType;
54
55 // OFF codes
56 enum OFFCodes {
57 NoError = 0, CantOpen, InvalidFile,
58 InvalidFile_MissingOFF,
59 UnsupportedFormat, ErrorNotTriangularFace, ErrorHighDimension, ErrorDegenerateFace
60 };
61
62 /*!
63 * Standard call for knowing the meaning of an error code
64 * \param message_code The code returned by <CODE>Open</CODE>
65 * \return The string describing the error code
66 */
67 static const char* ErrorMsg(int message_code)
68 {
69 static const char* error_msg[] =
70 {
71 "No errors", "Can't open file", "Invalid file",
72 "Invalid file: OFF file should have in the first line the OFF keyword as a first token",
73 "Unsupported format", "Face with more than 3 vertices","File with high dimensional vertexes are not supported", "Error Degenerate Face with less than 3 vertices" };
74
75 if (message_code > 6 || message_code < 0)
76 return "Unknown error";
77 else
78 return error_msg[message_code];
79 };
80
81 /**
82 * Load only the properties of the 3D objects.
83 *
84 * \param filename the name of the file to read from
85 * \param loadmask the mask which encodes the properties
86 * \return the operation result
87 */
88 static bool LoadMask(const char *filename, int &loadmask)
89 {
90 // To obtain the loading mask all the file must be parsed
91 // to distinguish between per-vertex and per-face color attribute.
92 loadmask = 0;
93 MESH_TYPE dummyMesh;
94 return (Open(dummyMesh, filename, loadmask) == NoError);
95 }
96
97 static int Open(MESH_TYPE &mesh, const char *filename, CallBackPos *cb = 0)
98 {
99 int loadmask;
100 return Open(mesh, filename, loadmask, cb);
101 }
102
103 static int OpenMem(MESH_TYPE &mesh, const char *mem, size_t sz, int &loadmask,
104 CallBackPos *cb = 0)
105 {
106 std::string str;
107 str.append(mem, sz);
108 std::istringstream strm(str);
109 return OpenStream(mesh, strm, loadmask, cb);
110 }
111
112 /*!
113 * Standard call for reading a mesh.
114 *
115 * \param mesh the destination mesh
116 * \param filename the name of the file to read from
117 * \return the operation result
118 */
119 static int Open(MESH_TYPE &mesh, const char *filename, int &loadmask,
120 CallBackPos *cb = 0)
121 {
122 std::ifstream stream(filename);
123 if (stream.fail())
124 return CantOpen;
125 return OpenStream(mesh, stream, loadmask, cb);
126 }
127
128 static int OpenStream(MESH_TYPE &mesh, std::istream &stream, int &loadmask,
129 CallBackPos *cb = 0)
130 {
131 std::vector< std::string > tokens;
132 TokenizeNextLine(stream, tokens);
133 if (tokens.empty()) return InvalidFile_MissingOFF;
134
135 bool isNormalDefined = false;
136 bool isColorDefined = false;
137 bool isTexCoordDefined = false;
138 int dimension = 3;
139 bool homogeneousComponents = false;
140
141
142 /*
143 [ST][C][N][4][n]OFF # Header keyword
144 [Ndim] # Space dimension of vertices, present only if nOFF
145 NVertices NFaces NEdges # NEdges not used or checked
146
147 x[0] y[0] z[0] # Vertices, possibly with normals, colors, and/or texture coordinates, in that order, if the prefixes N, C, ST are present.
148 # If 4OFF, each vertex has 4 components including a final homogeneous component.
149 # If nOFF, each vertex has Ndim components.
150 # If 4nOFF, each vertex has Ndim+1 components.
151 ...
152 x[NVertices-1] y[NVertices-1] z[NVertices-1]
153
154 # Faces
155 # Nv = # vertices on this face
156 # v[0] ... v[Nv-1]: vertex indices
157 # in range 0..NVertices-1
158 Nv v[0] v[1] ... v[Nv-1] colorspec
159 ...
160 # colorspec continues past v[Nv-1] to end-of-line; may be 0 to 4 numbers
161 # nothing: default
162 # integer: colormap index
163 # 3 or 4 integers: RGB[A] values 0..255
164 # 3 or 4 floats: RGB[A] values 0..1
165 */
166 std::string header = tokens[0];
167 if (header.rfind("OFF") != std::basic_string<char>::npos)
168 { // the OFF string is in the header go on parsing it.
169 for (int u = static_cast<int>(header.rfind("OFF") - 1); u >= 0; u--)
170 {
171 if (header[u] == 'C')
172 isColorDefined = true;
173 else if (header[u] == 'N')
174 isNormalDefined = true;
175 else if (u > 0 && header[u - 1] == 'S' && header[u] == 'T')
176 isTexCoordDefined = true;
177 else if (header[u] == '4')
178 homogeneousComponents = true;
179 else if (header[u] == 'n')
180 return ErrorHighDimension;
181 }
182 }
183 else return InvalidFile_MissingOFF;
184
185 // If the file is slightly malformed and it has nvert and nface AFTER the OFF string instead of in the next line
186 // we manage it here...
187 if (tokens.size() == 1) TokenizeNextLine(stream, tokens);
188 else tokens.erase(tokens.begin(), tokens.begin() + 1);
189
190 // Update loading mask
191 ///////////////////////////////////////
192
193 loadmask = Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX;
194
195 if (isNormalDefined) loadmask |= Mask::IOM_VERTNORMAL;
196 if (isTexCoordDefined) loadmask |= Mask::IOM_VERTTEXCOORD;
197 //if (isColorDefined) { loadmask |= Mask::IOM_VERTCOLOR;loadmask |= Mask::IOM_FACECOLOR;}
198
199
200 //if(onlyMaskFlag) return NoError;
201
202
203 mesh.Clear();
204
205 // check on next 2 lines to detect corrupted files
206 if (tokens.size() < 3)
207 return InvalidFile;
208
209 unsigned int nVertices, nFaces, nEdges;
210 nVertices = atoi(tokens[0].c_str());
211 nFaces = atoi(tokens[1].c_str());
212 nEdges = atoi(tokens[2].c_str());
213 (void)nEdges; // unused
214
215 // dimension is the space dimension of vertices => it must be three(!)
216 if (dimension != 3)
217 return UnsupportedFormat;
218
219 if (homogeneousComponents)
220 return UnsupportedFormat;
221
222 // READ VERTICES
223 //////////////////////////////////////////////////////
224
225 VertexIterator v_iter = Allocator<MESH_TYPE>::AddVertices(mesh, nVertices);
226 TokenizeNextLine(stream, tokens);
227 size_t k = 0; // next token to read
228
229 for (unsigned int i = 0; i < nVertices; i++, v_iter++)
230 {
231 if (cb && (i % 1000) == 0)
232 cb(i * 50 / nVertices, "Vertex Loading");
233
234 // Read 3 vertex coordinates
235 for (unsigned int j = 0; j < 3; j++)
236 {
237 // Go to next line when needed
238 if (k == tokens.size()) // if EOL
239 {
240 TokenizeNextLine(stream, tokens);
241 if (tokens.size() == 0) // if EOF
242 return InvalidFile;
243 k = 0;
244 }
245
246 // Read vertex coordinate
247 (*v_iter).P()[j] = (ScalarType)atof(tokens[k].c_str());
248 k++;
249 }
250
251 if (isNormalDefined)
252 {
253 // Read 3 normal coordinates
254 for (unsigned int j = 0; j < 3; j++)
255 {
256 // Go to next line when needed
257 if (k == tokens.size()) // if EOL
258 {
259 TokenizeNextLine(stream, tokens);
260 if (tokens.size() == 0) // if EOF
261 return InvalidFile;
262 k = 0;
263 }
264
265 // Read normal coordinate
266 (*v_iter).N()[j] = (ScalarType)atof(tokens[k].c_str());
267 k++;
268 }
269 }
270
271 // NOTE: It is assumed that colored vertex takes exactly one text line
272 // (otherwise it is impossible to parse color information since
273 // color components can vary)
274 if (isColorDefined)
275 {
276 // The number of color components varies from 0 to 4.
277 // The OFF format guaranties that there is 1 vertex per line.
278 int nb_color_components = static_cast<int>(tokens.size())
279 - static_cast<int>(k) /* tokens already parsed */
280 - 2 * (isTexCoordDefined ? 1 : 0);
281
282 if (nb_color_components < 0 || nb_color_components > 4)
283 return InvalidFile;
284
285 // set per-vertex color attribute
286 if (nb_color_components > 0)
287 loadmask |= Mask::IOM_VERTCOLOR;
288
289 // Store color components
290 if (tri::HasPerVertexColor(mesh))
291 {
292 // Read color components
293
294 if (nb_color_components == 1)
295 {
296 // read color index
297 (*v_iter).C().Import(ColorMap(atoi(tokens[k].c_str())));
298 }
299 else if (nb_color_components == 3)
300 {
301 // read RGB color
302 if (tokens[k].find(".") == size_t(-1))// if it is a float there is a dot
303 {
304 // integers
305 unsigned char r =
306 static_cast<unsigned char>(atoi(tokens[k].c_str()));
307 unsigned char g =
308 static_cast<unsigned char>(atoi(tokens[k + 1].c_str()));
309 unsigned char b =
310 static_cast<unsigned char>(atoi(tokens[k + 2].c_str()));
311
312 vcg::Color4b color(r, g, b, 255);
313 (*v_iter).C().Import(color);
314 }
315 else
316 {
317 // floats
318 float r = static_cast<float>(atof(tokens[k].c_str()));
319 float g = static_cast<float>(atof(tokens[k + 1].c_str()));
320 float b = static_cast<float>(atof(tokens[k + 2].c_str()));
321
322 vcg::Color4f color(r, g, b, 1.0);
323 (*v_iter).C().Import(color);
324 }
325 }
326 else if (nb_color_components == 4)
327 {
328 // read RGBA color
329 if (tokens[k].find(".") == size_t(-1))
330 {
331 // integers
332 unsigned char r =
333 static_cast<unsigned char>(atoi(tokens[k].c_str()));
334 unsigned char g =
335 static_cast<unsigned char>(atoi(tokens[k + 1].c_str()));
336 unsigned char b =
337 static_cast<unsigned char>(atoi(tokens[k + 2].c_str()));
338 unsigned char a =
339 static_cast<unsigned char>(atoi(tokens[k + 3].c_str()));
340
341 Color4b color(r, g, b, a);
342 (*v_iter).C().Import(color);
343 }
344 else
345 {
346 // floats
347 float r = static_cast<float>(atof(tokens[k].c_str()));
348 float g = static_cast<float>(atof(tokens[k + 1].c_str()));
349 float b = static_cast<float>(atof(tokens[k + 2].c_str()));
350 float a = static_cast<float>(atof(tokens[k + 3].c_str()));
351
352 vcg::Color4f color(r, g, b, a);
353 (*v_iter).C().Import(color);
354 }
355 }
356 }
357
358 k += nb_color_components;
359 }
360
361 if (isTexCoordDefined)
362 {
363 for (unsigned int j = 0; j < 2; j++)
364 {
365 // Go to next line when needed
366 if (k == tokens.size()) // if EOL
367 {
368 TokenizeNextLine(stream, tokens);
369 if (tokens.size() == 0) // if EOF
370 return InvalidFile;
371 k = 0;
372 }
373
374 std::string str = tokens[k];
375 k++;
376
377 // Store texture coordinates
378 if (tri::HasPerWedgeTexCoord(mesh))
379 {
380 //...TODO...
381 }
382 }
383 }
384 } // for i=...
385
386 // READ FACES
387 //////////////////////////////////////////////////////
388 if (FaceType::HasPolyInfo())
389 {
390 for (unsigned int f = 0; f < nFaces; f++)
391 {
392 if (cb && (f % 1000) == 0) cb(50 + f * 50 / nFaces, "Face Loading");
393 TokenizeNextLine(stream, tokens);
394 int vert_per_face = atoi(tokens[0].c_str());
395 std::vector<int> vInd(vert_per_face);
396 k = 1;
397 for (int j = 0; j < vert_per_face; j++)
398 {
399 if (k == tokens.size()) // if EOL // Go to next line when needed
400 {
401 TokenizeNextLine(stream, tokens);
402 if (tokens.size() == 0) return InvalidFile; // if EOF
403 k = 0;
404 }
405 vInd[j] = atoi(tokens[k].c_str());
406 k++;
407 }
408 if (vert_per_face == 3)
409 Allocator<MESH_TYPE>::AddFace(mesh, &mesh.vert[vInd[0]], &mesh.vert[vInd[1]], &mesh.vert[vInd[2]]);
410
411 if (vert_per_face == 4)
412 Allocator<MESH_TYPE>::AddQuadFace(mesh, &mesh.vert[vInd[0]], &mesh.vert[vInd[1]], &mesh.vert[vInd[2]], &mesh.vert[vInd[3]]);
413
414 }
415 }
416 else // Standard Triangular Mesh Loading
417 {
418 // Allocator<MESH_TYPE>::AddFaces(mesh, nFaces);
419 // unsigned int f0 = 0;
420
421
422
423 // Initial call to the QuadTriangulate with an empty vector to just reset the static set of existing diagonals
424 std::vector<VertexPointer> qtmp;
425 BitQuad<MESH_TYPE>::QuadTriangulate(qtmp);
426
427 for (unsigned int ff = 0; ff < nFaces; ff++)
428 {
429 if (stream.fail())
430 return InvalidFile;
431
432 if (cb && (ff % 1000) == 0)
433 cb(50 + ff * 50 / nFaces, "Face Loading");
434
435 TokenizeNextLine(stream, tokens);
436 int vert_per_face = atoi(tokens[0].c_str());
437 if (vert_per_face < 2)
438 return ErrorDegenerateFace;
439 k = 1;
440 if(tokens.size()==1) {// to handle the case when you have the number of vert is on a different line
441 TokenizeNextLine(stream, tokens, true);
442 if ((tokens.size() + 1) < vert_per_face ) return InvalidFile; // if EOF
443 }
444 if (vert_per_face == 2)
445 {
446 int vInd[2];
447 vInd[0] = atoi(tokens[1].c_str());
448 vInd[1] = atoi(tokens[2].c_str());
449 Allocator<MESH_TYPE>::AddEdge(mesh, vInd[0], vInd[1]);
450 }
451 if (vert_per_face == 3)
452 {
453 int vInd[3];
454 vInd[0] = atoi(tokens[1].c_str());
455 vInd[1] = atoi(tokens[2].c_str());
456 vInd[2] = atoi(tokens[3].c_str());
457 Allocator<MESH_TYPE>::AddFace(mesh, vInd[0], vInd[1], vInd[2]);
458 }
459 if(vert_per_face > 3) // The face must be triangulated
460 {
461 std::vector<int> vertIndices(vert_per_face);
462 std::vector<vcg::Point3f > polygonVect(vert_per_face); // vec of polygon loops used for the triangulation of polygonal face
463 for (int j = 0; j < vert_per_face; j++)
464 {
465 vertIndices[j] = atoi(tokens[j+1].c_str());
466 polygonVect[j].Import<ScalarType>(mesh.vert[vertIndices[j]].P());
467 }
468 if (vert_per_face == 4)
469 { // To well triangulate use the bitquad support function that reorders vertex for a simple fan
470 if (tri::HasPerFaceFlags(mesh)) loadmask |= Mask::IOM_BITPOLYGONAL;
471 std::vector<VertexPointer> q(4);
472 for (int qqi = 0; qqi < 4; ++qqi)
473 q[qqi] = &mesh.vert[vertIndices[qqi]];
474 BitQuad<MESH_TYPE>::QuadTriangulate(q);
475 for (int qqi = 0; qqi < 4; ++qqi)
476 vertIndices[qqi] = q[qqi] - &mesh.vert[0];
477 // build a two face fan
478 Allocator<MESH_TYPE>::AddFace(mesh, vertIndices[0],vertIndices[1],vertIndices[2]);
479 if (tri::HasPerFaceFlags(mesh)) mesh.face.back().SetF(2);
480 Allocator<MESH_TYPE>::AddFace(mesh, vertIndices[0],vertIndices[2],vertIndices[3]);
481 if (tri::HasPerFaceFlags(mesh)) mesh.face.back().SetF(0);
482 }
483 else // standard fan triangulation (we hope the polygon is convex...)
484 {
485 std::vector<int> indexTriangulatedVect;
486 // TessellatePlanarPolygon3(polygonVect,indexTriangulatedVect);
487 std::vector< std::vector<Point3f> > loopVect;
488 loopVect.push_back(polygonVect);
489 #ifdef __gl_h_
490 //qDebug("OK: using opengl tessellation for a polygon of %i vertices",vertexesPerFace);
491 vcg::glu_tesselator::tesselate<vcg::Point3f>(loopVect, indexTriangulatedVect);
492 #else
493 //qDebug("Warning: using fan tessellation for a polygon of %i vertices",vertexesPerFace);
494 tri::io::FanTessellator(loopVect, indexTriangulatedVect);
495 #endif
496 for (size_t j = 0; j < indexTriangulatedVect.size(); j += 3)
497 {
498 Allocator<MESH_TYPE>::AddFace(mesh, indexTriangulatedVect[j], indexTriangulatedVect[j+1], indexTriangulatedVect[j+2]);
499 if (tri::HasPerFaceFlags(mesh)) mesh.face.back().SetF(0);
500 // To correctly set Faux edges we have to clear the faux bit for all the edges that do not correspond to consecutive vertices
501 // Consecutivity is in the space of the index of the polygon.
502 for (int qq = 0; qq < 3; ++qq)
503 {
504 if ((indexTriangulatedVect[j + qq] + 1) % vert_per_face == indexTriangulatedVect[j + (qq + 1) % 3])
505 mesh.face.back().ClearF(qq);
506 else mesh.face.back().SetF(qq);
507 }
508 }
509 }
510 }
511
512 // NOTE: It is assumed that colored face takes exactly one text line
513 // (otherwise it is impossible to parse color information since
514 // color components can vary)
515 size_t color_elements = tokens.size() - vert_per_face - 1;
516 //isColorDefined |= (color_elements>0);
517 //if(isColorDefined) loadmask |= Mask::IOM_FACECOLOR;
518
519 if (color_elements > 0)
520 {
521 loadmask |= Mask::IOM_FACECOLOR;
522
523 if (tri::HasPerFaceColor(mesh))
524 {
525 int triToColor = vert_per_face-2;
526 switch (color_elements)
527 {
528 case 0:
529 {
530 for (int i=0; i< triToColor;++i)
531 mesh.face[mesh.fn - triToColor + i].C().Import(vcg::Color4f(.666f, .666f, .666f, .666f));
532 break;
533 }
534 case 1:
535 {
536 for (int i=0; i<vert_per_face-2;++i)
537 mesh.face[mesh.fn - vert_per_face + i].C().Import(ColorMap(atoi(tokens[vert_per_face + 1].c_str())));
538 break;
539 }
540 case 3:
541 {
542 if (tokens[vert_per_face + 1].find('.') == std::string::npos) // if there is a float there is a dot
543 {
544 Color4b cc(Color4b::White);
545 cc[0] = (unsigned char)atoi(tokens[vert_per_face + 1].c_str());
546 cc[1] = (unsigned char)atoi(tokens[vert_per_face + 2].c_str());
547 cc[2] = (unsigned char)atoi(tokens[vert_per_face + 3].c_str());
548 for (int i=0; i<triToColor;++i)
549 mesh.face[mesh.fn - triToColor + i].C() = cc;
550 }
551 else
552 {
553 float color[3];
554 color[0] = (float)atof(tokens[vert_per_face + 1].c_str());
555 color[1] = (float)atof(tokens[vert_per_face + 2].c_str());
556 color[2] = (float)atof(tokens[vert_per_face + 3].c_str());
557 for (int i=0; i<triToColor;++i)
558 mesh.face[mesh.fn - triToColor + i].C().Import(vcg::Color4f(color[0], color[1], color[2], 1.0f));
559 }
560 break;
561 }
562 case 4:
563 {
564 if (tokens[vert_per_face + 1].find('.') == std::string::npos) // if it is a float there is a dot
565 {
566 Color4b cc;
567 cc[0] = (unsigned char)atoi(tokens[vert_per_face + 1].c_str());
568 cc[1] = (unsigned char)atoi(tokens[vert_per_face + 2].c_str());
569 cc[2] = (unsigned char)atoi(tokens[vert_per_face + 3].c_str());
570 cc[3] = (unsigned char)atoi(tokens[vert_per_face + 4].c_str());
571 for (int i=0; i<triToColor;++i)
572 mesh.face[mesh.fn - triToColor + i].C() = cc;
573 }
574 else
575 {
576 float color[4];
577 color[0] = float(atof(tokens[vert_per_face + 1].c_str()));
578 color[1] = float(atof(tokens[vert_per_face + 2].c_str()));
579 color[2] = float(atof(tokens[vert_per_face + 3].c_str()));
580 color[3] = float(atof(tokens[vert_per_face + 4].c_str()));
581 for (int i=0; i<triToColor;++i)
582 mesh.face[mesh.fn - triToColor + i].C().Import(vcg::Color4f(color[0], color[1], color[2], color[3]));
583 }
584 break;
585 }
586 } //end switch
587 }
588 } // end if (isColorDefined)
589 } // end of for f=...
590 }
591 return NoError;
592
593 } // end Open
594
595 protected:
596
597 /*!
598 * Read the next valid line and parses it into "tokens", allowing the tokens to be read one at a time.
599 * \param stream The object providing the input stream
600 * \param tokens the vector that will contain the tokens
601 * \param appendTokens if true the tokens are appended to the token vector. Default the vector is cleared
602 */
603 inline static void TokenizeNextLine(std::istream &stream, std::vector< std::string > &tokens, bool appendTokens=false)
604 {
605 std::string line;
606 do
607 std::getline(stream, line, '\n');
608 while ((line[0] == '#' || line.length() == 0 || line[0] == '\r') && (!stream.eof()));
609
610 size_t from = 0;
611 size_t to = 0;
612 size_t length = line.size();
613 if(!appendTokens) tokens.clear();
614 do
615 {
616 while (from != length && (line[from] == ' ' || line[from] == '\t' || line[from] == '\r'))
617 from++;
618 if (from != length)
619 {
620 to = from + 1;
621 while (to != length && (((line[to] != ' ') && (line[to] != '\t')) || (line[to] == '\r')))
622 to++;
623 tokens.push_back(line.substr(from, to - from).c_str());
624 from = to;
625 }
626 } while (from < length);
627 } // end Tokenize
628
629 /*!
630 * Provide the int->color mapping, according to the Geomview's `cmap.fmap' file.
631 * \param i the color index
632 * \return the corresponding <CODE>vcg::Color4f</CODE> color
633 */
634 static const vcg::Color4f ColorMap(int i)
635 {
636 static const float colorMap[148][4] =
637 {
638 { 1.0f, 1.0f, 1.0f, 1.0f },
639 { 1.0f, 1.0f, 1.0f, 1.0f },
640 { 1.0f, 1.0f, 1.0f, 1.0f },
641 { 1.0f, 1.0f, 1.0f, 1.0f },
642 { 1.0f, 1.0f, 1.0f, 1.0f },
643 { 1.0f, 1.0f, 1.0f, 1.0f },
644 { 0.7f, 0.7f, 0.7f, 0.7f },
645 { 0.2f, 0.2f, 0.2f, 0.2f },
646 { 0.9f, 0.9f, 0.9f, 0.9f },
647 { 0.1f, 0.1f, 0.1f, 0.1f },
648 { 0.1f, 0.1f, 0.1f, 0.1f },
649 { 0.8f, 0.8f, 0.8f, 0.8f },
650 { 0.7f, 0.7f, 0.7f, 0.7f },
651 { 0.7f, 0.7f, 0.7f, 0.7f },
652 { 0.0f, 0.0f, 0.0f, 0.0f },
653 { 0.9f, 0.9f, 0.9f, 0.9f },
654 { 0.2f, 0.2f, 0.2f, 0.2f },
655 { 0.0f, 0.0f, 0.0f, 0.0f },
656 { 0.75f, 0.75f, 0.75f, 0.75f },
657 { 0.8f, 0.8f, 0.8f, 0.8f },
658 { 0.8f, 0.8f, 0.8f, 0.8f },
659 { 0.0f, 0.0f, 0.0f, 0.0f },
660 { 0.0f, 0.0f, 0.0f, 0.0f },
661 { 0.0f, 0.0f, 0.0f, 0.0f },
662 { 0.0f, 0.0f, 0.0f, 0.0f },
663 { 0.4f, 0.4f, 0.4f, 0.4f },
664 { 0.4f, 0.4f, 0.4f, 0.4f },
665 { 0.8f, 0.8f, 0.8f, 0.8f },
666 { 0.8f, 0.8f, 0.8f, 0.8f },
667 { 0.7f, 0.7f, 0.7f, 0.7f },
668 { 0.7f, 0.7f, 0.7f, 0.7f },
669 { 0.7f, 0.7f, 0.7f, 0.7f },
670 { 0.7f, 0.7f, 0.7f, 0.7f },
671 { 0.0f, 0.0f, 0.0f, 0.0f },
672 { 0.9f, 0.9f, 0.9f, 0.9f },
673 { 0.0f, 0.0f, 0.0f, 0.0f },
674 { 0.0f, 0.0f, 0.0f, 0.0f },
675 { 0.75f, 0.75f, 0.75f, 0.75f },
676 { 0.8f, 0.8f, 0.8f, 0.8f },
677 { 0.4f, 0.4f, 0.4f, 0.4f },
678 { 0.0f, 0.0f, 0.0f, 0.0f },
679 { 0.0f, 0.0f, 0.0f, 0.0f },
680 { 0.4f, 0.4f, 0.4f, 0.4f },
681 { 0.8f, 0.8f, 0.8f, 0.8f },
682 { 0.7f, 0.7f, 0.7f, 0.7f },
683 { 0.7f, 0.7f, 0.7f, 0.7f },
684 { 0.0f, 0.0f, 0.0f, 0.0f },
685 { 0.9f, 0.9f, 0.9f, 0.9f },
686 { 0.0f, 0.0f, 0.0f, 0.0f },
687 { 0.0f, 0.0f, 0.0f, 0.0f },
688 { 0.75f, 0.75f, 0.75f, 0.75f },
689 { 0.8f, 0.8f, 0.8f, 0.8f },
690 { 0.4f, 0.4f, 0.4f, 0.4f },
691 { 0.0f, 0.0f, 0.0f, 0.0f },
692 { 0.0f, 0.0f, 0.0f, 0.0f },
693 { 0.4f, 0.4f, 0.4f, 0.4f },
694 { 0.8f, 0.8f, 0.8f, 0.8f },
695 { 0.7f, 0.7f, 0.7f, 0.7f },
696 { 0.7f, 0.7f, 0.7f, 0.7f },
697 { 0.0f, 0.0f, 0.0f, 0.0f },
698 { 0.9f, 0.9f, 0.9f, 0.9f },
699 { 0.0f, 0.0f, 0.0f, 0.0f },
700 { 0.0f, 0.0f, 0.0f, 0.0f },
701 { 0.75f, 0.75f, 0.75f, 0.75f },
702 { 0.8f, 0.8f, 0.8f, 0.8f },
703 { 0.4f, 0.4f, 0.4f, 0.4f },
704 { 0.0f, 0.0f, 0.0f, 0.0f },
705 { 0.0f, 0.0f, 0.0f, 0.0f },
706 { 0.4f, 0.4f, 0.4f, 0.4f },
707 { 0.8f, 0.8f, 0.8f, 0.8f },
708 { 1.0f, 1.0f, 1.0f, 1.0f },
709 { 1.0f, 1.0f, 1.0f, 1.0f },
710 { 1.0f, 1.0f, 1.0f, 1.0f },
711 { 1.0f, 1.0f, 1.0f, 1.0f },
712 { 1.0f, 1.0f, 1.0f, 1.0f },
713 { 1.0f, 1.0f, 1.0f, 1.0f },
714 { 0.05f, 0.05f, 0.05f, 0.05f },
715 { 0.7f, 0.7f, 0.7f, 0.7f },
716 { 0.2f, 0.2f, 0.2f, 0.2f },
717 { 0.9f, 0.9f, 0.9f, 0.9f },
718 { 0.0f, 0.0f, 0.0f, 0.0f },
719 { 0.1f, 0.1f, 0.1f, 0.1f },
720 { 0.8f, 0.8f, 0.8f, 0.8f },
721 { 0.7f, 0.7f, 0.7f, 0.7f },
722 { 0.7f, 0.7f, 0.7f, 0.7f },
723 { 0.7f, 0.7f, 0.7f, 0.7f },
724 { 0.7f, 0.7f, 0.7f, 0.7f },
725 { 0.0f, 0.0f, 0.0f, 0.0f },
726 { 0.0f, 0.0f, 0.0f, 0.0f },
727 { 0.9f, 0.9f, 0.9f, 0.9f },
728 { 0.9f, 0.9f, 0.9f, 0.9f },
729 { 0.0f, 0.0f, 0.0f, 0.0f },
730 { 0.0f, 0.0f, 0.0f, 0.0f },
731 { 0.0f, 0.0f, 0.0f, 0.0f },
732 { 0.0f, 0.0f, 0.0f, 0.0f },
733 { 0.75f, 0.75f, 0.75f, 0.75f },
734 { 0.75f, 0.75f, 0.75f, 0.75f },
735 { 0.8f, 0.8f, 0.8f, 0.8f },
736 { 0.8f, 0.8f, 0.8f, 0.8f },
737 { 0.0f, 0.0f, 0.0f, 0.0f },
738 { 0.0f, 0.0f, 0.0f, 0.0f },
739 { 0.0f, 0.0f, 0.0f, 0.0f },
740 { 0.0f, 0.0f, 0.0f, 0.0f },
741 { 0.4f, 0.4f, 0.4f, 0.4f },
742 { 0.4f, 0.4f, 0.4f, 0.4f },
743 { 0.8f, 0.8f, 0.8f, 0.8f },
744 { 0.8f, 0.8f, 0.8f, 0.8f },
745 { 0.7f, 0.7f, 0.7f, 0.7f },
746 { 0.7f, 0.7f, 0.7f, 0.7f },
747 { 0.7f, 0.7f, 0.7f, 0.7f },
748 { 0.7f, 0.7f, 0.7f, 0.7f },
749 { 0.0f, 0.0f, 0.0f, 0.0f },
750 { 0.9f, 0.9f, 0.9f, 0.9f },
751 { 0.0f, 0.0f, 0.0f, 0.0f },
752 { 0.0f, 0.0f, 0.0f, 0.0f },
753 { 0.75f, 0.75f, 0.75f, 0.75f },
754 { 0.8f, 0.8f, 0.8f, 0.8f },
755 { 0.4f, 0.4f, 0.4f, 0.4f },
756 { 0.0f, 0.0f, 0.0f, 0.0f },
757 { 0.0f, 0.0f, 0.0f, 0.0f },
758 { 0.4f, 0.4f, 0.4f, 0.4f },
759 { 0.8f, 0.8f, 0.8f, 0.8f },
760 { 0.7f, 0.7f, 0.7f, 0.7f },
761 { 0.7f, 0.7f, 0.7f, 0.7f },
762 { 0.0f, 0.0f, 0.0f, 0.0f },
763 { 0.9f, 0.9f, 0.9f, 0.9f },
764 { 0.0f, 0.0f, 0.0f, 0.0f },
765 { 0.0f, 0.0f, 0.0f, 0.0f },
766 { 0.75f, 0.75f, 0.75f, 0.75f },
767 { 0.8f, 0.8f, 0.8f, 0.8f },
768 { 0.4f, 0.4f, 0.4f, 0.4f },
769 { 0.0f, 0.0f, 0.0f, 0.0f },
770 { 0.0f, 0.0f, 0.0f, 0.0f },
771 { 0.4f, 0.4f, 0.4f, 0.4f },
772 { 0.8f, 0.8f, 0.8f, 0.8f },
773 { 0.7f, 0.7f, 0.7f, 0.7f },
774 { 0.7f, 0.7f, 0.7f, 0.7f },
775 { 0.0f, 0.0f, 0.0f, 0.0f },
776 { 0.9f, 0.9f, 0.9f, 0.9f },
777 { 0.0f, 0.0f, 0.0f, 0.0f },
778 { 0.0f, 0.0f, 0.0f, 0.0f },
779 { 0.75f, 0.75f, 0.75f, 0.75f },
780 { 0.8f, 0.8f, 0.8f, 0.8f },
781 { 0.4f, 0.4f, 0.4f, 0.4f },
782 { 0.0f, 0.0f, 0.0f, 0.0f },
783 { 0.0f, 0.0f, 0.0f, 0.0f },
784 { 0.4f, 0.4f, 0.4f, 0.4f },
785 { 0.8f, 0.8f, 0.8f, 0.8f }
786 };
787 return Color4f(colorMap[i][0], colorMap[i][1], colorMap[i][2], colorMap[i][3]);
788 }
789 };
790 // /*! @} */
791 } //namespace io
792 }//namespace tri
793 } // namespace vcg
794
795 #endif //__VCGLIB_IMPORT_OFF