Commit a5abe530 authored by Berk Geveci's avatar Berk Geveci
Browse files

ENH: Added new data types. Restructure of composite datasets....

ENH: Added new data types. Restructure of composite datasets. vtkMultiGroupDataSet is the new superclass with two subclasses: vtkMultiBlockDataSet and vtkHierarchicalDataSet
parent 89b90941
......@@ -114,6 +114,11 @@ vtkMergeFields.cxx
vtkMergeFilter.cxx
vtkMeshQuality.cxx
vtkModelMetadata.cxx
vtkMultiGroupDataExtractDataSets.cxx
vtkMultiGroupDataExtractGroup.cxx
vtkMultiGroupDataGeometryFilter.cxx
vtkMultiGroupDataGroupFilter.cxx
vtkMultiGroupDataGroupIdScalars.cxx
vtkOBBDicer.cxx
vtkOBBTree.cxx
vtkOutlineCornerFilter.cxx
......
......@@ -102,7 +102,7 @@ int TestMultiBlock(int argc, char* argv[])
vtkHierarchicalDataExtractDataSets* eds =
vtkHierarchicalDataExtractDataSets::New();
eds->SetInputConnection(0, reader->GetOutputPort(0));
eds->AddDataSet(0, 1);
eds->AddDataSet(1, 0);
// contour
vtkContourFilter* contour = vtkContourFilter::New();
......
......@@ -14,244 +14,18 @@ PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkHierarchicalDataExtractDataSets.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
#include "vtkDataSet.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkHierarchicalDataInformation.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"
#include <vtkstd/list>
vtkCxxRevisionMacro(vtkHierarchicalDataExtractDataSets, "1.2");
vtkCxxRevisionMacro(vtkHierarchicalDataExtractDataSets, "1.3");
vtkStandardNewMacro(vtkHierarchicalDataExtractDataSets);
struct vtkHierarchicalDataExtractDataSetsInternals
{
typedef
vtkstd::list<vtkHierarchicalDataExtractDataSets::DataSetNode> DataSetsTypes;
DataSetsTypes DataSets;
};
//----------------------------------------------------------------------------
vtkHierarchicalDataExtractDataSets::vtkHierarchicalDataExtractDataSets()
{
this->Internal = new vtkHierarchicalDataExtractDataSetsInternals;
}
//----------------------------------------------------------------------------
vtkHierarchicalDataExtractDataSets::~vtkHierarchicalDataExtractDataSets()
{
delete this->Internal;
}
//----------------------------------------------------------------------------
void vtkHierarchicalDataExtractDataSets::AddDataSet(
unsigned int level, unsigned int idx)
{
this->Internal->DataSets.push_back(DataSetNode(level, idx));
this->Modified();
}
//----------------------------------------------------------------------------
void vtkHierarchicalDataExtractDataSets::ClearDataSetList()
{
this->Internal->DataSets.clear();
this->Modified();
}
//----------------------------------------------------------------------------
unsigned int vtkHierarchicalDataExtractDataSets::ComputeOutputLevels(
unsigned int inputNumLevels)
{
unsigned int numLevels = 0;
vtkHierarchicalDataExtractDataSetsInternals::DataSetsTypes::iterator it =
this->Internal->DataSets.begin();
for (; it != this->Internal->DataSets.end(); it++)
{
DataSetNode& node = *it;
unsigned int curNumLevels = node.Level + 1;
if (curNumLevels > numLevels && curNumLevels <= inputNumLevels)
{
numLevels = curNumLevels;
}
}
return numLevels;
}
//----------------------------------------------------------------------------
int vtkHierarchicalDataExtractDataSets::RequestDataObject(
vtkInformation*,
vtkInformationVector** inputVector ,
vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
if (!inInfo)
{
return 0;
}
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
inInfo->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (input)
{
vtkInformation* info = outputVector->GetInformationObject(0);
vtkCompositeDataSet *output = vtkCompositeDataSet::SafeDownCast(
info->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (!output || !output->IsA(input->GetClassName()))
{
output = input->NewInstance();
output->SetPipelineInformation(info);
output->Delete();
}
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
int vtkHierarchicalDataExtractDataSets::RequestInformation(
vtkInformation*,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkHierarchicalDataInformation* inCompInfo =
vtkHierarchicalDataInformation::SafeDownCast(
inInfo->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION()));
if (!inCompInfo)
{
vtkDebugMacro("Expected information not found. "
"Cannot provide information.");
return 1;
}
unsigned int numInputLevels = inCompInfo->GetNumberOfLevels();
unsigned int numOutputLevels = this->ComputeOutputLevels(numInputLevels);
vtkHierarchicalDataInformation* compInfo =
vtkHierarchicalDataInformation::New();
if (numOutputLevels > 0)
{
compInfo->SetNumberOfLevels(numOutputLevels);
vtkHierarchicalDataExtractDataSetsInternals::DataSetsTypes::iterator it =
this->Internal->DataSets.begin();
for (; it != this->Internal->DataSets.end(); it++)
{
DataSetNode& node = *it;
unsigned int numInputDataSets =
inCompInfo->GetNumberOfDataSets(node.Level);
if (node.DataSetId <= numInputDataSets)
{
if (node.DataSetId >= compInfo->GetNumberOfDataSets(node.Level))
{
compInfo->SetNumberOfDataSets(node.Level, node.DataSetId+1);
if (inCompInfo->HasInformation(node.Level, node.DataSetId))
{
vtkInformation* outdInfo =
compInfo->GetInformation(node.Level, node.DataSetId);
vtkInformation* indInfo =
inCompInfo->GetInformation(node.Level, node.DataSetId);
outdInfo->Copy(indInfo);
}
}
}
}
}
vtkInformation* outInfo = outputVector->GetInformationObject(0);
outInfo->Set(
vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION(), compInfo);
compInfo->Delete();
return 1;
}
//----------------------------------------------------------------------------
int vtkHierarchicalDataExtractDataSets::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkHierarchicalDataSet *input = vtkHierarchicalDataSet::SafeDownCast(
inInfo->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (!input) {return 0;}
vtkInformation* info = outputVector->GetInformationObject(0);
vtkHierarchicalDataSet *output = vtkHierarchicalDataSet::SafeDownCast(
info->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (!output) {return 0;}
unsigned int numInputLevels = input->GetNumberOfLevels();
unsigned int numOutputLevels = this->ComputeOutputLevels(numInputLevels);
if (numOutputLevels > 0)
{
output->SetNumberOfLevels(numOutputLevels);
vtkHierarchicalDataExtractDataSetsInternals::DataSetsTypes::iterator it =
this->Internal->DataSets.begin();
for (; it != this->Internal->DataSets.end(); it++)
{
DataSetNode& node = *it;
unsigned int numInputDataSets = input->GetNumberOfDataSets(node.Level);
if (node.DataSetId <= numInputDataSets)
{
if (node.DataSetId >= output->GetNumberOfDataSets(node.Level))
{
output->SetNumberOfDataSets(node.Level, node.DataSetId+1);
}
vtkDataObject* dObj =
input->GetDataSet(node.Level, node.DataSetId);
if (dObj)
{
vtkDataObject* copy = dObj->NewInstance();
copy->ShallowCopy(dObj);
output->SetDataSet(node.Level, node.DataSetId, copy);
// Remove blanking from output datasets.
vtkUniformGrid* ug = vtkUniformGrid::SafeDownCast(copy);
if (ug)
{
ug->SetCellVisibilityArray(0);
}
output->SetDataSet(node.Level, node.DataSetId, copy);
copy->Delete();
}
}
}
vtkHierarchicalDataInformation* compInfo =
vtkHierarchicalDataInformation::SafeDownCast(
info->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION()));
if (compInfo)
{
output->SetHierarchicalDataInformation(compInfo);
}
unsigned int numLevels = output->GetNumberOfLevels();
vtkHierarchicalBoxDataSet* hbds =
vtkHierarchicalBoxDataSet::SafeDownCast(output);
if (hbds)
{
vtkHierarchicalBoxDataSet* ihbds =
vtkHierarchicalBoxDataSet::SafeDownCast(input);
for (unsigned int level=0; level<numLevels-1; level++)
{
hbds->SetRefinementRatio(level, ihbds->GetRefinementRatio(level));
}
hbds->GenerateVisibilityArrays();
}
}
return 1;
}
//----------------------------------------------------------------------------
......
......@@ -14,67 +14,32 @@
=========================================================================*/
// .NAME vtkHierarchicalDataExtractDataSets - extract a number of datasets
// .SECTION Description
// vtkHierarchicalDataExtractDataSets extracts the user specified list
// of datasets from a hierarchical dataset.
// Legacy class. Use vtkMultiGroupDataExtractDataSets instead.
//
// .SECTION See Also
// vtkMultiGroupDataExtractDataSets
#ifndef __vtkHierarchicalDataExtractDataSets_h
#define __vtkHierarchicalDataExtractDataSets_h
#include "vtkHierarchicalDataSetAlgorithm.h"
#include "vtkMultiGroupDataExtractDataSets.h"
//BTX
struct vtkHierarchicalDataExtractDataSetsInternals;
//ETX
class VTK_GRAPHICS_EXPORT vtkHierarchicalDataExtractDataSets : public vtkHierarchicalDataSetAlgorithm
class VTK_GRAPHICS_EXPORT vtkHierarchicalDataExtractDataSets : public vtkMultiGroupDataExtractDataSets
{
public:
vtkTypeRevisionMacro(vtkHierarchicalDataExtractDataSets,vtkHierarchicalDataSetAlgorithm);
vtkTypeRevisionMacro(vtkHierarchicalDataExtractDataSets,vtkMultiGroupDataExtractDataSets);
void PrintSelf(ostream& os, vtkIndent indent);
static vtkHierarchicalDataExtractDataSets *New();
// Description:
// Add a dataset to be extracted.
void AddDataSet(unsigned int level, unsigned int idx);
// Description:
// Remove all entries from the list of datasets to be extracted.
void ClearDataSetList();
protected:
vtkHierarchicalDataExtractDataSets();
~vtkHierarchicalDataExtractDataSets();
virtual int RequestDataObject(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
virtual int RequestInformation(vtkInformation *,
vtkInformationVector **,
vtkInformationVector *);
virtual int RequestData(vtkInformation *,
vtkInformationVector **,
vtkInformationVector *);
unsigned int ComputeOutputLevels(unsigned int inputNumLevels);
//BTX
friend struct vtkHierarchicalDataExtractDataSetsInternals;
struct DataSetNode
{
unsigned int Level;
unsigned int DataSetId;
int Initialized;
DataSetNode() : Initialized(0) {}
DataSetNode(unsigned int level, unsigned int dsid) :
Level(level), DataSetId(dsid), Initialized(1) {}
};
//ETX
private:
vtkHierarchicalDataExtractDataSetsInternals* Internal;
vtkHierarchicalDataExtractDataSets(const vtkHierarchicalDataExtractDataSets&); // Not implemented.
void operator=(const vtkHierarchicalDataExtractDataSets&); // Not implemented.
};
......
......@@ -14,27 +14,14 @@ PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkHierarchicalDataExtractLevel.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
#include "vtkDataSet.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkHierarchicalDataInformation.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"
vtkCxxRevisionMacro(vtkHierarchicalDataExtractLevel, "1.7");
vtkCxxRevisionMacro(vtkHierarchicalDataExtractLevel, "1.8");
vtkStandardNewMacro(vtkHierarchicalDataExtractLevel);
//----------------------------------------------------------------------------
vtkHierarchicalDataExtractLevel::vtkHierarchicalDataExtractLevel()
{
this->MinLevel = 0;
this->MaxLevel = 0;
this->InputLevels[0] = 0;
this->InputLevels[1] = 0;
}
//----------------------------------------------------------------------------
......@@ -42,182 +29,9 @@ vtkHierarchicalDataExtractLevel::~vtkHierarchicalDataExtractLevel()
{
}
//----------------------------------------------------------------------------
int vtkHierarchicalDataExtractLevel::RequestDataObject(
vtkInformation*,
vtkInformationVector** inputVector ,
vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
if (!inInfo)
{
return 0;
}
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
inInfo->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (input)
{
vtkInformation* info = outputVector->GetInformationObject(0);
vtkCompositeDataSet *output = vtkCompositeDataSet::SafeDownCast(
info->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (!output || !output->IsA(input->GetClassName()))
{
output = input->NewInstance();
output->SetPipelineInformation(info);
output->Delete();
}
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
int vtkHierarchicalDataExtractLevel::RequestInformation(
vtkInformation*,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkHierarchicalDataInformation* inCompInfo =
vtkHierarchicalDataInformation::SafeDownCast(
inInfo->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION()));
if (!inCompInfo)
{
vtkDebugMacro("Expected information not found. "
"Cannot provide information.");
return 1;
}
unsigned int numInputLevels = inCompInfo->GetNumberOfLevels();
this->InputLevels[1] = numInputLevels-1;
unsigned int numLevels;
vtkHierarchicalDataInformation* compInfo =
vtkHierarchicalDataInformation::New();
if (this->MaxLevel >= numInputLevels)
{
numLevels = numInputLevels;
}
else
{
numLevels = this->MaxLevel+1;
}
compInfo->SetNumberOfLevels(numLevels);
for (unsigned int i=0; i<numLevels; i++)
{
if (i < this->MinLevel || i > this->MaxLevel)
{
compInfo->SetNumberOfDataSets(i, 0);
}
else
{
compInfo->SetNumberOfDataSets(i, inCompInfo->GetNumberOfDataSets(i));
}
unsigned int numDataSets = compInfo->GetNumberOfDataSets(i);
for (unsigned int j=0; j<numDataSets; j++)
{
if (inCompInfo->HasInformation(i, j))
{
vtkInformation* outdInfo = compInfo->GetInformation(i, j);
vtkInformation* indInfo = inCompInfo->GetInformation(i, j);
outdInfo->Copy(indInfo);
}
}
}
vtkInformation* outInfo = outputVector->GetInformationObject(0);
outInfo->Set(
vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION(), compInfo);
compInfo->Delete();
return 1;
}
//----------------------------------------------------------------------------
int vtkHierarchicalDataExtractLevel::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkHierarchicalDataSet *input = vtkHierarchicalDataSet::SafeDownCast(
inInfo->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (!input) {return 0;}
vtkInformation* info = outputVector->GetInformationObject(0);
vtkHierarchicalDataSet *output = vtkHierarchicalDataSet::SafeDownCast(
info->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET()));
if (!output) {return 0;}
output->SetNumberOfLevels(this->MaxLevel+1);
unsigned int numLevels = output->GetNumberOfLevels();
for (unsigned int level=0; level<numLevels; level++)
{
if (level < this->MinLevel || level > this->MaxLevel)
{
output->SetNumberOfDataSets(level, 0);
continue;
}
unsigned int numDataSets = input->GetNumberOfDataSets(level);
output->SetNumberOfDataSets(level, numDataSets);
for (unsigned int dataSet=0; dataSet<numDataSets; dataSet++)
{
vtkDataSet* dObj = vtkDataSet::SafeDownCast(
input->GetDataSet(level, dataSet));
if (dObj)
{
vtkDataSet* copy = dObj->NewInstance();
copy->ShallowCopy(dObj);
output->SetDataSet(level, dataSet, copy);
copy->Delete();
}
}
}
vtkHierarchicalDataInformation* compInfo =
vtkHierarchicalDataInformation::SafeDownCast(
info->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION()));
output->SetHierarchicalDataInformation(compInfo);
vtkHierarchicalBoxDataSet* hbds =
vtkHierarchicalBoxDataSet::SafeDownCast(output);
if (hbds)
{
vtkHierarchicalBoxDataSet* ihbds =
vtkHierarchicalBoxDataSet::SafeDownCast(input);
for (unsigned int level=0; level<numLevels-1; level++)
{
hbds->SetRefinementRatio(level, ihbds->GetRefinementRatio(level));
}
}
// Last level should not be blanked (uniform grid only)
unsigned int numDataSets = output->GetNumberOfDataSets(numLevels-1);
for (unsigned int dataSet=0; dataSet<numDataSets; dataSet++)
{
vtkUniformGrid* ug = vtkUniformGrid::SafeDownCast(
output->GetDataSet(numLevels-1, dataSet));
if (ug)
{
ug->SetCellVisibilityArray(0);
}
}
return 1;
}
//----------------------------------------------------------------------------
void vtkHierarchicalDataExtractLevel::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "MinLevel:" << this->MinLevel << endl;
os << indent << "MaxLevel:" << this->MaxLevel << endl;
os << indent << "InputLevels: (" << this->InputLevels[0] << ","
<< this->InputLevels[1] << ")" << endl;
}
......@@ -14,31 +14,44 @@
=========================================================================*/
// .NAME vtkHierarchicalDataExtractLevel - extact levels between min and max
// .SECTION Description
// vtkHierarchicalDataExtractLevel is a filter to that extracts levels
// between user specified min and max.
// Legacy class. Use vtkMultiGroupDataExtractGroup instead.
// .SECTION See Also
// vtkMultiGroupDataExtractGroup
#ifndef __vtkHierarchicalDataExtractLevel_h
#define __vtkHierarchicalDataExtractLevel_h
#include "vtkHierarchicalDataSetAlgorithm.h"
#include "vtkMultiGroupDataExtractGroup.h"
class VTK_GRAPHICS_EXPORT vtkHierarchicalDataExtractLevel : public vtkHierarchicalDataSetAlgorithm
class VTK_GRAPHICS_EXPORT vtkHierarchicalDataExtractLevel : public vtkMultiGroupDataExtractGroup
{
public:
vtkTypeRevisionMacro(vtkHierarchicalDataExtractLevel,vtkHierarchicalDataSetAlgorithm);
vtkTypeRevisionMacro(vtkHierarchicalDataExtractLevel,vtkMultiGroupDataExtractGroup);
void PrintSelf(ostream& os, vtkIndent indent);
static vtkHierarchicalDataExtractLevel *New();
// Description:
// Minimum level to be extacted
vtkSetMacro(MinLevel, unsigned int);
vtkGetMacro(MinLevel, unsigned int);
void SetMinLevel(unsigned int level)
{
this->Superclass::SetMinGroup(level);
}
unsigned int GetMinLevel()
{
return this->Superclass::GetMinGroup();
}
// Description:
// Maximum level to be extacted
vtkSetMacro(MaxLevel, unsigned int);
vtkGetMacro(MaxLevel, unsigned int);
void SetMaxLevel(unsigned int level)