From cf9605f1089098775bfa5eb1b691aecdd95a74c0 Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 20 Mar 2017 15:56:31 -0600 Subject: [PATCH 1/6] Missing Shapes, support for voids --- src/ifcgeom/kernels/cgal/CgalEntityMapping.h | 6 ++- .../kernels/cgal/CgalIfcGeomShapes.cpp | 52 ++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalEntityMapping.h b/src/ifcgeom/kernels/cgal/CgalEntityMapping.h index e0ecad5298..e438b3ace1 100644 --- a/src/ifcgeom/kernels/cgal/CgalEntityMapping.h +++ b/src/ifcgeom/kernels/cgal/CgalEntityMapping.h @@ -28,14 +28,16 @@ #include "../../../ifcparse/IfcUtil.h" #include "../../../ifcparse/IfcParse.h" +SHAPES(IfcShellBasedSurfaceModel); +SHAPES(IfcFaceBasedSurfaceModel); SHAPES(IfcRepresentation); +SHAPES(IfcMappedItem); // IfcFacetedBrep included // IfcAdvancedBrep included // IfcFacetedBrepWithVoids included // IfcAdvancedBrepWithVoids included SHAPES(IfcManifoldSolidBrep); -SHAPES(IfcMappedItem); -SHAPES(IfcFaceBasedSurfaceModel); +SHAPES(IfcGeometricSet); SHAPE(IfcExtrudedAreaSolid); SHAPE(IfcConnectedFaceSet); diff --git a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp index 15e5054dc4..7e912c8b5b 100644 --- a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp +++ b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp @@ -1,6 +1,46 @@ #include "CgalKernel.h" #include "CgalConversionResult.h" +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcGeometricSet* l, ConversionResults& shapes) { + IfcEntityList::ptr elements = l->Elements(); + if ( !elements->size() ) return false; + bool part_succes = false; + const IfcGeom::SurfaceStyle* parent_style = get_style(l); + for ( IfcEntityList::it it = elements->begin(); it != elements->end(); ++ it ) { + IfcSchema::IfcGeometricSetSelect* element = *it; + cgal_shape_t s; + if (convert_shape(element, s)) { + part_succes = true; + const IfcGeom::SurfaceStyle* style = 0; + if (element->is(IfcSchema::Type::IfcPoint)) { + style = get_style((IfcSchema::IfcPoint*) element); + } else if (element->is(IfcSchema::Type::IfcCurve)) { + style = get_style((IfcSchema::IfcCurve*) element); + } else if (element->is(IfcSchema::Type::IfcSurface)) { + style = get_style((IfcSchema::IfcSurface*) element); + } + shapes.push_back(ConversionResult(new CgalShape(s), style ? style : parent_style)); + } + } + return part_succes; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcShellBasedSurfaceModel* l, ConversionResults& shapes) { + IfcEntityList::ptr shells = l->SbsmBoundary(); + const SurfaceStyle* collective_style = get_style(l); + for( IfcEntityList::it it = shells->begin(); it != shells->end(); ++ it ) { + cgal_shape_t s; + const SurfaceStyle* shell_style = 0; + if ((*it)->is(IfcSchema::Type::IfcRepresentationItem)) { + shell_style = get_style((IfcSchema::IfcRepresentationItem*)*it); + } + if (convert_shape(*it,s)) { + shapes.push_back(ConversionResult(new CgalShape(s), shell_style ? shell_style : collective_style)); + } + } + return true; +} + bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcManifoldSolidBrep* l, ConversionResults& shape) { cgal_shape_t s; const SurfaceStyle* collective_style = get_style(l); @@ -18,12 +58,12 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcManifoldSolidBrep* l, Conv #endif for (IfcSchema::IfcClosedShell::list::it it = voids->begin(); it != voids->end(); ++it) { - // TopoDS_Shape s2; - // /// @todo No extensive shapefixing since shells should be disjoint. - // /// @todo Awaiting generalized boolean ops module with appropriate checking - // if (convert_shape(l->Outer(), s2)) { - // s = BRepAlgoAPI_Cut(s, s2).Shape(); - // } + cgal_shape_t s2; + /// @todo No extensive shapefixing since shells should be disjoint. + /// @todo Awaiting generalized boolean ops module with appropriate checking + if (convert_shape(l->Outer(), s2)) { + s -= s2; + } } shape.push_back(ConversionResult(new CgalShape(s), indiv_style ? indiv_style : collective_style)); From cf6bd5a6291b3d11b7e81158eed46873e7746cb6 Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 20 Mar 2017 16:31:06 -0600 Subject: [PATCH 2/6] Enabled missing Cartesian transformations --- src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp index 7e912c8b5b..39c505386a 100644 --- a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp +++ b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp @@ -78,17 +78,11 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcMappedItem* l, ConversionR if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator3DnonUniform) ) { IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3DnonUniform*)transform,gtrsf); } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator2DnonUniform) ) { - Logger::Message(Logger::LOG_ERROR, "Unsupported MappingTarget:", transform->entity); - return false; + IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2DnonUniform*)transform,gtrsf); } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator3D) ) { - cgal_placement_t trsf; - IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3D*)transform,trsf); - gtrsf = trsf; + IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3D*)transform,gtrsf); } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator2D) ) { - cgal_placement_t trsf_2d; - Logger::Message(Logger::LOG_ERROR, "Unsupported MappingTarget:", transform->entity); -// IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2D*)transform,trsf_2d); - gtrsf = (cgal_placement_t) trsf_2d; + IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2D*)transform,gtrsf); } IfcSchema::IfcRepresentationMap* map = l->MappingSource(); IfcSchema::IfcAxis2Placement* placement = map->MappingOrigin(); From 8090bb4c0070650b8d5a30313392b0b448846656 Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 20 Mar 2017 16:35:14 -0600 Subject: [PATCH 3/6] Shapes with styles in separate file --- .../kernels/cgal/CgalConversionFunctions.cpp | 21 --- .../kernels/cgal/CgalIfcGeomShapes.cpp | 139 --------------- .../cgal/CgalIfcGeomShapesWithStyles.cpp | 160 ++++++++++++++++++ 3 files changed, 160 insertions(+), 160 deletions(-) create mode 100644 src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp diff --git a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp index 3291059fb5..a7a52b34ad 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp @@ -1,27 +1,6 @@ #include "../../../ifcparse/IfcParse.h" #include "CgalKernel.h" -#include "CgalConversionResult.h" - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRepresentation* l, ConversionResults& shapes) { - IfcSchema::IfcRepresentationItem::list::ptr items = l->Items(); - bool part_succes = false; - if (items->size()) { - for (IfcSchema::IfcRepresentationItem::list::it it = items->begin(); it != items->end(); ++it) { - IfcSchema::IfcRepresentationItem* representation_item = *it; - if (shape_type(representation_item) == ST_SHAPELIST) { - part_succes |= convert_shapes(*it, shapes); - } else { - cgal_shape_t s; - if (convert_shape(representation_item, s)) { - shapes.push_back(ConversionResult(new CgalShape(s), get_style(representation_item))); - part_succes |= true; - } - } - } - } - return part_succes; -} bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianPoint* l, cgal_point_t& point) { std::vector xyz = l->Coordinates(); diff --git a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp index 39c505386a..80a5da0066 100644 --- a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp +++ b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapes.cpp @@ -1,143 +1,4 @@ #include "CgalKernel.h" -#include "CgalConversionResult.h" - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcGeometricSet* l, ConversionResults& shapes) { - IfcEntityList::ptr elements = l->Elements(); - if ( !elements->size() ) return false; - bool part_succes = false; - const IfcGeom::SurfaceStyle* parent_style = get_style(l); - for ( IfcEntityList::it it = elements->begin(); it != elements->end(); ++ it ) { - IfcSchema::IfcGeometricSetSelect* element = *it; - cgal_shape_t s; - if (convert_shape(element, s)) { - part_succes = true; - const IfcGeom::SurfaceStyle* style = 0; - if (element->is(IfcSchema::Type::IfcPoint)) { - style = get_style((IfcSchema::IfcPoint*) element); - } else if (element->is(IfcSchema::Type::IfcCurve)) { - style = get_style((IfcSchema::IfcCurve*) element); - } else if (element->is(IfcSchema::Type::IfcSurface)) { - style = get_style((IfcSchema::IfcSurface*) element); - } - shapes.push_back(ConversionResult(new CgalShape(s), style ? style : parent_style)); - } - } - return part_succes; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcShellBasedSurfaceModel* l, ConversionResults& shapes) { - IfcEntityList::ptr shells = l->SbsmBoundary(); - const SurfaceStyle* collective_style = get_style(l); - for( IfcEntityList::it it = shells->begin(); it != shells->end(); ++ it ) { - cgal_shape_t s; - const SurfaceStyle* shell_style = 0; - if ((*it)->is(IfcSchema::Type::IfcRepresentationItem)) { - shell_style = get_style((IfcSchema::IfcRepresentationItem*)*it); - } - if (convert_shape(*it,s)) { - shapes.push_back(ConversionResult(new CgalShape(s), shell_style ? shell_style : collective_style)); - } - } - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcManifoldSolidBrep* l, ConversionResults& shape) { - cgal_shape_t s; - const SurfaceStyle* collective_style = get_style(l); - if (convert_shape(l->Outer(),s) ) { - const SurfaceStyle* indiv_style = get_style(l->Outer()); - - IfcSchema::IfcClosedShell::list::ptr voids(new IfcSchema::IfcClosedShell::list); - if (l->is(IfcSchema::Type::IfcFacetedBrepWithVoids)) { - voids = l->as()->Voids(); - } -#ifdef USE_IFC4 - if (l->is(IfcSchema::Type::IfcAdvancedBrepWithVoids)) { - voids = l->as()->Voids(); - } -#endif - - for (IfcSchema::IfcClosedShell::list::it it = voids->begin(); it != voids->end(); ++it) { - cgal_shape_t s2; - /// @todo No extensive shapefixing since shells should be disjoint. - /// @todo Awaiting generalized boolean ops module with appropriate checking - if (convert_shape(l->Outer(), s2)) { - s -= s2; - } - } - - shape.push_back(ConversionResult(new CgalShape(s), indiv_style ? indiv_style : collective_style)); - return true; - } - return false; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcMappedItem* l, ConversionResults& shapes) { - cgal_placement_t gtrsf; - IfcSchema::IfcCartesianTransformationOperator* transform = l->MappingTarget(); - if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator3DnonUniform) ) { - IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3DnonUniform*)transform,gtrsf); - } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator2DnonUniform) ) { - IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2DnonUniform*)transform,gtrsf); - } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator3D) ) { - IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3D*)transform,gtrsf); - } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator2D) ) { - IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2D*)transform,gtrsf); - } - IfcSchema::IfcRepresentationMap* map = l->MappingSource(); - IfcSchema::IfcAxis2Placement* placement = map->MappingOrigin(); - cgal_placement_t trsf; - if (placement->is(IfcSchema::Type::IfcAxis2Placement3D)) { - IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement3D*)placement,trsf); - } else { - cgal_placement_t trsf_2d; - IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement2D*)placement,trsf_2d); - trsf = trsf_2d; - } - - // TODO: Check - gtrsf = trsf * gtrsf; - -// std::cout << std::endl; -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 4; ++j) { -// std::cout << gtrsf.cartesian(i, j) << " "; -// } std::cout << std::endl; -// } - - const IfcGeom::SurfaceStyle* mapped_item_style = get_style(l); - - const size_t previous_size = shapes.size(); - bool b = convert_shapes(map->MappedRepresentation(), shapes); - - for (size_t i = previous_size; i < shapes.size(); ++ i ) { - IfcGeom::CgalPlacement place(gtrsf); - shapes[i].prepend(&place); - - // Apply styles assigned to the mapped item only if on - // a more granular level no styles have been applied - if (!shapes[i].hasStyle()) { - shapes[i].setStyle(mapped_item_style); - } - } - - return b; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcFaceBasedSurfaceModel* l, ConversionResults& shapes) { - bool part_success = false; - IfcSchema::IfcConnectedFaceSet::list::ptr facesets = l->FbsmFaces(); - const SurfaceStyle* collective_style = get_style(l); - for( IfcSchema::IfcConnectedFaceSet::list::it it = facesets->begin(); it != facesets->end(); ++ it ) { - cgal_shape_t s; - const SurfaceStyle* shell_style = get_style(*it); - if (convert_shape(*it,s)) { - shapes.push_back(ConversionResult(new CgalShape(s), shell_style ? shell_style : collective_style)); - part_success |= true; - } - } - return part_success; -} bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcExtrudedAreaSolid *l, cgal_shape_t &shape) { const double height = l->Depth() * getValue(GV_LENGTH_UNIT); diff --git a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp new file mode 100644 index 0000000000..4898625956 --- /dev/null +++ b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp @@ -0,0 +1,160 @@ +#include "CgalKernel.h" +#include "CgalConversionResult.h" + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRepresentation* l, ConversionResults& shapes) { + IfcSchema::IfcRepresentationItem::list::ptr items = l->Items(); + bool part_succes = false; + if (items->size()) { + for (IfcSchema::IfcRepresentationItem::list::it it = items->begin(); it != items->end(); ++it) { + IfcSchema::IfcRepresentationItem* representation_item = *it; + if (shape_type(representation_item) == ST_SHAPELIST) { + part_succes |= convert_shapes(*it, shapes); + } else { + cgal_shape_t s; + if (convert_shape(representation_item, s)) { + shapes.push_back(ConversionResult(new CgalShape(s), get_style(representation_item))); + part_succes |= true; + } + } + } + } + return part_succes; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcGeometricSet* l, ConversionResults& shapes) { + IfcEntityList::ptr elements = l->Elements(); + if ( !elements->size() ) return false; + bool part_succes = false; + const IfcGeom::SurfaceStyle* parent_style = get_style(l); + for ( IfcEntityList::it it = elements->begin(); it != elements->end(); ++ it ) { + IfcSchema::IfcGeometricSetSelect* element = *it; + cgal_shape_t s; + if (convert_shape(element, s)) { + part_succes = true; + const IfcGeom::SurfaceStyle* style = 0; + if (element->is(IfcSchema::Type::IfcPoint)) { + style = get_style((IfcSchema::IfcPoint*) element); + } else if (element->is(IfcSchema::Type::IfcCurve)) { + style = get_style((IfcSchema::IfcCurve*) element); + } else if (element->is(IfcSchema::Type::IfcSurface)) { + style = get_style((IfcSchema::IfcSurface*) element); + } + shapes.push_back(ConversionResult(new CgalShape(s), style ? style : parent_style)); + } + } + return part_succes; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcShellBasedSurfaceModel* l, ConversionResults& shapes) { + IfcEntityList::ptr shells = l->SbsmBoundary(); + const SurfaceStyle* collective_style = get_style(l); + for( IfcEntityList::it it = shells->begin(); it != shells->end(); ++ it ) { + cgal_shape_t s; + const SurfaceStyle* shell_style = 0; + if ((*it)->is(IfcSchema::Type::IfcRepresentationItem)) { + shell_style = get_style((IfcSchema::IfcRepresentationItem*)*it); + } + if (convert_shape(*it,s)) { + shapes.push_back(ConversionResult(new CgalShape(s), shell_style ? shell_style : collective_style)); + } + } + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcManifoldSolidBrep* l, ConversionResults& shape) { + cgal_shape_t s; + const SurfaceStyle* collective_style = get_style(l); + if (convert_shape(l->Outer(),s) ) { + const SurfaceStyle* indiv_style = get_style(l->Outer()); + + IfcSchema::IfcClosedShell::list::ptr voids(new IfcSchema::IfcClosedShell::list); + if (l->is(IfcSchema::Type::IfcFacetedBrepWithVoids)) { + voids = l->as()->Voids(); + } +#ifdef USE_IFC4 + if (l->is(IfcSchema::Type::IfcAdvancedBrepWithVoids)) { + voids = l->as()->Voids(); + } +#endif + + for (IfcSchema::IfcClosedShell::list::it it = voids->begin(); it != voids->end(); ++it) { + cgal_shape_t s2; + /// @todo No extensive shapefixing since shells should be disjoint. + /// @todo Awaiting generalized boolean ops module with appropriate checking + if (convert_shape(l->Outer(), s2)) { + s -= s2; + } + } + + shape.push_back(ConversionResult(new CgalShape(s), indiv_style ? indiv_style : collective_style)); + return true; + } + return false; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcMappedItem* l, ConversionResults& shapes) { + cgal_placement_t gtrsf; + IfcSchema::IfcCartesianTransformationOperator* transform = l->MappingTarget(); + if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator3DnonUniform) ) { + IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3DnonUniform*)transform,gtrsf); + } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator2DnonUniform) ) { + IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2DnonUniform*)transform,gtrsf); + } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator3D) ) { + IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3D*)transform,gtrsf); + } else if ( transform->is(IfcSchema::Type::IfcCartesianTransformationOperator2D) ) { + IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2D*)transform,gtrsf); + } + IfcSchema::IfcRepresentationMap* map = l->MappingSource(); + IfcSchema::IfcAxis2Placement* placement = map->MappingOrigin(); + cgal_placement_t trsf; + if (placement->is(IfcSchema::Type::IfcAxis2Placement3D)) { + IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement3D*)placement,trsf); + } else { + cgal_placement_t trsf_2d; + IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement2D*)placement,trsf_2d); + trsf = trsf_2d; + } + + // TODO: Check + gtrsf = trsf * gtrsf; + + // std::cout << std::endl; + // for (int i = 0; i < 3; ++i) { + // for (int j = 0; j < 4; ++j) { + // std::cout << gtrsf.cartesian(i, j) << " "; + // } std::cout << std::endl; + // } + + const IfcGeom::SurfaceStyle* mapped_item_style = get_style(l); + + const size_t previous_size = shapes.size(); + bool b = convert_shapes(map->MappedRepresentation(), shapes); + + for (size_t i = previous_size; i < shapes.size(); ++ i ) { + IfcGeom::CgalPlacement place(gtrsf); + shapes[i].prepend(&place); + + // Apply styles assigned to the mapped item only if on + // a more granular level no styles have been applied + if (!shapes[i].hasStyle()) { + shapes[i].setStyle(mapped_item_style); + } + } + + return b; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcFaceBasedSurfaceModel* l, ConversionResults& shapes) { + bool part_success = false; + IfcSchema::IfcConnectedFaceSet::list::ptr facesets = l->FbsmFaces(); + const SurfaceStyle* collective_style = get_style(l); + for( IfcSchema::IfcConnectedFaceSet::list::it it = facesets->begin(); it != facesets->end(); ++ it ) { + cgal_shape_t s; + const SurfaceStyle* shell_style = get_style(*it); + if (convert_shape(*it,s)) { + shapes.push_back(ConversionResult(new CgalShape(s), shell_style ? shell_style : collective_style)); + part_success |= true; + } + } + return part_success; +} From 62ca6f6a7d2e79a03f9033b79b8d04fbc0425caf Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 20 Mar 2017 16:45:27 -0600 Subject: [PATCH 4/6] Checked shapes with styles. Found bug? --- src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp index 4898625956..2bfd8caaac 100644 --- a/src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp +++ b/src/ifcgeom/kernels/cgal/CgalIfcGeomShapesWithStyles.cpp @@ -79,8 +79,9 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcManifoldSolidBrep* l, Conv for (IfcSchema::IfcClosedShell::list::it it = voids->begin(); it != voids->end(); ++it) { cgal_shape_t s2; - /// @todo No extensive shapefixing since shells should be disjoint. - /// @todo Awaiting generalized boolean ops module with appropriate checking + // TODO: This looks weird. Aren't we removing the outer shell again and again? + // Maybe it should be + // if (convert_shape(*it, s2)) { if (convert_shape(l->Outer(), s2)) { s -= s2; } From 71d7bbd6bab33de8a533b39b67fee2a91b757917 Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 20 Mar 2017 20:06:48 -0600 Subject: [PATCH 5/6] =?UTF-8?q?Ordering=20things=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernels/cgal/CgalConversionFunctions.cpp | 286 ------------------ .../kernels/cgal/CgalIfcGeomPrimitives.cpp | 285 +++++++++++++++++ 2 files changed, 285 insertions(+), 286 deletions(-) create mode 100644 src/ifcgeom/kernels/cgal/CgalIfcGeomPrimitives.cpp diff --git a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp index a7a52b34ad..818ee56f47 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp @@ -1,296 +1,10 @@ -#include "../../../ifcparse/IfcParse.h" - #include "CgalKernel.h" -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianPoint* l, cgal_point_t& point) { - std::vector xyz = l->Coordinates(); - point = Kernel::Point_3(xyz.size() ? (xyz[0]*getValue(GV_LENGTH_UNIT)) : 0.0f, - xyz.size() > 1 ? (xyz[1]*getValue(GV_LENGTH_UNIT)) : 0.0f, - xyz.size() > 2 ? (xyz[2]*getValue(GV_LENGTH_UNIT)) : 0.0f); -// std::cout << "Converted Point(" << point << ")" << std::endl; - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcDirection* l, cgal_direction_t& dir) { -// IN_CACHE(IfcDirection,l,cgal_direction_t,dir) - std::vector xyz = l->DirectionRatios(); - dir = Kernel::Vector_3(xyz.size() ? xyz[0] : 0.0f, - xyz.size() > 1 ? xyz[1] : 0.0f, - xyz.size() > 2 ? xyz[2] : 0.0f); -// CACHE(IfcDirection,l,dir) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcVector* l, cgal_vector_t& v) { -// IN_CACHE(IfcVector,l,cgal_vector_t,v) - cgal_direction_t d; - IfcGeom::CgalKernel::convert(l->Orientation(),d); - v = l->Magnitude() * getValue(GV_LENGTH_UNIT) * d; -// CACHE(IfcVector,l,v) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcPlane* pln, cgal_plane_t& plane) { -// IN_CACHE(IfcPlane,pln,gp_Pln,plane) - IfcSchema::IfcAxis2Placement3D* l = pln->Position(); - cgal_point_t o; - cgal_direction_t axis = Kernel::Vector_3(0,0,1); - cgal_direction_t refDirection = Kernel::Vector_3(1,0,0); - IfcGeom::CgalKernel::convert(l->Location(),o); - bool hasRef = l->hasRefDirection(); - if ( l->hasAxis() ) IfcGeom::CgalKernel::convert(l->Axis(),axis); - if ( hasRef ) IfcGeom::CgalKernel::convert(l->RefDirection(),refDirection); - Kernel::Vector_3 y = CGAL::cross_product(axis, refDirection); - Kernel::Vector_3 x = CGAL::cross_product(y, axis); - - cgal_plane_t ax3; - if ( hasRef ) ax3 = Kernel::Plane_3(o,o+x,o+y); - else ax3 = Kernel::Plane_3(o,axis); - plane = ax3; - -// std::cout << "IfcPlane C = " << o << std::endl; -// std::cout << "IfcPlane z (axis, exact) = " << axis << std::endl; -// std::cout << "IfcPlane x (refDirection, approximate) = " << refDirection << std::endl; -// std::cout << "IfcPlane y (computed, exact) = " << y << std::endl; -// std::cout << "IfcPlane x (computed, exact) = " << x << std::endl; -// -// std::cout << "Plane_3 o = " << o << std::endl; -// std::cout << "Plane_3 o+x = " << o+x << std::endl; -// std::cout << "Plane_3 o+y = " << o+y << std::endl; - - // ax + by + cz + d = 0 -// std::cout << "Plane: a = " << plane.a() << ", b = " << plane.b() << ", c = " << plane.c() << ", d = " << plane.d() << std::endl; - -// std::ofstream fresult; -// fresult.open("/Users/ken/Desktop/plane.obj"); -// // x = -5, y = -5, z = (5a +5b -d)/c -// fresult << "v -5 -5 " << (5.0*CGAL::to_double(plane.a())+5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; -// // x = -5, y = +5, z = (5a -5b -d)/c -// fresult << "v -5 5 " << (5.0*CGAL::to_double(plane.a())-5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; -// // x = 5, y = -5, z = (-5a +5b -d)/c -// fresult << "v 5 -5 " << (-5.0*CGAL::to_double(plane.a())+5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; -// // x = 5, y = +5, z = (-5a -5b -d)/c -// fresult << "v 5 5 " << (-5.0*CGAL::to_double(plane.a())-5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; -// fresult << "f 1 2 3" << std::endl; -// fresult << "f 4 3 2" << std::endl; -// fresult.close(); - -// CACHE(IfcPlane,pln,plane) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcAxis2Placement2D* l, cgal_placement_t& trsf) { - // IN_CACHE(IfcAxis2Placement3D,l,gp_Trsf,trsf) - cgal_point_t o; - cgal_direction_t refDirection = Kernel::Vector_3(1,0,0); - IfcGeom::CgalKernel::convert(l->Location(),o); - bool hasRef = l->hasRefDirection(); - if ( hasRef ) IfcGeom::CgalKernel::convert(l->RefDirection(),refDirection); - cgal_direction_t y = Kernel::Vector_3(-refDirection.y(), refDirection.x(), 0.0); - - // TODO: Should be checked. - trsf = Kernel::Aff_transformation_3(refDirection.cartesian(0), y.cartesian(0), 0.0, o.cartesian(0), - refDirection.cartesian(1), y.cartesian(1), 0.0, o.cartesian(1), - 0.0, 0.0, 1.0, 0.0); - - // CACHE(IfcAxis2Placement3D,l,trsf) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcAxis2Placement3D* l, cgal_placement_t& trsf) { -// IN_CACHE(IfcAxis2Placement3D,l,gp_Trsf,trsf) - cgal_point_t o; - cgal_direction_t axis = Kernel::Vector_3(0,0,1); - cgal_direction_t refDirection = Kernel::Vector_3(1,0,0); - IfcGeom::CgalKernel::convert(l->Location(),o); - bool hasRef = l->hasRefDirection(); - if ( l->hasAxis() ) IfcGeom::CgalKernel::convert(l->Axis(),axis); - if ( hasRef ) IfcGeom::CgalKernel::convert(l->RefDirection(),refDirection); - Kernel::Vector_3 y = CGAL::cross_product(axis, refDirection); - Kernel::Vector_3 x = CGAL::cross_product(y, axis); - -// std::cout << "Ref direction: " << refDirection << std::endl; -// std::cout << "Axis: " << axis << std::endl; -// std::cout << "Origin: " << o << std::endl; - - // TODO: Should be checked. - trsf = Kernel::Aff_transformation_3(x.cartesian(0), y.cartesian(0), axis.cartesian(0), o.cartesian(0), - x.cartesian(1), y.cartesian(1), axis.cartesian(1), o.cartesian(1), - x.cartesian(2), y.cartesian(2), axis.cartesian(2), o.cartesian(2)); - -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 4; ++j) { -// std::cout << trsf.cartesian(i, j) << " "; -// } std::cout << std::endl; -// } - -// CACHE(IfcAxis2Placement3D,l,trsf) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcObjectPlacement* l, cgal_placement_t& trsf) { - // TODO: These macros don't work for the CGAL types. Need to check why. -// IN_CACHE(IfcObjectPlacement,l,cgal_placement_t,trsf) - if ( ! l->is(IfcSchema::Type::IfcLocalPlacement) ) { - Logger::Message(Logger::LOG_ERROR, "Unsupported IfcObjectPlacement:", l->entity); - return false; - } - -// std::cout << "initial trsf (identity?)" << std::endl; -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 4; ++j) { -// std::cout << trsf.cartesian(i, j) << " "; -// } std::cout << std::endl; -// } - - IfcSchema::IfcLocalPlacement* current = (IfcSchema::IfcLocalPlacement*)l; - for (;;) { - cgal_placement_t trsf2; - - IfcSchema::IfcAxis2Placement* relplacement = current->RelativePlacement(); - if ( relplacement->is(IfcSchema::Type::IfcAxis2Placement3D) ) { - IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement3D*)relplacement,trsf2); - -// std::cout << "trsf2" << std::endl; -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 4; ++j) { -// std::cout << trsf2.cartesian(i, j) << " "; -// } std::cout << std::endl; -// } - - trsf = trsf * trsf2; // TODO: I think it's fine, but maybe should it be the other way around? - -// std::cout << "trsf (after multiplication)" << std::endl; -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 4; ++j) { -// std::cout << trsf.cartesian(i, j) << " "; -// } std::cout << std::endl; -// } - } - if ( current->hasPlacementRelTo() ) { - IfcSchema::IfcObjectPlacement* relto = current->PlacementRelTo(); - if ( relto->is(IfcSchema::Type::IfcLocalPlacement) ) - current = (IfcSchema::IfcLocalPlacement*)current->PlacementRelTo(); - else break; - } else break; - } -// CACHE(IfcObjectPlacement,l,trsf) - return true; -} - bool IfcGeom::CgalKernel::convert_wire_to_face(const cgal_wire_t& wire, cgal_face_t& face) { face.outer = wire; return true; } -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator2D* l, cgal_placement_t& trsf) { -// IN_CACHE(IfcCartesianTransformationOperator2D,l,cgal_placement_t,trsf) - - cgal_point_t origin; - cgal_direction_t axis1 (1.,0.,0.); - cgal_direction_t axis2 (0.,1.,0.); - - IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); - if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); - if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); - double scale = 1.0; - if (l->hasScale()) { - scale = l->Scale(); - } - - // TODO: Untested - trsf = Kernel::Aff_transformation_3(scale*axis1.cartesian(0), axis2.cartesian(0), 0.0, origin.cartesian(0), - axis1.cartesian(1), scale*axis2.cartesian(1), 0.0, origin.cartesian(1), - 0.0, 0.0, 1.0, 0.0); - -// CACHE(IfcCartesianTransformationOperator2D,l,trsf) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator2DnonUniform* l, cgal_placement_t& gtrsf) { -// IN_CACHE(IfcCartesianTransformationOperator2DnonUniform,l,cgal_placement_t,gtrsf) - - cgal_placement_t trsf; - cgal_point_t origin; - cgal_direction_t axis1 (1.,0.,0.); - cgal_direction_t axis2 (0.,1.,0.); - - IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); - if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); - if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); - - const double scale1 = l->hasScale() ? l->Scale() : 1.0f; - const double scale2 = l->hasScale2() ? l->Scale2() : scale1; - - // TODO: Untested - trsf = Kernel::Aff_transformation_3(scale1*axis1.cartesian(0), axis2.cartesian(0), 0.0, origin.cartesian(0), - axis1.cartesian(1), scale2*axis2.cartesian(1), 0.0, origin.cartesian(1), - 0.0, 0.0, 1.0, 0.0); - -// CACHE(IfcCartesianTransformationOperator2DnonUniform,l,gtrsf) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator3D* l, cgal_placement_t& trsf) { -// IN_CACHE(IfcCartesianTransformationOperator3D,l,gp_Trsf,trsf) - cgal_point_t origin; - IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); - cgal_direction_t axis1 (1.,0.,0.); - cgal_direction_t axis2 (0.,1.,0.); - cgal_direction_t axis3 (0.,0.,1.); - if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); - if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); - if ( l->hasAxis3() ) IfcGeom::CgalKernel::convert(l->Axis3(),axis3); - double scale = 1.0; - if (l->hasScale()) { - scale = l->Scale(); - } - - // TODO: Untested - trsf = Kernel::Aff_transformation_3(scale*axis1.cartesian(0), axis2.cartesian(0), axis3.cartesian(0), origin.cartesian(0), - axis1.cartesian(1), scale*axis2.cartesian(1), axis3.cartesian(1), origin.cartesian(1), - axis1.cartesian(2), axis2.cartesian(2), scale*axis3.cartesian(2), origin.cartesian(2)); - -// std::cout << std::endl; -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 4; ++j) { -// std::cout << trsf.cartesian(i, j) << " "; -// } std::cout << std::endl; -// } - -// CACHE(IfcCartesianTransformationOperator3D,l,trsf) - return true; -} - -bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator3DnonUniform* l, cgal_placement_t& gtrsf) { -// IN_CACHE(IfcCartesianTransformationOperator3DnonUniform,l,gp_GTrsf,gtrsf) - cgal_point_t origin; - IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); - cgal_direction_t axis1 (1.,0.,0.); - cgal_direction_t axis2 (0.,1.,0.); - cgal_direction_t axis3 (0.,0.,1.); - if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); - if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); - if ( l->hasAxis3() ) IfcGeom::CgalKernel::convert(l->Axis3(),axis3); - const double scale1 = l->hasScale() ? l->Scale() : 1.0f; - const double scale2 = l->hasScale2() ? l->Scale2() : scale1; - const double scale3 = l->hasScale3() ? l->Scale3() : scale1; - - // TODO: Untested - gtrsf = Kernel::Aff_transformation_3(scale1*axis1.cartesian(0), axis2.cartesian(0), axis3.cartesian(0), origin.cartesian(0), - axis1.cartesian(1), scale2*axis2.cartesian(1), axis3.cartesian(1), origin.cartesian(1), - axis1.cartesian(2), axis2.cartesian(2), scale3*axis3.cartesian(2), origin.cartesian(2)); - -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 4; ++j) { -// std::cout << gtrsf.cartesian(i, j) << " "; -// } std::cout << std::endl; -// } - -// CACHE(IfcCartesianTransformationOperator3DnonUniform,l,gtrsf) - return true; -} - void IfcGeom::CgalKernel::remove_duplicate_points_from_loop(cgal_wire_t& polygon, bool closed, double tol) { if (tol <= 0.) tol = getValue(GV_PRECISION); tol *= tol; diff --git a/src/ifcgeom/kernels/cgal/CgalIfcGeomPrimitives.cpp b/src/ifcgeom/kernels/cgal/CgalIfcGeomPrimitives.cpp new file mode 100644 index 0000000000..2a878e40fe --- /dev/null +++ b/src/ifcgeom/kernels/cgal/CgalIfcGeomPrimitives.cpp @@ -0,0 +1,285 @@ +#include "CgalKernel.h" + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianPoint* l, cgal_point_t& point) { + std::vector xyz = l->Coordinates(); + point = Kernel::Point_3(xyz.size() ? (xyz[0]*getValue(GV_LENGTH_UNIT)) : 0.0f, + xyz.size() > 1 ? (xyz[1]*getValue(GV_LENGTH_UNIT)) : 0.0f, + xyz.size() > 2 ? (xyz[2]*getValue(GV_LENGTH_UNIT)) : 0.0f); + // std::cout << "Converted Point(" << point << ")" << std::endl; + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcDirection* l, cgal_direction_t& dir) { + // IN_CACHE(IfcDirection,l,cgal_direction_t,dir) + std::vector xyz = l->DirectionRatios(); + dir = Kernel::Vector_3(xyz.size() ? xyz[0] : 0.0f, + xyz.size() > 1 ? xyz[1] : 0.0f, + xyz.size() > 2 ? xyz[2] : 0.0f); + // CACHE(IfcDirection,l,dir) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcVector* l, cgal_vector_t& v) { + // IN_CACHE(IfcVector,l,cgal_vector_t,v) + cgal_direction_t d; + IfcGeom::CgalKernel::convert(l->Orientation(),d); + v = l->Magnitude() * getValue(GV_LENGTH_UNIT) * d; + // CACHE(IfcVector,l,v) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcPlane* pln, cgal_plane_t& plane) { + // IN_CACHE(IfcPlane,pln,gp_Pln,plane) + IfcSchema::IfcAxis2Placement3D* l = pln->Position(); + cgal_point_t o; + cgal_direction_t axis = Kernel::Vector_3(0,0,1); + cgal_direction_t refDirection = Kernel::Vector_3(1,0,0); + IfcGeom::CgalKernel::convert(l->Location(),o); + bool hasRef = l->hasRefDirection(); + if ( l->hasAxis() ) IfcGeom::CgalKernel::convert(l->Axis(),axis); + if ( hasRef ) IfcGeom::CgalKernel::convert(l->RefDirection(),refDirection); + Kernel::Vector_3 y = CGAL::cross_product(axis, refDirection); + Kernel::Vector_3 x = CGAL::cross_product(y, axis); + + cgal_plane_t ax3; + if ( hasRef ) ax3 = Kernel::Plane_3(o,o+x,o+y); + else ax3 = Kernel::Plane_3(o,axis); + plane = ax3; + + // std::cout << "IfcPlane C = " << o << std::endl; + // std::cout << "IfcPlane z (axis, exact) = " << axis << std::endl; + // std::cout << "IfcPlane x (refDirection, approximate) = " << refDirection << std::endl; + // std::cout << "IfcPlane y (computed, exact) = " << y << std::endl; + // std::cout << "IfcPlane x (computed, exact) = " << x << std::endl; + // + // std::cout << "Plane_3 o = " << o << std::endl; + // std::cout << "Plane_3 o+x = " << o+x << std::endl; + // std::cout << "Plane_3 o+y = " << o+y << std::endl; + + // ax + by + cz + d = 0 + // std::cout << "Plane: a = " << plane.a() << ", b = " << plane.b() << ", c = " << plane.c() << ", d = " << plane.d() << std::endl; + + // std::ofstream fresult; + // fresult.open("/Users/ken/Desktop/plane.obj"); + // // x = -5, y = -5, z = (5a +5b -d)/c + // fresult << "v -5 -5 " << (5.0*CGAL::to_double(plane.a())+5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; + // // x = -5, y = +5, z = (5a -5b -d)/c + // fresult << "v -5 5 " << (5.0*CGAL::to_double(plane.a())-5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; + // // x = 5, y = -5, z = (-5a +5b -d)/c + // fresult << "v 5 -5 " << (-5.0*CGAL::to_double(plane.a())+5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; + // // x = 5, y = +5, z = (-5a -5b -d)/c + // fresult << "v 5 5 " << (-5.0*CGAL::to_double(plane.a())-5.0*CGAL::to_double(plane.b())-CGAL::to_double(plane.d()))/CGAL::to_double(plane.c()) << std::endl; + // fresult << "f 1 2 3" << std::endl; + // fresult << "f 4 3 2" << std::endl; + // fresult.close(); + + // CACHE(IfcPlane,pln,plane) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcAxis2Placement2D* l, cgal_placement_t& trsf) { + // IN_CACHE(IfcAxis2Placement3D,l,gp_Trsf,trsf) + cgal_point_t o; + cgal_direction_t refDirection = Kernel::Vector_3(1,0,0); + IfcGeom::CgalKernel::convert(l->Location(),o); + bool hasRef = l->hasRefDirection(); + if ( hasRef ) IfcGeom::CgalKernel::convert(l->RefDirection(),refDirection); + cgal_direction_t y = Kernel::Vector_3(-refDirection.y(), refDirection.x(), 0.0); + + // TODO: Should be checked. + trsf = Kernel::Aff_transformation_3(refDirection.cartesian(0), y.cartesian(0), 0.0, o.cartesian(0), + refDirection.cartesian(1), y.cartesian(1), 0.0, o.cartesian(1), + 0.0, 0.0, 1.0, 0.0); + + // CACHE(IfcAxis2Placement3D,l,trsf) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcAxis2Placement3D* l, cgal_placement_t& trsf) { + // IN_CACHE(IfcAxis2Placement3D,l,gp_Trsf,trsf) + cgal_point_t o; + cgal_direction_t axis = Kernel::Vector_3(0,0,1); + cgal_direction_t refDirection = Kernel::Vector_3(1,0,0); + IfcGeom::CgalKernel::convert(l->Location(),o); + bool hasRef = l->hasRefDirection(); + if ( l->hasAxis() ) IfcGeom::CgalKernel::convert(l->Axis(),axis); + if ( hasRef ) IfcGeom::CgalKernel::convert(l->RefDirection(),refDirection); + Kernel::Vector_3 y = CGAL::cross_product(axis, refDirection); + Kernel::Vector_3 x = CGAL::cross_product(y, axis); + + // std::cout << "Ref direction: " << refDirection << std::endl; + // std::cout << "Axis: " << axis << std::endl; + // std::cout << "Origin: " << o << std::endl; + + // TODO: Should be checked. + trsf = Kernel::Aff_transformation_3(x.cartesian(0), y.cartesian(0), axis.cartesian(0), o.cartesian(0), + x.cartesian(1), y.cartesian(1), axis.cartesian(1), o.cartesian(1), + x.cartesian(2), y.cartesian(2), axis.cartesian(2), o.cartesian(2)); + + // for (int i = 0; i < 3; ++i) { + // for (int j = 0; j < 4; ++j) { + // std::cout << trsf.cartesian(i, j) << " "; + // } std::cout << std::endl; + // } + + // CACHE(IfcAxis2Placement3D,l,trsf) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcObjectPlacement* l, cgal_placement_t& trsf) { + // TODO: These macros don't work for the CGAL types. Need to check why. + // IN_CACHE(IfcObjectPlacement,l,cgal_placement_t,trsf) + if ( ! l->is(IfcSchema::Type::IfcLocalPlacement) ) { + Logger::Message(Logger::LOG_ERROR, "Unsupported IfcObjectPlacement:", l->entity); + return false; + } + + // std::cout << "initial trsf (identity?)" << std::endl; + // for (int i = 0; i < 3; ++i) { + // for (int j = 0; j < 4; ++j) { + // std::cout << trsf.cartesian(i, j) << " "; + // } std::cout << std::endl; + // } + + IfcSchema::IfcLocalPlacement* current = (IfcSchema::IfcLocalPlacement*)l; + for (;;) { + cgal_placement_t trsf2; + + IfcSchema::IfcAxis2Placement* relplacement = current->RelativePlacement(); + if ( relplacement->is(IfcSchema::Type::IfcAxis2Placement3D) ) { + IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement3D*)relplacement,trsf2); + + // std::cout << "trsf2" << std::endl; + // for (int i = 0; i < 3; ++i) { + // for (int j = 0; j < 4; ++j) { + // std::cout << trsf2.cartesian(i, j) << " "; + // } std::cout << std::endl; + // } + + trsf = trsf * trsf2; // TODO: I think it's fine, but maybe should it be the other way around? + + // std::cout << "trsf (after multiplication)" << std::endl; + // for (int i = 0; i < 3; ++i) { + // for (int j = 0; j < 4; ++j) { + // std::cout << trsf.cartesian(i, j) << " "; + // } std::cout << std::endl; + // } + } + if ( current->hasPlacementRelTo() ) { + IfcSchema::IfcObjectPlacement* relto = current->PlacementRelTo(); + if ( relto->is(IfcSchema::Type::IfcLocalPlacement) ) + current = (IfcSchema::IfcLocalPlacement*)current->PlacementRelTo(); + else break; + } else break; + } + // CACHE(IfcObjectPlacement,l,trsf) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator2D* l, cgal_placement_t& trsf) { + // IN_CACHE(IfcCartesianTransformationOperator2D,l,cgal_placement_t,trsf) + + cgal_point_t origin; + cgal_direction_t axis1 (1.,0.,0.); + cgal_direction_t axis2 (0.,1.,0.); + + IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); + if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); + if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); + double scale = 1.0; + if (l->hasScale()) { + scale = l->Scale(); + } + + // TODO: Untested + trsf = Kernel::Aff_transformation_3(scale*axis1.cartesian(0), axis2.cartesian(0), 0.0, origin.cartesian(0), + axis1.cartesian(1), scale*axis2.cartesian(1), 0.0, origin.cartesian(1), + 0.0, 0.0, 1.0, 0.0); + + // CACHE(IfcCartesianTransformationOperator2D,l,trsf) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator2DnonUniform* l, cgal_placement_t& gtrsf) { + // IN_CACHE(IfcCartesianTransformationOperator2DnonUniform,l,cgal_placement_t,gtrsf) + + cgal_placement_t trsf; + cgal_point_t origin; + cgal_direction_t axis1 (1.,0.,0.); + cgal_direction_t axis2 (0.,1.,0.); + + IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); + if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); + if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); + + const double scale1 = l->hasScale() ? l->Scale() : 1.0f; + const double scale2 = l->hasScale2() ? l->Scale2() : scale1; + + // TODO: Untested + trsf = Kernel::Aff_transformation_3(scale1*axis1.cartesian(0), axis2.cartesian(0), 0.0, origin.cartesian(0), + axis1.cartesian(1), scale2*axis2.cartesian(1), 0.0, origin.cartesian(1), + 0.0, 0.0, 1.0, 0.0); + + // CACHE(IfcCartesianTransformationOperator2DnonUniform,l,gtrsf) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator3D* l, cgal_placement_t& trsf) { + // IN_CACHE(IfcCartesianTransformationOperator3D,l,gp_Trsf,trsf) + cgal_point_t origin; + IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); + cgal_direction_t axis1 (1.,0.,0.); + cgal_direction_t axis2 (0.,1.,0.); + cgal_direction_t axis3 (0.,0.,1.); + if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); + if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); + if ( l->hasAxis3() ) IfcGeom::CgalKernel::convert(l->Axis3(),axis3); + double scale = 1.0; + if (l->hasScale()) { + scale = l->Scale(); + } + + // TODO: Untested + trsf = Kernel::Aff_transformation_3(scale*axis1.cartesian(0), axis2.cartesian(0), axis3.cartesian(0), origin.cartesian(0), + axis1.cartesian(1), scale*axis2.cartesian(1), axis3.cartesian(1), origin.cartesian(1), + axis1.cartesian(2), axis2.cartesian(2), scale*axis3.cartesian(2), origin.cartesian(2)); + + // std::cout << std::endl; + // for (int i = 0; i < 3; ++i) { + // for (int j = 0; j < 4; ++j) { + // std::cout << trsf.cartesian(i, j) << " "; + // } std::cout << std::endl; + // } + + // CACHE(IfcCartesianTransformationOperator3D,l,trsf) + return true; +} + +bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianTransformationOperator3DnonUniform* l, cgal_placement_t& gtrsf) { + // IN_CACHE(IfcCartesianTransformationOperator3DnonUniform,l,gp_GTrsf,gtrsf) + cgal_point_t origin; + IfcGeom::CgalKernel::convert(l->LocalOrigin(),origin); + cgal_direction_t axis1 (1.,0.,0.); + cgal_direction_t axis2 (0.,1.,0.); + cgal_direction_t axis3 (0.,0.,1.); + if ( l->hasAxis1() ) IfcGeom::CgalKernel::convert(l->Axis1(),axis1); + if ( l->hasAxis2() ) IfcGeom::CgalKernel::convert(l->Axis2(),axis2); + if ( l->hasAxis3() ) IfcGeom::CgalKernel::convert(l->Axis3(),axis3); + const double scale1 = l->hasScale() ? l->Scale() : 1.0f; + const double scale2 = l->hasScale2() ? l->Scale2() : scale1; + const double scale3 = l->hasScale3() ? l->Scale3() : scale1; + + // TODO: Untested + gtrsf = Kernel::Aff_transformation_3(scale1*axis1.cartesian(0), axis2.cartesian(0), axis3.cartesian(0), origin.cartesian(0), + axis1.cartesian(1), scale2*axis2.cartesian(1), axis3.cartesian(1), origin.cartesian(1), + axis1.cartesian(2), axis2.cartesian(2), scale3*axis3.cartesian(2), origin.cartesian(2)); + + // for (int i = 0; i < 3; ++i) { + // for (int j = 0; j < 4; ++j) { + // std::cout << gtrsf.cartesian(i, j) << " "; + // } std::cout << std::endl; + // } + + // CACHE(IfcCartesianTransformationOperator3DnonUniform,l,gtrsf) + return true; +} From 4061f93560ab90d93db17d5ec49c339490bb7277 Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 20 Mar 2017 20:57:17 -0600 Subject: [PATCH 6/6] Export non-simple Nef too --- .../kernels/cgal/CgalConversionFunctions.cpp | 16 +++++++-- .../kernels/cgal/CgalConversionResult.cpp | 34 +++++++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp index 818ee56f47..6d69e9c384 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionFunctions.cpp @@ -41,13 +41,23 @@ CGAL::Nef_polyhedron_3 IfcGeom::CgalKernel::create_nef_polyhedron(std::l // fresult.close(); return CGAL::Nef_polyhedron_3(); } if (!polyhedron.is_closed()) { - std::cout << "create_nef_polyhedron: Polyhedron not closed" << std::endl; // std::ofstream fresult; // fresult.open("/Users/ken/Desktop/open.off"); // fresult << polyhedron << std::endl; // fresult.close(); - // TODO: Nef constructor doesn't support open meshes - return CGAL::Nef_polyhedron_3(polyhedron); + CGAL::Nef_polyhedron_3 mesh; + unsigned int current_face = 0; + for (auto &face: faces(polyhedron)) { + ++current_face; +// if (current_face%10 == 0) std::cout << current_face << "/" << polyhedron.size_of_facets() << std::endl; + std::list points_in_face; + CGAL::Polyhedron_3::Halfedge_around_facet_const_circulator current_halfedge = face->facet_begin(); + do { + points_in_face.push_back(current_halfedge->vertex()->point()); + ++current_halfedge; + } while (current_halfedge != face->facet_begin()); + mesh += CGAL::Nef_polyhedron_3(points_in_face.begin(), points_in_face.end()); + } return mesh; } if (!CGAL::Polygon_mesh_processing::is_outward_oriented(polyhedron)) { CGAL::Polygon_mesh_processing::reverse_face_orientations(polyhedron); diff --git a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp index 171b7ee2e8..93abf453b4 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp @@ -4,11 +4,39 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const { cgal_shape_t s = shape_; const cgal_placement_t& trsf = dynamic_cast(place)->trsf(); -// std::cout << "Model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl; -// std::cout << "Valid: " << s.is_valid() << std::endl; + + std::cout << "Nef Model: " << s.number_of_facets() << " facets and " << s.number_of_vertices() << " vertices" << std::endl; + std::cout << "Simple: " << s.is_simple() << std::endl; CGAL::Polyhedron_3 polyhedron; - s.convert_to_polyhedron(polyhedron); + if (s.is_simple()) s.convert_to_polyhedron(polyhedron); + else { + std::list face_list; + face_list.push_back(cgal_face_t()); + std::set::Halffacet_const_handle> visited_halffacets; + for (CGAL::Nef_polyhedron_3::Halffacet_const_iterator current_halffacet = s.halffacets_begin(); + current_halffacet != s.halffacets_end(); + ++current_halffacet) { + if (visited_halffacets.count(current_halffacet->twin())) continue; + for (CGAL::Nef_polyhedron_3::Halffacet_cycle_const_iterator current_halffacet_cycle = current_halffacet->facet_cycles_begin(); + current_halffacet_cycle != current_halffacet->facet_cycles_end(); + ++current_halffacet_cycle) { + if (current_halffacet_cycle.is_shalfloop()) continue; + CGAL::Nef_polyhedron_3::SHalfedge_const_handle first_shalfedge = current_halffacet_cycle; + CGAL::Nef_polyhedron_3::SHalfedge_const_handle current_shalfedge = first_shalfedge; + if (!face_list.back().outer.empty()) face_list.push_back(cgal_face_t()); + do { + face_list.back().outer.push_back(current_shalfedge->source()->center_vertex()->point()); + current_shalfedge = current_shalfedge->next(); + } while (current_shalfedge != first_shalfedge); + } + } if (face_list.back().outer.empty()) face_list.pop_back(); + PolyhedronBuilder builder(&face_list); + polyhedron.delegate(builder); + } + + std::cout << "Polyhedron Model: " << polyhedron.size_of_facets() << " facets and " << polyhedron.size_of_vertices() << " vertices" << std::endl; + std::cout << "Valid: " << polyhedron.is_valid() << std::endl; // Apply transformation if (place != NULL) for (auto &vertex: vertices(polyhedron)) {