Merge commit '6b47e9ca1d18df4b1cd2c66e488ad91f9730ecdf' into v0.7.0

# Conflicts:
#	cmake/CMakeLists.txt
#	nix/build-all.py
#	test/input
This commit is contained in:
Thomas Krijnen
2019-01-22 13:00:49 +01:00
7 changed files with 511 additions and 20 deletions
@@ -2,7 +2,47 @@
template <typename Precision>
void triangulate_helper(const cgal_shape_t, const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<Precision>* t, int surface_style_id) {
throw std::runtime_error("Not implemented Triangulate()");
cgal_shape_t s = shape_;
const cgal_placement_t& trsf = dynamic_cast<const CgalPlacement*>(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;
// Apply transformation
if (place != NULL) for (auto &vertex: vertices(s)) {
vertex->point() = vertex->point().transform(trsf);
}
// Triangulate the shape and compute the normals
std::map<cgal_vertex_descriptor_t, Kernel::Vector_3> vertex_normals;
boost::associative_property_map<std::map<cgal_vertex_descriptor_t, Kernel::Vector_3>> vertex_normals_map(vertex_normals);
std::map<cgal_face_descriptor_t, Kernel::Vector_3> face_normals;
boost::associative_property_map<std::map<cgal_face_descriptor_t, Kernel::Vector_3>> face_normals_map(face_normals);
if (CGAL::Polygon_mesh_processing::triangulate_faces(s)) {
// std::cout << "Triangulated model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
} else {
Logger::Message(Logger::LOG_ERROR, "Failed to triangulate shape");
return;
}
CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
// Iterates over the faces of the shape
int num_faces = 0, num_vertices = 0;
for (auto &face: faces(s)) {
CGAL::Polyhedron_3<Kernel>::Halfedge_around_facet_const_circulator current_halfedge = face->facet_begin();
do {
t->addVertex(surface_style_id,
CGAL::to_double(current_halfedge->vertex()->point().cartesian(0)),
CGAL::to_double(current_halfedge->vertex()->point().cartesian(1)),
CGAL::to_double(current_halfedge->vertex()->point().cartesian(2)));
for (int i = 0; i < 3; ++i) t->normals().push_back(CGAL::to_double(face_normals_map[face].cartesian(i)));
t->faces().push_back(num_vertices);
++num_vertices;
++current_halfedge;
} while (current_halfedge != face->facet_begin());
t->material_ids().push_back(surface_style_id);
++num_faces;
}
}
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<float>* t, int surface_style_id) const {
@@ -20,12 +20,31 @@
#ifndef CGALCONVERSIONRESULT_H
#define CGALCONVERSIONRESULT_H
typedef void* cgal_shape_t;
typedef void* cgal_face_t;
typedef void* cgal_wire_t;
typedef void* cgal_curve_t;
typedef void* cgal_placement_t;
typedef void* cgal_point_t;
#include <boost/property_map/property_map.hpp>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/Polygon_mesh_processing/stitch_borders.h>
#include <CGAL/Polygon_mesh_processing/orientation.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Aff_transformation_3 cgal_placement_t;
typedef Kernel::Point_3 cgal_point_t;
typedef Kernel::Vector_3 cgal_direction_t;
typedef std::vector<Kernel::Point_3> cgal_curve_t;
typedef std::vector<Kernel::Point_3> cgal_wire_t;
struct cgal_face_t {
cgal_wire_t outer;
std::vector<cgal_wire_t> inner;
};
typedef CGAL::Polyhedron_3<Kernel> cgal_shape_t;
typedef boost::graph_traits<CGAL::Polyhedron_3<Kernel>>::vertex_descriptor cgal_vertex_descriptor_t;
typedef boost::graph_traits<CGAL::Polyhedron_3<Kernel>>::face_descriptor cgal_face_descriptor_t;
#include "../../../ifcgeom/schema_agnostic/ConversionResult.h"
@@ -41,18 +60,19 @@ namespace IfcGeom {
operator const cgal_placement_t& () { return trsf_; }
virtual double Value(int i, int j) const {
// Get cell from placement as 4x3 matrix as implemented in OCCT. We'll have to check exact semantics.
throw std::runtime_error("Not implemented");
// TODO: Check
// std::cout << "Getting CgalPlacement with i = " << i << " and j = " << j << std::endl;
return CGAL::to_double(trsf_.cartesian(i-1, j-1));
}
virtual void Multiply(const ConversionResultPlacement* other) {
// Multiply matrix as implemented in OCCT. We'll have to check exact semantics.
throw std::runtime_error("Not implemented");
// TODO: Check
trsf_ = ((CgalPlacement *)other)->trsf_ * trsf_;
}
virtual void PreMultiply(const ConversionResultPlacement* other) {
// PreMultiply matrix as implemented in OCCT. We'll have to check exact semantics.
throw std::runtime_error("Not implemented");
// TODO: Check
trsf_ = trsf_ * ((CgalPlacement *)other)->trsf_;
}
virtual ConversionResultPlacement* clone() const {
@@ -73,7 +93,7 @@ namespace IfcGeom {
private:
cgal_placement_t trsf_;
};
class CgalShape : public ConversionResultShape {
public:
CgalShape(const cgal_shape_t& shape)
@@ -104,4 +124,4 @@ namespace IfcGeom {
}
#endif
#endif