Skip to content

Commit 219c1c7

Browse files
Fixed BUG #10615: Issues with 2D AMR blocks.
vtkHierarchicalBoxDataSet didn't save AMR box dimensionality. Nor was it preserved by readers/writers. This fixes that issue.
1 parent 24f6a0f commit 219c1c7

6 files changed

+42
-5
lines changed

Filtering/vtkHierarchicalBoxDataSet.cxx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
#include <assert.h>
3232

3333
vtkStandardNewMacro(vtkHierarchicalBoxDataSet);
34-
35-
vtkInformationKeyMacro(vtkHierarchicalBoxDataSet,BOX,IntegerVector);
34+
vtkInformationKeyRestrictedMacro(vtkHierarchicalBoxDataSet,BOX,IntegerVector, 6);
3635
vtkInformationKeyMacro(vtkHierarchicalBoxDataSet,NUMBER_OF_BLANKED_POINTS,IdType);
3736
vtkInformationKeyMacro(vtkHierarchicalBoxDataSet,REFINEMENT_RATIO,Integer);
37+
vtkInformationKeyMacro(vtkHierarchicalBoxDataSet,BOX_DIMENSIONALITY,Integer);
3838

3939
typedef vtkstd::vector<vtkAMRBox> vtkAMRBoxList;
4040
//----------------------------------------------------------------------------
@@ -139,6 +139,7 @@ void vtkHierarchicalBoxDataSet::SetDataSet(
139139
{
140140
const int *loCorner=box.GetLoCorner();
141141
const int *hiCorner=box.GetHiCorner();
142+
info->Set(BOX_DIMENSIONALITY(), box.GetDimensionality());
142143
info->Set(BOX(),
143144
loCorner[0], loCorner[1], loCorner[2],
144145
hiCorner[0], hiCorner[1], hiCorner[2]);
@@ -165,6 +166,10 @@ vtkUniformGrid* vtkHierarchicalBoxDataSet::GetDataSet(unsigned int level,
165166
vtkInformation* info = levelDS->GetMetaData(id);
166167
if (info)
167168
{
169+
int dimensionality = info->Has(BOX_DIMENSIONALITY())?
170+
info->Get(BOX_DIMENSIONALITY()) : 3;
171+
box.SetDimensionality(dimensionality);
172+
168173
int* boxVec = info->Get(BOX());
169174
if (boxVec)
170175
{
@@ -287,7 +292,9 @@ void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays()
287292
vtkInformation* info = this->GetMetaData(
288293
levelIdx+1,dataSetIdx);
289294
int* boxVec = info->Get(BOX());
290-
vtkAMRBox coarsebox(3,boxVec,boxVec+3);
295+
int dimensionality = info->Has(BOX_DIMENSIONALITY())?
296+
info->Get(BOX_DIMENSIONALITY()) : 3;
297+
vtkAMRBox coarsebox(dimensionality,boxVec,boxVec+3);
291298
int refinementRatio = this->GetRefinementRatio(levelIdx);
292299
if (refinementRatio == 0)
293300
{
@@ -356,6 +363,9 @@ vtkAMRBox vtkHierarchicalBoxDataSet::GetAMRBox(vtkCompositeDataIterator* iter)
356363
if (this->HasMetaData(iter))
357364
{
358365
vtkInformation* info = this->GetMetaData(iter);
366+
int dimensionality = info->Has(BOX_DIMENSIONALITY())?
367+
info->Get(BOX_DIMENSIONALITY()) : 3;
368+
box.SetDimensionality(dimensionality);
359369
int* boxVec = info->Get(BOX());
360370
if (boxVec)
361371
{

Filtering/vtkHierarchicalBoxDataSet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class VTK_FILTERING_EXPORT vtkHierarchicalBoxDataSet : public vtkCompositeDataSe
164164
void GenerateVisibilityArrays();
165165

166166
static vtkInformationIntegerVectorKey* BOX();
167+
static vtkInformationIntegerKey* BOX_DIMENSIONALITY();
167168
static vtkInformationIntegerKey* REFINEMENT_RATIO();
168169
static vtkInformationIdTypeKey* NUMBER_OF_BLANKED_POINTS();
169170

IO/vtkXMLHierarchicalBoxDataReader.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ void vtkXMLHierarchicalBoxDataReader::ReadComposite(vtkXMLDataElement* element,
200200
vtkWarningMacro("Missing amr box for level " << level << ", dataset " << index);
201201
}
202202

203+
int dimensionality = 3;
204+
if (!datasetXML->GetScalarAttribute("dimensionality", dimensionality))
205+
{
206+
// default.
207+
dimensionality = 3;
208+
}
209+
amrBox.SetDimensionality(dimensionality);
210+
203211
vtkSmartPointer<vtkUniformGrid> childDS = 0;
204212
if (this->ShouldReadDataSet(dataSetIndex))
205213
{

IO/vtkXMLHierarchicalBoxDataWriter.cxx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ vtkStandardNewMacro(vtkXMLHierarchicalBoxDataWriter);
3131
vtkXMLHierarchicalBoxDataWriter::vtkXMLHierarchicalBoxDataWriter()
3232
{
3333
this->AMRBoxes = NULL;
34+
this->AMRBoxDims = NULL;
3435
}
3536

3637
//----------------------------------------------------------------------------
3738
vtkXMLHierarchicalBoxDataWriter::~vtkXMLHierarchicalBoxDataWriter()
3839
{
39-
delete this->AMRBoxes;
40+
delete [] this->AMRBoxes;
4041
this->AMRBoxes = NULL;
42+
43+
delete [] this->AMRBoxDims;
44+
this->AMRBoxDims = NULL;
4145
}
4246

4347
//----------------------------------------------------------------------------
@@ -60,11 +64,15 @@ void vtkXMLHierarchicalBoxDataWriter::FillDataTypes(vtkCompositeDataSet* cdInput
6064
assert("dataset must be vtkHierarchicalBoxDataSet" && hdInput != NULL);
6165

6266
delete [] this->AMRBoxes;
67+
delete [] this->AMRBoxDims;
6368

6469
unsigned int numLeafNodes = this->GetNumberOfDataTypes();
6570
this->AMRBoxes = new int[numLeafNodes * 6];
6671
memset(this->AMRBoxes, 0, numLeafNodes*6*sizeof(int));
6772

73+
this->AMRBoxDims = new int[numLeafNodes];
74+
memset(this->AMRBoxDims, 0, numLeafNodes*sizeof(int));
75+
6876
vtkCompositeDataIterator* iter = hdInput->NewIterator();
6977
iter->SkipEmptyNodesOff();
7078
int leafNo = 0;
@@ -75,6 +83,7 @@ void vtkXMLHierarchicalBoxDataWriter::FillDataTypes(vtkCompositeDataSet* cdInput
7583
{
7684
vtkAMRBox box = hdInput->GetAMRBox(iter);
7785
box.GetDimensions(&this->AMRBoxes[leafNo*6]);
86+
this->AMRBoxDims[leafNo] = box.GetDimensionality();
7887
}
7988
}
8089
iter->Delete();
@@ -106,6 +115,8 @@ int vtkXMLHierarchicalBoxDataWriter::WriteComposite(vtkCompositeDataSet* composi
106115
// we use the box from this->AMRBoxes since that datastructure is
107116
// synchronized when running in parallel.
108117
datasetXML->SetVectorAttribute("amr_box", 6, &this->AMRBoxes[writerIdx*6]);
118+
datasetXML->SetIntAttribute("dimensionality",
119+
this->AMRBoxDims[writerIdx]);
109120
vtkStdString fileName = this->CreatePieceFileName(writerIdx);
110121
if (fileName != "")
111122
{

IO/vtkXMLHierarchicalBoxDataWriter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class VTK_IO_EXPORT vtkXMLHierarchicalBoxDataWriter : public vtkXMLCompositeData
4242

4343
virtual int FillInputPortInformation(int port, vtkInformation* info);
4444

45-
// Fills up this->AMRBoxes with boxes for the dataset.
45+
// Fills up this->AMRBoxes, this->AMRBoxDims with boxes for the dataset.
4646
virtual void FillDataTypes(vtkCompositeDataSet*);
4747

4848
// Internal method called recursively to create the xml tree for the children
@@ -51,6 +51,7 @@ class VTK_IO_EXPORT vtkXMLHierarchicalBoxDataWriter : public vtkXMLCompositeData
5151
vtkXMLDataElement* parent, int &writerIdx);
5252

5353
int *AMRBoxes;
54+
int *AMRBoxDims;
5455
private:
5556
vtkXMLHierarchicalBoxDataWriter(const vtkXMLHierarchicalBoxDataWriter&); // Not implemented.
5657
void operator=(const vtkXMLHierarchicalBoxDataWriter&); // Not implemented.

Parallel/vtkXMLPHierarchicalBoxDataWriter.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void vtkXMLPHierarchicalBoxDataWriter::FillDataTypes(
9898
// ratio informations since those are certainly consistent on all processes
9999
// since we expect the same composite structure on all nodes.
100100
assert(this->AMRBoxes != NULL);
101+
assert(this->AMRBoxDims != NULL);
101102

102103
if (myid == 0)
103104
{
@@ -113,6 +114,8 @@ void vtkXMLPHierarchicalBoxDataWriter::FillDataTypes(
113114
memset(gathered_amx_box_dims, 0, numLeafNodes*6*numProcs*sizeof(int));
114115
this->Controller->Gather(this->AMRBoxes, gathered_amx_box_dims,
115116
numLeafNodes*6, 0);
117+
this->Controller->Gather(this->AMRBoxDims, gathered_amx_box_dims,
118+
numLeafNodes, 0);
116119

117120
for (int procNo=1; procNo<numProcs; procNo++)
118121
{
@@ -126,6 +129,8 @@ void vtkXMLPHierarchicalBoxDataWriter::FillDataTypes(
126129
memcpy(&this->AMRBoxes[pieceNo*6],
127130
&gathered_amx_box_dims[(procNo*numLeafNodes + pieceNo)*6],
128131
sizeof(int)*6);
132+
this->AMRBoxDims[pieceNo] = gathered_amx_box_dims[
133+
procNo*numLeafNodes + pieceNo];
129134
}
130135
}
131136
}
@@ -136,6 +141,7 @@ void vtkXMLPHierarchicalBoxDataWriter::FillDataTypes(
136141
{
137142
this->Controller->Gather(myDataTypes, NULL, numLeafNodes, 0);
138143
this->Controller->Gather(this->AMRBoxes, NULL, numLeafNodes*6, 0);
144+
this->Controller->Gather(this->AMRBoxDims, NULL, numLeafNodes, 0);
139145
}
140146
}
141147

0 commit comments

Comments
 (0)