Rework vtkCompositeDataSet::ShallowCopy

- vtkCompositeDataSet::ShallowCopy now perfoms a true shallow copy (up to array pointers)
- Introduce a vtkCompositeDataSet::CompositeShallowCopy(vtkCompositeDataSet*) that shallow dataset pointers only
- Deprecate vtkCompositeDataSet::RecursiveShallowCopy
dev
Mathieu Westphal 2 months ago
parent 08c4b0ad52
commit 4a1994d926

@ -109,7 +109,7 @@ void vtkAMRDataInternals::GenerateIndex(bool force)
}
}
void vtkAMRDataInternals::ShallowCopy(vtkObject* src)
void vtkAMRDataInternals::CompositeShallowCopy(vtkObject* src)
{
if (src == this)
{
@ -124,7 +124,7 @@ void vtkAMRDataInternals::ShallowCopy(vtkObject* src)
this->Modified();
}
void vtkAMRDataInternals::RecursiveShallowCopy(vtkObject* src)
void vtkAMRDataInternals::ShallowCopy(vtkObject* src)
{
if (src == this)
{

@ -53,8 +53,8 @@ public:
void Insert(unsigned int index, vtkUniformGrid* grid);
vtkUniformGrid* GetDataSet(unsigned int compositeIndex);
virtual void ShallowCopy(vtkObject* src);
void RecursiveShallowCopy(vtkObject* src);
void CompositeShallowCopy(vtkObject* src);
void ShallowCopy(vtkObject* src);
bool Empty() const { return this->GetNumberOfBlocks() == 0; }

@ -281,7 +281,7 @@ void vtkAMRUtilities::StripGhostLayers(
if (!vtkAMRUtilities::HasPartiallyOverlappingGhostCells(ghostedAMRData))
{
strippedAMRData->ShallowCopy(ghostedAMRData);
strippedAMRData->CompositeShallowCopy(ghostedAMRData);
return;
}

@ -22,6 +22,7 @@
#include "vtkInformationIntegerKey.h"
#include "vtkInformationStringKey.h"
#include "vtkInformationVector.h"
#include "vtkLegacy.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
@ -50,36 +51,22 @@ vtkCompositeDataSet* vtkCompositeDataSet::GetData(vtkInformationVector* v, int i
//------------------------------------------------------------------------------
void vtkCompositeDataSet::CopyStructure(vtkCompositeDataSet* input)
{
if (input != this)
{
// copy data-information and other common stuff by calling
// superclass' ShallowCopy.
this->Superclass::ShallowCopy(input);
}
// copy data-information and other common stuff by calling
// superclass' ShallowCopy.
this->Superclass::ShallowCopy(input);
}
//------------------------------------------------------------------------------
void vtkCompositeDataSet::ShallowCopy(vtkDataObject* src)
void vtkCompositeDataSet::CompositeShallowCopy(vtkCompositeDataSet* src)
{
if (src == this)
{
return;
}
this->Superclass::ShallowCopy(src);
this->Modified();
}
//------------------------------------------------------------------------------
void vtkCompositeDataSet::DeepCopy(vtkDataObject* src)
void vtkCompositeDataSet::RecursiveShallowCopy(vtkDataObject* src)
{
if (src == this)
{
return;
}
this->Superclass::DeepCopy(src);
this->Modified();
VTK_LEGACY_REPLACED_BODY(RecursiveShallowCopy, "VTK 9.3", ShallowCopy);
this->ShallowCopy(src);
}
//------------------------------------------------------------------------------

@ -35,6 +35,7 @@
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkDataObject.h"
#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
#include <vector> // For GetDataSets
@ -115,21 +116,20 @@ public:
*/
void Initialize() override;
///@{
/**
* Shallow and Deep copy.
* The goal of the method is to copy the data up to the dataset pointers only.
* The implementation is delegated to the differenent subclasses.
* If you want to copy up to array pointers, @see vtkDataObject::ShallowCopy.
*
* This method just calls vtkDataObject::ShallowCopy.
*/
void ShallowCopy(vtkDataObject* src) override;
void DeepCopy(vtkDataObject* src) override;
///@}
virtual void CompositeShallowCopy(vtkCompositeDataSet* src);
/**
* For historical reasons, `vtkCompositeDataSet::ShallowCopy` simply pass
* pointers to the leaf non-composite datasets. In some cases, we truly want
* to shallow copy those leaf non-composite datasets as well. For those cases,
* use this method.
* @deprecated RecursiveShallowCopy method, @see ShallowCopy
*/
virtual void RecursiveShallowCopy(vtkDataObject* src) = 0;
VTK_DEPRECATED_IN_9_3_0("Use ShallowCopy instead.")
virtual void RecursiveShallowCopy(vtkDataObject* src);
/**
* Returns the total number of points of all blocks. This will

@ -225,7 +225,7 @@ bool vtkDataAssemblyUtilities::GenerateHierarchyInternal(
}
if (auto pdc = vtkPartitionedDataSetCollection::SafeDownCast(dobj))
{
output->GetPartitionedDataSet(oid)->ShallowCopy(pdc);
output->GetPartitionedDataSet(oid)->CompositeShallowCopy(pdc);
}
else if (auto mp = vtkMultiPieceDataSet::SafeDownCast(dobj))
{
@ -319,7 +319,7 @@ bool vtkDataAssemblyUtilities::GenerateHierarchyInternal(vtkPartitionedDataSetCo
assert(input != nullptr && hierarchy != nullptr);
if (output)
{
output->ShallowCopy(input);
output->CompositeShallowCopy(input);
}
std::map<int, unsigned int> output_node2dataset_map;

@ -501,6 +501,12 @@ void vtkDataObject::ShallowCopy(vtkDataObject* src)
return;
}
if (src == this)
{
vtkWarningMacro("Attempted to ShallowCopy the data object into itself.");
return;
}
this->InternalDataObjectCopy(src);
if (!src->FieldData)
@ -526,6 +532,18 @@ void vtkDataObject::ShallowCopy(vtkDataObject* src)
//------------------------------------------------------------------------------
void vtkDataObject::DeepCopy(vtkDataObject* src)
{
if (!src)
{
vtkWarningMacro("Attempted to DeepCopy from null.");
return;
}
if (src == this)
{
vtkWarningMacro("Attempted to DeepCopy the data object into itself.");
return;
}
vtkFieldData* srcFieldData = src->GetFieldData();
this->InternalDataObjectCopy(src);
@ -581,6 +599,8 @@ void vtkDataObject::InternalDataObjectCopy(vtkDataObject* src)
// this->PipelineMTime = src->PipelineMTime;
// this->UpdateTime = src->UpdateTime;
// this->Locality = src->Locality;
this->Modified();
}
//------------------------------------------------------------------------------

@ -217,14 +217,23 @@ public:
*/
virtual void PrepareForNewData() { this->Initialize(); }
///@{
/**
* Shallow and Deep copy. These copy the data, but not any of the
* pipeline connections.
* The goal of the method is to copy the data up to the array pointers only.
* The implementation is delegated to the differenent subclasses.
* If you want to copy the actual data, @see DeepCopy.
*
* This method shallow copy the field data and copy the internal structure.
*/
virtual void ShallowCopy(vtkDataObject* src);
/**
* The goal of the method is to copy the complete data from src into this object.
* The implementation is delegated to the differenent subclasses.
* If you want to copy the data up to the array pointers only, @see ShallowCopy.
*
* This method deep copy the field data and copy the internal structure.
*/
virtual void DeepCopy(vtkDataObject* src);
///@}
/**
* The ExtentType will be left as VTK_PIECES_EXTENT for data objects

@ -21,6 +21,7 @@
#include "vtkInformationIntegerKey.h"
#include "vtkInformationStringKey.h"
#include "vtkInformationVector.h"
#include "vtkLegacy.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkObjectFactory.h"
@ -470,7 +471,7 @@ int vtkDataObjectTree::HasMetaData(vtkCompositeDataIterator* compositeIter)
}
//------------------------------------------------------------------------------
void vtkDataObjectTree::ShallowCopy(vtkDataObject* src)
void vtkDataObjectTree::CompositeShallowCopy(vtkCompositeDataSet* src)
{
if (src == this)
{
@ -478,7 +479,7 @@ void vtkDataObjectTree::ShallowCopy(vtkDataObject* src)
}
this->Internals->Children.clear();
this->Superclass::ShallowCopy(src);
this->Superclass::CompositeShallowCopy(src);
vtkDataObjectTree* from = vtkDataObjectTree::SafeDownCast(src);
if (from)
@ -490,10 +491,11 @@ void vtkDataObjectTree::ShallowCopy(vtkDataObject* src)
vtkDataObject* child = from->GetChild(cc);
if (child)
{
if (child->IsA("vtkDataObjectTree"))
vtkDataObjectTree* childTree = vtkDataObjectTree::SafeDownCast(child);
if (childTree)
{
vtkDataObject* clone = child->NewInstance();
clone->ShallowCopy(child);
vtkDataObjectTree* clone = childTree->NewInstance();
clone->CompositeShallowCopy(childTree);
this->SetChild(cc, clone);
clone->FastDelete();
}
@ -505,7 +507,7 @@ void vtkDataObjectTree::ShallowCopy(vtkDataObject* src)
if (from->HasChildMetaData(cc))
{
vtkInformation* toInfo = this->GetChildMetaData(cc);
toInfo->Copy(from->GetChildMetaData(cc), /*deep=*/0);
toInfo->Copy(from->GetChildMetaData(cc), 0);
}
}
}
@ -549,7 +551,7 @@ void vtkDataObjectTree::DeepCopy(vtkDataObject* src)
}
//------------------------------------------------------------------------------
void vtkDataObjectTree::RecursiveShallowCopy(vtkDataObject* src)
void vtkDataObjectTree::ShallowCopy(vtkDataObject* src)
{
if (src == this)
{
@ -584,6 +586,13 @@ void vtkDataObjectTree::RecursiveShallowCopy(vtkDataObject* src)
this->Modified();
}
//------------------------------------------------------------------------------
void vtkDataObjectTree::RecursiveShallowCopy(vtkDataObject* src)
{
VTK_LEGACY_REPLACED_BODY(RecursiveShallowCopy, "VTK 9.3", ShallowCopy);
this->ShallowCopy(src);
}
//------------------------------------------------------------------------------
void vtkDataObjectTree::Initialize()
{

@ -35,6 +35,7 @@
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkCompositeDataSet.h"
#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
VTK_ABI_NAMESPACE_BEGIN
class vtkCompositeDataIterator;
@ -125,13 +126,19 @@ public:
///@{
/**
* Shallow and Deep copy.
* CompositeShallow, Shallow and Deep copy.
*/
void CompositeShallowCopy(vtkCompositeDataSet* src) override;
void ShallowCopy(vtkDataObject* src) override;
void DeepCopy(vtkDataObject* src) override;
void RecursiveShallowCopy(vtkDataObject* src) override;
///@}
/**
* @deprecated RecursiveShallowCopy method, @see ShallowCopy
*/
VTK_DEPRECATED_IN_9_3_0("Please use ShallowCopy instead.")
void RecursiveShallowCopy(vtkDataObject* src) override;
/**
* Returns the total number of points of all blocks. This will
* iterate over all blocks and call GetNumberOfPoints() so it

@ -174,6 +174,16 @@ void vtkPartitionedDataSetCollection::CopyStructure(vtkCompositeDataSet* input)
}
}
//------------------------------------------------------------------------------
void vtkPartitionedDataSetCollection::CompositeShallowCopy(vtkCompositeDataSet* src)
{
this->Superclass::CompositeShallowCopy(src);
if (auto pdc = vtkPartitionedDataSetCollection::SafeDownCast(src))
{
this->SetDataAssembly(pdc->GetDataAssembly());
}
}
//------------------------------------------------------------------------------
void vtkPartitionedDataSetCollection::ShallowCopy(vtkDataObject* src)
{

@ -164,6 +164,7 @@ public:
/**
* Overridden to handle vtkDataAssembly.
*/
void CompositeShallowCopy(vtkCompositeDataSet* src) override;
void ShallowCopy(vtkDataObject* src) override;
void DeepCopy(vtkDataObject* src) override;
void CopyStructure(vtkCompositeDataSet* input) override;

@ -18,6 +18,7 @@
#include "vtkInformation.h"
#include "vtkInformationKey.h"
#include "vtkInformationVector.h"
#include "vtkLegacy.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkType.h"
@ -257,19 +258,19 @@ vtkUniformGridAMR* vtkUniformGridAMR::GetData(vtkInformationVector* v, int i)
}
//------------------------------------------------------------------------------
void vtkUniformGridAMR::ShallowCopy(vtkDataObject* src)
void vtkUniformGridAMR::CompositeShallowCopy(vtkCompositeDataSet* src)
{
if (src == this)
{
return;
}
this->Superclass::ShallowCopy(src);
this->Superclass::CompositeShallowCopy(src);
if (vtkUniformGridAMR* hbds = vtkUniformGridAMR::SafeDownCast(src))
{
this->SetAMRInfo(hbds->GetAMRInfo());
this->AMRData->ShallowCopy(hbds->GetAMRData());
this->AMRData->CompositeShallowCopy(hbds->GetAMRData());
memcpy(this->Bounds, hbds->Bounds, sizeof(double) * 6);
}
@ -316,7 +317,7 @@ void vtkUniformGridAMR::CopyStructure(vtkCompositeDataSet* src)
}
//------------------------------------------------------------------------------
void vtkUniformGridAMR::RecursiveShallowCopy(vtkDataObject* src)
void vtkUniformGridAMR::ShallowCopy(vtkDataObject* src)
{
if (src == this)
{
@ -328,13 +329,20 @@ void vtkUniformGridAMR::RecursiveShallowCopy(vtkDataObject* src)
if (vtkUniformGridAMR* hbds = vtkUniformGridAMR::SafeDownCast(src))
{
this->SetAMRInfo(hbds->GetAMRInfo());
this->AMRData->RecursiveShallowCopy(hbds->GetAMRData());
this->AMRData->ShallowCopy(hbds->GetAMRData());
memcpy(this->Bounds, hbds->Bounds, sizeof(double) * 6);
}
this->Modified();
}
//------------------------------------------------------------------------------
void vtkUniformGridAMR::RecursiveShallowCopy(vtkDataObject* src)
{
VTK_LEGACY_REPLACED_BODY(RecursiveShallowCopy, "VTK 9.3", ShallowCopy);
this->ShallowCopy(src);
}
//------------------------------------------------------------------------------
const double* vtkUniformGridAMR::GetBounds()
{

@ -27,6 +27,7 @@
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkCompositeDataSet.h"
#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
VTK_ABI_NAMESPACE_BEGIN
class vtkCompositeDataIterator;
@ -133,10 +134,16 @@ public:
/**
* ShallowCopy.
*/
void CompositeShallowCopy(vtkCompositeDataSet* src) override;
void ShallowCopy(vtkDataObject* src) override;
void RecursiveShallowCopy(vtkDataObject* src) override;
///@}
/**
* Depreacted RecursiveShallowCopy method, uses ShallowCopy
*/
VTK_DEPRECATED_IN_9_3_0("Please use ShallowCopy instead.")
void RecursiveShallowCopy(vtkDataObject* src) override;
/**
* DeepCopy.
*/

Loading…
Cancel
Save