Commit 2ab5219f authored by Berk Geveci's avatar Berk Geveci
Browse files

ENH: Updating composite datasets. Added a vtkHierarchicalDataInformation...

ENH: Updating composite datasets. Added a vtkHierarchicalDataInformation object to store information about each dataset
parent 5360e821
......@@ -16,8 +16,12 @@
#include "vtkCompositeDataIterator.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
vtkCxxRevisionMacro(vtkCompositeDataSet, "1.3");
vtkCxxRevisionMacro(vtkCompositeDataSet, "1.4");
vtkInformationKeyMacro(vtkCompositeDataSet,INDEX,Integer);
//----------------------------------------------------------------------------
vtkCompositeDataSet::vtkCompositeDataSet()
......
......@@ -28,6 +28,7 @@
#include "vtkDataObject.h"
class vtkCompositeDataIterator;
class vtkInformation;
class VTK_FILTERING_EXPORT vtkCompositeDataSet : public vtkDataObject
{
......@@ -74,6 +75,19 @@ public:
void SetUpdateExtent( int ext[6] )
{ this->Superclass::SetUpdateExtent( ext ); };
// Description:
// Adds dobj to the composite dataset. Where the dataset goes is determined
// by appropriate keys in the index information object. Which keys are used
// depends on the actual subclass.
virtual void AddDataSet(vtkInformation* index, vtkDataObject* dobj) = 0;
// Description:
// Returns a dataset pointed by appropriate keys in the index information
// object. Which keys are used depends on the actual subclass.
virtual vtkDataObject* GetDataSet(vtkInformation* index) = 0;
static vtkInformationIntegerKey* INDEX();
protected:
vtkCompositeDataSet();
~vtkCompositeDataSet();
......
......@@ -16,13 +16,19 @@
#include "vtkHierarchicalBoxDataSetInternal.h"
#include "vtkHierarchicalDataInformation.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerVectorKey.h"
#include "vtkInformationKey.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"
#include "vtkUnsignedCharArray.h"
vtkCxxRevisionMacro(vtkHierarchicalBoxDataSet, "1.4");
vtkCxxRevisionMacro(vtkHierarchicalBoxDataSet, "1.5");
vtkStandardNewMacro(vtkHierarchicalBoxDataSet);
vtkInformationKeyMacro(vtkHierarchicalBoxDataSet,BOX,IntegerVector);
//----------------------------------------------------------------------------
vtkHierarchicalBoxDataSet::vtkHierarchicalBoxDataSet()
{
......@@ -35,21 +41,20 @@ vtkHierarchicalBoxDataSet::~vtkHierarchicalBoxDataSet()
delete this->BoxInternal;
}
//----------------------------------------------------------------------------
vtkHDSNode* vtkHierarchicalBoxDataSet::NewNode()
{
return new vtkHBDSNode;
}
//----------------------------------------------------------------------------
void vtkHierarchicalBoxDataSet::SetDataSet(
unsigned int level, unsigned int id, vtkAMRBox& box, vtkUniformGrid* dataSet)
{
this->Superclass::SetDataSet(level, id, dataSet);
vtkHierarchicalDataSetInternal::LevelDataSetsType& ldataSets =
this->Internal->DataSets[level];
static_cast<vtkHBDSNode*>(ldataSets[id])->Box = box;
vtkInformation* info =
this->HierarchicalDataInformation->GetInformation(level, id);
if (info)
{
info->Set(BOX(),
box.LoCorner[0], box.LoCorner[1], box.LoCorner[2],
box.HiCorner[0], box.HiCorner[1], box.HiCorner[2]);
}
}
//----------------------------------------------------------------------------
......@@ -74,8 +79,18 @@ vtkUniformGrid* vtkHierarchicalBoxDataSet::GetDataSet(unsigned int level,
return 0;
}
box = static_cast<vtkHBDSNode*>(ldataSets[id])->Box;
return static_cast<vtkUniformGrid*>(ldataSets[id]->DataSet.GetPointer());
vtkInformation* info =
this->HierarchicalDataInformation->GetInformation(level, id);
if (info)
{
int* boxVec = info->Get(BOX());
if (boxVec)
{
memcpy(&box.LoCorner, boxVec , 3*sizeof(int));
memcpy(&box.HiCorner, boxVec+3, 3*sizeof(int));
}
}
return static_cast<vtkUniformGrid*>(ldataSets[id].GetPointer());
}
//----------------------------------------------------------------------------
......@@ -114,17 +129,14 @@ void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays()
// Copy boxes of higher level and coarsen to this level
vtkstd::vector<vtkAMRBox> boxes;
vtkHierarchicalDataSetInternal::LevelDataSetsType& ldataSets =
this->Internal->DataSets[levelIdx+1];
vtkHierarchicalDataSetInternal::LevelDataSetsIterator ldx;
for (ldx = ldataSets.begin(); ldx != ldataSets.end(); ldx++)
unsigned int numDataSets = this->GetNumberOfDataSets(levelIdx+1);
unsigned int dataSetIdx;
for (dataSetIdx=0; dataSetIdx<numDataSets; dataSetIdx++)
{
if (! *ldx )
{
continue;
}
vtkAMRBox coarsebox =
static_cast<vtkHBDSNode*>(*ldx)->Box;
vtkInformation* info =
this->HierarchicalDataInformation->GetInformation(levelIdx+1,dataSetIdx);
int* boxVec = info->Get(BOX());
vtkAMRBox coarsebox(3, boxVec, boxVec+3);
if (this->BoxInternal->RefinementRatios.size() <= levelIdx)
{
continue;
......@@ -133,9 +145,7 @@ void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays()
boxes.push_back(coarsebox);
}
unsigned int numDataSets = this->GetNumberOfDataSets(levelIdx);
for (unsigned int dataSetIdx=0; dataSetIdx<numDataSets; dataSetIdx++)
for (dataSetIdx=0; dataSetIdx<numDataSets; dataSetIdx++)
{
vtkAMRBox box;
vtkUniformGrid* grid = this->GetDataSet(levelIdx, dataSetIdx, box);
......@@ -263,5 +273,27 @@ void vtkHierarchicalBoxDataSet::DeepCopy(vtkDataObject *src)
void vtkHierarchicalBoxDataSet::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
unsigned int numLevels = this->GetNumberOfLevels();
os << indent << "Number of levels: " << numLevels << endl;
for (unsigned int i=0; i<numLevels; i++)
{
unsigned int numDataSets = this->GetNumberOfDataSets(i);
os << indent << "Level " << i << " number of datasets: " << numDataSets
<< endl;
for (unsigned j=0; j<numDataSets; j++)
{
os << indent << "DataSet(" << i << "," << j << "):";
vtkDataObject* dobj = this->GetDataSet(i, j);
if (dobj)
{
os << endl;
dobj->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << "(none)" << endl;
}
}
}
}
......@@ -77,12 +77,12 @@ public:
virtual void ShallowCopy(vtkDataObject *src);
virtual void DeepCopy(vtkDataObject *src);
static vtkInformationIntegerVectorKey* BOX();
protected:
vtkHierarchicalBoxDataSet();
~vtkHierarchicalBoxDataSet();
virtual vtkHDSNode* NewNode();
vtkHierarchicalBoxDataSetInternal* BoxInternal;
private:
......
......@@ -24,10 +24,4 @@ struct vtkHierarchicalBoxDataSetInternal
vtkstd::vector<int> RefinementRatios;
};
class vtkHBDSNode : public vtkHDSNode
{
public:
vtkAMRBox Box;
};
#endif
......@@ -18,7 +18,7 @@
#include "vtkHierarchicalDataSetInternal.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkHierarchicalDataIterator, "1.2");
vtkCxxRevisionMacro(vtkHierarchicalDataIterator, "1.3");
vtkStandardNewMacro(vtkHierarchicalDataIterator);
class vtkHierarchicalDataIteratorInternal
......@@ -172,8 +172,7 @@ vtkDataObject* vtkHierarchicalDataIterator::GetCurrentDataObject()
{
return 0;
}
vtkHDSNode* node = *this->Internal->LDSIterator;
return (node ? node->DataSet.GetPointer() : 0);
return this->Internal->LDSIterator->GetPointer();
}
//----------------------------------------------------------------------------
......
......@@ -14,17 +14,26 @@
=========================================================================*/
#include "vtkHierarchicalDataSet.h"
#include "vtkHierarchicalDataInformation.h"
#include "vtkHierarchicalDataIterator.h"
#include "vtkHierarchicalDataSetInternal.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkHierarchicalDataSet, "1.1");
vtkCxxRevisionMacro(vtkHierarchicalDataSet, "1.2");
vtkStandardNewMacro(vtkHierarchicalDataSet);
vtkCxxSetObjectMacro(vtkHierarchicalDataSet,HierarchicalDataInformation,vtkHierarchicalDataInformation);
vtkInformationKeyMacro(vtkHierarchicalDataSet,LEVEL,Integer);
//----------------------------------------------------------------------------
vtkHierarchicalDataSet::vtkHierarchicalDataSet()
{
this->Internal = new vtkHierarchicalDataSetInternal;
this->HierarchicalDataInformation = vtkHierarchicalDataInformation::New();
}
//----------------------------------------------------------------------------
......@@ -32,6 +41,7 @@ vtkHierarchicalDataSet::~vtkHierarchicalDataSet()
{
this->InitializeDataSets();
delete this->Internal;
this->SetHierarchicalDataInformation(0);
}
//----------------------------------------------------------------------------
......@@ -51,21 +61,8 @@ vtkHDSNode* vtkHierarchicalDataSet::NewNode()
//----------------------------------------------------------------------------
void vtkHierarchicalDataSet::InitializeDataSets()
{
// We need to delete all nodes since we manage memory for them.
vtkHierarchicalDataSetInternal::DataSetsIterator idx;
for(idx = this->Internal->DataSets.begin();
idx != this->Internal->DataSets.end() ;
++idx)
{
vtkHierarchicalDataSetInternal::LevelDataSetsType& ldataSets = *idx;
vtkHierarchicalDataSetInternal::LevelDataSetsIterator ldx;
for (ldx = ldataSets.begin(); ldx != ldataSets.end(); ldx++)
{
delete *ldx;
}
idx->clear();
}
this->Internal->DataSets.clear();
this->HierarchicalDataInformation->Clear();
}
//----------------------------------------------------------------------------
......@@ -73,6 +70,8 @@ void vtkHierarchicalDataSet::Initialize()
{
this->Superclass::Initialize();
this->InitializeDataSets();
this->SetHierarchicalDataInformation(0);
this->HierarchicalDataInformation = vtkHierarchicalDataInformation::New();
}
//----------------------------------------------------------------------------
......@@ -84,26 +83,13 @@ unsigned int vtkHierarchicalDataSet::GetNumberOfLevels()
//----------------------------------------------------------------------------
void vtkHierarchicalDataSet::SetNumberOfLevels(unsigned int numLevels)
{
this->HierarchicalDataInformation->SetNumberOfLevels(numLevels);
if (numLevels == this->GetNumberOfLevels())
{
return;
}
unsigned int curNumLevels = this->Internal->DataSets.size();
if (curNumLevels > numLevels)
{
// We need to delete all extra nodes since we manage memory for them.
for(unsigned int i=numLevels; i<curNumLevels; i++)
{
vtkHierarchicalDataSetInternal::LevelDataSetsType& ldataSets =
this->Internal->DataSets[i];
vtkHierarchicalDataSetInternal::LevelDataSetsIterator ldx;
for (ldx = ldataSets.begin(); ldx != ldataSets.end(); ldx++)
{
delete *ldx;
}
}
}
this->Internal->DataSets.resize(numLevels);
this->HierarchicalDataInformation->SetNumberOfLevels(numLevels);
this->Modified();
}
......@@ -125,6 +111,7 @@ unsigned int vtkHierarchicalDataSet::GetNumberOfDataSets(unsigned int level)
void vtkHierarchicalDataSet::SetNumberOfDataSets(unsigned int level,
unsigned int numDataSets)
{
this->HierarchicalDataInformation->SetNumberOfDataSets(level, numDataSets);
if (numDataSets == this->GetNumberOfDataSets(level))
{
return;
......@@ -140,13 +127,6 @@ void vtkHierarchicalDataSet::SetNumberOfDataSets(unsigned int level,
// We need to delete all extra nodes since we manage memory for them.
unsigned int curNumDataSets = ldataSets.size();
if (curNumDataSets > numDataSets)
{
for (unsigned int i=numDataSets; i<curNumDataSets; i++)
{
delete ldataSets[i];
}
}
ldataSets.resize(numDataSets);
// Assign NULL to all new pointers. We use this later to figure out
......@@ -158,6 +138,7 @@ void vtkHierarchicalDataSet::SetNumberOfDataSets(unsigned int level,
ldataSets[i] = 0;
}
}
this->HierarchicalDataInformation->SetNumberOfDataSets(level, numDataSets);
this->Modified();
}
......@@ -181,16 +162,17 @@ void vtkHierarchicalDataSet::InitializeNode(unsigned int level,
this->SetNumberOfDataSets(level, id+1);
}
if (ldataSets[id])
{
ldataSets[id]->DisconnectAll(vtkHDSNodeRef(level, id),
this->Internal->DataSets);
ldataSets[id]->DataSet = 0;
}
else
{
ldataSets[id] = this->NewNode();
}
ldataSets[id] = 0;
// if (ldataSets[id])
// {
// ldataSets[id]->DisconnectAll(vtkHDSNodeRef(level, id),
// this->Internal->DataSets);
// ldataSets[id]->DataSet = 0;
// }
// else
// {
// ldataSets[id] = this->NewNode();
// }
this->Modified();
}
......@@ -214,37 +196,17 @@ void vtkHierarchicalDataSet::SetDataSet(unsigned int level,
this->SetNumberOfDataSets(level, id+1);
}
if (!ldataSets[id])
{
ldataSets[id] = this->NewNode();
}
ldataSets[id]->DataSet = ds;
ldataSets[id] = ds;
this->Modified();
}
//----------------------------------------------------------------------------
int vtkHierarchicalDataSet::IsNodePresent(unsigned int level,
unsigned int id)
void vtkHierarchicalDataSet::AddDataSet(vtkInformation* index, vtkDataObject* dobj)
{
if (this->Internal->DataSets.size() <= level)
if (index->Has(INDEX()) && index->Has(LEVEL()))
{
return 0;
this->SetDataSet(index->Get(LEVEL()), index->Get(INDEX()), dobj);
}
vtkHierarchicalDataSetInternal::LevelDataSetsType& ldataSets =
this->Internal->DataSets[level];
if (ldataSets.size() <= id)
{
return 0;
}
if (!ldataSets[id])
{
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
......@@ -268,7 +230,17 @@ vtkDataObject* vtkHierarchicalDataSet::GetDataSet(unsigned int level,
return 0;
}
return ldataSets[id]->DataSet.GetPointer();
return ldataSets[id];
}
//----------------------------------------------------------------------------
vtkDataObject* vtkHierarchicalDataSet::GetDataSet(vtkInformation* index)
{
if (index->Has(INDEX()) && index->Has(LEVEL()))
{
return this->GetDataSet(index->Get(LEVEL()), index->Get(INDEX()));
}
return 0;
}
//----------------------------------------------------------------------------
......@@ -280,11 +252,11 @@ void vtkHierarchicalDataSet::ShallowCopy(vtkDataObject *src)
}
this->InitializeDataSets();
this->Superclass::ShallowCopy(src);
this->Modified();
vtkHierarchicalDataSet* from = vtkHierarchicalDataSet::SafeDownCast(src);
if (from)
{
this->SetHierarchicalDataInformation(from->HierarchicalDataInformation);
unsigned int numLevels = from->GetNumberOfLevels();
this->SetNumberOfLevels(numLevels);
for (unsigned int i=0; i<numLevels; i++)
......@@ -297,6 +269,8 @@ void vtkHierarchicalDataSet::ShallowCopy(vtkDataObject *src)
}
}
}
this->Modified();
}
//----------------------------------------------------------------------------
......@@ -308,11 +282,14 @@ void vtkHierarchicalDataSet::DeepCopy(vtkDataObject *src)
}
this->InitializeDataSets();
this->Superclass::ShallowCopy(src);
this->Modified();
this->SetHierarchicalDataInformation(0);
this->HierarchicalDataInformation = vtkHierarchicalDataInformation::New();
vtkHierarchicalDataSet* from = vtkHierarchicalDataSet::SafeDownCast(src);
if (from)
{
this->HierarchicalDataInformation->DeepCopy(
from->HierarchicalDataInformation);
unsigned int numLevels = from->GetNumberOfLevels();
this->SetNumberOfLevels(numLevels);
for (unsigned int i=0; i<numLevels; i++)
......@@ -331,6 +308,8 @@ void vtkHierarchicalDataSet::DeepCopy(vtkDataObject *src)
}
}
}
this->Modified();
}
//----------------------------------------------------------------------------
......
......@@ -30,10 +30,13 @@ struct vtkHierarchicalDataSetInternal;
//ETX
class vtkDataObject;
class vtkHDSNode;
class vtkHierarchicalDataInformation;
class VTK_FILTERING_EXPORT vtkHierarchicalDataSet : public vtkCompositeDataSet
{
public:
static vtkHierarchicalDataSet *New();
vtkTypeRevisionMacro(vtkHierarchicalDataSet,vtkCompositeDataSet);
virtual void PrintSelf(ostream& os, vtkIndent indent);
......@@ -76,32 +79,44 @@ public:
// parent/child links between the given node and others.
void InitializeNode(unsigned int level, unsigned int id);
// Description:
// Returns 1 if the node [level, id] is initialized. Since
// GetDataSet() returns NULL when either an existing node
// has NULL dataset pointer or the node does not exit, this
// is the only way to check if a node really exists.
int IsNodePresent(unsigned int level, unsigned int id);
// Description:
// Set the dataset pointer for a given node. This method does
// not remove the existing parent/child links. It only replaces
// the dataset pointer.
void SetDataSet(unsigned int level, unsigned int id, vtkDataObject* dataSet);
// Description:
// Uses keys LEVEL() and INDEX() to call SetDataSet(LEVEL, INDEX, dobj)
virtual void AddDataSet(vtkInformation* index, vtkDataObject* dobj);
// Description:
// Get a dataset give a level and an id.
vtkDataObject* GetDataSet(unsigned int level, unsigned int id);
// Description:
// Uses keys LEVEL() and INDEX() to call GetDataSet(LEVEL, INDEX)
virtual vtkDataObject* GetDataSet(vtkInformation* index);
// Description:
// Shallow and Deep copy.
virtual void ShallowCopy(vtkDataObject *src);
virtual void DeepCopy(vtkDataObject *src);
// Description:
// Returns the data structure containing information about
// the datasets.
vtkGetObjectMacro(HierarchicalDataInformation,vtkHierarchicalDataInformation);
// Description:
// Set the information about the datasets.
void SetHierarchicalDataInformation(vtkHierarchicalDataInformation* info);
//BTX
friend class vtkHierarchicalDataIterator;
//ETX
static vtkInformationIntegerKey* LEVEL();
protected:
vtkHierarchicalDataSet();
~vtkHierarchicalDataSet();
......@@ -112,6 +127,8 @@ protected:
virtual vtkHDSNode* NewNode();
vtkHierarchicalDataInformation* HierarchicalDataInformation;
private:
vtkHierarchicalDataSet(const vtkHierarchicalDataSet&); // Not implemented.
void operator=(const vtkHierarchicalDataSet&); // Not implemented.
......
......@@ -26,7 +26,7 @@ class vtkHDSNode;
struct vtkHierarchicalDataSetInternal
{
typedef vtkstd::vector<vtkHDSNode*> LevelDataSetsType;
typedef vtkstd::vector<vtkSmartPointer<vtkDataObject> > LevelDataSetsType;
typedef LevelDataSetsType::iterator LevelDataSetsIterator;
typedef vtkstd::vector<LevelDataSetsType> DataSetsType;
typedef DataSetsType::iterator DataSetsIterator;
......@@ -55,117 +55,114 @@ class vtkHDSNode
{
public:
vtkHDSNode() : DataSet(0) {}
vtkSmartPointer<vtkDataObject> DataSet;
// void AddParent(const vtkHDSNodeRef& parent);
// void AddChild (const vtkHDSNodeRef& child );
void AddParent(const vtkHDSNodeRef& parent);
void AddChild (const vtkHDSNodeRef& child );
// void RemoveParent(const vtkHDSNodeRef& parent);
// void RemoveChild (const vtkHDSNodeRef& child );
void RemoveParent(const vtkHDSNodeRef& parent);
void RemoveChild (const vtkHDSNodeRef& child );
// void DisconnectFromParent(const vtkHDSNodeRef& self,
// const vtkHDSNodeRef& parent,
// vtkHierarchicalDataSetInternal::DataSetsType& ds);
// void DisconnectFromChild (const vtkHDSNodeRef& self,
// const vtkHDSNodeRef& child,
// vtkHierarchicalDataSetInternal::DataSetsType& ds);
// void ConnectToParent(const vtkHDSNodeRef& self,
// const vtkHDSNodeRef& parent,
// vtkHierarchicalDataSetInternal::DataSetsType& ds);
// void ConnectToChild (const vtkHDSNodeRef& self,
// const vtkHDSNodeRef& child,
// vtkHierarchicalDataSetInternal::DataSetsType& ds);
void DisconnectFromParent(const vtkHDSNodeRef& self,
const vtkHDSNodeRef& parent,
vtkHierarchicalDataSetInternal::DataSetsType& ds);
void DisconnectFromChild (const vtkHDSNodeRef& self,
const vtkHDSNodeRef& child,
vtkHierarchicalDataSetInternal::DataSetsType& ds);
void ConnectToParent(const vtkHDSNodeRef& self,
const vtkHDSNodeRef& parent,
vtkHierarchicalDataSetInternal::DataSetsType& ds);
void ConnectToChild (const vtkHDSNodeRef& self,
const vtkHDSNodeRef& child,
vtkHierarchicalDataSetInternal::DataSetsType& ds);
void DisconnectAll(const vtkHDSNodeRef& self,
vtkHierarchicalDataSetInternal::DataSetsType& ds);
// void DisconnectAll(const vtkHDSNodeRef& self,
// vtkHierarchicalDataSetInternal::DataSetsType& ds);
protected:
vtkstd::vector<vtkHDSNodeRef> Parents;
vtkstd::vector<vtkHDSNodeRef> Children;
};