Commit aab86574 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

ENH: Redesigned the composite dataset and subclasses. The details of this

redesign can be found at http://www.vtk.org/Wiki/VTK/Composite_Data_Redesign.
parent bd79e472
......@@ -81,6 +81,7 @@
#define VTK_SELECTION 22
#define VTK_DIRECTED_GRAPH 23
#define VTK_UNDIRECTED_GRAPH 24
#define VTK_MULTIPIECE_DATA_SET 25
/*--------------------------------------------------------------------------*/
/* Define a casting macro for use by the constants below. */
......
......@@ -25,7 +25,7 @@
#include "vtkCompositeDataPipeline.h"
#include "vtkContourFilter.h"
#include "vtkDebugLeaks.h"
#include "vtkHierarchicalDataExtractLevel.h"
#include "vtkExtractLevel.h"
#include "vtkHierarchicalDataSetGeometryFilter.h"
#include "vtkOutlineCornerFilter.h"
#include "vtkHierarchicalPolyDataMapper.h"
......@@ -79,6 +79,9 @@ int main(int argc, char* argv[])
// corner outline
vtkOutlineCornerFilter* ocf = vtkOutlineCornerFilter::New();
vtkCompositeDataPipeline* pipeline = vtkCompositeDataPipeline::New();
ocf->SetExecutive(pipeline);
pipeline->Delete();
ocf->SetInputConnection(0, reader->GetOutputPort(0));
// Rendering objects
......@@ -92,14 +95,20 @@ int main(int argc, char* argv[])
ren->AddActor(ocActor);
// cell 2 point and contour
vtkHierarchicalDataExtractLevel* el = vtkHierarchicalDataExtractLevel::New();
vtkExtractLevel* el = vtkExtractLevel::New();
el->SetInputConnection(0, reader->GetOutputPort(0));
el->SetLevelRange(2,2);
el->AddLevel(2);
vtkCellDataToPointData* c2p = vtkCellDataToPointData::New();
pipeline = vtkCompositeDataPipeline::New();
c2p->SetExecutive(pipeline);
pipeline->Delete();
c2p->SetInputConnection(0, el->GetOutputPort(0));
vtkContourFilter* contour = vtkContourFilter::New();
pipeline = vtkCompositeDataPipeline::New();
contour->SetExecutive(pipeline);
pipeline->Delete();
contour->SetInputConnection(0, c2p->GetOutputPort(0));
contour->SetValue(0, -0.013);
contour->SetInputArrayToProcess(
......
......@@ -13,7 +13,7 @@
=========================================================================*/
// This example demonstrates how multi-block datasets can be processed
// using the new vtkHierarchicalDataSet class.
// using the new vtkMultiBlockDataSet class.
//
// The command line arguments are:
// -D <path> => path to the data (VTKData); the data should be in <path>/Data/
......@@ -22,8 +22,8 @@
#include "vtkCellDataToPointData.h"
#include "vtkContourFilter.h"
#include "vtkDebugLeaks.h"
#include "vtkHierarchicalDataSet.h"
#include "vtkHierarchicalDataSetGeometryFilter.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkCompositeDataGeometryFilter.h"
#include "vtkOutlineCornerFilter.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
......@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
// vtkMultiBlockDataSet respresents multi-block datasets. See
// the class documentation for more information.
vtkHierarchicalDataSet* mb = vtkHierarchicalDataSet::New();
vtkMultiBlockDataSet* mb = vtkMultiBlockDataSet::New();
for (i=0; i<3; i++)
{
......@@ -79,14 +79,14 @@ int main(int argc, char* argv[])
sg->ShallowCopy(reader->GetOutput());
// Add the structured grid to the multi-block dataset
mb->SetDataSet(0, i, sg);
mb->SetBlock(i, sg);
sg->Delete();
}
reader->Delete();
// Multi-block can be processed with regular VTK filters in two ways:
// 1. Pass through a multi-block aware consumer. Since a multi-block
// aware mapper is not yet available, vtkHierarchicalDataSetGeometryFilter
// aware mapper is not yet available, vtkCompositeDataGeometryFilter
// can be used
// 2. Assign the composite executive (vtkCompositeDataPipeline) to
// all "simple" (that work only on simple, non-composite datasets) filters
......@@ -99,8 +99,8 @@ int main(int argc, char* argv[])
// This filter is multi-block aware and will request blocks from the
// input. These blocks will be processed by simple processes as if they
// are the whole dataset
vtkHierarchicalDataSetGeometryFilter* geom1 =
vtkHierarchicalDataSetGeometryFilter::New();
vtkCompositeDataGeometryFilter* geom1 =
vtkCompositeDataGeometryFilter::New();
geom1->SetInputConnection(0, of->GetOutputPort(0));
// Rendering objects
......@@ -121,8 +121,8 @@ int main(int argc, char* argv[])
contour->SetValue(0, 0.45);
// geometry filter
vtkHierarchicalDataSetGeometryFilter* geom2 =
vtkHierarchicalDataSetGeometryFilter::New();
vtkCompositeDataGeometryFilter* geom2 =
vtkCompositeDataGeometryFilter::New();
geom2->SetInputConnection(0, contour->GetOutputPort(0));
// Rendering objects
......
......@@ -7,20 +7,21 @@ SET(KIT_LIBS vtkCommon)
SET( Kit_SRCS
vtkAbstractMapper.cxx
vtkActor2D.cxx
vtkActor2DCollection.cxx
vtkActor2D.cxx
vtkAdjacentVertexIterator.cxx
vtkAlgorithm.cxx
vtkAlgorithmOutput.cxx
vtkAttributesErrorMetric.cxx
vtkBiQuadraticQuad.cxx
vtkBiQuadraticQuadraticHexahedron.cxx
vtkBiQuadraticQuadraticWedge.cxx
vtkCachedStreamingDemandDrivenPipeline.cxx
vtkCardinalSpline.cxx
vtkCastToConcrete.cxx
vtkCell.cxx
vtkCell3D.cxx
vtkCellArray.cxx
vtkCell.cxx
vtkCellData.cxx
vtkCellLinks.cxx
vtkCellLocator.cxx
......@@ -28,20 +29,21 @@ vtkCellTypes.cxx
vtkColorTransferFunction.cxx
vtkCompositeDataIterator.cxx
vtkCompositeDataPipeline.cxx
vtkCompositeDataSetAlgorithm.cxx
vtkCompositeDataSet.cxx
vtkCone.cxx
vtkConvexPointSet.cxx
vtkCoordinate.cxx
vtkCylinder.cxx
vtkDataObject.cxx
vtkDataObjectAlgorithm.cxx
vtkDataObjectCollection.cxx
vtkDataObject.cxx
vtkDataObjectSource.cxx
vtkDataObjectTypes.cxx
vtkDataSet.cxx
vtkDataSetAlgorithm.cxx
vtkDataSetAttributes.cxx
vtkDataSetCollection.cxx
vtkDataSet.cxx
vtkDataSetSource.cxx
vtkDataSetToDataSetFilter.cxx
vtkDataSetToImageFilter.cxx
......@@ -50,8 +52,8 @@ vtkDataSetToStructuredGridFilter.cxx
vtkDataSetToStructuredPointsFilter.cxx
vtkDataSetToUnstructuredGridFilter.cxx
vtkDemandDrivenPipeline.cxx
vtkDirectedGraph.cxx
vtkDirectedGraphAlgorithm.cxx
vtkDirectedGraph.cxx
vtkEdgeListIterator.cxx
vtkEmptyCell.cxx
vtkExecutive.cxx
......@@ -59,31 +61,28 @@ vtkExplicitCell.cxx
vtkFieldData.cxx
vtkFilteringInformationKeyManager.cxx
vtkGenericAdaptorCell.cxx
vtkGenericAttribute.cxx
vtkGenericAttributeCollection.cxx
vtkGenericAttribute.cxx
vtkGenericCell.cxx
vtkGenericCellIterator.cxx
vtkGenericCellTessellator.cxx
vtkGenericDataSet.cxx
vtkGenericDataSetAlgorithm.cxx
vtkGenericDataSet.cxx
vtkGenericEdgeTable.cxx
vtkGenericInterpolatedVelocityField.cxx
vtkGenericPointIterator.cxx
vtkGenericSubdivisionErrorMetric.cxx
vtkGeometricErrorMetric.cxx
vtkGraphAlgorithm.cxx
vtkGraph.cxx
vtkGraphEdge.cxx
vtkGraphAlgorithm.cxx
vtkAttributesErrorMetric.cxx
vtkHexagonalPrism.cxx
vtkHexahedron.cxx
vtkHierarchicalDataInformation.cxx
vtkHierarchicalDataIterator.cxx
vtkHierarchicalBoxDataSetAlgorithm.cxx
vtkHierarchicalBoxDataSet.cxx
vtkHierarchicalDataSet.cxx
vtkHierarchicalDataSetAlgorithm.cxx
vtkHyperOctree.cxx
vtkHyperOctreeAlgorithm.cxx
vtkHyperOctreeCursor.cxx
vtkHyperOctree.cxx
vtkHyperOctreePointsGrabber.cxx
vtkImageAlgorithm.cxx
vtkImageData.cxx
......@@ -112,12 +111,9 @@ vtkLine.cxx
vtkLocator.cxx
vtkMapper2D.cxx
vtkMergePoints.cxx
vtkMultiBlockDataSet.cxx
vtkMultiBlockDataSetAlgorithm.cxx
vtkMultiGroupDataInformation.cxx
vtkMultiGroupDataIterator.cxx
vtkMultiGroupDataSet.cxx
vtkMultiGroupDataSetAlgorithm.cxx
vtkMultiBlockDataSet.cxx
vtkMultiPieceDataSet.cxx
vtkMutableDirectedGraph.cxx
vtkMutableUndirectedGraph.cxx
vtkNonLinearCell.cxx
......@@ -127,92 +123,91 @@ vtkParametricSpline.cxx
vtkPassInputTypeAlgorithm.cxx
vtkPentagonalPrism.cxx
vtkPerlinNoise.cxx
vtkPiecewiseFunction.cxx
vtkPiecewiseFunctionAlgorithm.cxx
vtkPiecewiseFunction.cxx
vtkPiecewiseFunctionShiftScale.cxx
vtkPixel.cxx
vtkPointData.cxx
vtkPointLocator.cxx
vtkPointSet.cxx
vtkPointSetAlgorithm.cxx
vtkPointSet.cxx
vtkPointSetSource.cxx
vtkPointSetToPointSetFilter.cxx
vtkPolyData.cxx
vtkPolyDataAlgorithm.cxx
vtkPolyDataCollection.cxx
vtkPolyData.cxx
vtkPolyDataSource.cxx
vtkPolyDataToPolyDataFilter.cxx
vtkPolygon.cxx
vtkPolyLine.cxx
vtkPolyVertex.cxx
vtkPolygon.cxx
vtkProcessObject.cxx
vtkPropAssembly.cxx
vtkPyramid.cxx
vtkQuad.cxx
vtkQuadraticEdge.cxx
vtkQuadraticHexahedron.cxx
vtkQuadraticPyramid.cxx
vtkQuadraticLinearQuad.cxx
vtkQuadraticLinearWedge.cxx
vtkQuadraticPyramid.cxx
vtkQuadraticQuad.cxx
vtkQuadraticTetra.cxx
vtkQuadraticTriangle.cxx
vtkQuadraticLinearWedge.cxx
vtkQuadraticWedge.cxx
vtkRectilinearGrid.cxx
vtkRectilinearGridAlgorithm.cxx
vtkRectilinearGrid.cxx
vtkRectilinearGridSource.cxx
vtkRectilinearGridToPolyDataFilter.cxx
vtkScalarTree.cxx
vtkSelection.cxx
vtkSelectionAlgorithm.cxx
vtkSelection.cxx
vtkSimpleCellTessellator.cxx
vtkSimpleImageToImageFilter.cxx
vtkSimpleScalarTree.cxx
vtkSmoothErrorMetric.cxx
vtkSphere.cxx
vtkSource.cxx
vtkSphere.cxx
vtkSpline.cxx
vtkStreamingDemandDrivenPipeline.cxx
vtkStructuredGrid.cxx
vtkStructuredGridAlgorithm.cxx
vtkStructuredGrid.cxx
vtkStructuredGridSource.cxx
vtkStructuredGridToPolyDataFilter.cxx
vtkStructuredGridToStructuredGridFilter.cxx
vtkStructuredPoints.cxx
vtkStructuredPointsCollection.cxx
vtkStructuredPoints.cxx
vtkStructuredPointsSource.cxx
vtkStructuredPointsToPolyDataFilter.cxx
vtkStructuredPointsToStructuredPointsFilter.cxx
vtkStructuredPointsToUnstructuredGridFilter.cxx
vtkSuperquadric.cxx
vtkTable.cxx
vtkTableAlgorithm.cxx
vtkTemporalDataSet.cxx
vtkTable.cxx
vtkTemporalDataSetAlgorithm.cxx
vtkTemporalDataSet.cxx
vtkTetra.cxx
vtkThreadedImageAlgorithm.cxx
vtkTree.cxx
vtkTreeAlgorithm.cxx
vtkTree.cxx
vtkTreeDFSIterator.cxx
vtkTriangle.cxx
vtkTriangleStrip.cxx
vtkTriQuadraticHexahedron.cxx
vtkTrivialProducer.cxx
vtkUndirectedGraph.cxx
vtkUndirectedGraphAlgorithm.cxx
vtkUndirectedGraph.cxx
vtkUniformGrid.cxx
vtkUnstructuredGrid.cxx
vtkUnstructuredGridAlgorithm.cxx
vtkUnstructuredGrid.cxx
vtkUnstructuredGridSource.cxx
vtkUnstructuredGridToPolyDataFilter.cxx
vtkUnstructuredGridToUnstructuredGridFilter.cxx
vtkVertex.cxx
vtkVertexListIterator.cxx
vtkViewDependentErrorMetric.cxx
vtkViewport.cxx
vtkVoxel.cxx
vtkWedge.cxx
vtkVertexListIterator.cxx
vtkViewport.cxx
vtkGenericInterpolatedVelocityField.cxx
)
SET_SOURCE_FILES_PROPERTIES(
......@@ -242,7 +237,6 @@ vtkGenericDataSetAlgorithm
vtkGenericPointIterator
vtkGenericSubdivisionErrorMetric
vtkGraph
vtkHierarchicalDataSetAlgorithm
vtkHyperOctreeAlgorithm
vtkHyperOctreeCursor
vtkHyperOctreePointsGrabber
......@@ -259,7 +253,6 @@ vtkInformationExecutivePortKey
vtkInformationExecutivePortVectorKey
vtkLocator
vtkMapper2D
vtkMultiGroupDataSetAlgorithm
vtkNonLinearCell
vtkPointSet
vtkPointSetSource
......@@ -290,7 +283,6 @@ vtkViewport
SET_SOURCE_FILES_PROPERTIES(
vtkFilteringInformationKeyManager.cxx
vtkHierarchicalDataIterator.cxx
vtkImageIterator.cxx
vtkInformation.cxx
vtkImageProgressIterator.cxx
......
......@@ -17,16 +17,14 @@ IF(PYTHON_EXECUTABLE)
vtkAMRBox.h
vtkApplyFilterCommandInternal.h
vtkCellType.h
vtkCompositeDataSetInternals.h
vtkDataObjectCollection.h
vtkDataSetCollection.h
vtkFilteringInformationKeyManager.h
vtkImageIterator.h
vtkImageProgressIterator.h
vtkMarchingCubesCases.h
vtkMarchingSquaresCases.h
vtkMultiBlockDataSetInternal.h
vtkMultiGroupDataSetInternal.h
vtkDataObjectCollection.h
vtkHierarchicalBoxDataSetInternal.h
vtkStructuredPoints.h
)
ENDIF(PYTHON_EXECUTABLE)
......@@ -14,26 +14,332 @@
=========================================================================*/
#include "vtkCompositeDataIterator.h"
vtkCxxRevisionMacro(vtkCompositeDataIterator, "1.3");
#include "vtkCompositeDataSet.h"
#include "vtkCompositeDataSetInternals.h"
#include "vtkObjectFactory.h"
class vtkCompositeDataIterator::vtkInternals
{
public:
class vtkLocation
{
vtkCompositeDataSetInternals::VectorOfDataObjects* VectorPtr;
vtkCompositeDataSetInternals::Iterator Iter;
vtkCompositeDataSetInternals::ReverseIterator ReverseIter;
bool Reverse;
unsigned int Index;
public:
// constructor
vtkLocation(vtkCompositeDataSetInternals::VectorOfDataObjects& ptr, bool reverse)
{
this->Reverse = reverse;
this->VectorPtr = &ptr;
this->Index = 0;
this->Iter = ptr.begin();
this->ReverseIter = ptr.rbegin();
}
unsigned int GetIndex()
{
// Note this will return invalid index if this->IsDoneWithTraversal()
// return true.
return this->Reverse?
(this->VectorPtr->size()-(this->Index+1)): this->Index;
}
void Next()
{
this->Index++;
if (this->Reverse)
{
this->ReverseIter++;
}
else
{
this->Iter++;
}
}
// tells if at end.
bool IsDoneWithTraversal()
{
return this->Reverse? (this->ReverseIter == this->VectorPtr->rend()):
(this->Iter == this->VectorPtr->end());
}
// must not be called if IsDoneWithTraversal() returns true.
vtkDataObject* Data()
{
return this->Reverse? this->ReverseIter->DataObject:
this->Iter->DataObject;
}
// must not be called if IsDoneWithTraversal() returns true.
vtkInformation* MetaData()
{
if (this->Reverse)
{
if (!this->ReverseIter->MetaData.GetPointer())
{
this->ReverseIter->MetaData.TakeReference(vtkInformation::New());
}
return this->ReverseIter->MetaData;
}
else
{
if (!this->Iter->MetaData.GetPointer())
{
this->Iter->MetaData.TakeReference(vtkInformation::New());
}
return this->Iter->MetaData;
}
}
// must not be called if IsDoneWithTraversal() returns true.
int HasMetaData()
{
return this->Reverse?
(this->ReverseIter->MetaData.GetPointer() != 0):
(this->Iter->MetaData.GetPointer() != 0);
}
};
// LocationStack is used to inorder traversal of the tree. As we go down the
// tree, the stack depth increases.
vtkstd::vector<vtkLocation> LocationStack;
// If Top of the stack has reached its end, the we pop it out and advance the
// new top of the stack. Note that the new top of the stack (if present) will
// always be a vtkCompositeDataSet.
void EnsureStackValidity()
{
if (this->LocationStack.size() > 0)
{
if (this->LocationStack.back().IsDoneWithTraversal())
{
this->LocationStack.pop_back();
if (this->LocationStack.size() > 0)
{
this->LocationStack.back().Next();
this->EnsureStackValidity();
}
}
}
}
// Returns the unique index for the current iterator location.
vtkCompositeDataSetIndex GetCurrentIndex()
{
vtkCompositeDataSetIndex vec;
vtkstd::vector<vtkLocation>::iterator iter = this->LocationStack.begin();
for (; iter != this->LocationStack.end(); ++iter)
{
vec.push_back(iter->GetIndex());
}
return vec;
}
};
vtkStandardNewMacro(vtkCompositeDataIterator);
vtkCxxRevisionMacro(vtkCompositeDataIterator, "1.4");
//----------------------------------------------------------------------------
vtkCompositeDataIterator::vtkCompositeDataIterator()
{
this->Reverse = 0;
this->DataSet = 0;
this->VisitOnlyLeaves = 1;
this->TraverseSubTree = 1;
this->CurrentFlatIndex = 1;
this->SkipEmptyNodes = 1;
this->Internals = new vtkInternals;
}
//----------------------------------------------------------------------------
vtkCompositeDataIterator::~vtkCompositeDataIterator()
{
this->SetDataSet(0);
delete this->Internals;
}
//----------------------------------------------------------------------------
void vtkCompositeDataIterator::PrintSelf(ostream& os, vtkIndent indent)
void vtkCompositeDataIterator::SetDataSet(vtkCompositeDataSet* ds)
{
vtkSetObjectBodyMacro(DataSet, vtkCompositeDataSet, ds);
if (this->DataSet)
{
this->GoToFirstItem();
}
}
//----------------------------------------------------------------------------
void vtkCompositeDataIterator::InitTraversal()
{
this->Superclass::PrintSelf(os,indent);
this->Reverse = 0;
this->GoToFirstItem();
}
//----------------------------------------------------------------------------
void vtkCompositeDataIterator::InitReverseTraversal()
{
this->Reverse = 1;
this->GoToFirstItem();
}
//----------------------------------------------------------------------------
void vtkCompositeDataIterator::GoToFirstItem()
{
this->CurrentFlatIndex = 1;
this->Internals->LocationStack.clear();
if (!this->DataSet)
{
vtkErrorMacro("DataSet must be specified.");
return;
}
vtkInternals::vtkLocation loc(this->DataSet->Internals->Children,
this->Reverse);
this->Internals->LocationStack.push_back(loc);
this->Internals->EnsureStackValidity();
// We need to ensure that the current data object is non-null. Also, if
// this->VisitOnlyLeaves is true, we additionally need to ensure that the
// current item is not a vtkCompositeDataSet.
while (!this->IsDoneWithTraversal())
{
vtkDataObject* dObj = this->Internals->LocationStack.back().Data();
if ((this->SkipEmptyNodes && !dObj) ||
(this->VisitOnlyLeaves && dObj->IsA("vtkCompositeDataSet")))
{
this->NextInternal();
}
else
{
break;
}
}
}
//----------------------------------------------------------------------------
int vtkCompositeDataIterator::IsDoneWithTraversal()
{
return (this->Internals->LocationStack.size() == 0);
}
os << indent << "VisitOnlyLeaves: "
<< (this->VisitOnlyLeaves?"(on)":"(off)")
<< endl;
//----------------------------------------------------------------------------
void vtkCompositeDataIterator::GoToNextItem()
{
if (!this->IsDoneWithTraversal())
{
this->NextInternal();
// We need to ensure that the current data object is non-null. Also, if
// this->VisitOnlyLeaves is true, we additionally need to ensure that the