diff --git a/packages/cgal.cmake b/packages/cgal.cmake index d8cced647..aa20fb364 100644 --- a/packages/cgal.cmake +++ b/packages/cgal.cmake @@ -1,56 +1,57 @@ #=============================================================================== # @file cgal.cmake # # @author Lucas Frérot # # @date creation: Thu Feb 19 2015 # @date last modification: Mon Mar 2 2015 # # @brief package description for CGAL # # @section LICENSE # # Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== package_declare(CGAL EXTERNAL DESCRIPTION "Add CGAL support in akantu" COMPILE_FLAGS "-frounding-math" ) package_declare_sources(CGAL geometry/mesh_geom_abstract.hh geometry/mesh_geom_abstract.cc geometry/mesh_geom_factory.hh geometry/mesh_geom_factory_tmpl.hh geometry/mesh_geom_container.hh geometry/mesh_geom_container.cc geometry/tree_type_helper.hh geometry/aabb_primitives/triangle.hh geometry/aabb_primitives/triangle_tmpl.hh geometry/aabb_primitives/triangle_primitive.hh geometry/aabb_primitives/triangle_primitive.cc + geometry/geom_helper_functions.hh ) package_boost_component_needed(system) ## Adding CGAL library #find_package(CGAL COMPONENTS Core) #if (NOT CGAL_FOUND) #message(STATUS "This project requires the CGAL library, and will not be compiled.") #return() #endif() diff --git a/src/geometry/mesh_geom_abstract.hh b/src/geometry/geom_helper_functions.hh similarity index 53% copy from src/geometry/mesh_geom_abstract.hh copy to src/geometry/geom_helper_functions.hh index 5a0443e6f..f7f04675a 100644 --- a/src/geometry/mesh_geom_abstract.hh +++ b/src/geometry/geom_helper_functions.hh @@ -1,70 +1,65 @@ /** - * @file mesh_geom_abstract.hh + * @file geom_helper_functions.hh * * @author Lucas Frérot * - * @date creation: Thu Feb 26 2015 - * @date last modification: Thu Feb 26 2015 + * @date creation: Wed Mar 4 2015 + * @date last modification: Thu Mar 5 2015 * - * @brief Class for constructing the CGAL primitives of a mesh + * @brief Helper functions for the computational geometry algorithms * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ -#ifndef __AKANTU_MESH_GEOM_ABSTRACT_HH__ -#define __AKANTU_MESH_GEOM_ABSTRACT_HH__ +#ifndef _AKANTU_GEOM_HELPER_FUNCTIONS_HH__ +#define _AKANTU_GEOM_HELPER_FUNCTIONS_HH__ #include "aka_common.hh" -#include "mesh.hh" #include -/* -------------------------------------------------------------------------- */ - __BEGIN_AKANTU__ typedef CGAL::Cartesian K; -class MeshGeomAbstract { - -public: - /// Construct from mesh - explicit MeshGeomAbstract(const Mesh & mesh); +#define EPS 1e-10 - /// Destructor - virtual ~MeshGeomAbstract(); +inline bool comparePoints(const K::Point_3 & a, const K::Point_3 & b) { + Math::setTolerance(EPS); + return Math::are_float_equal(a.x(), b.x()) && Math::are_float_equal(a.y(), b.y()); +} -public: - /// Construct geometric data for computational geometry algorithms - virtual void constructData() = 0; +inline bool compareSegments(const K::Segment_3 & a, const K::Segment_3 & b) { + Math::setTolerance(EPS); + return (comparePoints(a.source(), b.source()) && comparePoints(a.target(), b.target())) || + (comparePoints(a.source(), b.target()) && comparePoints(a.target(), b.source())); +} - /// Compute number of intersections with geometric interface - virtual UInt numberOfIntersectionsWithInterface(const K::Segment_3 & interface) const = 0; - -protected: - /// Mesh used to construct the primitives - const Mesh & mesh; +struct CompareSegmentPairs { + bool operator()(const std::pair & a, const std::pair & b) { + return compareSegments(a.first, b.first); + } }; - __END_AKANTU__ -#endif // __AKANTU_MESH_GEOM_ABSTRACT_HH__ +#endif // _AKANTU_GEOM_HELPER_FUNCTIONS_HH__ + diff --git a/src/geometry/mesh_geom_abstract.hh b/src/geometry/mesh_geom_abstract.hh index 5a0443e6f..f341267d5 100644 --- a/src/geometry/mesh_geom_abstract.hh +++ b/src/geometry/mesh_geom_abstract.hh @@ -1,70 +1,73 @@ /** * @file mesh_geom_abstract.hh * * @author Lucas Frérot * * @date creation: Thu Feb 26 2015 - * @date last modification: Thu Feb 26 2015 + * @date last modification: Thu Mar 5 2015 * * @brief Class for constructing the CGAL primitives of a mesh * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_MESH_GEOM_ABSTRACT_HH__ #define __AKANTU_MESH_GEOM_ABSTRACT_HH__ #include "aka_common.hh" #include "mesh.hh" #include /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ typedef CGAL::Cartesian K; class MeshGeomAbstract { public: /// Construct from mesh explicit MeshGeomAbstract(const Mesh & mesh); /// Destructor virtual ~MeshGeomAbstract(); public: /// Construct geometric data for computational geometry algorithms virtual void constructData() = 0; /// Compute number of intersections with geometric interface virtual UInt numberOfIntersectionsWithInterface(const K::Segment_3 & interface) const = 0; + /// Compute the mesh created by a linear interface + virtual Mesh * computeIntersectionWithLinearInterface(const K::Segment_3 & interface) = 0; + protected: /// Mesh used to construct the primitives const Mesh & mesh; }; __END_AKANTU__ #endif // __AKANTU_MESH_GEOM_ABSTRACT_HH__ diff --git a/src/geometry/mesh_geom_container.cc b/src/geometry/mesh_geom_container.cc index 76b351f35..9a9d47ff9 100644 --- a/src/geometry/mesh_geom_container.cc +++ b/src/geometry/mesh_geom_container.cc @@ -1,124 +1,128 @@ /** * @file mesh_geom_container.cc * * @author Lucas Frérot * * @date creation: Fri Feb 27 2015 - * @date last modification: Mon Mar 2 2015 + * @date last modification: Thu Mar 5 2015 * * @brief Contains the CGAL representation of a mesh * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "mesh_geom_container.hh" #include "mesh_geom_factory.hh" #include "mesh.hh" #include __BEGIN_AKANTU__ typedef CGAL::Cartesian K; MeshGeomContainer::MeshGeomContainer(const Mesh & mesh): MeshGeomAbstract(mesh) {} MeshGeomContainer::~MeshGeomContainer() { GeomMap::type_iterator it, end; it = constructor_map.firstType(); end = constructor_map.lastType(); for (; it != end ; it++) { MeshGeomAbstract * p = constructor_map(*it); if (p) { delete p; } } } void MeshGeomContainer::constructData() { const UInt spatial_dim = mesh.getSpatialDimension(); Mesh::type_iterator it = mesh.firstType(spatial_dim, _not_ghost); Mesh::type_iterator end = mesh.lastType(spatial_dim, _not_ghost); /// Loop over the element types of the mesh and construct the primitive trees for (; it != end ; ++it) { switch(spatial_dim) { case 1: AKANTU_DEBUG_WARNING("Geometry in 1D is undefined"); break; case 2: switch(*it) { case _triangle_3: { MeshGeomFactory<2, _triangle_3> * factory = new MeshGeomFactory<2, _triangle_3>(mesh); constructor_map(factory, _triangle_3); factory->constructData(); break; } /// Need to implement these cases when needed case _not_defined: case _point_1: case _segment_2: case _segment_3: case _triangle_6: // 2nd order element : harder to implement (cf Gomes & Awruch 2001) case _tetrahedron_4: // needs implementing case _tetrahedron_10: case _quadrangle_4: // may need implementing case _quadrangle_8: // 2nd order element : harder to implement (cf Gomes & Awruch 2001) case _hexahedron_8: // may need implementing case _pentahedron_6: case _max_element_type: break; } break; case 3: break; } } } UInt MeshGeomContainer::numberOfIntersectionsWithInterface(const K::Segment_3 & interface) const { UInt total = 0; GeomMap::type_iterator it = constructor_map.firstType(); GeomMap::type_iterator end = constructor_map.lastType(); for (; it != end ; ++it) { total += constructor_map(*it)->numberOfIntersectionsWithInterface(interface); } return total; } +Mesh * MeshGeomContainer::computeIntersectionWithLinearInterface(const K::Segment_3 & interface) { + return NULL; +} + const MeshGeomAbstract * MeshGeomContainer::getFactoryForElementType(ElementType el_type) const { return constructor_map(el_type); } __END_AKANTU__ diff --git a/src/geometry/mesh_geom_container.hh b/src/geometry/mesh_geom_container.hh index b5eb1a71d..b512aa562 100644 --- a/src/geometry/mesh_geom_container.hh +++ b/src/geometry/mesh_geom_container.hh @@ -1,74 +1,76 @@ /** * @file mesh_geom_container.hh * * @author Lucas Frérot * * @date creation: Fri Feb 27 2015 - * @date last modification: Mon Mar 2 2015 + * @date last modification: Thu Mar 5 2015 * * @brief Contains the CGAL representation of a mesh * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_MESH_GEOM_CONTAINER__ #define __AKANTU_MESH_GEOM_CONTAINER__ #include "aka_common.hh" #include "mesh.hh" #include "mesh_geom_abstract.hh" #include /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ typedef CGAL::Cartesian K; class MeshGeomContainer : MeshGeomAbstract { typedef ElementTypeMap GeomMap; public: /// Construct from mesh explicit MeshGeomContainer(const Mesh & mesh); /// Destructor virtual ~MeshGeomContainer(); public: /// Constructs the geometric data from the mesh virtual void constructData(); /// Compute the number of intersections with geometric interface virtual UInt numberOfIntersectionsWithInterface(const K::Segment_3 & interface) const; + virtual Mesh * computeIntersectionWithLinearInterface(const K::Segment_3 & interface); + /// Get the factory object for an element type const MeshGeomAbstract * getFactoryForElementType(ElementType el_type) const; protected: GeomMap constructor_map; }; __END_AKANTU__ #endif // __AKANTU_MESH_GEOM_CONTAINER__ diff --git a/src/geometry/mesh_geom_factory.hh b/src/geometry/mesh_geom_factory.hh index cfecdfe2b..df0bd73ce 100644 --- a/src/geometry/mesh_geom_factory.hh +++ b/src/geometry/mesh_geom_factory.hh @@ -1,77 +1,88 @@ /** * @file mesh_geom_factory.hh * * @author Lucas Frérot * * @date creation: Thu Feb 26 2015 - * @date last modification: Mon Mar 2 2015 + * @date last modification: Thu Mar 5 2015 * * @brief Class for constructing the CGAL primitives of a mesh * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_MESH_GEOM_FACTORY_HH__ #define __AKANTU_MESH_GEOM_FACTORY_HH__ #include "aka_common.hh" #include "mesh.hh" #include "mesh_geom_abstract.hh" #include "tree_type_helper.hh" #include /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ typedef CGAL::Cartesian K; template class MeshGeomFactory : public MeshGeomAbstract { public: /// Construct from mesh explicit MeshGeomFactory(const Mesh & mesh); /// Desctructor virtual ~MeshGeomFactory(); public: /// Construct AABB tree for fast intersection computing virtual void constructData(); /// Compute the number of intersections with primitive virtual UInt numberOfIntersectionsWithInterface(const K::Segment_3 & interface) const; + /// Create a mesh of the intersection with a linear interface + virtual Mesh * computeIntersectionWithLinearInterface(const K::Segment_3 & interface); + + /// Construct segment list from intersections and remove duplicates + void constructSegments(const std::list::linear_intersection> & intersections, + std::list< std::pair > & segments); + const typename TreeTypeHelper::tree & getTree() const { return *data_tree; } protected: typename TreeTypeHelper::tree * data_tree; typename TreeTypeHelper::container_type primitive_list; + + Array * nodes; + Array * associated_id; + Array * associated_type; }; __END_AKANTU__ #include "mesh_geom_factory_tmpl.hh" #endif // __AKANTU_MESH_GEOM_FACTORY_HH__ diff --git a/src/geometry/mesh_geom_factory_tmpl.hh b/src/geometry/mesh_geom_factory_tmpl.hh index 065446106..cc044727e 100644 --- a/src/geometry/mesh_geom_factory_tmpl.hh +++ b/src/geometry/mesh_geom_factory_tmpl.hh @@ -1,121 +1,216 @@ /** * @file mesh_geom_factory_tmpl.hh * * @author Lucas Frérot * * @date creation: Thu Feb 26 2015 - * @date last modification: Mon Mar 2 2015 + * @date last modification: Thu Mar 5 2015 * * @brief Class for constructing the CGAL primitives of a mesh * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef _AKANTU_MESH_GEOM_FACTORY_TMPL_HH__ #define _AKANTU_MESH_GEOM_FACTORY_TMPL_HH__ #include "mesh_geom_factory.hh" #include "aka_common.hh" #include "tree_type_helper.hh" #include "triangle.hh" +#include "geom_helper_functions.hh" #include /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ typedef CGAL::Cartesian K; template MeshGeomFactory::MeshGeomFactory(const Mesh & mesh) : MeshGeomAbstract(mesh), data_tree(NULL), - primitive_list() + primitive_list(), + nodes(NULL), + associated_id(NULL), + associated_type(NULL) {} template MeshGeomFactory::~MeshGeomFactory() { delete data_tree; + delete nodes; + delete associated_id; + delete associated_type; } +// Need to implement this method for every case needed template<> void MeshGeomFactory<2, _triangle_3>::constructData() { /// Variable declaration instead of template arguments const UInt d = 2; const ElementType type = _triangle_3; const GhostType ghost_type = _not_ghost; primitive_list.clear(); UInt nb_nodes_per_element = mesh.getNbNodesPerElement(type); const Array & connectivity = mesh.getConnectivity(type, ghost_type); const Array & nodes = mesh.getNodes(); Array::const_vector_iterator begin = connectivity.begin(nb_nodes_per_element); Array::const_vector_iterator it = connectivity.begin(nb_nodes_per_element); Array::const_vector_iterator end = connectivity.end(nb_nodes_per_element); /// This loop builds the list of triangle primitives for (; it != end ; ++it) { const Vector & el_connectivity = *it; Matrix node_coordinates(d, nb_nodes_per_element); for (UInt i = 0 ; i < nb_nodes_per_element ; i++) for (UInt j = 0 ; j < d ; j++) node_coordinates(j, i) = nodes(el_connectivity(i), j); /// There's a problem here with constructors : /// - 2D constructors take 2 arguments /// - 3D constructors take 3 arguments /// Need for a solution that can treat the two cases together TreeTypeHelper::point_type a(node_coordinates(0, 0), node_coordinates(1, 0), 0.); TreeTypeHelper::point_type b(node_coordinates(0, 1), node_coordinates(1, 1), 0.); TreeTypeHelper::point_type c(node_coordinates(0, 2), node_coordinates(1, 2), 0.); /// Number of arguments here should not be a problem with polygon/polyhedra /// Also it is possible to create tree or lists from polyhedric surfaces Triangle t(a, b, c); - //TreeTypeHelper::primitive_type t(a, b, c); - UInt id = it - begin; - t.setId(id); + t.setId(it - begin); primitive_list.push_back(t); } /// Construct the tree if (data_tree) { delete data_tree; data_tree = NULL; } data_tree = new TreeTypeHelper::tree(primitive_list.begin(), primitive_list.end()); } template UInt MeshGeomFactory::numberOfIntersectionsWithInterface(const K::Segment_3 & interface) const { return data_tree->number_of_intersected_primitives(interface); } +template +Mesh * MeshGeomFactory::computeIntersectionWithLinearInterface(const K::Segment_3 & interface) { + UInt number_of_intersections = this->numberOfIntersectionsWithInterface(interface); + + if (!number_of_intersections) + return NULL; + + std::list::linear_intersection> list_of_intersections; + std::list< std::pair > list_of_segments; // Contains no duplicate elements + + data_tree->all_intersections(interface, std::back_inserter(list_of_intersections)); + this->constructSegments(list_of_intersections, list_of_segments); + + if (nodes) { + delete nodes; + nodes = NULL; + } + + nodes = new Array(2 * list_of_segments.size(), d); + Array connectivity(list_of_segments.size(), 2); + + std::list< std::pair >::iterator it = list_of_segments.begin(); + std::list< std::pair >::iterator end = list_of_segments.end(); + + Array::vector_iterator nodes_it = nodes->begin(d); + Array::vector_iterator connectivity_it = connectivity.begin(2); + + for (; it != end ; ++it, nodes_it += 2, ++connectivity_it) { + UInt node_id = nodes_it - nodes->begin(d); + (*connectivity_it)(0) = node_id; + (*connectivity_it)(1) = node_id + 1; + + for (UInt j = 0 ; j < d ; j++) { + (*nodes_it)(j) = it->first.source()[j]; + (*(nodes_it + 1))(j) = it->first.target()[j]; + } + } + + Mesh * mesh = new Mesh(d, *nodes, "interface_mesh"); + mesh->addConnectivityType(_segment_2); + mesh->getConnectivity(_segment_2).copy(connectivity); + + if (associated_id) { + delete associated_id; + associated_id = NULL; + } + + if (associated_type) { + delete associated_type; + associated_type = NULL; + } + + associated_id = new Array(mesh->getNbElement(_segment_2), 1, (UInt) 0); + associated_type = new Array(mesh->getNbElement(_segment_2)); + + Array::scalar_iterator associated_id_it = associated_id->begin(); + Array::scalar_iterator associated_type_it = associated_type->begin(); + + it = list_of_segments.begin(); + + for (; it != end ; ++it, ++associated_id_it, ++associated_type_it) { + *associated_id_it = it->second; + associated_type_it->type = el_type; + } + + mesh->registerData("associated_id").setArray(_segment_2, _not_ghost, *associated_id); + mesh->registerData("associated_type").setArray(_segment_2, _not_ghost, *associated_type); + + return mesh; +} + +template +void MeshGeomFactory::constructSegments(const std::list< typename TreeTypeHelper::linear_intersection > & intersections, + std::list< std::pair > & segments) { + typename std::list::linear_intersection>::const_iterator int_it = intersections.begin(), + int_end = intersections.end(); + + for (; int_it != int_end ; ++int_it) { + if (const K::Segment_3 * segment = boost::get(&((*int_it)->first))) { + std::pair segment_id(*segment, (*int_it)->second); + segments.push_back(segment_id); + } + } + + segments.unique(CompareSegmentPairs()); +} + + + __END_AKANTU__ #endif // _AKANTU_MESH_GEOM_FACTORY_TMPL_HH__ diff --git a/src/geometry/tree_type_helper.hh b/src/geometry/tree_type_helper.hh index 51a9af9c5..b681fd91c 100644 --- a/src/geometry/tree_type_helper.hh +++ b/src/geometry/tree_type_helper.hh @@ -1,67 +1,69 @@ /** * @file tree_type_helper.hh * * @author Lucas Frérot * * @date creation: Fri Feb 27 2015 - * @date last modification: Fri Feb 27 2015 + * @date last modification: Thu Mar 5 2015 * * @brief Converts element types of a mesh to CGAL primitive types * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_TREE_TYPE_HELPER_HH__ #define __AKANTU_TREE_TYPE_HELPER_HH__ #include "aka_common.hh" #include "triangle.hh" #include "triangle_primitive.hh" #include #include #include __BEGIN_AKANTU__ typedef CGAL::Cartesian Kernel; /* -------------------------------------------------------------------------- */ template struct TreeTypeHelper; template<> struct TreeTypeHelper<2, _triangle_3> { typedef Triangle primitive_type; typedef Kernel::Point_3 point_type; typedef std::list container_type; typedef container_type::iterator iterator; typedef Triangle_primitive aabb_primitive_type; typedef CGAL::AABB_traits aabb_traits_type; typedef CGAL::AABB_tree tree; + + typedef boost::optional < tree::Intersection_and_primitive_id< CGAL::Segment_3 >::Type > linear_intersection; }; __END_AKANTU__ #endif // __AKANTU_TREE_TYPE_HELPER_HH__ diff --git a/test/test_geometry/test_geometry_intersection.cc b/test/test_geometry/test_geometry_intersection.cc index a5f53c3f9..ed939cb60 100644 --- a/test/test_geometry/test_geometry_intersection.cc +++ b/test/test_geometry/test_geometry_intersection.cc @@ -1,131 +1,102 @@ /** * @file test_geometry_intersection.cc * * @author Lucas Frérot * * @date creation: Fri Feb 27 2015 - * @date last modification: Fri Feb 27 2015 + * @date last modification: Thu Mar 5 2015 * * @brief Tests the intersection module * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh_geom_container.hh" #include "mesh_geom_factory.hh" #include "tree_type_helper.hh" +#include "geom_helper_functions.hh" #include #include /* -------------------------------------------------------------------------- */ using namespace akantu; typedef CGAL::Cartesian K; -typedef boost::optional < TreeTypeHelper<2, _triangle_3>::tree::Intersection_and_primitive_id::Type > Line_intersection; +typedef TreeTypeHelper<2, _triangle_3>::linear_intersection Line_intersection; typedef TreeTypeHelper<2, _triangle_3>::tree::Primitive_id Primitive_id; /* -------------------------------------------------------------------------- */ -bool comparePoints(const K::Point_3 & a, const K::Point_3 & b); -bool compareSegments(const K::Segment_3 & a, const K::Segment_3 & b); - -/* -------------------------------------------------------------------------- */ - int main (int argc, char * argv[]) { debug::setDebugLevel(dblWarning); initialize("", argc, argv); Math::setTolerance(1e-10); Mesh mesh(2); mesh.read("mesh.msh"); MeshGeomContainer container(mesh); container.constructData(); const MeshGeomFactory<2, _triangle_3> * factory = dynamic_cast *>(container.getFactoryForElementType(_triangle_3)); const TreeTypeHelper<2, _triangle_3>::tree & tree = factory->getTree(); K::Point_3 a(0., 0.25, 0.), b(1., 0.25, 0.); K::Segment_3 line(a, b); if (container.numberOfIntersectionsWithInterface(line) != 2) return EXIT_FAILURE; K::Point_3 begin(a), intermediate(0.25, 0.25, 0.), end(0.75, 0.25, 0.); K::Segment_3 result_0(begin, intermediate), result_1(intermediate, end); std::list list_of_intersections; tree.all_intersections(line, std::back_inserter(list_of_intersections)); const Line_intersection & intersection_0 = list_of_intersections.front(); const Line_intersection & intersection_1 = list_of_intersections.back(); if (!intersection_0 || !intersection_1) return EXIT_FAILURE; /// *-> first is the intersection ; *->second is the primitive id if (const K::Segment_3 * segment = boost::get(&(intersection_0->first))) { if (!compareSegments(*segment, result_0)) { return EXIT_FAILURE; } } if (const K::Segment_3 * segment = boost::get(&(intersection_1->first))) { if (!compareSegments(*segment, result_1)) { return EXIT_FAILURE; } } -#if 0 - std::list intersected_primitives; - tree.all_intersected_primitives(line, std::back_inserter(intersected_primitives)); - - std::list::iterator it, it_end; - it = intersected_primitives.begin(); - it_end = intersected_primitives.end(); - - for (; it != it_end ; ++it) { - std::cout << *it << std::endl; - } -#endif - finalize(); return EXIT_SUCCESS; } -/* -------------------------------------------------------------------------- */ - - -bool comparePoints(const K::Point_3 & a, const K::Point_3 & b) { - return Math::are_float_equal(a.x(), b.x()) && Math::are_float_equal(a.y(), b.y()); -} - -bool compareSegments(const K::Segment_3 & a, const K::Segment_3 & b) { - return (comparePoints(a.source(), b.source()) && comparePoints(a.target(), b.target())) || - (comparePoints(a.source(), b.target()) && comparePoints(a.target(), b.source())); -} -