Commit df935a54 authored by Philippe Pébay's avatar Philippe Pébay
Browse files

Fixed bug that was causing failure for dim < 3.

Also improved documentation as this code becomes increasingly
complex

Change-Id: If39b01b73256bd638341b785cc4f065e9184550f
parent 829f4139
......@@ -2217,8 +2217,8 @@ vtkIdTypeArray* vtkHyperTreeGrid::GetCornerLeafIds()
}
//-----------------------------------------------------------------------------
void vtkHyperTreeGrid::InitializeSuperCursor(vtkHyperTreeSuperCursor* superCursor,
int i, int j, int k)
void vtkHyperTreeGrid::InitializeSuperCursor( vtkHyperTreeSuperCursor* superCursor,
int i, int j, int k )
{
// TODO: This only needs to be done once. Use MTime ...
this->UpdateCellTreeLeafIdOffsets();
......@@ -2262,7 +2262,7 @@ void vtkHyperTreeGrid::InitializeSuperCursor(vtkHyperTreeSuperCursor* superCurso
superCursor->NumberOfCursors = 27;
}
// Now initialize all connectivity cursors by generating all possible cases
for ( int c = -1; c < 2; ++ c )
{
bool tk = true;
......@@ -2307,14 +2307,17 @@ void vtkHyperTreeGrid::InitializeSuperCursor(vtkHyperTreeSuperCursor* superCurso
int d = a + 3 * b + 9 * c;
if ( ti && tj && tk )
{
superCursor->GetCursor(d)->Initialize( this,
this->CellTreeLeafIdOffsets,
index, a, b, c );
superCursor->GetCursor( d )->Initialize( this,
this->CellTreeLeafIdOffsets,
index, a, b, c );
} // if ( ti && tj && tk )
else
{
superCursor->GetCursor( d )->Clear();
}
if ( this->Dimension < 3 && ! c )
{
superCursor->GetCursor( d )->Clear();
}
} // else
} // c
} // b
} // a
......@@ -2448,12 +2451,12 @@ void vtkHyperTreeGrid::UpdateDualArrays()
// owns the corner and generates that dual cell.
// Note: The recursion here is the same as TraverseGridRecursively. The only
// difference is which arrays are generated. We should merge the two.
void vtkHyperTreeGrid::TraverseDualRecursively(vtkHyperTreeSuperCursor* superCursor,
int level )
void vtkHyperTreeGrid::TraverseDualRecursively( vtkHyperTreeSuperCursor* superCursor,
int level )
{
// Level of the middle cursor.
int midLevel = superCursor->GetCursor(0)->GetLevel();
if ( superCursor->GetCursor(0)->GetIsLeaf() )
int midLevel = superCursor->GetCursor( 0 )->GetLevel();
if ( superCursor->GetCursor( 0 )->GetIsLeaf() )
{
// Center is a leaf. Make a dual point.
double pt[3];
......@@ -2464,8 +2467,8 @@ void vtkHyperTreeGrid::TraverseDualRecursively(vtkHyperTreeSuperCursor* superCur
pt[2] = superCursor->Origin[2];
// Adjust point so the boundary of the dataset does not shrink.
if ( superCursor->GetCursor(-1)->GetTree() &&
superCursor->GetCursor(1)->GetTree() )
if ( superCursor->GetCursor( -1 )->GetTree() &&
superCursor->GetCursor( 1 )->GetTree() )
{
// Middle of cell
pt[0] += superCursor->Size[0] * 0.5;
......@@ -2476,34 +2479,34 @@ void vtkHyperTreeGrid::TraverseDualRecursively(vtkHyperTreeSuperCursor* superCur
pt[0] += superCursor->Size[0];
}
if ( this->Dimension > 1 &&
superCursor->GetCursor(-3)->GetTree() &&
superCursor->GetCursor(3)->GetTree() )
superCursor->GetCursor( -3 )->GetTree() &&
superCursor->GetCursor( 3 )->GetTree() )
{
// Middle of cell
pt[1] += superCursor->Size[1] * 0.5;
}
else if ( this->Dimension > 1 &&
superCursor->GetCursor(3)->GetTree() == 0 )
superCursor->GetCursor( 3 )->GetTree() == 0 )
{
// Move to maximum boundary of cell
pt[1] += superCursor->Size[1];
}
if ( this->Dimension > 2 &&
superCursor->GetCursor(-9)->GetTree() &&
superCursor->GetCursor(9)->GetTree() )
superCursor->GetCursor( -9 )->GetTree() &&
superCursor->GetCursor( 9 )->GetTree() )
{
// Middle of cell
pt[2] += superCursor->Size[2] * 0.5;
}
else if ( this->Dimension > 2 &&
superCursor->GetCursor(9)->GetTree() == 0 )
superCursor->GetCursor( 9 )->GetTree() == 0 )
{
// Move to maximum boundary of cell
pt[2] += superCursor->Size[2];
}
// Insert point with given offset into leaf centers array
int index = superCursor->GetCursor(0)->GetGlobalLeafIndex();
int index = superCursor->GetCursor( 0 )->GetGlobalLeafIndex();
this->LeafCenters->InsertPoint( index, pt );
// Now see if the center leaf owns any of the corners.
......@@ -2775,8 +2778,8 @@ void vtkHyperTreeGrid::TraverseGridRecursively( vtkHyperTreeSuperCursor* superCu
int cornerId;
int cornerIds[8];
int level = superCursor->GetCursor(0)->GetLevel();
if ( superCursor->GetCursor(0)->GetIsLeaf() )
int level = superCursor->GetCursor( 0 )->GetLevel();
if ( superCursor->GetCursor( 0 )->GetIsLeaf() )
{
// Center is a leaf.
// Evaluate each corner to see if we should process it now.
......@@ -2826,7 +2829,7 @@ void vtkHyperTreeGrid::TraverseGridRecursively( vtkHyperTreeSuperCursor* superCu
}
// Mark this leaf as visited.
// Neighbor value is leafId for leaves, nodeId for nodes.
visited[superCursor->GetCursor(0)->GetLeafIndex()] = 1;
visited[superCursor->GetCursor( 0 )->GetLeafIndex()] = 1;
return;
}
......
......@@ -376,15 +376,15 @@ public:
// Description:
// Initialize a super cursor to point to one of the root trees
// in the grid. The super cursor points to a node in a tre and
// also keeps pointers to the nodes 26 neighbors.
// in the grid. The super cursor points to a node in a tree and
// also keeps pointers to the 26 neighbors of said node.
void InitializeSuperCursor(vtkHyperTreeSuperCursor* superCursor, int i, int j, int k);
// Description:
// Generate the table before calling InitializeSuperCursorChild.
void GenerateSuperCursorTraversalTable();
// Description:
// Initializa a cursor to point to a child of an existing super cursor.
// This will not work inplace.
// Initialize a cursor to point to a child of an existing super cursor.
// This will not work in place.
void InitializeSuperCursorChild(vtkHyperTreeSuperCursor* parent,
vtkHyperTreeSuperCursor* child,
int childIdx);
......@@ -503,20 +503,20 @@ private:
};
// Public structure filters use to move around the tree.
// Public structure filters used to move around the tree.
// The super cursor keeps neighbor cells so filters can
// easily access neighbor to leaves. The super cursor
// easily access neighbor to leaves.
// The super cursor is static. Methods in vtkHyperTreeGrid
// initialize and compute children for moving toward leaves.
// initialize and compute children for moving toward leaves.
class vtkHyperTreeSuperCursor
{
public:
public:
vtkHyperTreeLightWeightCursor Cursors[27];
int NumberOfCursors;
int MiddleCursorId;
double Origin[3];
double Size[3];
vtkHyperTreeLightWeightCursor* GetCursor(int idx) { return this->Cursors + this->MiddleCursorId + idx;}
vtkHyperTreeLightWeightCursor* GetCursor(int idx) { return this->Cursors + this->MiddleCursorId + idx; }
};
......
......@@ -33,13 +33,35 @@
int TestHyperTreeGrid( int argc, char* argv[] )
{
// Initialize return value of test
int testIntValue = 0;
// Dimension of hyper trees
int dim = 2;
//vtkNew<vtkHyperTreeGenerator> fractal;
//vtkNew<vtkHyperTreeGridFractalSource> fractal;
vtkHyperTreeGridFractalSource* fractal = vtkHyperTreeGridFractalSource::New();
fractal->SetMaximumLevel( 3 );
fractal->DualOn();
fractal->SetGridSize( 3, 4, 2 );
fractal->SetDimension( 3 );
if ( dim == 3 )
{
fractal->SetGridSize( 3, 4, 2 );
}
else if ( dim == 2 )
{
fractal->SetGridSize( 3, 4, 1 );
}
else if ( dim == 1 )
{
fractal->SetGridSize( 3, 1, 1 );
}
else
{
return 1;
}
fractal->SetDimension( dim );
fractal->SetAxisBranchFactor( 3 );
//vtkHyperTreeGrid* htGrid = fractal->NewHyperTreeGrid();
fractal->Update();
......@@ -80,15 +102,19 @@ int TestHyperTreeGrid( int argc, char* argv[] )
writer2->SetInputConnection( cut->GetOutputPort() );
writer2->Write();
cerr << "# HyperTreeGridAxisCut" << endl;
vtkNew<vtkHyperTreeGridAxisCut> axisCut;
axisCut->SetInputConnection( fractal->GetOutputPort() );
axisCut->SetPlaneNormalAxis( 2 );
axisCut->SetPlanePosition( .1 );
vtkNew<vtkPolyDataWriter> writer3;
writer3->SetFileName( "./hyperTreeGridAxisCut.vtk" );
writer3->SetInputConnection( axisCut->GetOutputPort() );
writer3->Write();
// Axis-aligned cut works only in 3D for now
if ( dim == 3 )
{
cerr << "# HyperTreeGridAxisCut" << endl;
vtkNew<vtkHyperTreeGridAxisCut> axisCut;
axisCut->SetInputConnection( fractal->GetOutputPort() );
axisCut->SetPlaneNormalAxis( 2 );
axisCut->SetPlanePosition( .1 );
vtkNew<vtkPolyDataWriter> writer3;
writer3->SetFileName( "./hyperTreeGridAxisCut.vtk" );
writer3->SetInputConnection( axisCut->GetOutputPort() );
writer3->Write();
}
vtkNew<vtkHyperTreeGridGeometry> geometry;
geometry->SetInputConnection( fractal->GetOutputPort() );
......@@ -139,5 +165,5 @@ int TestHyperTreeGrid( int argc, char* argv[] )
//htGrid->Delete();
fractal->Delete();
return 0;
return testIntValue;
}
......@@ -23,9 +23,8 @@ int TestHyperTreeGridGeometry( int argc, char* argv[] )
{
vtkNew<vtkHyperTreeGridFractalSource> fractal;
fractal->SetMaximumLevel( 3 );
// fractal->SetGridSize( 3, 4, 2 );
fractal->SetGridSize( 3, 2, 1 );
fractal->SetDimension( 2 );
fractal->SetGridSize( 3, 4, 2 );
fractal->SetDimension( 3 );
fractal->SetAxisBranchFactor( 3 );
vtkNew<vtkHyperTreeGridGeometry> geometry;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment