Do not collect in a vector per patch, but do the tests directly (@janetournois please double-check this commit)

This commit is contained in:
Andreas Fabri 2021-03-03 14:23:56 +00:00
parent 2ac977b7c5
commit 82e5b3a02d
1 changed files with 12 additions and 27 deletions

View File

@ -43,6 +43,7 @@
#include <boost/unordered_set.hpp> #include <boost/unordered_set.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/container/flat_set.hpp> #include <boost/container/flat_set.hpp>
#include <boost/optional.hpp>
#include <map> #include <map>
#include <list> #include <list>
@ -1885,8 +1886,8 @@ private:
bool check_normals(const HalfedgeRange& hedges) const bool check_normals(const HalfedgeRange& hedges) const
{ {
std::size_t nb_patches = patch_id_to_index_map.size(); std::size_t nb_patches = patch_id_to_index_map.size();
std::vector<boost::optional<Vector_3> > normal_per_patch(nb_patches,boost::none);
std::vector< std::vector<Vector_3> > normals_per_patch(nb_patches);
for(halfedge_descriptor hd : hedges) for(halfedge_descriptor hd : hedges)
{ {
Halfedge_status s = status(hd); Halfedge_status s = status(hd);
@ -1898,19 +1899,16 @@ private:
if (n == CGAL::NULL_VECTOR) //for degenerate faces if (n == CGAL::NULL_VECTOR) //for degenerate faces
continue; continue;
Patch_id pid = get_patch_id(face(hd, mesh_)); Patch_id pid = get_patch_id(face(hd, mesh_));
normals_per_patch[patch_id_to_index_map.at(pid)].push_back(n); std::size_t index = patch_id_to_index_map.at(pid);
} if(normal_per_patch[index]){
const Vector_3& vec = *normal_per_patch[index];
//on each surface patch, double dot = to_double(n * vec);
//check all normals have same orientation if (dot <= 0.){
for (std::size_t i=0; i < nb_patches; ++i)
{
const std::vector<Vector_3>& normals = normals_per_patch[i];
if (normals.empty()) continue;
if (!check_orientation(normals))
return false; return false;
} }
}
normal_per_patch[index] = boost::make_optional(n);
}
return true; return true;
} }
@ -1923,19 +1921,6 @@ private:
return n * no > 0.; return n * no > 0.;
} }
bool check_orientation(const std::vector<Vector_3>& normals) const
{
if (normals.size() < 2)
return true;
for (std::size_t i = 1; i < normals.size(); ++i)/*start at 1 on purpose*/
{
double dot = to_double(normals[i - 1] * normals[i]);
if (dot <= 0.)
return false;
}
return true;
}
public: public:
const Triangle_list& input_triangles() const { const Triangle_list& input_triangles() const {
return input_triangles_; return input_triangles_;