Commit cd4589aa authored by Philip Trettner's avatar Philip Trettner
Browse files

deprecated make_attribute_with_default, moved functionality to make_attribute

parent 0eb4baf7
......@@ -9,3 +9,4 @@
* `Mesh::copy` and `Mesh::create` now work on `pm::unique_ptr`
* `properties.hh` was renamed to `view.hh`
* `algorithms/properties.hh` was moved to `properties.hh`
* deprecated `make_attribute_with_default` and moved functionality to `make_attribute`
......@@ -6,7 +6,7 @@ using namespace polymesh;
vertex_attribute<int> polymesh::vertex_components(const Mesh& m, int* comps)
{
auto comp = m.vertices().make_attribute_with_default(-1);
auto comp = m.vertices().make_attribute(-1);
auto c_cnt = 0;
for (auto seed : m.vertices())
......@@ -40,7 +40,7 @@ vertex_attribute<int> polymesh::vertex_components(const Mesh& m, int* comps)
face_attribute<int> polymesh::face_components(const Mesh& m, int* comps)
{
auto comp = m.faces().make_attribute_with_default(-1);
auto comp = m.faces().make_attribute(-1);
auto c_cnt = 0;
for (auto seed : m.faces())
......
......@@ -139,8 +139,8 @@ void decimate(pm::Mesh& m, //
std::priority_queue<entry> queue;
auto gen = 0;
auto edge_gen = m.halfedges().make_attribute_with_default(0);
auto vreach = m.vertices().make_attribute_with_default(-1);
auto edge_gen = m.halfedges().make_attribute(0);
auto vreach = m.vertices().make_attribute(-1);
auto const enqueue = [&](pm::halfedge_handle h) {
auto const v_to = h.vertex_to();
......
......@@ -18,7 +18,7 @@ inline face_handle farthest_face(face_handle f)
std::vector<face_index> q_next;
auto const& m = *f.mesh;
auto visited = m.faces().make_attribute_with_default(false);
auto visited = m.faces().make_attribute(false);
q_curr.push_back(f.idx);
......
......@@ -232,9 +232,9 @@ struct halfedge_attribute final : primitive_attribute<halfedge_tag, AttrT>
};
template <class AttrT, class Collection>
auto attribute(Collection const& c, AttrT const& defaultValue = {}) -> decltype(c.make_attribute_with_default(defaultValue))
auto attribute(Collection const& c, AttrT const& defaultValue = {}) -> decltype(c.make_attribute(defaultValue))
{
return c.make_attribute_with_default(defaultValue);
return c.make_attribute(defaultValue);
}
} // namespace polymesh
......@@ -506,10 +506,11 @@ typename smart_collection<mesh_ptr, tag, iterator>::handle smart_collection<mesh
template <class mesh_ptr, class tag, class iterator>
template <class AttrT>
typename primitive<tag>::template attribute<AttrT> smart_collection<mesh_ptr, tag, iterator>::make_attribute() const
typename primitive<tag>::template attribute<AttrT> smart_collection<mesh_ptr, tag, iterator>::make_attribute(AttrT const& def_value) const
{
return typename primitive<tag>::template attribute<AttrT>(m, AttrT());
return typename primitive<tag>::template attribute<AttrT>(m, def_value);
}
template <class mesh_ptr, class tag, class iterator>
template <class AttrT>
typename primitive<tag>::template attribute<AttrT> smart_collection<mesh_ptr, tag, iterator>::make_attribute_with_default(AttrT const& def_value) const
......@@ -537,21 +538,14 @@ typename primitive<tag>::template attribute<AttrT> smart_collection<mesh_ptr, ta
template <class mesh_ptr, class tag, class iterator>
template <class FuncT, class AttrT>
typename primitive<tag>::template attribute<AttrT> smart_collection<mesh_ptr, tag, iterator>::make_attribute(FuncT&& f, AttrT const& def_value) const
typename primitive<tag>::template attribute<AttrT> smart_collection<mesh_ptr, tag, iterator>::map(FuncT&& f, AttrT const& def_value) const
{
auto attr = make_attribute_with_default<AttrT>(def_value);
auto attr = make_attribute<AttrT>(def_value);
for (auto&& h : *this)
attr[h] = f(h);
return attr; // copy elison
}
template <class mesh_ptr, class tag, class iterator>
template <class FuncT, class AttrT>
typename primitive<tag>::template attribute<AttrT> smart_collection<mesh_ptr, tag, iterator>::map(FuncT&& f, AttrT const& def_value) const
{
return this->make_attribute(f, def_value);
}
template <class mesh_ptr, class tag, class iterator>
iterator smart_collection<mesh_ptr, tag, iterator>::begin() const
{
......
......@@ -188,7 +188,7 @@ struct low_level_attribute_api
static int offset_attribute_dataptr()
{
MeshT mesh;
auto attr = mesh.vertices().make_attribute_with_default(0.f);
auto attr = mesh.vertices().make_attribute_(0.f);
auto offset = int(size_t(&(attr.mData)) - size_t(&attr));
return offset;
}
......
......@@ -526,7 +526,7 @@ template <class Pos3, class Scalar>
vertex_attribute<Scalar> vertex_voronoi_areas(vertex_attribute<Pos3> const& position)
{
auto const& m = position.mesh();
vertex_attribute<Scalar> areas = m.vertices().make_attribute_with_default(Scalar(0));
vertex_attribute<Scalar> areas = m.vertices().make_attribute(Scalar(0));
for (auto f : m.faces())
{
......@@ -544,7 +544,7 @@ vertex_attribute<typename field3<Pos3>::vec_t> vertex_normals_uniform(vertex_att
{
auto const& m = position.mesh();
auto fnormals = m.faces().map([&](face_handle f) { return triangle_normal(f, position); });
auto normals = m.vertices().make_attribute_with_default(field3<Pos3>::make_vec(0, 0, 0));
auto normals = m.vertices().make_attribute(field3<Pos3>::make_vec(0, 0, 0));
for (auto f : m.faces())
for (auto v : f.vertices())
......@@ -565,7 +565,7 @@ vertex_attribute<typename field3<Pos3>::vec_t> vertex_normals_by_area(vertex_att
{
auto const& m = position.mesh();
auto fnormals = m.faces().map([&](face_handle f) { return triangle_normal_unorm(f, position); });
auto normals = m.vertices().make_attribute_with_default(field3<Pos3>::make_vec(0, 0, 0));
auto normals = m.vertices().make_attribute(field3<Pos3>::make_vec(0, 0, 0));
for (auto f : m.faces())
for (auto v : f.vertices())
......
......@@ -217,21 +217,17 @@ struct smart_collection : smart_range<smart_collection<mesh_ptr, tag, iterator>,
/// Ensures that a given number of primitives can be stored without reallocation
void reserve(int capacity) const;
/// Creates a new primitive attribute
/// Creates a new primitive attribute (optionally with a default value)
template <class AttrT>
attribute<AttrT> make_attribute() const;
/// Creates a new primitive attribute with a given default value
attribute<AttrT> make_attribute(AttrT const& def_value = AttrT()) const;
template <class AttrT>
attribute<AttrT> make_attribute_with_default(AttrT const& def_value) const;
[[deprecated("use make_attribute instead")]] attribute<AttrT> make_attribute_with_default(AttrT const& def_value) const;
/// Creates a new primitive attribute and copies the given data
template <class AttrT>
attribute<AttrT> make_attribute_from_data(std::vector<AttrT> const& data) const;
/// Creates a new primitive attribute and copies the given data
template <class AttrT>
attribute<AttrT> make_attribute_from_data(AttrT const* data, int cnt) const;
/// Creates a new primitive attribute and initializes it with f(h) for each handle h
template <class FuncT, class AttrT = tmp::decayed_result_type_of<FuncT, handle>>
attribute<AttrT> make_attribute(FuncT&& f, AttrT const& def_value = AttrT()) const;
/// same as make_attribute(f, def_value)
template <class FuncT, class AttrT = tmp::decayed_result_type_of<FuncT, handle>>
attribute<AttrT> map(FuncT&& f, AttrT const& def_value = AttrT()) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment