Commit 0f6d8394 authored by Berk Geveci's avatar Berk Geveci

Introduced new composite datasets for partitioned data.

This is the first step in our attempt to create next
generation composite datasets for partitioned data and
arbitrary dataset collections. The main idea is that
partitioned datasets are instances of
vtkPartitionedDataSet, which is a vector of datasets.
It is required that these datasets are compatible, i.e.
can be processed by the same type of filters together.
This is similar to vtkMultiPieceDataSet but will
formalize that partition concept further. The second
new data type is vtkPartitionedDataSetCollection. This
is a vector of vtkPartitionedDataSets. It can be an
arbitrary collection but is not a tree like its
predecessor vtkMultiBlockDataSet. Any further grouping
of the blocks will be done by the use of SIL data
structures, which will be supported later.

Also added basic IO support for these data types.
parent 4656844e
......@@ -125,6 +125,8 @@
#define VTK_PISTON_DATA_OBJECT 34
#define VTK_PATH 35
#define VTK_UNSTRUCTURED_GRID_BASE 36
#define VTK_PARTITIONED_DATA_SET 37
#define VTK_PARTITIONED_DATA_SET_COLLECTION 38
/*--------------------------------------------------------------------------*/
/* Define a casting macro for use by the constants below. */
......
......@@ -118,6 +118,8 @@ set(Module_SRCS
vtkOctreePointLocatorNode.cxx
vtkOrderedTriangulator.cxx
vtkOutEdgeIterator.cxx
vtkPartitionedDataSet.cxx
vtkPartitionedDataSetCollection.cxx
vtkPath.cxx
vtkPentagonalPrism.cxx
vtkPeriodicDataArray.txx
......
......@@ -6,6 +6,7 @@ vtk_add_test_python(
TestBoxPlaneIntersection.py
TestCopyStructuredData.py,NO_DATA,NO_VALID
TestNumericArrayImageData.py,NO_DATA,NO_VALID
TestPartitionedData.py,NO_DATA,NO_VALID
TestQuadricClustering.py
TestStaticPointLocator.py,NO_DATA,NO_VALID
TestStaticPointLocator2.py,NO_DATA,NO_VALID
......
from vtkmodules import vtkCommonCore as cc
from vtkmodules import vtkCommonDataModel as dm
from vtkmodules import vtkCommonExecutionModel as em
from vtkmodules import vtkImagingCore as ic
from vtk.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtk.test import Testing
class SimpleFilter(VTKPythonAlgorithmBase):
def __init__(self):
VTKPythonAlgorithmBase.__init__(self)
self.InputType = "vtkDataSet"
self.OutputType = "vtkDataObject"
self.Counter = 0
def FillInputPortInformation(self, port, info):
"""Sets the required input type to InputType."""
info.Set(em.vtkAlgorithm.INPUT_REQUIRED_DATA_TYPE(), self.InputType)
info.Append(em.vtkAlgorithm.INPUT_REQUIRED_DATA_TYPE(), "vtkPartitionedDataSet")
return 1
def RequestDataObject(self, request, inInfo, outInfo):
inp = dm.vtkDataObject.GetData(inInfo[0])
opt = dm.vtkDataObject.GetData(outInfo)
if opt and opt.IsA(inp.GetClassName()):
return 1
opt = inp.NewInstance()
outInfo.GetInformationObject(0).Set(dm.vtkDataObject.DATA_OBJECT(), opt)
return 1
def RequestData(self, request, inInfo, outInfo):
global key
inp = dm.vtkDataObject.GetData(inInfo[0])
opt = dm.vtkDataObject.GetData(outInfo)
a = cc.vtkTypeUInt8Array()
a.SetName("counter")
a.SetNumberOfTuples(1)
a.SetValue(0, self.Counter)
opt.GetFieldData().AddArray(a)
self.Counter += 1
return 1
class TestPartitionedData(Testing.vtkTest):
def test(self):
p = dm.vtkPartitionedDataSet()
s = ic.vtkRTAnalyticSource()
s.SetWholeExtent(0, 10, 0, 10, 0, 5)
s.Update()
p1 = dm.vtkImageData()
p1.ShallowCopy(s.GetOutput())
s.SetWholeExtent(0, 10, 0, 10, 5, 10)
s.Update()
p2 = dm.vtkImageData()
p2.ShallowCopy(s.GetOutput())
p.SetPartition(0, p1)
p.SetPartition(1, p2)
p2 = dm.vtkPartitionedDataSet()
p2.ShallowCopy(p)
c = dm.vtkPartitionedDataSetCollection()
c.SetPartitionedDataSet(0, p)
c.SetPartitionedDataSet(1, p2)
s = SimpleFilter()
s.SetInputDataObject(c)
s.Update()
for i in (0,1):
self.assertEqual(s.GetOutputDataObject(0).GetPartitionedDataSet(i).GetFieldData().GetArray("counter").GetValue(0), i)
if __name__ == "__main__":
Testing.main([(TestPartitionedData, 'test')])
vtk_module(vtkCommonDataModel
GROUPS
StandAlone
TEST_DEPENDS
set(TEST_DEPENDS_MODULES
vtkTestingCore
vtkTestingRendering
vtkInteractionStyle
......@@ -18,6 +15,16 @@ vtk_module(vtkCommonDataModel
vtkRenderingCore
vtkRenderingContextOpenGL2
vtkRenderingOpenGL2
)
if(VTK_WRAP_PYTHON)
list(APPEND TEST_DEPENDS_MODULES vtkFiltersPython)
endif()
vtk_module(vtkCommonDataModel
GROUPS
StandAlone
TEST_DEPENDS
${TEST_DEPENDS_MODULES}
KIT
vtkCommon
DEPENDS
......
......@@ -32,6 +32,8 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkImageData.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkPartitionedDataSet.h"
#include "vtkPartitionedDataSetCollection.h"
#include "vtkPath.h"
#include "vtkPiecewiseFunction.h"
#include "vtkPointSet.h"
......@@ -93,6 +95,8 @@ static const char* vtkDataObjectTypesStrings[] = {
"vtkPistonDataObject", // OBSOLETE
"vtkPath",
"vtkUnstructuredGridBase",
"vtkPartitionedDataSet",
"vtkPartitionedDataSetCollection",
nullptr
};
......@@ -268,6 +272,14 @@ vtkDataObject* vtkDataObjectTypes::NewDataObject(const char* type)
{
return vtkPath::New();
}
else if(strcmp(type, "vtkPartitionedDataSet") == 0)
{
return vtkPartitionedDataSet::New();
}
else if(strcmp(type, "vtkPartitionedDataSetCollection") == 0)
{
return vtkPartitionedDataSetCollection::New();
}
vtkGenericWarningMacro("NewDataObject(): You are trying to instantiate DataObjectType \"" << type
<< "\" which does not exist.");
......
......@@ -63,7 +63,9 @@ vtkDataObject* vtkMultiBlockDataSet::GetBlock(unsigned int blockno)
void vtkMultiBlockDataSet::SetBlock(unsigned int blockno, vtkDataObject* block)
{
if (block && block->IsA("vtkCompositeDataSet") &&
!block->IsA("vtkMultiBlockDataSet") && !block->IsA("vtkMultiPieceDataSet"))
!block->IsA("vtkMultiBlockDataSet") &&
!block->IsA("vtkMultiPieceDataSet") &&
!block->IsA("vtkPartitionedDataSet"))
{
vtkErrorMacro(<< block->GetClassName() << " cannot be added as a block.");
return;
......
......@@ -14,7 +14,6 @@
=========================================================================*/
#include "vtkMultiPieceDataSet.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
......@@ -40,43 +39,6 @@ vtkMultiPieceDataSet* vtkMultiPieceDataSet::GetData(vtkInformationVector* v,
return vtkMultiPieceDataSet::GetData(v->GetInformationObject(i));
}
//----------------------------------------------------------------------------
void vtkMultiPieceDataSet::SetNumberOfPieces(unsigned int numPieces)
{
this->Superclass::SetNumberOfChildren(numPieces);
}
//----------------------------------------------------------------------------
unsigned int vtkMultiPieceDataSet::GetNumberOfPieces()
{
return this->Superclass::GetNumberOfChildren();
}
//----------------------------------------------------------------------------
vtkDataSet* vtkMultiPieceDataSet::GetPiece(unsigned int blockno)
{
return vtkDataSet::SafeDownCast(this->GetPieceAsDataObject(blockno));
}
//----------------------------------------------------------------------------
vtkDataObject* vtkMultiPieceDataSet::GetPieceAsDataObject(unsigned int blockno)
{
return this->Superclass::GetChild(blockno);
}
//----------------------------------------------------------------------------
void vtkMultiPieceDataSet::SetPiece(unsigned int blockno, vtkDataObject* block)
{
if (block && block->IsA("vtkCompositeDataSet"))
{
vtkErrorMacro("Piece cannot be a vtkCompositeDataSet.");
return;
}
this->Superclass::SetChild(blockno, block);
}
//----------------------------------------------------------------------------
void vtkMultiPieceDataSet::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -34,14 +34,14 @@
#define vtkMultiPieceDataSet_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkDataObjectTree.h"
#include "vtkPartitionedDataSet.h"
class vtkDataSet;
class VTKCOMMONDATAMODEL_EXPORT vtkMultiPieceDataSet : public vtkDataObjectTree
class VTKCOMMONDATAMODEL_EXPORT vtkMultiPieceDataSet : public vtkPartitionedDataSet
{
public:
static vtkMultiPieceDataSet* New();
vtkTypeMacro(vtkMultiPieceDataSet, vtkDataObjectTree);
vtkTypeMacro(vtkMultiPieceDataSet, vtkPartitionedDataSet);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
......@@ -55,41 +55,41 @@ public:
* pieces is greater than the current size. All new pieces are initialized to
* null.
*/
void SetNumberOfPieces(unsigned int numpieces);
void SetNumberOfPieces(unsigned int numpieces)
{
this->SetNumberOfPartitions(numpieces);
}
/**
* Returns the number of pieces.
*/
unsigned int GetNumberOfPieces();
unsigned int GetNumberOfPieces()
{
return this->GetNumberOfPartitions();
}
//@{
/**
* Returns the piece at the given index.
*/
vtkDataSet* GetPiece(unsigned int pieceno);
vtkDataObject* GetPieceAsDataObject(unsigned int pieceno);
vtkDataSet* GetPiece(unsigned int pieceno)
{
return this->GetPartition(pieceno);
}
vtkDataObject* GetPieceAsDataObject(unsigned int pieceno)
{
return this->GetPartitionAsDataObject(pieceno);
}
//@}
/**
* Sets the data object as the given piece. The total number of pieces will
* be resized to fit the requested piece no.
*/
void SetPiece(unsigned int pieceno, vtkDataObject* piece);
/**
* Returns true if meta-data is available for a given piece.
*/
int HasMetaData(unsigned int piece)
{ return this->Superclass::HasChildMetaData(piece); }
/**
* Returns the meta-data for the piece. If none is already present, a new
* vtkInformation object will be allocated. Use HasMetaData to avoid
* allocating vtkInformation objects.
*/
vtkInformation* GetMetaData(unsigned int pieceno)
{ return this->Superclass::GetChildMetaData(pieceno); }
void SetPiece(unsigned int pieceno, vtkDataObject* piece)
{
this->SetPartition(pieceno, piece);
}
//@{
/**
......@@ -99,18 +99,6 @@ public:
static vtkMultiPieceDataSet* GetData(vtkInformationVector* v, int i=0);
//@}
/**
* Unhiding superclass method.
*/
vtkInformation* GetMetaData(vtkCompositeDataIterator* iter) override
{ return this->Superclass::GetMetaData(iter); }
/**
* Unhiding superclass method.
*/
int HasMetaData(vtkCompositeDataIterator* iter) override
{ return this->Superclass::HasMetaData(iter); }
protected:
vtkMultiPieceDataSet();
~vtkMultiPieceDataSet() override;
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPartitionedDataSet.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPartitionedDataSet.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkPartitionedDataSet);
//----------------------------------------------------------------------------
vtkPartitionedDataSet::vtkPartitionedDataSet()
{
}
//----------------------------------------------------------------------------
vtkPartitionedDataSet::~vtkPartitionedDataSet()
{
}
//----------------------------------------------------------------------------
vtkPartitionedDataSet* vtkPartitionedDataSet::GetData(vtkInformation* info)
{
return
info? vtkPartitionedDataSet::SafeDownCast(info->Get(DATA_OBJECT())) : nullptr;
}
//----------------------------------------------------------------------------
vtkPartitionedDataSet* vtkPartitionedDataSet::GetData(vtkInformationVector* v,
int i)
{
return vtkPartitionedDataSet::GetData(v->GetInformationObject(i));
}
//----------------------------------------------------------------------------
void vtkPartitionedDataSet::SetNumberOfPartitions(unsigned int numPartitions)
{
this->Superclass::SetNumberOfChildren(numPartitions);
}
//----------------------------------------------------------------------------
unsigned int vtkPartitionedDataSet::GetNumberOfPartitions()
{
return this->Superclass::GetNumberOfChildren();
}
//----------------------------------------------------------------------------
vtkDataSet* vtkPartitionedDataSet::GetPartition(unsigned int idx)
{
return vtkDataSet::SafeDownCast(this->GetPartitionAsDataObject(idx));
}
//----------------------------------------------------------------------------
vtkDataObject* vtkPartitionedDataSet::GetPartitionAsDataObject(unsigned int idx)
{
return this->Superclass::GetChild(idx);
}
//----------------------------------------------------------------------------
void vtkPartitionedDataSet::SetPartition(unsigned int idx, vtkDataObject* partition)
{
if (partition && partition->IsA("vtkCompositeDataSet"))
{
vtkErrorMacro("Partition cannot be a vtkCompositeDataSet.");
return;
}
this->Superclass::SetChild(idx, partition);
}
//----------------------------------------------------------------------------
void vtkPartitionedDataSet::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPartitionedDataSet.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkPartitionedDataSet
* @brief composite dataset to encapsulates a dataset consisting of
* partitions.
*
* A vtkPartitionedDataSet dataset groups multiple datasets together.
* For example, say a simulation running in parallel on 16 processes
* generated 16 datasets that when considering together form a whole
* dataset. These are referred to as the partitions of the whole dataset.
* Now imagine that we want to load a volume of 16 partitions in a
* visualization cluster of 4 nodes. Each node could get 4 partitions,
* not necessarily forming a whole rectangular region. In this case,
* it is not possible to append the 4 partitions together into a vtkImageData.
* We can then collect these 4 partitions together using a
* vtkPartitionedDataSet.
*
* It is required that all non-empty partitions have the same arrays
* and that they can be processed together as a whole by the same kind of
* filter. However, it is not required that they are of the same type.
* For example, it is possible to have structured datasets together with
* unstructured datasets as long as they are compatible meshes (i.e. can
* be processed together for the same kind of filter).
*/
#ifndef vtkPartitionedDataSet_h
#define vtkPartitionedDataSet_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkDataObjectTree.h"
class vtkDataSet;
class VTKCOMMONDATAMODEL_EXPORT vtkPartitionedDataSet : public vtkDataObjectTree
{
public:
static vtkPartitionedDataSet* New();
vtkTypeMacro(vtkPartitionedDataSet, vtkDataObjectTree);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Return class name of data type (see vtkType.h for
* definitions).
*/
int GetDataObjectType() override {return VTK_PARTITIONED_DATA_SET;}
/**
* Set the number of partitionss. This will cause allocation if the new number of
* partitions is greater than the current size. All new partitions are initialized to
* null.
*/
void SetNumberOfPartitions(unsigned int numPartitions);
/**
* Returns the number of partitions.
*/
unsigned int GetNumberOfPartitions();
//@{
/**
* Returns the partition at the given index.
*/
vtkDataSet* GetPartition(unsigned int idx);
vtkDataObject* GetPartitionAsDataObject(unsigned int idx);
//@}
/**
* Sets the data object as the given partition. The total number of partitions will
* be resized to fit the requested partition no.
*/
void SetPartition(unsigned int idx, vtkDataObject* partition);
/**
* Returns true if meta-data is available for a given partition.
*/
int HasMetaData(unsigned int idx)
{ return this->Superclass::HasChildMetaData(idx); }
/**
* Returns the meta-data for the partition. If none is already present, a new
* vtkInformation object will be allocated. Use HasMetaData to avoid
* allocating vtkInformation objects.
*/
vtkInformation* GetMetaData(unsigned int idx)
{ return this->Superclass::GetChildMetaData(idx); }
//@{
/**
* Retrieve an instance of this class from an information object.
*/
static vtkPartitionedDataSet* GetData(vtkInformation* info);
static vtkPartitionedDataSet* GetData(vtkInformationVector* v, int i=0);
//@}
/**
* Unhiding superclass method.
*/
vtkInformation* GetMetaData(vtkCompositeDataIterator* iter) override
{ return this->Superclass::GetMetaData(iter); }
/**
* Unhiding superclass method.
*/
int HasMetaData(vtkCompositeDataIterator* iter) override
{ return this->Superclass::HasMetaData(iter); }
protected:
vtkPartitionedDataSet();
~vtkPartitionedDataSet() override;
private:
vtkPartitionedDataSet(const vtkPartitionedDataSet&) = delete;
void operator=(const vtkPartitionedDataSet&) = delete;
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPartitionedDataSetCollection.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPartitionedDataSetCollection.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPartitionedDataSet.h"
vtkStandardNewMacro(vtkPartitionedDataSetCollection);
//----------------------------------------------------------------------------
vtkPartitionedDataSetCollection::vtkPartitionedDataSetCollection()
{
}
//----------------------------------------------------------------------------
vtkPartitionedDataSetCollection::~vtkPartitionedDataSetCollection()
{
}
//----------------------------------------------------------------------------
vtkPartitionedDataSetCollection* vtkPartitionedDataSetCollection::GetData(
vtkInformation* info)
{
return
info? vtkPartitionedDataSetCollection::SafeDownCast(
info->Get(DATA_OBJECT())) : nullptr;
}
//----------------------------------------------------------------------------
vtkPartitionedDataSetCollection* vtkPartitionedDataSetCollection::GetData(
vtkInformationVector* v, int i)
{
return vtkPartitionedDataSetCollection::GetData(v->GetInformationObject(i));
}
//----------------------------------------------------------------------------
void vtkPartitionedDataSetCollection::SetNumberOfPartitionedDataSets(
unsigned int numDataSets)
{
this->Superclass::SetNumberOfChildren(numDataSets);
}
//----------------------------------------------------------------------------
unsigned int vtkPartitionedDataSetCollection::GetNumberOfPartitionedDataSets()
{
return this->Superclass::GetNumberOfChildren();
}
//----------------------------------------------------------------------------
vtkPartitionedDataSet* vtkPartitionedDataSetCollection::GetPartitionedDataSet(
unsigned int idx)
{
return vtkPartitionedDataSet::SafeDownCast(this->Superclass::GetChild(idx));
}
//----------------------------------------------------------------------------
void vtkPartitionedDataSetCollection::SetPartitionedDataSet(
unsigned int idx, vtkPartitionedDataSet* dataset)
{
this->Superclass::SetChild(idx, dataset);
}
//----------------------------------------------------------------------------
void vtkPartitionedDataSetCollection::RemovePartitionedDataSet(
unsigned int idx)
{
this->Superclass::RemoveChild(idx);
}
//----------------------------------------------------------------------------
void vtkPartitionedDataSetCollection::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPartitionedDataSetCollection.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkPartitionedDataSetCollection
* @brief Composite dataset that groups datasets as a collection.
*
* vtkPartitionedDataSetCollection is a vtkCompositeDataSet that stores
* a collection of vtkPartitionedDataSets. These items can represent
* different concepts depending on the context. For example, they can
* represent region of different materials in a simulation or parts in
* an assembly. It is not requires that items have anything in common.
* For example, they can have completely different point or cell arrays.
*/
#ifndef vtkPartitionedDataSetCollection_h
#define vtkPartitionedDataSetCollection_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkDataObjectTree.h"
class vtkPartitionedDataSet;
class VTKCOMMONDATAMODEL_EXPORT vtkPartitionedDataSetCollection : public vtkDataObjectTree
{
public:
static vtkPartitionedDataSetCollection* New();
vtkTypeMacro(vtkPartitionedDataSetCollection, vtkDataObjectTree);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Return class name of data type (see vtkType.h for
* definitions).
*/
int GetDataObjectType() override {return VTK_PARTITIONED_DATA_SET_COLLECTION;}
/**
* Set the number of blocks. This will cause allocation if the new number of
* blocks is greater than the current size. All new blocks are initialized to
* null.
*/
void SetNumberOfPartitionedDataSets(unsigned int numDataSets);
/**
* Returns the number of blocks.
*/
unsigned int GetNumberOfPartitionedDataSets();
/**
* Returns the block at the given index. It is recommended that one uses the
* iterators to iterate over composite datasets rather than using this API.
*/
vtkPartitionedDataSet* GetPartitionedDataSet(unsigned int idx);
/**
* Sets the data object as the given block. The total number of blocks will
* be resized to fit the requested block no.
*/
void SetPartitionedDataSet(unsigned int idx, vtkPartitionedDataSet* dataset);
/**
* Remove the given block from the dataset.
*/
void RemovePartitionedDataSet(unsigned int idx);