15 namespace DataStructures {
21 AddPropertyMap< AIFVertex::ptr, Point >(
50 typedef boost::iterator_range< vertex_iterator > vertex_range;
52 typedef boost::iterator_range< edge_iterator > edge_range;
54 typedef boost::iterator_range< face_iterator > face_range;
55 typedef helpers::vertex_container_in_face::const_iterator
57 typedef boost::iterator_range< vertex_face_iterator > vertex_face_range;
63 typedef unsigned long index_type;
65 std::vector< std::vector< coord_type > > points_coords;
66 std::vector< std::vector< coordN_type > > normals_coords;
67 std::vector< std::vector< coordT_type > > texture_coords;
68 std::vector< std::vector< coordC_type > > vertex_color_coords;
69 std::vector< std::vector< coordC_type > > face_color_coords;
70 std::vector< std::vector< index_type > > lines_indices, faces_indices;
71 std::vector< std::vector< index_type > > texture_face_indices;
72 std::vector< std::vector< index_type > > normal_face_indices;
73 std::vector< std::vector< coordC_type > > line_color_coords;
74 std::vector< std::vector< std::vector< double > > > field_attributes ;
75 std::vector< std::string > field_names ;
77 std::string texture_file_name;
79 bool useVertexNormal =
false;
80 bool useVertexColor =
false;
81 bool useVertexTextureCoord =
false;
82 bool useVertexDatafield =
false;
83 bool useFaceDatafield =
false;
85 AddPropertyMap< AIFVertex::ptr, Point >(
90 useVertexNormal =
true;
92 useVertexColor =
true;
94 useVertexTextureCoord =
true;
96 bool useLineColor =
false;
100 bool useFaceColor =
false;
105 useVertexDatafield =
true;
107 useFaceDatafield =
true;
113 long vertexIndex = 0;
114 std::map< helpers::vertex_descriptor, long > indexMap;
119 for(vertex_iterator itV = vRange.begin(); itV != vRange.end(); ++itV)
122 PropHelpers::get_point(
const_cast< Self *
>(&other), *itV);
123 std::vector< coord_type > point;
125 for(
unsigned int i = 0; i < p.size(); ++i)
126 point.push_back(p[i]);
128 points_coords.push_back(point);
130 indexMap[*itV] = vertexIndex;
140 "v:normal", (*itV)->GetIndex());
141 std::vector< coordN_type > normal(vn.cbegin(), vn.cend());
142 normals_coords.push_back(normal);
150 "v:color", (*itV)->GetIndex());
151 std::vector< coordC_type > color(vc.cbegin(), vc.cend());
152 vertex_color_coords.push_back(color);
155 if(useVertexTextureCoord)
160 "v:texcoord", (*itV)->GetIndex());
161 std::vector< coordT_type > vt(uv.cbegin(), uv.cend());
162 texture_coords.push_back(vt);
165 if (useVertexDatafield)
167 auto it_s = dfv_names.begin(), it_se = dfv_names.end();
169 for (; it_s != it_se; ++it_s, ++i)
171 const std::vector< double >&vdata =
173 *it_s, (*itV)->GetIndex());
175 if (itV == vRange.begin())
177 field_names.push_back(*it_s);
178 field_attributes.resize(field_attributes.size() + 1);
181 field_attributes[i].push_back(vdata);
189 for(edge_iterator itE = eRange.begin(); itE != eRange.end(); ++itE)
193 std::vector< index_type > line;
195 line.push_back(indexMap[(*itE)->get_first_vertex()]);
196 line.push_back(indexMap[(*itE)->get_second_vertex()]);
198 lines_indices.push_back(line);
205 "e:color", (*itE)->GetIndex());
206 std::vector< coordC_type > color(vc.cbegin(), vc.cend());
207 line_color_coords.push_back(color);
215 for(face_iterator itF = fRange.begin(); itF != fRange.end(); ++itF)
217 std::vector< index_type >
face;
218 std::vector< index_type > normal_indices;
219 std::vector< index_type > texture_indices;
223 for(vertex_face_iterator itVF = vfRange.begin(); itVF != vfRange.end();
226 face.push_back(indexMap[*itVF]);
230 normal_indices.push_back(indexMap[*itVF]);
231 if(useVertexTextureCoord)
232 texture_indices.push_back(indexMap[*itVF]);
235 faces_indices.push_back(
face);
237 normal_face_indices.push_back(normal_indices);
238 if(useVertexTextureCoord)
239 texture_face_indices.push_back(texture_indices);
246 "f:color", (*itF)->GetIndex());
247 std::vector< coordC_type > color(vc.cbegin(), vc.cend());
248 face_color_coords.push_back(color);
251 if (useFaceDatafield)
253 auto it_s = dff_names.begin(), it_se = dff_names.end();
255 for (; it_s != it_se; ++it_s, ++i)
257 const std::vector< double >&vdata =
259 *it_s, (*itF)->GetIndex());
261 if (itF == fRange.begin())
263 field_names.push_back(*it_s);
264 field_attributes.resize(field_attributes.size() + 1);
266 if (useVertexDatafield && (it_s == dff_names.begin()))
269 field_attributes[i].push_back(vdata);
275 if(vertex_color_coords.size() != points_coords.size())
276 vertex_color_coords.clear();
277 for(
auto &color : vertex_color_coords)
279 if(color.size() < 3 || color.size() > 4)
281 std::cout <<
"AIFMesh copy constructor: found vertex color with size != "
282 "3 and !=4. Disabling vertex color for all vertices."
284 vertex_color_coords.clear();
289 if(face_color_coords.size() != faces_indices.size())
290 face_color_coords.clear();
291 for(
auto &color : face_color_coords)
293 if(color.size() < 3 || color.size() > 4)
295 std::cout <<
"AIFMesh copy constructor: found face color with size != 3 "
296 "and !=4. Disabling face color for all faces."
298 face_color_coords.clear();
303 if(!texture_file_name.empty())
306 auto tfn_pm = this->AddAssocPropertyMap< helpers::ptr_mesh, std::string >(
307 "m:texturefilename");
309 throw std::runtime_error(
310 "Failed to create texture-filename property map.");
312 (*tfn_pm)[
this] = texture_file_name;
314 std::cout <<
"AIF property map for texture-filename created." << std::endl;
318 bool useCornerTextureCoord =
false;
319 bool useFaceNormal =
false;
320 if(!texture_coords.empty())
322 if(texture_coords.size() == points_coords.size())
325 useVertexTextureCoord =
true;
328 this->AddPropertyMap< AIFVertex::ptr, AIFMesh::PointUV >(
"v:texcoord");
329 if(!this->isPropertyMap< AIFVertex::ptr >(
"v:texcoord"))
330 throw std::runtime_error(
331 "Failed to create vertex-texture-coordinate property map.");
333 std::cout <<
"AIF property map for vertex-texture-coordinate created."
336 else if(texture_face_indices.size() == faces_indices.size())
339 useCornerTextureCoord =
true;
345 throw std::runtime_error(
346 "Failed to create halfedge-texture-coordinate property map.");
348 std::cout <<
"AIF property map for halfedge-texture-coordinate created."
353 if(!normals_coords.empty())
358 if(normals_coords.size() == points_coords.size())
360 useVertexNormal =
true;
363 this->AddPropertyMap< AIFVertex::ptr, AIFMesh::Normal >(
"v:normal");
364 if(!this->isPropertyMap< AIFVertex::ptr >(
"v:normal"))
365 throw std::runtime_error(
366 "Failed to create vertex-normal property map.");
368 std::cout <<
"AIF property map for vertex-normal created." << std::endl;
370 else if(!normal_face_indices[0].empty())
373 useFaceNormal =
true;
376 this->AddPropertyMap< AIFFace::ptr, AIFMesh::Normal >(
"f:normal");
377 if(!this->isPropertyMap< AIFFace::ptr >(
"f:normal"))
378 throw std::runtime_error(
"Failed to create face-normal property map.");
380 std::cout <<
"AIF property map for face-normal created." << std::endl;
384 if(!vertex_color_coords.empty())
387 this->AddPropertyMap< AIFVertex::ptr, AIFMesh::Vector >(
"v:color");
388 if(!this->isPropertyMap< AIFVertex::ptr >(
"v:color"))
389 throw std::runtime_error(
"Failed to create vertex-color property map.");
391 std::cout <<
"AIF property map for vertex-color created." << std::endl;
393 if(!face_color_coords.empty())
396 this->AddPropertyMap< AIFFace::ptr, AIFMesh::Vector >(
"f:color");
397 if(!this->isPropertyMap< AIFFace::ptr >(
"f:color"))
398 throw std::runtime_error(
"Failed to create face-color property map.");
400 std::cout <<
"AIF property map for face-color created." << std::endl;
403 if (!field_names.empty())
405 auto it = field_names.begin();
406 auto ite = field_names.end();
407 for (; it != ite; ++it)
409 if (it->find(
"v:datafield:") != std::string::npos)
413 this->AddPropertyMap< AIFVertex::ptr, std::vector<double> >(
415 if (!this->isPropertyMap< AIFVertex::ptr >(*it))
416 throw std::runtime_error(
417 "Failed to create a vertex data field property map.");
419 else if (it->find(
"f:datafield:") != std::string::npos)
423 this->AddPropertyMap< AIFFace::ptr, std::vector<double> >(
425 if (!this->isPropertyMap< AIFFace::ptr >(*it))
426 throw std::runtime_error(
427 "Failed to create a face data field property map.");
435 std::vector< helpers::vertex_type::ptr >
vertices;
436 vertices.reserve(points_coords.size());
438 typedef std::vector< std::vector< coord_type > >::const_iterator point_it;
440 for(point_it itP = points_coords.begin(); itP != points_coords.end(); ++itP)
445 PropHelpers::set_point(
446 this, currentVertex, (*itP)[0], (*itP)[1], (*itP)[2]);
453 if(useVertexNormal || useVertexColor || useVertexTextureCoord)
459 std::vector< coordN_type > &coords = normals_coords[index - 1];
461 if(coords.size() != 3)
462 throw std::runtime_error(
"Support of normal coordinates of size != 3 "
463 "not yet implemented!");
466 this->SetProperty< AIFVertex::ptr, AIFMesh::Normal >(
467 "v:normal", currentVertex->GetIndex(), vn);
472 std::vector< coordC_type > &coords = vertex_color_coords[index - 1];
478 this->SetProperty< AIFVertex::ptr, AIFMesh::Vector >(
479 "v:color", currentVertex->GetIndex(), vc);
481 if(useVertexTextureCoord)
485 std::vector< coordT_type > &coords = texture_coords[index - 1];
487 if(coords.size() != 2)
488 throw std::runtime_error(
"Support of texture coordinates of size != "
489 "2 not yet implemented!");
493 this->SetProperty< AIFVertex::ptr, AIFMesh::PointUV >(
494 "v:texcoord", currentVertex->GetIndex(), texCoords);
497 if (!field_names.empty())
499 auto it = field_names.begin();
500 auto ite = field_names.end();
501 auto it_d = field_attributes.begin();
502 for (; it != ite; ++it, ++it_d)
504 if (it->find(
"v:datafield:") != std::string::npos)
507 this->SetProperty< AIFVertex::ptr, std::vector<double> >(
508 *it, currentVertex->GetIndex(), (*it_d)[index - 1]);
517 typedef std::vector< std::vector< index_type > >::const_iterator line_it;
519 for(line_it itL = lines_indices.begin(); itL != lines_indices.end(); ++itL)
531 firstVertex, danglingEdge, helpers::vertex_pos::FIRST);
533 secondVertex, danglingEdge, helpers::vertex_pos::SECOND);
537 std::vector< coordC_type > &coords = line_color_coords[index++];
541 this->SetProperty< AIFEdge::ptr, AIFMesh::Vector >(
542 "e:color", danglingEdge->GetIndex(), vc);
549 typedef std::vector< std::vector< index_type > >::const_iterator face_it;
550 typedef std::vector< index_type >::const_iterator index_it;
552 for(face_it itF = faces_indices.begin(); itF != faces_indices.end();
557 throw std::runtime_error(
"AIFMesh copy constructor -> find a face with "
558 "less than two vertices : not complying case.");
560 else if(itF->size() == 2)
571 firstVertex, danglingEdge, helpers::vertex_pos::FIRST);
573 secondVertex, danglingEdge, helpers::vertex_pos::SECOND);
587 index_type faceVertexId = 0;
588 for(index_it it = itF->begin(); it != itF->end(); ++it, ++faceVertexId)
601 prevVertex, currentEdge, helpers::vertex_pos::FIRST);
603 currentVertex, currentEdge, helpers::vertex_pos::SECOND);
609 if(useCornerTextureCoord)
615 index_type textureId = texture_face_indices[faceId][faceVertexId];
616 std::vector< coordT_type > &coords = texture_coords[textureId];
617 if(coords.size() != 2)
618 throw std::runtime_error(
"Support of texture coordinates of size "
619 "!= 2 not yet implemented!");
629 (*pm)[he] = texCoords;
645 index_type normalId = normal_face_indices[faceId][faceVertexId];
646 std::vector< coordN_type > &normal = normals_coords[normalId];
647 if(normal.size() != 3)
648 throw std::runtime_error(
649 "Support of normals of size != 3 not yet implemented!");
654 this->GetPropertyMap< AIFFace::ptr, AIFMesh::Normal >(
"f:normal");
658 fnormal = fnormal + vnormal;
659 if(it == itF->end() - 1)
661 fnormal / (faceVertexId +
667 (*pm)[currentFace] = fnormal;
670 prevVertex = currentVertex;
676 std::vector< coordC_type > &coords = face_color_coords[faceId];
680 this->SetProperty< AIFFace::ptr, AIFMesh::Vector >(
681 "f:color", currentFace->GetIndex(), vc);
683 if (!field_names.empty())
685 auto it = field_names.begin();
686 auto ite = field_names.end();
687 auto it_d = field_attributes.begin();
688 for (; it != ite; ++it, ++it_d)
690 if (it->find(
"f:datafield:") != std::string::npos)
693 this->SetProperty< AIFFace::ptr, std::vector<double> >(
694 *it, currentFace->GetIndex(), (*it_d)[faceId]);
741 std::cout <<
"-----------------------------------------------------------"
749 std::cout <<
"-----------------------------------------------------------"
767 return &m_VertexPropertyMaps;
775 return &m_EdgePropertyMaps;
783 return &m_FacePropertyMaps;
791 return &m_VertexPropertyMaps;
799 return &m_EdgePropertyMaps;
807 return &m_FacePropertyMaps;