diff --git a/BGL/include/CGAL/boost/graph/named_params_helper.h b/BGL/include/CGAL/boost/graph/named_params_helper.h index 303ab8c9ba1..b70872a7334 100644 --- a/BGL/include/CGAL/boost/graph/named_params_helper.h +++ b/BGL/include/CGAL/boost/graph/named_params_helper.h @@ -335,10 +335,10 @@ struct Point_set_processing_3_np_helper return parameters::choose_parameter(parameters::get_parameter(np, internal_np::geom_traits)); } - static constexpr bool has_normal_map() + static constexpr bool has_normal_map(const PointRange&, const NamedParameters&) { - return !std::is_same< typename internal_np::Get_param::type, - internal_np::Param_not_found> ::value; + using CGAL::parameters::is_default_parameter; + return !(is_default_parameter::value); } }; diff --git a/Point_set_3/include/CGAL/Point_set_3.h b/Point_set_3/include/CGAL/Point_set_3.h index 304cf589d5f..c48e0ad463c 100644 --- a/Point_set_3/include/CGAL/Point_set_3.h +++ b/Point_set_3/include/CGAL/Point_set_3.h @@ -465,8 +465,9 @@ public: \note Properties of the added point other than its normal vector are initialized to their default value. - \note A normal property must have been added to the point set - before using this method. + \note If not already added, a normal property is automatically + added to the point set when using this method. The default value + for normal vectors is `CGAL::NULL_VECTOR`. \note If a reallocation happens, all iterators, pointers and references related to the container are invalidated. Otherwise, @@ -479,8 +480,7 @@ public: iterator insert (const Point& p, const Vector& n) { iterator out = insert (p); - CGAL_assertion(has_normal_map()); - m_normals[size()-1] = n; + normal_map()[size()-1] = n; return out; } @@ -550,17 +550,17 @@ public: /*! \brief returns a reference to the normal corresponding to `index`. - \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + \note If not already added, a normal property is automatically + added to the point set (see `add_normal_map()`). */ - Vector& normal (const Index& index) { return m_normals[index]; } + Vector& normal (const Index& index) { return normal_map()[index]; } /*! \brief returns a constant reference to the normal corresponding to `index`. - \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + \note If not already added, a normal property is automatically + added to the point set (see `add_normal_map()`). */ - const Vector& normal (const Index& index) const { return m_normals[index]; } + const Vector& normal (const Index& index) const { return normal_map()[index]; } /// @} @@ -869,11 +869,14 @@ public: /*! \brief returns the property map of the normal property. - \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + \note If the normal property has not been added yet to the point set + before calling this method, the property map is automatically added + with `add_normal_map()`. */ Vector_map normal_map () { + if (!m_normals) + add_normal_map(); return m_normals; } /*! @@ -982,7 +985,7 @@ public: inline parameters() const { return CGAL::parameters::point_map (m_points). - normal_map (m_normals). + normal_map (normal_map()). geom_traits (typename Kernel_traits::Kernel()); } @@ -1036,7 +1039,7 @@ public: */ Vector_range normals () const { - return this->range (m_normals); + return this->range (normal_map()); } /// @} @@ -1354,11 +1357,18 @@ struct Point_set_processing_3_np_helper, NamedParamet return parameters::choose_parameter(parameters::get_parameter(np, internal_np::geom_traits)); } - static constexpr bool has_normal_map() + static bool has_normal_map(const Point_set_3& ps, const NamedParameters&) { - return true; + if (ps.has_normal_map()) + return true; + using CGAL::parameters::is_default_parameter; + return !(is_default_parameter::value); } + static constexpr bool has_normal_map(Point_set_3&, const NamedParameters&) + { + return true; // either available in named parameters, and always available in Point_set_3 otherwise + } }; /// \endcond diff --git a/Point_set_processing_3/include/CGAL/IO/read_off_points.h b/Point_set_processing_3/include/CGAL/IO/read_off_points.h index e002a834c5f..660601cb985 100644 --- a/Point_set_processing_3/include/CGAL/IO/read_off_points.h +++ b/Point_set_processing_3/include/CGAL/IO/read_off_points.h @@ -97,8 +97,6 @@ bool read_OFF(std::istream& is, typedef typename NP_helper::Geom_traits Kernel; typedef typename Kernel::FT FT; - bool has_normals = NP_helper::has_normal_map(); - PointMap point_map = NP_helper::get_point_map(np); NormalMap normal_map = NP_helper::get_normal_map(np); @@ -182,8 +180,7 @@ bool read_OFF(std::istream& is, Enriched_point pwn; put(point_map, pwn, point); // point_map[&pwn] = point - if (has_normals) - put(normal_map, pwn, normal); // normal_map[&pwn] = normal + put(normal_map, pwn, normal); // normal_map[&pwn] = normal *output++ = pwn; ++pointsRead; diff --git a/Point_set_processing_3/include/CGAL/IO/read_ply_points.h b/Point_set_processing_3/include/CGAL/IO/read_ply_points.h index 282ad59d4a3..93cf9c91356 100644 --- a/Point_set_processing_3/include/CGAL/IO/read_ply_points.h +++ b/Point_set_processing_3/include/CGAL/IO/read_ply_points.h @@ -257,17 +257,12 @@ bool read_PLY(std::istream& is, typedef typename NP_helper::Point_map PointMap; typedef typename NP_helper::Normal_map NormalMap; - bool has_normals = NP_helper::has_normal_map(); - PointMap point_map = NP_helper::get_point_map(np); NormalMap normal_map = NP_helper::get_normal_map(np); - if(has_normals) - return read_PLY_with_properties(is, output, - make_ply_point_reader(point_map), - make_ply_normal_reader(normal_map)); - // else - return read_PLY_with_properties(is, output, make_ply_point_reader(point_map)); + return read_PLY_with_properties(is, output, + make_ply_point_reader(point_map), + make_ply_normal_reader(normal_map)); } /** diff --git a/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h b/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h index caf7e062a5e..b930b167d09 100644 --- a/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h +++ b/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h @@ -89,8 +89,6 @@ bool read_XYZ(std::istream& is, typedef typename NP_helper::Normal_map NormalMap; typedef typename NP_helper::Geom_traits Kernel; - bool has_normals = NP_helper::has_normal_map(); - PointMap point_map = NP_helper::get_point_map(np); NormalMap normal_map = NP_helper::get_normal_map(np); @@ -155,8 +153,7 @@ bool read_XYZ(std::istream& is, Enriched_point pwn; put(point_map, pwn, point); // point_map[pwn] = point - if (has_normals) - put(normal_map, pwn, normal); // normal_map[pwn] = normal + put(normal_map, pwn, normal); // normal_map[pwn] = normal *output++ = pwn; continue; diff --git a/Point_set_processing_3/include/CGAL/IO/write_off_points.h b/Point_set_processing_3/include/CGAL/IO/write_off_points.h index 0be0e4183a3..d5411b67fd9 100644 --- a/Point_set_processing_3/include/CGAL/IO/write_off_points.h +++ b/Point_set_processing_3/include/CGAL/IO/write_off_points.h @@ -45,7 +45,7 @@ bool write_OFF_PSP(std::ostream& os, typedef typename NP_helper::Const_point_map PointMap; typedef typename NP_helper::Normal_map NormalMap; - const bool has_normals = !(is_default_parameter::value); + const bool has_normals = NP_helper::has_normal_map(points, np); PointMap point_map = NP_helper::get_const_point_map(points, np); NormalMap normal_map = NP_helper::get_normal_map(points, np); diff --git a/Point_set_processing_3/include/CGAL/IO/write_ply_points.h b/Point_set_processing_3/include/CGAL/IO/write_ply_points.h index 6dca998ae72..525bc159023 100644 --- a/Point_set_processing_3/include/CGAL/IO/write_ply_points.h +++ b/Point_set_processing_3/include/CGAL/IO/write_ply_points.h @@ -201,7 +201,7 @@ bool write_PLY(std::ostream& os, typedef typename NP_helper::Const_point_map PointMap; typedef typename NP_helper::Normal_map NormalMap; - bool has_normals = NP_helper::has_normal_map(); + const bool has_normals = NP_helper::has_normal_map(points, np); PointMap point_map = NP_helper::get_const_point_map(points, np); NormalMap normal_map = NP_helper::get_normal_map(points, np); diff --git a/Point_set_processing_3/include/CGAL/IO/write_xyz_points.h b/Point_set_processing_3/include/CGAL/IO/write_xyz_points.h index 2f2cc0ae701..43875b1a5d8 100644 --- a/Point_set_processing_3/include/CGAL/IO/write_xyz_points.h +++ b/Point_set_processing_3/include/CGAL/IO/write_xyz_points.h @@ -46,7 +46,7 @@ bool write_XYZ_PSP(std::ostream& os, typedef typename NP_helper::Const_point_map PointMap; typedef typename NP_helper::Normal_map NormalMap; - bool has_normals = NP_helper::has_normal_map(); + const bool has_normals = NP_helper::has_normal_map(points, np); PointMap point_map = NP_helper::get_const_point_map(points, np); NormalMap normal_map = NP_helper::get_normal_map(points, np); diff --git a/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h b/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h index 396d9cdb0e0..6588d5f32f2 100644 --- a/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h +++ b/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h @@ -278,7 +278,7 @@ bilateral_smooth_point_set( typedef typename Kernel::Point_3 Point_3; typedef typename Kernel::Vector_3 Vector_3; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); typedef typename Kernel::FT FT; diff --git a/Point_set_processing_3/include/CGAL/edge_aware_upsample_point_set.h b/Point_set_processing_3/include/CGAL/edge_aware_upsample_point_set.h index bf4b589d788..c74414b6cb2 100644 --- a/Point_set_processing_3/include/CGAL/edge_aware_upsample_point_set.h +++ b/Point_set_processing_3/include/CGAL/edge_aware_upsample_point_set.h @@ -367,7 +367,7 @@ edge_aware_upsample_point_set( typedef typename NP_helper::Geom_traits Kernel; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); typedef typename Kernel::Point_3 Point; typedef typename Kernel::Vector_3 Vector; diff --git a/Point_set_processing_3/include/CGAL/jet_estimate_normals.h b/Point_set_processing_3/include/CGAL/jet_estimate_normals.h index 30a7f34d48c..d808a6ee46f 100644 --- a/Point_set_processing_3/include/CGAL/jet_estimate_normals.h +++ b/Point_set_processing_3/include/CGAL/jet_estimate_normals.h @@ -196,7 +196,7 @@ jet_estimate_normals( typedef typename Kernel::FT FT; typedef typename GetSvdTraits::type SvdTraits; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); CGAL_static_assertion_msg(!(std::is_same::NoTraits>::value), "Error: no SVD traits"); diff --git a/Point_set_processing_3/include/CGAL/mst_orient_normals.h b/Point_set_processing_3/include/CGAL/mst_orient_normals.h index 2a284b2e859..aa576df9f80 100644 --- a/Point_set_processing_3/include/CGAL/mst_orient_normals.h +++ b/Point_set_processing_3/include/CGAL/mst_orient_normals.h @@ -631,7 +631,7 @@ mst_orient_normals( typedef typename NP_helper::Geom_traits Kernel; typedef typename Point_set_processing_3::GetIsConstrainedMap::type ConstrainedMap; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); PointMap point_map = NP_helper::get_point_map(points, np); NormalMap normal_map = NP_helper::get_normal_map(points, np); diff --git a/Point_set_processing_3/include/CGAL/pca_estimate_normals.h b/Point_set_processing_3/include/CGAL/pca_estimate_normals.h index 4d5e04b9491..897ade8967c 100644 --- a/Point_set_processing_3/include/CGAL/pca_estimate_normals.h +++ b/Point_set_processing_3/include/CGAL/pca_estimate_normals.h @@ -168,7 +168,7 @@ pca_estimate_normals( typedef typename NP_helper::Geom_traits Kernel; typedef typename Kernel::FT FT; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); PointMap point_map = NP_helper::get_point_map(points, np); NormalMap normal_map = NP_helper::get_normal_map(points, np); diff --git a/Point_set_processing_3/include/CGAL/scanline_orient_normals.h b/Point_set_processing_3/include/CGAL/scanline_orient_normals.h index 62c0ea1f76d..2623dbc112c 100644 --- a/Point_set_processing_3/include/CGAL/scanline_orient_normals.h +++ b/Point_set_processing_3/include/CGAL/scanline_orient_normals.h @@ -479,7 +479,7 @@ void scanline_orient_normals (PointRange& points, const NamedParameters& np = pa ::type; using Fallback_scanline_ID = Boolean_tag::value>; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); PointMap point_map = NP_helper::get_point_map(points, np); NormalMap normal_map = NP_helper::get_normal_map(points, np); diff --git a/Point_set_processing_3/include/CGAL/structure_point_set.h b/Point_set_processing_3/include/CGAL/structure_point_set.h index f2d9bd447c3..b421f811b4b 100644 --- a/Point_set_processing_3/include/CGAL/structure_point_set.h +++ b/Point_set_processing_3/include/CGAL/structure_point_set.h @@ -233,7 +233,7 @@ public: typedef typename Point_set_processing_3::GetPlaneMap::type PlaneMap; typedef typename Point_set_processing_3::GetPlaneIndexMap::type PlaneIndexMap; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); CGAL_static_assertion_msg((!is_default_parameter::value), "Error: no plane index map"); diff --git a/Point_set_processing_3/include/CGAL/vcm_estimate_normals.h b/Point_set_processing_3/include/CGAL/vcm_estimate_normals.h index bf7a7f5225c..b85d68cc9e9 100644 --- a/Point_set_processing_3/include/CGAL/vcm_estimate_normals.h +++ b/Point_set_processing_3/include/CGAL/vcm_estimate_normals.h @@ -321,7 +321,7 @@ vcm_estimate_normals_internal (PointRange& points, typedef typename NP_helper::Geom_traits Kernel; typedef typename GetDiagonalizeTraits::type DiagonalizeTraits; - CGAL_static_assertion_msg(NP_helper::has_normal_map(), "Error: no normal map"); + CGAL_assertion_msg(NP_helper::has_normal_map(points, np), "Error: no normal map"); PointMap point_map = NP_helper::get_point_map(points, np); NormalMap normal_map = NP_helper::get_normal_map(points, np);