Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
ObjParser Namespace Reference

Classes

struct  ObjData
 
struct  ObjGroup
 
struct  ObjObject
 
struct  ObjSmoothingGroup
 
struct  ObjUseMtl
 
struct  ObjVertex
 

Functions

static bool obj_parseline (const char *line, ObjData &data)
 
bool objparse (const char *path, ObjData &data)
 
bool objparse (std::istream &stream, ObjData &data)
 
template<typename T >
bool savevector (FILE *pFile, const std::vector< T > &v)
 
bool savevector (FILE *pFile, const std::vector< std::string > &v)
 
template<typename T >
bool savevectornameidx (FILE *pFile, const std::vector< T > &v)
 
template<typename T >
bool loadvector (FILE *pFile, std::vector< T > &v)
 
bool loadvector (FILE *pFile, std::vector< std::string > &v)
 
template<typename T >
bool loadvectornameidx (FILE *pFile, std::vector< T > &v)
 
bool objbinsave (const char *path, const ObjData &data)
 
bool objbinload (const char *path, ObjData &data)
 
template<typename T >
bool vectorequal (const std::vector< T > &v1, const std::vector< T > &v2)
 
bool vectorequal (const std::vector< std::string > &v1, const std::vector< std::string > &v2)
 
bool objequal (const ObjData &data1, const ObjData &data2)
 
bool operator== (const ObjVertex &v1, const ObjVertex &v2)
 
bool operator== (const ObjUseMtl &v1, const ObjUseMtl &v2)
 
bool operator== (const ObjObject &v1, const ObjObject &v2)
 
bool operator== (const ObjGroup &v1, const ObjGroup &v2)
 
bool operator== (const ObjSmoothingGroup &v1, const ObjSmoothingGroup &v2)
 

Class Documentation

◆ ObjParser::ObjData

struct ObjParser::ObjData
+ Collaboration diagram for ObjParser::ObjData:
Class Members
vector< float > coordinates
vector< ObjGroup > groups
vector< string > mtllibs
vector< float > normals
vector< ObjObject > objects
vector< float > parameters
vector< ObjSmoothingGroup > smoothingGroups
vector< float > textureCoordinates
vector< ObjUseMtl > usemtls
int version
vector< ObjVertex > vertices

◆ ObjParser::ObjGroup

struct ObjParser::ObjGroup
+ Collaboration diagram for ObjParser::ObjGroup:
Class Members
string name
int vertexIdxFirst

◆ ObjParser::ObjObject

struct ObjParser::ObjObject
+ Collaboration diagram for ObjParser::ObjObject:
Class Members
string name
int vertexIdxFirst

◆ ObjParser::ObjSmoothingGroup

struct ObjParser::ObjSmoothingGroup
Class Members
int smoothingGroupID
int vertexIdxFirst

◆ ObjParser::ObjUseMtl

struct ObjParser::ObjUseMtl
+ Collaboration diagram for ObjParser::ObjUseMtl:
Class Members
string name
int vertexIdxFirst

◆ ObjParser::ObjVertex

struct ObjParser::ObjVertex
Class Members
int coordIdx
int normalIdx
int textureCoordIdx

Function Documentation

◆ loadvector() [1/2]

bool ObjParser::loadvector ( FILE *  pFile,
std::vector< std::string > &  v 
)
458{
459 v.clear();
460 size_t cnt = 0;
461 if (::fread(&cnt, sizeof(cnt), 1, pFile) != 1)
462 return false;
463 v.reserve(cnt);
464 for (size_t i = 0; i < cnt; ++ i) {
465 size_t len = 0;
466 if (::fread(&len, sizeof(len), 1, pFile) != 1)
467 return false;
468 std::string s(" ", len);
469 if (::fread(s.data(), 1, len, pFile) != len)
470 return false;
471 v.push_back(std::move(s));
472 }
473 return true;
474}

◆ loadvector() [2/2]

