mirror of https://github.com/CGAL/cgal
update tests
This commit is contained in:
parent
eee363df27
commit
2e7e6341dd
|
|
@ -18,19 +18,18 @@
|
|||
|
||||
#include <CGAL/array.h>
|
||||
#include <CGAL/boost/graph/Euler_operations.h>
|
||||
#include <CGAL/Cartesian_converter.h>
|
||||
#include <CGAL/Kernel_traits.h>
|
||||
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
|
||||
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
|
||||
#include <CGAL/Named_function_parameters.h>
|
||||
#include <CGAL/boost/graph/named_params_helper.h>
|
||||
#include <CGAL/Time_stamper.h>
|
||||
#include <CGAL/property_map.h>
|
||||
#include <CGAL/Container_helper.h>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace CGAL {
|
||||
|
|
@ -39,6 +38,18 @@ namespace SMDS_3 {
|
|||
|
||||
namespace internal {
|
||||
|
||||
template <class Polygon>
|
||||
void resize(Polygon& p, std::size_t size)
|
||||
{
|
||||
p.resize(size);
|
||||
}
|
||||
|
||||
template <std::size_t N, class INT>
|
||||
void resize(std::array<INT, N>&, std::size_t CGAL_assertion_code(size))
|
||||
{
|
||||
CGAL_assertion(size == N);
|
||||
}
|
||||
|
||||
template<class C3T3, class PointContainer, class FaceContainer, class PatchIndexContainer>
|
||||
void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3,
|
||||
const typename C3T3::Subdomain_index sd_index,
|
||||
|
|
@ -54,22 +65,26 @@ void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3,
|
|||
typedef typename C3T3::Triangulation Tr;
|
||||
typedef typename C3T3::Surface_patch_index Surface_patch_index;
|
||||
|
||||
typedef typename Tr::Vertex_handle Vertex_handle;
|
||||
typedef typename Tr::Cell_handle Cell_handle;
|
||||
typedef typename Tr::Weighted_point Weighted_point;
|
||||
typedef typename Tr::Facet Facet;
|
||||
|
||||
typedef CGAL::Hash_handles_with_or_without_timestamps Hash_fct;
|
||||
typedef boost::unordered_map<Vertex_handle, std::size_t, Hash_fct> VHmap;
|
||||
typedef typename C3T3::Facets_in_complex_iterator Ficit;
|
||||
|
||||
typedef std::unordered_map<Point_3, std::size_t> PIM;
|
||||
|
||||
typedef typename C3T3::size_type size_type;
|
||||
|
||||
// triangulation point to range point
|
||||
CGAL::Cartesian_converter<typename CGAL::Kernel_traits<typename Tr::Geom_traits::Point_3>::type,
|
||||
typename CGAL::Kernel_traits<Point_3>::type> t2r;
|
||||
|
||||
size_type nf = c3t3.number_of_facets_in_complex();
|
||||
faces.reserve(faces.size() + nf);
|
||||
patches.reserve(faces.size() + nf);
|
||||
points.reserve(points.size() + nf/2); // approximating Euler
|
||||
|
||||
VHmap vh_to_ids;
|
||||
PIM p_to_ids;
|
||||
std::size_t inum = 0;
|
||||
|
||||
for(Facet fit : c3t3.facets_in_complex())
|
||||
|
|
@ -78,7 +93,7 @@ void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3,
|
|||
int s = fit.second;
|
||||
const Surface_patch_index spi = c->surface_patch_index(s);
|
||||
Face f;
|
||||
CGAL::internal::resize(f, 3);
|
||||
resize(f, 3);
|
||||
|
||||
typename C3T3::Subdomain_index cell_sdi = c3t3.subdomain_index(c);
|
||||
typename C3T3::Subdomain_index opp_sdi = c3t3.subdomain_index(c->neighbor(s));
|
||||
|
|
@ -88,23 +103,21 @@ void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3,
|
|||
|
||||
for(std::size_t i=1; i<4; ++i)
|
||||
{
|
||||
typename VHmap::iterator map_entry;
|
||||
bool is_new;
|
||||
Vertex_handle v = c->vertex((s+i)&3);
|
||||
CGAL_assertion_code(typedef typename Tr::Vertex_handle Vertex_handle;)
|
||||
CGAL_assertion_code(Vertex_handle v = c->vertex((s+i)&3);)
|
||||
CGAL_assertion(v != Vertex_handle() && !c3t3.triangulation().is_infinite(v));
|
||||
|
||||
boost::tie(map_entry, is_new) = vh_to_ids.insert(std::make_pair(v, inum));
|
||||
if(is_new)
|
||||
const Weighted_point& wp = c3t3.triangulation().point(c, (s+i)&3);
|
||||
const Point_3& bp = t2r(c3t3.triangulation().geom_traits().construct_point_3_object()(wp));
|
||||
|
||||
auto insertion_res = p_to_ids.emplace(bp, inum);
|
||||
if(insertion_res.second) // new point
|
||||
{
|
||||
const Weighted_point& p = c3t3.triangulation().point(c, (s+i)&3);
|
||||
const Point_3 bp = Point_3(CGAL::to_double(p.x()),
|
||||
CGAL::to_double(p.y()),
|
||||
CGAL::to_double(p.z()));
|
||||
points.push_back(bp);
|
||||
++inum;
|
||||
}
|
||||
|
||||
f[i-1] = map_entry->second;
|
||||
f[i-1] = insertion_res.first->second;
|
||||
}
|
||||
|
||||
if(export_all_facets)
|
||||
|
|
@ -163,21 +176,24 @@ void set_face_patches(const Index2FaceMap& i2f,
|
|||
/**
|
||||
* @ingroup PkgSMDS3Functions
|
||||
*
|
||||
* @brief builds a `TriangleMesh` from the surface facets, with a consistent orientation at the interface of two subdomains.
|
||||
* @brief builds a `TriangleMesh` from the surface facets, with a consistent orientation
|
||||
* at the interface of two subdomains.
|
||||
*
|
||||
* This function exports the surface as a `TriangleMesh` and appends it to `tm`, using `orient_polygon_soup()`.
|
||||
* This function exports the surface as a `TriangleMesh` and appends it to `graph`, using
|
||||
* `orient_polygon_soup()`.
|
||||
*
|
||||
* @tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`.
|
||||
* @tparam TriangleMesh a model of `MutableFaceGraph` with an internal point property map. The point type must be compatible with the one used in `C3T3`.
|
||||
* @tparam TriangleMesh a model of `MutableFaceGraph` with an internal point property map.
|
||||
* The point type must be compatible with the one used in `C3T3`.
|
||||
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
|
||||
*
|
||||
* @param c3t3 an instance of `C3T3`
|
||||
* @param tm an instance of `TriangleMesh`
|
||||
* @param graph an instance of `TriangleMesh`
|
||||
* @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
|
||||
*
|
||||
* \cgalNamedParamsBegin
|
||||
* \cgalParamNBegin{face_patch_map}
|
||||
* \cgalParamDescription{a property map with the patch id's associated to the faces of `faces(tm)`}
|
||||
* \cgalParamDescription{a property map with the patch id's associated to the faces of `faces(graph)`}
|
||||
* \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits<TriangleMesh>::%face_descriptor`
|
||||
* as key type and the desired property, model of `CopyConstructible` and `LessThanComparable` as value type.}
|
||||
* \cgalParamDefault{If not provided, faces patch ids are ignored.}
|
||||
|
|
@ -187,7 +203,7 @@ void set_face_patches(const Index2FaceMap& i2f,
|
|||
*/
|
||||
template<class C3T3, class TriangleMesh, typename NamedParameters>
|
||||
void facets_in_complex_3_to_triangle_mesh(const C3T3& c3t3,
|
||||
TriangleMesh& tm,
|
||||
TriangleMesh& graph,
|
||||
const NamedParameters& np)
|
||||
{
|
||||
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||
|
|
@ -209,13 +225,11 @@ void set_face_patches(const Index2FaceMap& i2f,
|
|||
PMP::orient_polygon_soup(points, faces);
|
||||
CGAL_postcondition(PMP::is_polygon_soup_a_polygon_mesh(faces));
|
||||
|
||||
boost::unordered_map<std::size_t, face_descriptor> i2f;
|
||||
PMP::polygon_soup_to_polygon_mesh(points, faces, tm,
|
||||
std::unordered_map<std::size_t, face_descriptor> i2f;
|
||||
PMP::polygon_soup_to_polygon_mesh(points, faces, graph,
|
||||
CGAL::parameters::polygon_to_face_output_iterator(std::inserter(i2f, i2f.end())));
|
||||
|
||||
using parameters::choose_parameter;
|
||||
using parameters::get_parameter;
|
||||
|
||||
SMDS_3::internal::set_face_patches(i2f,
|
||||
patches,
|
||||
get_parameter(np, internal_np::face_patch));
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ struct Tester
|
|||
//-------------------------------------------------------
|
||||
std::cout << "Insert 6 points from domain in c3t3_bis, add 1 cell to c3t3_bis\n";
|
||||
Polyhedron polyhedron;
|
||||
std::ifstream input("data/sphere.off");
|
||||
std::ifstream input(CGAL::data_file_path("meshes/sphere.off"));
|
||||
input >> polyhedron;
|
||||
input.close();
|
||||
Mesh_domain domain(polyhedron);
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ int main (int argc, char** argv){
|
|||
Cell_base_with_info>::type Tr;
|
||||
|
||||
typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3;
|
||||
|
||||
typedef C3t3::Triangulation::Cell_handle Cell_handle;
|
||||
|
||||
// Open file
|
||||
std::ifstream in (argc > 1 ? argv[1] : "data/elephant.mesh",
|
||||
std::ifstream in (argc > 1 ? argv[1] : CGAL::data_file_path("meshes/elephant.mesh"),
|
||||
std::ios_base::in);
|
||||
if(!in) {
|
||||
std::cerr << "Error! Cannot open file " << argv[1] << std::endl;
|
||||
|
|
@ -45,13 +45,11 @@ int main (int argc, char** argv){
|
|||
C3t3 c3t3;
|
||||
if(CGAL::SMDS_3::build_triangulation_from_file(in, c3t3.triangulation()))
|
||||
{
|
||||
for( C3t3::Triangulation::Finite_cells_iterator
|
||||
cit = c3t3.triangulation().finite_cells_begin();
|
||||
cit != c3t3.triangulation().finite_cells_end();
|
||||
++cit)
|
||||
for( Cell_handle cit : c3t3.triangulation().finite_cell_handles())
|
||||
{
|
||||
assert(cit->subdomain_index() >= 0);
|
||||
c3t3.add_to_complex(cit, cit->subdomain_index());
|
||||
if(cit->subdomain_index() > 0)
|
||||
c3t3.add_to_complex(cit, cit->subdomain_index());
|
||||
for(int i=0; i < 4; ++i)
|
||||
{
|
||||
if(cit->surface_patch_index(i)>0)
|
||||
|
|
@ -64,10 +62,7 @@ int main (int argc, char** argv){
|
|||
//if there is no facet in the complex, we add the border facets.
|
||||
if(c3t3.number_of_facets_in_complex() == 0)
|
||||
{
|
||||
for( C3t3::Triangulation::All_cells_iterator
|
||||
cit = c3t3.triangulation().all_cells_begin();
|
||||
cit != c3t3.triangulation().all_cells_end();
|
||||
++cit)
|
||||
for( Cell_handle cit : c3t3.triangulation().all_cell_handles())
|
||||
{
|
||||
if(c3t3.triangulation().is_infinite(cit))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -462,13 +462,13 @@ struct Test_c3t3_io {
|
|||
int main()
|
||||
{
|
||||
std::cout << "First test I/O when all indices are integers" << std::endl;
|
||||
bool ok = Test_c3t3_io<MD_homogeneous_types>()("data/c3t3_io-homo");
|
||||
bool ok = Test_c3t3_io<MD_homogeneous_types>()("c3t3_io-homo");
|
||||
if(!ok) {
|
||||
std::cerr << "Error\n";
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Then test I/O when all indices are different types" << std::endl;
|
||||
ok = Test_c3t3_io<MD_heterogeneous_types>()("data/c3t3_io-hetero");
|
||||
ok = Test_c3t3_io<MD_heterogeneous_types>()("c3t3_io-hetero");
|
||||
if(!ok) {
|
||||
std::cerr << "Error\n";
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue