diff --git a/Property_map/include/CGAL/Properties.h b/Property_map/include/CGAL/Properties.h index 47c0c6041fd..94e7dd729d1 100644 --- a/Property_map/include/CGAL/Properties.h +++ b/Property_map/include/CGAL/Properties.h @@ -102,8 +102,11 @@ public: public: - // todo: there's not really a good reason to use this, maybe it should be removed - std::size_t capacity() const { return m_data.size(); } + // todo: there's not really a good reason to use these, maybe they should be removed + + [[nodiscard]] std::size_t size() const { return std::count(m_active_indices.begin(), m_active_indices.end(), true); } + + [[nodiscard]] std::size_t capacity() const { return m_data.size(); } const_reference operator[](Index i) const { CGAL_precondition(std::size_t(i) < m_data.size()); @@ -142,6 +145,12 @@ public: Property_array_handle(Property_array& array) : m_array(array) {} + //Property_array_handle(Property_array_handle& handle) : m_array(handle.m_array) {} + + [[nodiscard]] std::size_t size() const { return m_array.size(); } + + [[nodiscard]] std::size_t capacity() const { return m_array.capacity(); } + const_reference operator[](Index i) const { return m_array[i]; } reference operator[](Index i) { return m_array[i]; } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 8e274941fc1..74830af23ad 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -57,10 +57,7 @@ private: public: PLY_property_to_surface_mesh_property(Surface_mesh& sm, const std::string& name) - : m_name(name) - { - m_map = sm.template add_property_map(prefix(Simplex()) + name).first; - } + : m_name(name), m_map(sm.template add_property_map(prefix(Simplex()) + name).first){} virtual void assign(PLY_element& element, size_type index) { @@ -79,11 +76,11 @@ private: std::vector m_map_v2v; bool m_use_floats; int m_normals; - typename Surface_mesh::template Property_map m_normal_map; + std::optional> m_normal_map; int m_vcolors; - typename Surface_mesh::template Property_map m_vcolor_map; + std::optional> m_vcolor_map; int m_fcolors; - typename Surface_mesh::template Property_map m_fcolor_map; + std::optional> m_fcolor_map; bool m_use_int32_t; std::string m_index_tag; std::vector m_vertex_properties; @@ -125,7 +122,7 @@ public: { ++ m_normals; if(m_normals == 3) - m_normal_map = m_mesh.template add_property_map("v:normal").first; + m_normal_map.emplace(m_mesh.template add_property_map("v:normal").first); return true; } if(name == "red" || @@ -134,7 +131,7 @@ public: { ++ m_vcolors; if(m_vcolors == 3) - m_vcolor_map = m_mesh.template add_property_map("v:color").first; + m_vcolor_map.emplace(m_mesh.template add_property_map("v:color").first); return true; } return false; @@ -157,7 +154,7 @@ public: { ++ m_fcolors; if(m_fcolors == 3) - m_fcolor_map = m_mesh.template add_property_map("f:color").first; + m_fcolor_map.emplace(m_mesh.template add_property_map("f:color").first); return true; } @@ -284,7 +281,7 @@ public: element.assign(ny, "ny"); element.assign(nz, "nz"); Vector normal(nx, ny, nz); - m_normal_map[vi] = normal; + (*m_normal_map)[vi] = normal; } if(m_vcolors == 3) @@ -305,7 +302,7 @@ public: g = static_cast(std::floor(gf*255)); b = static_cast(std::floor(bf*255)); } - m_vcolor_map[vi] = CGAL::IO::Color(r, g, b); + (*m_vcolor_map)[vi] = CGAL::IO::Color(r, g, b); } } @@ -359,7 +356,7 @@ public: g = static_cast(std::floor(gf*255)); b = static_cast(std::floor(bf*255)); } - m_fcolor_map[fi] = CGAL::IO::Color(r, g, b); + (*m_fcolor_map)[fi] = CGAL::IO::Color(r, g, b); } } @@ -658,19 +655,22 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, internal_np::vertex_color_map_t, CGAL_NP_CLASS, typename Surface_mesh::template Property_map >::type; + // typedef typename internal_np::Lookup_named_param_def< + // internal_np::vertex_color_map_t, CGAL_NP_CLASS, + // Constant_property_map >::type VCM; using parameters::choose_parameter; using parameters::is_default_parameter; using parameters::get_parameter; - VCM vcm = choose_parameter(get_parameter(np, internal_np::vertex_color_map), VCM()); + VCM vcm = choose_parameter(get_parameter(np, internal_np::vertex_color_map)); bool has_vcolor = !is_default_parameter::value; using FCM = typename internal_np::Lookup_named_param_def< internal_np::face_color_map_t, CGAL_NP_CLASS, typename Surface_mesh::template Property_map >::type; - FCM fcm = choose_parameter(get_parameter(np, internal_np::face_color_map), FCM()); + FCM fcm = choose_parameter(get_parameter(np, internal_np::face_color_map)); bool has_fcolor = !is_default_parameter::value; std::vector prop = sm.template properties(); @@ -710,8 +710,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, bool okay = false; { - Int8_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property char " << name << std::endl; @@ -720,8 +719,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Uint8_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property uchar " << name << std::endl; @@ -730,8 +728,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Int16_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property short " << name << std::endl; @@ -740,8 +737,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Uint16_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property ushort " << name << std::endl; @@ -750,8 +746,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Int32_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property int " << name << std::endl; @@ -760,8 +755,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Uint32_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property uint " << name << std::endl; @@ -770,8 +764,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Int64_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property int " << name << std::endl; @@ -780,8 +773,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Uint64_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property uint " << name << std::endl; @@ -790,8 +782,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Float_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property float " << name << std::endl; @@ -800,8 +791,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, } } { - Double_map pmap; - boost::tie(pmap, okay) = sm.template property_map(prop[i]); + auto [pmap, okay] = sm.template property_map(prop[i]); if(okay) { os << "property double " << name << std::endl;