template<typename T >
bool ObjParser::loadvector ( FILE *  pFile,
std::vector< T > &  v 
)
443{
444 v.clear();
445 size_t cnt = 0;
446 if (::fread(&cnt, sizeof(cnt), 1, pFile) != 1)
447 return false;
448 //FIXME sizeof(T) works for data types leaving no gaps in the allocated vector because of alignment of the T type.
449 if (cnt != 0) {
450 v.assign(cnt, T());
451 if (::fread(&v.front(), sizeof(T), cnt, pFile) != cnt)
452 return false;
453 }
454 return true;
455}

Referenced by objbinload().

+ Here is the caller graph for this function:

◆ loadvectornameidx()

template<typename T >
bool ObjParser::loadvectornameidx ( FILE *  pFile,
std::vector< T > &  v 
)
478{
479 v.clear();
480 size_t cnt = 0;
481 if (::fread(&cnt, sizeof(cnt), 1, pFile) != 1)
482 return false;
483 v.assign(cnt, T());
484 for (size_t i = 0; i < cnt; ++ i) {
485 if (::fread(&v[i].vertexIdxFirst, sizeof(int), 1, pFile) != 1)
486 return false;
487 size_t len = 0;
488 if (::fread(&len, sizeof(len), 1, pFile) != 1)
489 return false;
490 v[i].name.assign(" ", len);
491 if (::fread(v[i].name.data(), 1, len, pFile) != len)
492 return false;
493 }
494 return true;
495}

Referenced by objbinload().

+ Here is the caller graph for this function:

◆ obj_parseline()

static bool ObjParser::obj_parseline ( const char *  line,
ObjData data 
)
static
14{
15#define EATWS() while (*line == ' ' || *line == '\t') ++ line
16
17 if (*line == 0)
18 return true;
19
21
22 // Ignore whitespaces at the beginning of the line.
23 //FIXME is this a good idea?
24 EATWS();
25
26 char c1 = *line ++;
27 switch (c1) {
28 case '#':
29 // Comment, ignore the rest of the line.
30 break;
31 case 'v':
32 {
33 // Parse vertex geometry (position, normal, texture coordinates)
34 char c2 = *line ++;
35 switch (c2) {
36 case 't':
37 {
38 // vt - vertex texture parameter
39 // u v [w], w == 0 (or w == 1)
40 char c2 = *line ++;
41 if (c2 != ' ' && c2 != '\t')
42 return false;
43 EATWS();
44 char *endptr = 0;
45 double u = strtod(line, &endptr);
46 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t'))
47 return false;
48 line = endptr;
49 EATWS();
50 double v = 0;
51 if (*line != 0) {
52 v = strtod(line, &endptr);
53 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
54 return false;
55 line = endptr;
56 EATWS();
57 }
58 double w = 0;
59 if (*line != 0) {
60 w = strtod(line, &endptr);
61 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
62 return false;
63 line = endptr;
64 EATWS();
65 }
66 if (*line != 0)
67 return false;
68 data.textureCoordinates.push_back((float)u);
69 data.textureCoordinates.push_back((float)v);
70 data.textureCoordinates.push_back((float)w);
71 break;
72 }
73 case 'n':
74 {
75 // vn - vertex normal
76 // x y z
77 char c2 = *line ++;
78 if (c2 != ' ' && c2 != '\t')
79 return false;
80 EATWS();
81 char *endptr = 0;
82 double x = strtod(line, &endptr);
83 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t'))
84 return false;
85 line = endptr;
86 EATWS();
87 double y = strtod(line, &endptr);
88 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t'))
89 return false;
90 line = endptr;
91 EATWS();
92 double z = strtod(line, &endptr);
93 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
94 return false;
95 line = endptr;
96 EATWS();
97 if (*line != 0)
98 return false;
99 data.normals.push_back((float)x);
100 data.normals.push_back((float)y);
101 data.normals.push_back((float)z);
102 break;
103 }
104 case 'p':
105 {
106 // vp - vertex parameter
107 char c2 = *line ++;
108 if (c2 != ' ' && c2 != '\t')
109 return false;
110 EATWS();
111 char *endptr = 0;
112 double u = strtod(line, &endptr);
113 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
114 return false;
115 line = endptr;
116 EATWS();
117 double v = strtod(line, &endptr);
118 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
119 return false;
120 line = endptr;
121 EATWS();
122 double w = 0;
123 if (*line != 0) {
124 w = strtod(line, &endptr);
125 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
126 return false;
127 line = endptr;
128 EATWS();
129 }
130 if (*line != 0)
131 return false;
132 data.parameters.push_back((float)u);
133 data.parameters.push_back((float)v);
134 data.parameters.push_back((float)w);
135 break;
136 }
137 default:
138 {
139 // v - vertex geometry
140 if (c2 != ' ' && c2 != '\t')
141 return false;
142 EATWS();
143 char *endptr = 0;
144 double x = strtod(line, &endptr);
145 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t'))
146 return false;
147 line = endptr;
148 EATWS();
149 double y = strtod(line, &endptr);
150 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t'))
151 return false;
152 line = endptr;
153 EATWS();
154 double z = strtod(line, &endptr);
155 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
156 return false;
157 line = endptr;
158 EATWS();
159 double w = 1.0;
160 if (*line != 0) {
161 w = strtod(line, &endptr);
162 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
163 return false;
164 line = endptr;
165 EATWS();
166 }
167 // the following check is commented out because there may be obj files containing extra data, as those generated by Meshlab,
168 // see https://dev.prusa3d.com/browse/SPE-1019 for an example,
169 // and this would lead to a crash because no vertex would be stored
170// if (*line != 0)
171// return false;
172 data.coordinates.push_back((float)x);
173 data.coordinates.push_back((float)y);
174 data.coordinates.push_back((float)z);
175 data.coordinates.push_back((float)w);
176 break;
177 }
178 }
179 break;
180 }
181 case 'f':
182 {
183 // face
184 EATWS();
185 if (*line == 0)
186 return false;
187
188 // current vertex to be parsed
189 ObjVertex vertex;
190 char *endptr = 0;
191 while (*line != 0) {
192 // Parse a single vertex reference.
193 vertex.coordIdx = 0;
194 vertex.normalIdx = 0;
195 vertex.textureCoordIdx = 0;
196 vertex.coordIdx = strtol(line, &endptr, 10);
197 // Coordinate has to be defined
198 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != '/' && *endptr != 0))
199 return false;
200 line = endptr;
201 if (*line == '/') {
202 ++ line;
203 // Texture coordinate index may be missing after a 1st slash, but then the normal index has to be present.
204 if (*line != '/') {
205 // Parse the texture coordinate index.
206 vertex.textureCoordIdx = strtol(line, &endptr, 10);
207 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != '/' && *endptr != 0))
208 return false;
209 line = endptr;
210 }
211 if (*line == '/') {
212 // Parse normal index.
213 ++ line;
214 vertex.normalIdx = strtol(line, &endptr, 10);
215 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
216 return false;
217 line = endptr;
218 }
219 }
220 if (vertex.coordIdx < 0)
221 vertex.coordIdx += (int)data.coordinates.size() / 4;
222 else
223 -- vertex.coordIdx;
224 if (vertex.normalIdx < 0)
225 vertex.normalIdx += (int)data.normals.size() / 3;
226 else
227 -- vertex.normalIdx;
228 if (vertex.textureCoordIdx < 0)
229 vertex.textureCoordIdx += (int)data.textureCoordinates.size() / 3;
230 else
231 -- vertex.textureCoordIdx;
232 data.vertices.push_back(vertex);
233 EATWS();
234 }
235 vertex.coordIdx = -1;
236 vertex.normalIdx = -1;
237 vertex.textureCoordIdx = -1;
238 data.vertices.push_back(vertex);
239 break;
240 }
241 case 'm':
242 {
243 if (*(line ++) != 't' ||
244 *(line ++) != 'l' ||
245 *(line ++) != 'l' ||
246 *(line ++) != 'i' ||
247 *(line ++) != 'b')
248 return false;
249 // mtllib [external .mtl file name]
250 // printf("mtllib %s\r\n", line);
251 EATWS();
252 data.mtllibs.push_back(std::string(line));
253 break;
254 }
255 case 'u':
256 {
257 if (*(line ++) != 's' ||
258 *(line ++) != 'e' ||
259 *(line ++) != 'm' ||
260 *(line ++) != 't' ||
261 *(line ++) != 'l')
262 return false;
263 // usemtl [material name]
264 // printf("usemtl %s\r\n", line);
265 EATWS();
266 ObjUseMtl usemtl;
267 usemtl.vertexIdxFirst = (int)data.vertices.size();
268 usemtl.name = line;
269 data.usemtls.push_back(usemtl);
270 break;
271 }
272 case 'o':
273 {
274 // o [object name]
275 EATWS();
276 while (*line != ' ' && *line != '\t' && *line != 0)
277 ++ line;
278 // copy name to line.
279 EATWS();
280 if (*line != 0)
281 return false;
282 ObjObject object;
283 object.vertexIdxFirst = (int)data.vertices.size();
284 object.name = line;
285 data.objects.push_back(object);
286 break;
287 }
288 case 'g':
289 {
290 // g [group name]
291 // printf("group %s\r\n", line);
292 ObjGroup group;
293 group.vertexIdxFirst = (int)data.vertices.size();
294 group.name = line;
295 data.groups.push_back(group);
296 break;
297 }
298 case 's':
299 {
300 // s 1 / off
301 char c2 = *line ++;
302 if (c2 != ' ' && c2 != '\t')
303 return false;
304 EATWS();
305 char *endptr = 0;
306 long g = strtol(line, &endptr, 10);
307 if (endptr == 0 || (*endptr != ' ' && *endptr != '\t' && *endptr != 0))
308 return false;
309 line = endptr;
310 EATWS();
311 if (*line != 0)
312 return false;
313 ObjSmoothingGroup group;
314 group.vertexIdxFirst = (int)data.vertices.size();
315 group.smoothingGroupID = g;
316 data.smoothingGroups.push_back(group);
317 break;
318 }
319 default:
320 BOOST_LOG_TRIVIAL(error) << "ObjParser: Unknown command: " << c1;
321 break;
322 }
323
324 return true;
325}
const Scalar & y
Definition MathFunctions.h:552
bool is_decimal_separator_point()
Definition LocalesUtils.cpp:47
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297
TPoint< S > & vertex(S &sh, unsigned long idx, const PolygonTag &)
Definition geometry_traits.hpp:1180
#define EATWS()
static char error[256]
Definition tga.cpp:50

