Commit ba19b93a authored by Martin Heistermann's avatar Martin Heistermann

implement/improve mesh assignment

parent 29a2730e
Pipeline #10415 passed with stage
in 4 minutes and 5 seconds
......@@ -62,6 +62,7 @@ public:
BaseProperty& operator=(const BaseProperty& _cpy) = delete;
virtual ~BaseProperty() {}
virtual const std::string& name() const = 0;
......@@ -92,6 +93,10 @@ public:
protected:
/// Copy data from other property. `other` MUST point to an object with the same type as `this`!
/// Currently no type check is performed.
virtual void assign_values_from(const BaseProperty *other) = 0;
virtual void delete_multiple_entries(const std::vector<bool>& _tags) = 0;
virtual void resize(size_t /*_size*/) = 0;
......
......@@ -64,6 +64,11 @@ public:
/// Destructor
~GeometryKernel() = default;
template<class OtherTopoKernel>
void assign(const GeometryKernel<VecT, OtherTopoKernel> *other) {
TopologyKernelT::assign(other);
other->clone_vertices(vertices_);
}
/// Override of empty add_vertex function
virtual VertexHandle add_vertex() { return add_vertex(VecT()); }
......
......@@ -115,6 +115,8 @@ public:
protected:
void assign_values_from(const BaseProperty *other) override;
virtual void delete_multiple_entries(const std::vector<bool>& _tags);
virtual void resize(size_t _size);
......
......@@ -59,6 +59,13 @@ PropertyPtr<PropT,Entity>::~PropertyPtr() {
}
}
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::assign_values_from(const BaseProperty *other) {
auto _other = static_cast<const PropertyPtr<PropT,Entity>*>(other);
// FIXME: would be nice to perform a type check here
ptr::shared_ptr<PropT>::get()->data_vector() = _other->get()->data_vector();
}
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::resize(size_t _size) {
ptr::shared_ptr<PropT>::get()->resize(_size);
......
......@@ -51,11 +51,34 @@ ResourceManager& ResourceManager::operator=(const ResourceManager &other)
if (this == &other)
return *this;
auto cloneProps = [this](const Properties &src, Properties &dest) {
dest.reserve(src.size());
for (BaseProperty *bp: src) {
dest.push_back(bp->clone(*this, bp->handle()));
auto cloneProps = [this](const Properties &src, Properties &dest)
{
// If possible, re-use existing properties instead of copying
// everything blindly.
// This way, references to properties of `this` do not expire
// if a corresponding property exists in `other`, e.g. attributes.
Properties out;
out.reserve(src.size());
for (BaseProperty *srcprop: src) {
bool found = false;
for (auto it = dest.begin(); it != dest.end(); ++it) {
auto dstprop = *it;
if (dstprop->name() == srcprop->name())
{
// TODO: type check
out.push_back(dstprop);
dest.erase(it);
dstprop->assign_values_from(srcprop);
found = true;
break;
}
}
if (!found) {
out.push_back(srcprop->clone(*this, OpenVolumeMeshHandle(-1)));
}
}
updatePropHandles(out);
dest = std::move(out);
};
cloneProps(other.vertex_props_, vertex_props_);
cloneProps(other.edge_props_, edge_props_);
......@@ -72,7 +95,8 @@ ResourceManager& ResourceManager::operator=(ResourceManager &&other)
if (this == &other)
return *this;
auto moveProps = [this](Properties &&src, Properties &dest) {
auto moveProps = [this](Properties &&src, Properties &dest){
// TODO: check for existing properties and move data contents instead of Property classes
dest = std::move(src);
for (auto prop: dest) {
prop->setResMan(this);
......
......@@ -62,6 +62,9 @@ public:
TopologyKernel& operator=(const TopologyKernel&) = default;
void assign(const TopologyKernel *other) {
*this = *other;
}
/*
* Defines and constants
......
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