From 04b6d96aab1c1356085198148467173d79c945af Mon Sep 17 00:00:00 2001 From: Li-Ta Lo Date: Fri, 2 Jun 2023 10:32:44 -0600 Subject: [PATCH] enable copying for Actor and ConnectivityProxy --- examples/demo/Demo.cxx | 2 +- examples/ising/Ising.cxx | 2 +- vtkm/rendering/Actor.cxx | 29 +++++++++++++++++++++++++++- vtkm/rendering/Actor.h | 5 ++--- vtkm/rendering/ConnectivityProxy.cxx | 29 ++++++++++++++++++++++++++++ vtkm/rendering/ConnectivityProxy.h | 4 ++-- 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/examples/demo/Demo.cxx b/examples/demo/Demo.cxx index 8f289fed1..35e099016 100644 --- a/examples/demo/Demo.cxx +++ b/examples/demo/Demo.cxx @@ -55,7 +55,7 @@ int main(int argc, char* argv[]) tangleData.GetField(fieldName), colorTable); vtkm::rendering::Scene scene; - scene.AddActor(std::move(actor)); + scene.AddActor(actor); // 2048x2048 pixels in the canvas: CanvasRayTracer canvas(2048, 2048); // Create a view and use it to render the input data using OS Mesa diff --git a/examples/ising/Ising.cxx b/examples/ising/Ising.cxx index e2942c1e7..48f748ff5 100644 --- a/examples/ising/Ising.cxx +++ b/examples/ising/Ising.cxx @@ -104,7 +104,7 @@ int main(int argc, char** argv) dataSet.GetCoordinateSystem(), dataSet.GetCellField("spins"), vtkm::cont::ColorTable("Cool To Warm")); - scene.AddActor(std::move(actor)); + scene.AddActor(actor); vtkm::rendering::CanvasRayTracer canvas(1024, 1024); vtkm::rendering::MapperRayTracer mapper; mapper.SetShadingOn(false); diff --git a/vtkm/rendering/Actor.cxx b/vtkm/rendering/Actor.cxx index 240cfaf39..e9be71c9e 100644 --- a/vtkm/rendering/Actor.cxx +++ b/vtkm/rendering/Actor.cxx @@ -81,9 +81,36 @@ Actor::Actor(const vtkm::cont::UnknownCellSet& cells, this->Init(coordinates, scalarField); } -Actor::~Actor() = default; +Actor::Actor(const Actor& rhs) + : Internals(nullptr) +{ + // rhs might have been moved, its Internal would be nullptr + if (rhs.Internals) + Internals = std::make_unique(*rhs.Internals); +} + +Actor& Actor::operator=(const Actor& rhs) +{ + // both *this and rhs might have been moved. + if (!rhs.Internals) + { + Internals.reset(); + } + else if (!Internals) + { + Internals = std::make_unique(*rhs.Internals); + } + else + { + *Internals = *rhs.Internals; + } + + return *this; +} + Actor::Actor(vtkm::rendering::Actor&&) noexcept = default; Actor& Actor::operator=(Actor&&) noexcept = default; +Actor::~Actor() = default; void Actor::Init(const vtkm::cont::CoordinateSystem& coordinates, const vtkm::cont::Field& scalarField) diff --git a/vtkm/rendering/Actor.h b/vtkm/rendering/Actor.h index 9716d9b79..820de6bf6 100644 --- a/vtkm/rendering/Actor.h +++ b/vtkm/rendering/Actor.h @@ -40,9 +40,8 @@ public: const vtkm::cont::Field& scalarField, const vtkm::rendering::Color& color); - // Disable copying due to unique_ptr; - Actor(const Actor&) = delete; - Actor& operator=(const Actor&) = delete; + Actor(const Actor&); + Actor& operator=(const Actor&); Actor(Actor&&) noexcept; Actor& operator=(Actor&&) noexcept; diff --git a/vtkm/rendering/ConnectivityProxy.cxx b/vtkm/rendering/ConnectivityProxy.cxx index 990875248..6e0f8dcbc 100644 --- a/vtkm/rendering/ConnectivityProxy.cxx +++ b/vtkm/rendering/ConnectivityProxy.cxx @@ -259,6 +259,35 @@ ConnectivityProxy::ConnectivityProxy(const vtkm::cont::UnknownCellSet& cellset, Internals = std::make_unique(dataset, scalarField.GetName()); } +ConnectivityProxy::ConnectivityProxy(const ConnectivityProxy& rhs) + : Internals(nullptr) +{ + // rhs might have been moved, its Internal would be nullptr + if (rhs.Internals) + { + Internals = std::make_unique(*rhs.Internals); + } +} + +ConnectivityProxy& ConnectivityProxy::operator=(const ConnectivityProxy& rhs) +{ + // both *this and rhs might have been moved. + if (!rhs.Internals) + { + Internals.reset(); + } + else if (!Internals) + { + Internals = std::make_unique(*rhs.Internals); + } + else + { + *Internals = *rhs.Internals; + } + + return *this; +} + VTKM_CONT ConnectivityProxy::ConnectivityProxy(ConnectivityProxy&&) noexcept = default; VTKM_CONT diff --git a/vtkm/rendering/ConnectivityProxy.h b/vtkm/rendering/ConnectivityProxy.h index 7054bef70..f5f2916a0 100644 --- a/vtkm/rendering/ConnectivityProxy.h +++ b/vtkm/rendering/ConnectivityProxy.h @@ -35,8 +35,8 @@ public: const vtkm::cont::CoordinateSystem& coords, const vtkm::cont::Field& scalarField); - ConnectivityProxy(const ConnectivityProxy&) = delete; - ConnectivityProxy& operator=(const ConnectivityProxy&) = delete; + ConnectivityProxy(const ConnectivityProxy&); + ConnectivityProxy& operator=(const ConnectivityProxy&); ConnectivityProxy(ConnectivityProxy&&) noexcept; ConnectivityProxy& operator=(ConnectivityProxy&&) noexcept;