References EATWS, error, Slic3r::is_decimal_separator_point(), ObjParser::ObjUseMtl::name, ObjParser::ObjGroup::name, ObjParser::ObjSmoothingGroup::smoothingGroupID, ObjParser::ObjUseMtl::vertexIdxFirst, ObjParser::ObjObject::vertexIdxFirst, ObjParser::ObjGroup::vertexIdxFirst, and ObjParser::ObjSmoothingGroup::vertexIdxFirst.

Referenced by objparse(), and objparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ objbinload()

bool ObjParser::objbinload ( const char *  path,
ObjData data 
)
523{
524 FILE *pFile = boost::nowide::fopen(path, "rb");
525 if (pFile == 0)
526 return false;
527
528 data.version = 0;
529 if (::fread(&data.version, sizeof(data.version), 1, pFile) != 1)
530 return false;
531 if (data.version != 1)
532 return false;
533
534 bool result =
535 loadvector(pFile, data.coordinates) &&
536 loadvector(pFile, data.textureCoordinates) &&
537 loadvector(pFile, data.normals) &&
538 loadvector(pFile, data.parameters) &&
539 loadvector(pFile, data.mtllibs) &&
540 loadvectornameidx(pFile, data.usemtls) &&
541 loadvectornameidx(pFile, data.objects) &&
542 loadvectornameidx(pFile, data.groups) &&
543 loadvector(pFile, data.smoothingGroups) &&
544 loadvector(pFile, data.vertices);
545
546 ::fclose(pFile);
547 return result;
548}
bool loadvectornameidx(FILE *pFile, std::vector< T > &v)
Definition objparser.cpp:477
bool loadvector(FILE *pFile, std::vector< T > &v)
Definition objparser.cpp:442

References loadvector(), and loadvectornameidx().

+ Here is the call graph for this function:

◆ objbinsave()

bool ObjParser::objbinsave ( const char *  path,
const ObjData data 
)
498{
499 FILE *pFile = boost::nowide::fopen(path, "wb");
500 if (pFile == 0)
501 return false;
502
503 size_t version = 1;
504 ::fwrite(&version, 1, sizeof(version), pFile);
505
506 bool result =
507 savevector(pFile, data.coordinates) &&
508 savevector(pFile, data.textureCoordinates) &&
509 savevector(pFile, data.normals) &&
510 savevector(pFile, data.parameters) &&
511 savevector(pFile, data.mtllibs) &&
512 savevectornameidx(pFile, data.usemtls) &&
513 savevectornameidx(pFile, data.objects) &&
514 savevectornameidx(pFile, data.groups) &&
515 savevector(pFile, data.smoothingGroups) &&
516 savevector(pFile, data.vertices);
517
518 ::fclose(pFile);
519 return result;
520}
char * version
Definition main.c:59
bool savevector(FILE *pFile, const std::vector< T > &v)
Definition objparser.cpp:405
bool savevectornameidx(FILE *pFile, const std::vector< T > &v)
Definition objparser.cpp:428

References savevector(), savevectornameidx(), and version.

+ Here is the call graph for this function:

◆ objequal()

bool ObjParser::objequal ( const ObjData data1,
const ObjData data2 
)
572{
573 //FIXME ignore version number
574 // version;
575
576 return
577 vectorequal(data1.coordinates, data2.coordinates) &&
579 vectorequal(data1.normals, data2.normals) &&
580 vectorequal(data1.parameters, data2.parameters) &&
581 vectorequal(data1.mtllibs, data2.mtllibs) &&
582 vectorequal(data1.usemtls, data2.usemtls) &&
583 vectorequal(data1.objects, data2.objects) &&
584 vectorequal(data1.groups, data2.groups) &&
585 vectorequal(data1.vertices, data2.vertices);
586}
std::vector< float > normals
Definition objparser.hpp:86
std::vector< ObjGroup > groups
Definition objparser.hpp:93
std::vector< ObjVertex > vertices
Definition objparser.hpp:97
std::vector< float > parameters
Definition objparser.hpp:88
std::vector< ObjUseMtl > usemtls
Definition objparser.hpp:91
std::vector< float > coordinates
Definition objparser.hpp:82
std::vector< std::string > mtllibs
Definition objparser.hpp:90
bool vectorequal(const std::vector< T > &v1, const std::vector< T > &v2)
Definition objparser.cpp:551
std::vector< float > textureCoordinates
Definition objparser.hpp:84
std::vector< ObjObject > objects
Definition objparser.hpp:92

References ObjParser::ObjData::coordinates, ObjParser::ObjData::groups, ObjParser::ObjData::mtllibs, ObjParser::ObjData::normals, ObjParser::ObjData::objects, ObjParser::ObjData::parameters, ObjParser::ObjData::textureCoordinates, ObjParser::ObjData::usemtls, vectorequal(), and ObjParser::ObjData::vertices.

+ Here is the call graph for this function:

◆ objparse() [1/2]

