| 24 | #ifdef SCHEMA_HAS_IfcIndexedPolyCurve |
| 25 | |
| 26 | taxonomy::ptr mapping::map_impl(const IfcSchema::IfcIndexedPolyCurve* inst) { |
| 27 | |
| 28 | IfcSchema::IfcCartesianPointList* point_list = inst->Points(); |
| 29 | std::vector< std::vector<double> > coordinates; |
| 30 | if (point_list->as<IfcSchema::IfcCartesianPointList2D>()) { |
| 31 | coordinates = point_list->as<IfcSchema::IfcCartesianPointList2D>()->CoordList(); |
| 32 | } else if (point_list->as<IfcSchema::IfcCartesianPointList3D>()) { |
| 33 | coordinates = point_list->as<IfcSchema::IfcCartesianPointList3D>()->CoordList(); |
| 34 | } |
| 35 | |
| 36 | std::vector<taxonomy::point3::ptr> points; |
| 37 | if (coordinates.size() < 2) { |
| 38 | throw IfcParse::IfcException("IfcIndexedPolyCurve has less than 2 points."); |
| 39 | } |
| 40 | |
| 41 | points.reserve(coordinates.size()); |
| 42 | for (auto& coords : coordinates) { |
| 43 | points.push_back(taxonomy::make<taxonomy::point3>( |
| 44 | coords.size() < 1 ? 0. : coords[0] * length_unit_, |
| 45 | coords.size() < 2 ? 0. : coords[1] * length_unit_, |
| 46 | coords.size() < 3 ? 0. : coords[2] * length_unit_)); |
| 47 | } |
| 48 | |
| 49 | int max_index = (int) points.size(); |
| 50 | |
| 51 | auto loop = taxonomy::make<taxonomy::loop>(); |
| 52 | |
| 53 | if(inst->Segments()) { |
| 54 | auto segments = *inst->Segments(); |
| 55 | for (auto it = segments->begin(); it != segments->end(); ++it) { |
| 56 | auto segment = *it; |
| 57 | if (segment->as<IfcSchema::IfcLineIndex>()) { |
| 58 | IfcSchema::IfcLineIndex* line = segment->as<IfcSchema::IfcLineIndex>(); |
| 59 | std::vector<int> indices = *line; |
| 60 | taxonomy::point3::ptr previous; |
| 61 | for (std::vector<int>::const_iterator jt = indices.begin(); jt != indices.end(); ++jt) { |
| 62 | if (*jt < 1 || *jt > max_index) { |
| 63 | throw IfcParse::IfcException("IfcIndexedPolyCurve index out of bounds for index " + boost::lexical_cast<std::string>(*jt)); |
| 64 | } |
| 65 | auto current = points[*jt - 1]; |
| 66 | if (jt != indices.begin()) { |
| 67 | loop->children.push_back(taxonomy::make<taxonomy::edge>(previous, current)); |
| 68 | } |
| 69 | previous = current; |
| 70 | } |
| 71 | } else if (segment->as<IfcSchema::IfcArcIndex>()) { |
| 72 | IfcSchema::IfcArcIndex* arc = segment->as<IfcSchema::IfcArcIndex>(); |
| 73 | std::vector<int> indices = *arc; |
| 74 | if (indices.size() != 3) { |
| 75 | throw IfcParse::IfcException("Invalid IfcArcIndex encountered"); |
| 76 | } |
| 77 | for (int i = 0; i < 3; ++i) { |
| 78 | const int& idx = indices[i]; |
| 79 | if (idx < 1 || idx > max_index) { |
| 80 | throw IfcParse::IfcException("IfcIndexedPolyCurve index out of bounds for index " + boost::lexical_cast<std::string>(idx)); |
| 81 | } |
| 82 | } |
| 83 | const auto& a = points[indices[0] - 1]; |