Indentation fixes

This commit is contained in:
Mael Rouxel-Labbé 2022-10-26 10:58:38 +02:00
parent bd52dc631a
commit d30b5c1a7f
1 changed files with 116 additions and 105 deletions

View File

@ -29,11 +29,9 @@
#include <map> #include <map>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
namespace CGAL {
namespace SMDS_3 {
namespace CGAL
{
namespace SMDS_3
{
template<typename Vh> template<typename Vh>
std::array<Vh, 3> make_ordered_vertex_array(const Vh vh0, const Vh vh1, const Vh vh2) std::array<Vh, 3> make_ordered_vertex_array(const Vh vh0, const Vh vh1, const Vh vh2)
{ {
@ -64,12 +62,12 @@ void build_vertices(Tr& tr,
} }
} }
template<class Tr> template <class Tr>
bool add_facet_to_incident_cells_map(const typename Tr::Cell_handle c, int i, bool add_facet_to_incident_cells_map(const typename Tr::Cell_handle c, int i,
boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>, boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>,
std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map, std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map,
const bool verbose, const bool verbose,
const bool allow_non_manifold) const bool allow_non_manifold)
{ {
typedef typename Tr::Vertex_handle Vertex_handle; typedef typename Tr::Vertex_handle Vertex_handle;
typedef typename Tr::Cell_handle Cell_handle; typedef typename Tr::Cell_handle Cell_handle;
@ -81,8 +79,8 @@ bool add_facet_to_incident_cells_map(const typename Tr::Cell_handle c, int i,
// the opposite vertex of f in c is i // the opposite vertex of f in c is i
Facet_vvv f = CGAL::SMDS_3::make_ordered_vertex_array(c->vertex((i + 1) % 4), Facet_vvv f = CGAL::SMDS_3::make_ordered_vertex_array(c->vertex((i + 1) % 4),
c->vertex((i + 2) % 4), c->vertex((i + 2) % 4),
c->vertex((i + 3) % 4)); c->vertex((i + 3) % 4));
CGAL_precondition(f[0] != f[1] && f[1] != f[2]); CGAL_precondition(f[0] != f[1] && f[1] != f[2]);
Incident_cell e = std::make_pair(c, i); Incident_cell e = std::make_pair(c, i);
@ -105,16 +103,16 @@ bool add_facet_to_incident_cells_map(const typename Tr::Cell_handle c, int i,
return success; return success;
} }
template<class Tr, typename CellRange, typename SubdomainsRange, typename FacetPatchMap> template <class Tr, typename CellRange, typename SubdomainsRange, typename FacetPatchMap>
bool build_finite_cells(Tr& tr, bool build_finite_cells(Tr& tr,
const CellRange& finite_cells, const CellRange& finite_cells,
const SubdomainsRange& subdomains, const SubdomainsRange& subdomains,
const std::vector<typename Tr::Vertex_handle>& vertex_handle_vector, const std::vector<typename Tr::Vertex_handle>& vertex_handle_vector,
boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>, boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>,
std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map, std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map,
const FacetPatchMap& border_facets, const FacetPatchMap& border_facets,
const bool verbose, const bool verbose,
const bool replace_domain_0) const bool replace_domain_0)
{ {
typedef typename Tr::Vertex_handle Vertex_handle; typedef typename Tr::Vertex_handle Vertex_handle;
typedef typename Tr::Cell_handle Cell_handle; typedef typename Tr::Cell_handle Cell_handle;
@ -123,11 +121,10 @@ bool build_finite_cells(Tr& tr,
bool success = true; bool success = true;
CGAL_assertion_code( CGAL_assertion_code(
typename Tr::Geom_traits::Construct_point_3 cp = typename Tr::Geom_traits::Construct_point_3 cp = tr.geom_traits().construct_point_3_object();
tr.geom_traits().construct_point_3_object(); typename Tr::Geom_traits::Orientation_3 orientation = tr.geom_traits().orientation_3_object();
typename Tr::Geom_traits::Orientation_3 orientation =
tr.geom_traits().orientation_3_object();
) )
typename SubdomainsRange::value_type max_domain = 0; typename SubdomainsRange::value_type max_domain = 0;
if(replace_domain_0) if(replace_domain_0)
{ {
@ -137,6 +134,7 @@ bool build_finite_cells(Tr& tr,
max_domain = subdomains[i]; max_domain = subdomains[i];
} }
} }
// build the finite cells // build the finite cells
for(std::size_t i=0; i<finite_cells.size(); ++i) for(std::size_t i=0; i<finite_cells.size(); ++i)
{ {
@ -154,15 +152,12 @@ bool build_finite_cells(Tr& tr,
// this assertion also tests for degeneracy // this assertion also tests for degeneracy
CGAL_assertion(orientation(cp(tr.point(vs[0])), cp(tr.point(vs[1])), CGAL_assertion(orientation(cp(tr.point(vs[0])), cp(tr.point(vs[1])),
cp(tr.point(vs[2])), cp(tr.point(vs[3]))) cp(tr.point(vs[2])), cp(tr.point(vs[3]))) == POSITIVE);
== POSITIVE);
Cell_handle c = tr.tds().create_cell(vs[0], vs[1], vs[2], vs[3]); Cell_handle c = tr.tds().create_cell(vs[0], vs[1], vs[2], vs[3]);
c->set_subdomain_index(subdomains[i]); // the cell's info keeps the reference of the tetrahedron c->set_subdomain_index(subdomains[i]); // the cell's info keeps the reference of the tetrahedron
if(replace_domain_0 && subdomains[i] == 0) if(replace_domain_0 && subdomains[i] == 0)
{
c->set_subdomain_index(max_domain+1); // the cell's info keeps the reference of the tetrahedron c->set_subdomain_index(max_domain+1); // the cell's info keeps the reference of the tetrahedron
}
// assign cells to vertices // assign cells to vertices
for(int j=0; j<4; ++j) for(int j=0; j<4; ++j)
@ -174,18 +169,20 @@ bool build_finite_cells(Tr& tr,
// build the map used for adjacency later // build the map used for adjacency later
for(int j=0; j<4; ++j) for(int j=0; j<4; ++j)
{ {
// do not allow non-manifold in the finite cells case
if(!CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, j, incident_cells_map, verbose, false)) if(!CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, j, incident_cells_map, verbose, false))
//do not allow non-manifold in the finite cells case
success = false; success = false;
if(border_facets.size() != 0) if(border_facets.size() != 0)
{ {
std::array<int,3> facet; std::array<int,3> facet;
facet[0]=tet[(j+1) % 4]; facet[0] = tet[(j+1) % 4];
facet[1]=tet[(j+2) % 4]; facet[1] = tet[(j+2) % 4];
facet[2]=tet[(j+3) % 4]; facet[2] = tet[(j+3) % 4];
//find the circular permutation that puts the smallest index in the first place.
// find the circular permutation that puts the smallest index in the first place.
int n0 = (std::min)((std::min)(facet[0], facet[1]), facet[2]); int n0 = (std::min)((std::min)(facet[0], facet[1]), facet[2]);
int k=0; int k = 0;
std::array<int,3> f; std::array<int,3> f;
do do
{ {
@ -193,7 +190,8 @@ bool build_finite_cells(Tr& tr,
f[1]=facet[(1+k)%3]; f[1]=facet[(1+k)%3];
f[2]=facet[(2+k)%3]; f[2]=facet[(2+k)%3];
++k; ++k;
} while(f[0] != n0); }
while(f[0] != n0);
typename FacetPatchMap::const_iterator it = border_facets.find(f); typename FacetPatchMap::const_iterator it = border_facets.find(f);
if(it != border_facets.end()) if(it != border_facets.end())
@ -215,16 +213,17 @@ bool build_finite_cells(Tr& tr,
} }
} }
} }
return success; return success;
} }
template<class Tr> template<class Tr>
bool add_infinite_facets_to_incident_cells_map(typename Tr::Cell_handle c, bool add_infinite_facets_to_incident_cells_map(typename Tr::Cell_handle c,
int inf_vert_pos, int inf_vert_pos,
boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>, boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>,
std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map, std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map,
const bool verbose, const bool verbose,
const bool allow_non_manifold) const bool allow_non_manifold)
{ {
int l = (inf_vert_pos + 1) % 4; int l = (inf_vert_pos + 1) % 4;
bool b1 = CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, l, incident_cells_map, verbose, allow_non_manifold); bool b1 = CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, l, incident_cells_map, verbose, allow_non_manifold);
@ -232,15 +231,16 @@ bool add_infinite_facets_to_incident_cells_map(typename Tr::Cell_handle c,
bool b2 = CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, l, incident_cells_map, verbose, allow_non_manifold); bool b2 = CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, l, incident_cells_map, verbose, allow_non_manifold);
l = (inf_vert_pos + 3) % 4; l = (inf_vert_pos + 3) % 4;
bool b3 = CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, l, incident_cells_map, verbose, allow_non_manifold); bool b3 = CGAL::SMDS_3::add_facet_to_incident_cells_map<Tr>(c, l, incident_cells_map, verbose, allow_non_manifold);
return b1 && b2 && b3; return b1 && b2 && b3;
} }
template<class Tr> template<class Tr>
bool build_infinite_cells(Tr& tr, bool build_infinite_cells(Tr& tr,
boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>, boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>,
std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map, std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map,
const bool verbose, const bool verbose,
const bool allow_non_manifold) const bool allow_non_manifold)
{ {
typedef typename Tr::Vertex_handle Vertex_handle; typedef typename Tr::Vertex_handle Vertex_handle;
typedef typename Tr::Cell_handle Cell_handle; typedef typename Tr::Cell_handle Cell_handle;
@ -260,13 +260,14 @@ bool build_infinite_cells(Tr& tr,
{ {
if(it->second.size() == 2) // facet already has both its incident cells if(it->second.size() == 2) // facet already has both its incident cells
continue; continue;
CGAL_assertion(it->second.size() == 1); CGAL_assertion(it->second.size() == 1);
Cell_handle c = it->second[0].first; Cell_handle c = it->second[0].first;
int i = it->second[0].second; int i = it->second[0].second;
Cell_handle opp_c;
// the infinite cell that we are creating needs to be well oriented... // the infinite cell that we are creating needs to be well oriented...
Cell_handle opp_c;
if(i == 0 || i == 2) if(i == 0 || i == 2)
opp_c = tr.tds().create_cell(tr.infinite_vertex(), opp_c = tr.tds().create_cell(tr.infinite_vertex(),
c->vertex((i + 2) % 4), c->vertex((i + 2) % 4),
@ -301,14 +302,15 @@ bool build_infinite_cells(Tr& tr,
for (int i = 1; i < 4; ++i) for (int i = 1; i < 4; ++i)
{ {
std::array<Vertex_handle, 3> vs = CGAL::SMDS_3::make_ordered_vertex_array(c->vertex((i + 1) % 4), std::array<Vertex_handle, 3> vs = CGAL::SMDS_3::make_ordered_vertex_array(c->vertex((i + 1) % 4),
c->vertex((i + 2) % 4), c->vertex((i + 2) % 4),
c->vertex((i + 3) % 4)); c->vertex((i + 3) % 4));
if (facets.find(vs) == facets.end()) if (facets.find(vs) == facets.end())
facets.insert(std::make_pair(vs, 1)); facets.insert(std::make_pair(vs, 1));
else else
facets[vs]++; facets[vs]++;
} }
} }
for (auto fp : facets) for (auto fp : facets)
{ {
if (fp.second != 2) if (fp.second != 2)
@ -326,12 +328,14 @@ bool build_infinite_cells(Tr& tr,
// add the facets to the incident cells map // add the facets to the incident cells map
for (const Cell_handle& c : infinite_cells) for (const Cell_handle& c : infinite_cells)
{
if(!CGAL::SMDS_3::add_infinite_facets_to_incident_cells_map<Tr>(c, if(!CGAL::SMDS_3::add_infinite_facets_to_incident_cells_map<Tr>(c,
0, 0,
incident_cells_map, incident_cells_map,
verbose, verbose,
allow_non_manifold)) allow_non_manifold))
success = false; success = false;
}
return success; return success;
} }
@ -350,9 +354,9 @@ bool has_infinite_vertex(const std::array<typename Tr::Vertex_handle, 3>& v,
template<class Tr> template<class Tr>
bool assign_neighbors(Tr& tr, bool assign_neighbors(Tr& tr,
const boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>, const boost::unordered_map<std::array<typename Tr::Vertex_handle, 3>,
std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map, std::vector<std::pair<typename Tr::Cell_handle, int> > >& incident_cells_map,
const bool allow_non_manifold) const bool allow_non_manifold)
{ {
typedef typename Tr::Cell_handle Cell_handle; typedef typename Tr::Cell_handle Cell_handle;
typedef std::pair<Cell_handle, int> Incident_cell; typedef std::pair<Cell_handle, int> Incident_cell;
@ -389,17 +393,18 @@ template<class Tr,
typename CellRange, typename CellRange,
typename FacetPatchMap> typename FacetPatchMap>
bool build_triangulation_impl(Tr& tr, bool build_triangulation_impl(Tr& tr,
const PointRange& points, const PointRange& points,
const CellRange& finite_cells, const CellRange& finite_cells,
const std::vector<typename Tr::Cell::Subdomain_index>& subdomains, const std::vector<typename Tr::Cell::Subdomain_index>& subdomains,
const FacetPatchMap& border_facets, const FacetPatchMap& border_facets,
std::vector<typename Tr::Vertex_handle>& vertex_handle_vector, std::vector<typename Tr::Vertex_handle>& vertex_handle_vector,
const bool verbose,// = false, const bool verbose,// = false,
const bool replace_domain_0,// = false, const bool replace_domain_0,// = false,
const bool allow_non_manifold) // = false const bool allow_non_manifold) // = false
{ {
if (verbose) if (verbose)
std::cout << "build_triangulation_impl()..." << std::endl; std::cout << "build_triangulation_impl()..." << std::endl;
typedef typename Tr::Vertex_handle Vertex_handle; typedef typename Tr::Vertex_handle Vertex_handle;
typedef typename Tr::Cell_handle Cell_handle; typedef typename Tr::Cell_handle Cell_handle;
typedef std::array<Vertex_handle, 3> Facet_vvv; typedef std::array<Vertex_handle, 3> Facet_vvv;
@ -408,48 +413,49 @@ bool build_triangulation_impl(Tr& tr,
typedef std::pair<Cell_handle, int> Incident_cell; typedef std::pair<Cell_handle, int> Incident_cell;
typedef boost::unordered_map<Facet_vvv, std::vector<Incident_cell> > Incident_cells_map; typedef boost::unordered_map<Facet_vvv, std::vector<Incident_cell> > Incident_cells_map;
bool success = true;
Incident_cells_map incident_cells_map;
vertex_handle_vector.resize(points.size() + 1); // id to vertex_handle
//index 0 is for infinite vertex
// 1 to n for points in `points`
CGAL_precondition(!points.empty()); CGAL_precondition(!points.empty());
if(finite_cells.empty()) bool success = true;
{ Incident_cells_map incident_cells_map;
std::cout << "WARNING: No finite cells were provided. Only the points will be loaded."<<std::endl;
}
tr.tds().clear(); // not tr.clear() since it calls tr.init() which we don't want // id to vertex_handle
// index 0 is for infinite vertex; 1 to n for points in `points`
vertex_handle_vector.resize(points.size() + 1);
if(finite_cells.empty())
std::cout << "WARNING: No finite cells were provided. Only the points will be loaded." << std::endl;
tr.tds().clear(); // not tr.clear() since it calls tr.init(), which we don't want
build_vertices<Tr>(tr, points, vertex_handle_vector); build_vertices<Tr>(tr, points, vertex_handle_vector);
for(Vertex_handle vh : vertex_handle_vector) for(Vertex_handle vh : vertex_handle_vector)
{
vh->set_dimension(-1); vh->set_dimension(-1);
}
if (!finite_cells.empty()) if (!finite_cells.empty())
{ {
if (!CGAL::SMDS_3::build_finite_cells<Tr>(tr, finite_cells, subdomains, vertex_handle_vector, incident_cells_map, if (!CGAL::SMDS_3::build_finite_cells<Tr>(tr, finite_cells, subdomains, vertex_handle_vector,
border_facets, verbose, replace_domain_0)) incident_cells_map, border_facets, verbose, replace_domain_0))
{ {
if (verbose) std::cout << "build_finite_cells went wrong" << std::endl; if (verbose)
std::cout << "build_finite_cells went wrong" << std::endl;
success = false; success = false;
} }
else else
std::cout << "build finite cells done" << std::endl; std::cout << "build finite cells done" << std::endl;
if (!CGAL::SMDS_3::build_infinite_cells<Tr>(tr, incident_cells_map, verbose, allow_non_manifold)) if (!CGAL::SMDS_3::build_infinite_cells<Tr>(tr, incident_cells_map, verbose, allow_non_manifold))
{ {
if(verbose) std::cout << "build_infinite_cells went wrong" << std::endl; if(verbose)
std::cout << "build_infinite_cells went wrong" << std::endl;
success = false; success = false;
} }
else else
std::cout << "build infinite cells done" << std::endl; std::cout << "build infinite cells done" << std::endl;
tr.tds().set_dimension(3); tr.tds().set_dimension(3);
if (!CGAL::SMDS_3::assign_neighbors<Tr>(tr, incident_cells_map, allow_non_manifold)) if (!CGAL::SMDS_3::assign_neighbors<Tr>(tr, incident_cells_map, allow_non_manifold))
{ {
if(verbose) std::cout << "assign_neighbors went wrong" << std::endl; if(verbose)
std::cout << "assign_neighbors went wrong" << std::endl;
success = false; success = false;
} }
else else
@ -460,6 +466,7 @@ bool build_triangulation_impl(Tr& tr,
std::cout << tr.number_of_cells() << " cells" << std::endl; std::cout << tr.number_of_cells() << " cells" << std::endl;
} }
} }
if(verbose) if(verbose)
std::cout << tr.number_of_vertices() << " vertices" << std::endl; std::cout << tr.number_of_vertices() << " vertices" << std::endl;
@ -472,14 +479,14 @@ template<class Tr,
typename CellRange, typename CellRange,
typename FacetPatchMap> typename FacetPatchMap>
bool build_triangulation_one_subdomain(Tr& tr, bool build_triangulation_one_subdomain(Tr& tr,
const PointRange& points, const PointRange& points,
const CellRange& finite_cells, const CellRange& finite_cells,
const typename Tr::Cell::Subdomain_index& subdomain, const typename Tr::Cell::Subdomain_index& subdomain,
const FacetPatchMap& border_facets, const FacetPatchMap& border_facets,
std::vector<typename Tr::Vertex_handle>& vertex_handle_vector, std::vector<typename Tr::Vertex_handle>& vertex_handle_vector,
const bool verbose,// = false, const bool verbose,// = false,
const bool replace_domain_0,// = false const bool replace_domain_0,// = false
const bool allow_non_manifold)// = false const bool allow_non_manifold)// = false
{ {
std::vector<typename Tr::Cell::Subdomain_index> subdomains(finite_cells.size(), subdomain); std::vector<typename Tr::Cell::Subdomain_index> subdomains(finite_cells.size(), subdomain);
return build_triangulation_impl(tr, points, finite_cells, subdomains, return build_triangulation_impl(tr, points, finite_cells, subdomains,
@ -493,13 +500,13 @@ template<class Tr,
typename CellRange, typename CellRange,
typename FacetPatchMap> typename FacetPatchMap>
bool build_triangulation_one_subdomain(Tr& tr, bool build_triangulation_one_subdomain(Tr& tr,
const PointRange& points, const PointRange& points,
const CellRange& finite_cells, const CellRange& finite_cells,
const typename Tr::Cell::Subdomain_index& subdomain, const typename Tr::Cell::Subdomain_index& subdomain,
const FacetPatchMap& border_facets, const FacetPatchMap& border_facets,
const bool verbose,// = false, const bool verbose,// = false,
const bool replace_domain_0,// = false const bool replace_domain_0,// = false
const bool allow_non_manifold)//= false const bool allow_non_manifold)//= false
{ {
std::vector<typename Tr::Cell::Subdomain_index> subdomains(finite_cells.size(), subdomain); std::vector<typename Tr::Cell::Subdomain_index> subdomains(finite_cells.size(), subdomain);
std::vector<typename Tr::Vertex_handle> vertex_handle_vector; std::vector<typename Tr::Vertex_handle> vertex_handle_vector;
@ -515,13 +522,13 @@ template<class Tr,
typename SubdomainsRange, typename SubdomainsRange,
typename FacetPatchMap> typename FacetPatchMap>
bool build_triangulation_with_subdomains_range(Tr& tr, bool build_triangulation_with_subdomains_range(Tr& tr,
const PointRange& points, const PointRange& points,
const CellRange& finite_cells, const CellRange& finite_cells,
const SubdomainsRange& subdomains, const SubdomainsRange& subdomains,
const FacetPatchMap& border_facets, const FacetPatchMap& border_facets,
const bool verbose,// = false const bool verbose,// = false
const bool replace_domain_0,// = false, const bool replace_domain_0,// = false,
const bool allow_non_manifold) const bool allow_non_manifold)
{ {
std::vector<typename Tr::Vertex_handle> vertex_handle_vector; std::vector<typename Tr::Vertex_handle> vertex_handle_vector;
std::vector<typename Tr::Cell::Subdomain_index> subdomains_vector( std::vector<typename Tr::Cell::Subdomain_index> subdomains_vector(
@ -571,7 +578,9 @@ bool build_triangulation_from_file(std::istream& is,
{ {
is >> word; is >> word;
if (word == "End") if (word == "End")
{
break; break;
}
else if (word == "CGAL::Mesh_complex_3_in_triangulation_3") else if (word == "CGAL::Mesh_complex_3_in_triangulation_3")
{ {
dont_replace_domain_0 = true;//with CGAL meshes, domain 0 should be kept dont_replace_domain_0 = true;//with CGAL meshes, domain 0 should be kept
@ -579,6 +588,7 @@ bool build_triangulation_from_file(std::istream& is,
} }
//else skip other comments //else skip other comments
} }
if(word == "Vertices") if(word == "Vertices")
{ {
is >> nv; is >> nv;
@ -644,17 +654,18 @@ bool build_triangulation_from_file(std::istream& is,
if(finite_cells.empty()) if(finite_cells.empty())
return false; return false;
CGAL_assertion(finite_cells.size() == subdomains.size()); CGAL_assertion(finite_cells.size() == subdomains.size());
return build_triangulation_with_subdomains_range(tr, return build_triangulation_with_subdomains_range(tr,
points, finite_cells, subdomains, border_facets, points, finite_cells, subdomains, border_facets,
verbose, verbose,
replace_domain_0 && !dont_replace_domain_0, replace_domain_0 && !is_CGAL_mesh,
allow_non_manifold); allow_non_manifold);
} }
} // namespace SMDS_3 } // namespace SMDS_3
} // namespace CGAL } // namespace CGAL
#include <CGAL/enable_warnings.h> #include <CGAL/enable_warnings.h>