do not build vector if not needed

This commit is contained in:
Sébastien Loriot 2021-04-03 11:22:14 +02:00
parent dd19b506ed
commit b7bafa1a34
1 changed files with 30 additions and 6 deletions

View File

@ -321,6 +321,11 @@ public:
* \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t`
* must be available in `TriangleMesh`.} * must be available in `TriangleMesh`.}
* \cgalParamNEnd * \cgalParamNEnd
* \cgalParamNBegin{face_epsilon_map}
* \cgalParamDescription{a property map associating to each face of `tm` a epsilon value}
* \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits<TriangleMesh>::%face_descriptor`
* as key type and `double` as value type}
* \cgalParamDefault{Use `epsilon` for all faces}
* \cgalNamedParamsEnd * \cgalNamedParamsEnd
* *
* \note The triangle mesh gets copied internally, that is it can be modifed after having passed as argument, * \note The triangle mesh gets copied internally, that is it can be modifed after having passed as argument,
@ -367,7 +372,7 @@ public:
} }
} }
if (is_default_parameter(get_parameter(np, internal_np::face_epsilon_map))) if (is_default_parameter(get_parameter(np, internal_np::face_epsilon_map)))
init(std::vector<double>(env_faces.size(), epsilon)); init(epsilon);
else else
{ {
std::vector<double> epsilon_values; std::vector<double> epsilon_values;
@ -385,6 +390,7 @@ public:
for(face_descriptor f : faces(tmesh)) for(face_descriptor f : faces(tmesh))
if(! Polygon_mesh_processing::is_degenerate_triangle_face(f, tmesh, parameters::geom_traits(gt).vertex_point_map(vpm))) if(! Polygon_mesh_processing::is_degenerate_triangle_face(f, tmesh, parameters::geom_traits(gt).vertex_point_map(vpm)))
epsilon_values.push_back( get(epsilon_map, f) ); epsilon_values.push_back( get(epsilon_map, f) );
init(epsilon_values);
} }
} }
@ -411,6 +417,12 @@ public:
* \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` * \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t`
* must be available in `TriangleMesh`.} * must be available in `TriangleMesh`.}
* \cgalParamNEnd * \cgalParamNEnd
* \cgalParamNBegin{face_epsilon_map}
* \cgalParamDescription{a property map associating to each face of `tm` a epsilon value}
* \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits<TriangleMesh>::%face_descriptor`
* as key type and `double` as value type}
* \cgalParamDefault{Use `epsilon` for all faces}
* \cgalParamNEnd
* \cgalNamedParamsEnd * \cgalNamedParamsEnd
* *
* \note The triangle mesh gets copied internally, that is it can be modifed after having passed as argument, * \note The triangle mesh gets copied internally, that is it can be modifed after having passed as argument,
@ -466,7 +478,7 @@ public:
} }
if (is_default_parameter(get_parameter(np, internal_np::face_epsilon_map))) if (is_default_parameter(get_parameter(np, internal_np::face_epsilon_map)))
init(std::vector<double>(env_faces.size(), epsilon)); init(epsilon);
else else
{ {
std::vector<double> epsilon_values; std::vector<double> epsilon_values;
@ -484,6 +496,7 @@ public:
for(face_descriptor f : face_range) for(face_descriptor f : face_range)
if(! Polygon_mesh_processing::is_degenerate_triangle_face(f, tmesh, parameters::geom_traits(gt).vertex_point_map(vpm))) if(! Polygon_mesh_processing::is_degenerate_triangle_face(f, tmesh, parameters::geom_traits(gt).vertex_point_map(vpm)))
epsilon_values.push_back( get(epsilon_map, f) ); epsilon_values.push_back( get(epsilon_map, f) );
init(epsilon_values);
} }
} }
@ -541,7 +554,7 @@ public:
Vector3i face = { int(t[0]), int(t[1]), int(t[2]) }; Vector3i face = { int(t[0]), int(t[1]), int(t[2]) };
env_faces.emplace_back(face); env_faces.emplace_back(face);
} }
init(std::vector<double>(env_faces.size(), epsilon)); init(epsilon);
} }
/// @} /// @}
@ -572,7 +585,8 @@ public:
private: private:
void init(const std::vector<double>& epsilon_values) template <class Epsilons>
void init(const Epsilons& epsilon_values)
{ {
halfspace_generation(env_vertices, env_faces, halfspace, bounding_boxes, epsilon_values); halfspace_generation(env_vertices, env_faces, halfspace, bounding_boxes, epsilon_values);
@ -1812,12 +1826,22 @@ private:
return Plane(plane0, plane1,plane2); return Plane(plane0, plane1,plane2);
} }
double get_epsilon(double epsilon, std::size_t)
{
return epsilon;
}
double get_epsilon(const std::vector<double>& epsilon_values, std::size_t i)
{
return epsilon_values[i];
}
// build prisms for a list of triangles. each prism is represented by 7-8 planes, which are represented by 3 points // build prisms for a list of triangles. each prism is represented by 7-8 planes, which are represented by 3 points
template <class Epsilons>
void void
halfspace_generation(const std::vector<Point_3> &ver, const std::vector<Vector3i> &faces, halfspace_generation(const std::vector<Point_3> &ver, const std::vector<Vector3i> &faces,
std::vector<Prism>& halfspace, std::vector<Prism>& halfspace,
std::vector<Iso_cuboid_3>& bounding_boxes, const std::vector<double>& epsilon_values) std::vector<Iso_cuboid_3>& bounding_boxes, const Epsilons& epsilon_values)
{ {
Vector_3 AB, AC, BC, normal; Vector_3 AB, AC, BC, normal;
Plane plane; Plane plane;
@ -1844,7 +1868,7 @@ private:
bounding_boxes.resize(faces.size()); bounding_boxes.resize(faces.size());
for (unsigned int i = 0; i < faces.size(); ++i) for (unsigned int i = 0; i < faces.size(); ++i)
{ {
const double epsilon = epsilon_values[i]; const double epsilon = get_epsilon(epsilon_values,i);
double tolerance = epsilon / std::sqrt(3);// the envelope thickness, to be conservative double tolerance = epsilon / std::sqrt(3);// the envelope thickness, to be conservative
double bbox_tolerance = epsilon *(1 + 1e-6); double bbox_tolerance = epsilon *(1 + 1e-6);