bool ObjParser::objparse ( const char *  path,
ObjData data 
)
328{
329 Slic3r::CNumericLocalesSetter locales_setter;
330
331 FILE *pFile = boost::nowide::fopen(path, "rt");
332 if (pFile == 0)
333 return false;
334
335 try {
336 char buf[65536 * 2];
337 size_t len = 0;
338 size_t lenPrev = 0;
339 while ((len = ::fread(buf + lenPrev, 1, 65536, pFile)) != 0) {
340 len += lenPrev;
341 size_t lastLine = 0;
342 for (size_t i = 0; i < len; ++ i)
343 if (buf[i] == '\r' || buf[i] == '\n') {
344 buf[i] = 0;
345 char *c = buf + lastLine;
346 while (*c == ' ' || *c == '\t')
347 ++ c;
348 //FIXME check the return value and exit on error?
349 // Will it break parsing of some obj files?
350 obj_parseline(c, data);
351 lastLine = i + 1;
352 }
353 lenPrev = len - lastLine;
354 if (lenPrev > 65536) {
355 BOOST_LOG_TRIVIAL(error) << "ObjParser: Excessive line length";
356 ::fclose(pFile);
357 return false;
358 }
359 memmove(buf, buf + lastLine, lenPrev);
360 }
361 }
362 catch (std::bad_alloc&) {
363 BOOST_LOG_TRIVIAL(error) << "ObjParser: Out of memory";
364 }
365 ::fclose(pFile);
366
367 // printf("vertices: %d\r\n", data.vertices.size() / 4);
368 // printf("coords: %d\r\n", data.coordinates.size());
369 return true;
370}
Definition LocalesUtils.hpp:18
static bool obj_parseline(const char *line, ObjData &data)
Definition objparser.cpp:13

References error, and obj_parseline().

Referenced by Slic3r::load_obj().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ objparse() [2/2]

bool ObjParser::objparse ( std::istream &  stream,
ObjData data 
)
373{
374 Slic3r::CNumericLocalesSetter locales_setter;
375
376 try {
377 char buf[65536 * 2];
378 size_t len = 0;
379 size_t lenPrev = 0;
380 while ((len = size_t(stream.read(buf + lenPrev, 65536).gcount())) != 0) {
381 len += lenPrev;
382 size_t lastLine = 0;
383 for (size_t i = 0; i < len; ++ i)
384 if (buf[i] == '\r' || buf[i] == '\n') {
385 buf[i] = 0;
386 char *c = buf + lastLine;
387 while (*c == ' ' || *c == '\t')
388 ++ c;
389 obj_parseline(c, data);
390 lastLine = i + 1;
391 }
392 lenPrev = len - lastLine;
393 memmove(buf, buf + lastLine, lenPrev);
394 }
395 }
396 catch (std::bad_alloc&) {
397 BOOST_LOG_TRIVIAL(error) << "ObjParser: Out of memory";
398 return false;
399 }
400
401 return true;
402}

References error, and obj_parseline().

+ Here is the call graph for this function:

◆ operator==() [1/5]

bool ObjParser::operator== ( const ObjGroup v1,
const ObjGroup v2 
)
inline
58{
59 return
61 v1.name.compare(v2.name) == 0;
62}
std::string name
Definition objparser.hpp:54
int vertexIdxFirst
Definition objparser.hpp:53

References ObjParser::ObjGroup::name, and ObjParser::ObjGroup::vertexIdxFirst.

◆ operator==() [2/5]

bool ObjParser::operator== ( const ObjObject v1,
const ObjObject v2 
)
inline
45{
46 return
48 v1.name.compare(v2.name) == 0;
49}
int vertexIdxFirst
Definition objparser.hpp:40
std::string name
Definition objparser.hpp:41

References ObjParser::ObjObject::name, and ObjParser::ObjObject::vertexIdxFirst.

◆ operator==() [3/5]

bool ObjParser::operator== ( const ObjSmoothingGroup v1,
const ObjSmoothingGroup v2 
)
inline
71{
72 return
75}
int smoothingGroupID
Definition objparser.hpp:67
int vertexIdxFirst
Definition objparser.hpp:66

References ObjParser::ObjSmoothingGroup::smoothingGroupID, and ObjParser::ObjSmoothingGroup::vertexIdxFirst.

◆ operator==() [4/5]

bool ObjParser::operator== ( const ObjUseMtl v1,
const ObjUseMtl v2 
)
inline
32{
33 return
35 v1.name.compare(v2.name) == 0;
36}
int vertexIdxFirst
Definition objparser.hpp:27
std::string name
Definition objparser.hpp:28

References ObjParser::ObjUseMtl::name, and ObjParser::ObjUseMtl::vertexIdxFirst.

◆ operator==() [5/5]

bool ObjParser::operator== ( const ObjVertex v1,
const ObjVertex v2 
)
inline
18{
19 return
20 v1.coordIdx == v2.coordIdx &&
22 v1.normalIdx == v2.normalIdx;
23}
int coordIdx
Definition objparser.hpp:12
int textureCoordIdx
Definition objparser.hpp:13
int normalIdx
Definition objparser.hpp:14

References ObjParser::ObjVertex::coordIdx, ObjParser::ObjVertex::normalIdx, and ObjParser::ObjVertex::textureCoordIdx.

◆ savevector() [1/2]

bool ObjParser::savevector ( FILE *  pFile,
const std::vector< std::string > &  v 
)
416{
417 size_t cnt = v.size();
418 ::fwrite(&cnt, 1, sizeof(cnt), pFile);
419 for (size_t i = 0; i < cnt; ++ i) {
420 size_t len = v[i].size();
421 ::fwrite(&len, 1, sizeof(cnt), pFile);
422 ::fwrite(v[i].c_str(), 1, len, pFile);
423 }
424 return true;
425}

◆ savevector() [2/2]

template<typename T >
bool ObjParser::savevector ( FILE *  pFile,
const std::vector< T > &  v 
)
406{
407 size_t cnt = v.size();
408 ::fwrite(&cnt, 1, sizeof(cnt), pFile);
409 //FIXME sizeof(T) works for data types leaving no gaps in the allocated vector because of alignment of the T type.
410 if (! v.empty())
411 ::fwrite(&v.front(), 1, sizeof(T) * cnt, pFile);
412 return true;
413}

Referenced by objbinsave().

+ Here is the caller graph for this function:

◆ savevectornameidx()

template<typename T >
bool ObjParser::savevectornameidx ( FILE *  pFile,
const std::vector< T > &  v 
)
429{
430 size_t cnt = v.size();
431 ::fwrite(&cnt, 1, sizeof(cnt), pFile);
432 for (size_t i = 0; i < cnt; ++ i) {
433 ::fwrite(&v[i].vertexIdxFirst, 1, sizeof(int), pFile);
434 size_t len = v[i].name.size();
435 ::fwrite(&len, 1, sizeof(cnt), pFile);
436 ::fwrite(v[i].name.c_str(), 1, len, pFile);
437 }
438 return true;
439}

Referenced by objbinsave().

+ Here is the caller graph for this function:

◆ vectorequal() [1/2]

bool ObjParser::vectorequal ( const std::vector< std::string > &  v1,
const std::vector< std::string > &  v2 
)
562{
563 if (v1.size() != v2.size())
564 return false;
565 for (size_t i = 0; i < v1.size(); ++ i)
566 if (v1[i].compare(v2[i]) != 0)
567 return false;
568 return true;
569}

◆ vectorequal() [2/2]

template<typename T >
bool ObjParser::vectorequal ( const std::vector< T > &  v1,
const std::vector< T > &  v2 
)
552{
553 if (v1.size() != v2.size())
554 return false;
555 for (size_t i = 0; i < v1.size(); ++ i)
556 if (! (v1[i] == v2[i]))
557 return false;
558 return true;
559}

Referenced by objequal().

+ Here is the caller graph for this function: