Commit 8ba9a63d authored by Philippe Pébay's avatar Philippe Pébay Committed by Code Review
Browse files

Merge topic 'ActivateRegressionTestsForHyperTrees' into master

17252695 Fixed array sizing error
44e7c97c Documentation clean up
251243e2 Removed this non-test, replaced it with an Example (HTGridDemonstrator)
8bc399f0 A program to illustrate the use of various hyper tree filters.
769b677f Giving credits for regression tests and hyper tree generator
17b47ce1 Header clean up
49f40cdd CMake list error
ae51d6b2 Removing the old hyper tree generator which was bypassing the pipeline
18951db8 Documentation
1860671f Allow for binary or ternary subdivisions
3f926f87 Allow for variable levels of recursion
b22181b3 Use smart pointers for testing
fbbc6c97 Make sure that global hyper tree test has consistent input
7393abaa Renaming tests for the sake of clarity
bfa34cee Renamed test and changed it to make it better (2D+binary)
c1a43716 Activate hyper tree grid axis cut
97bd43ab Active hyper tree grid geometry test
parents 80de64c0 17252695
......@@ -40,12 +40,6 @@
#include <assert.h>
// Issues:
// 1: Order of leaf id's due to refining nodes. Reader could order leaves base on its own needs.
// 2: Default cell interface creates connectivity arrays (effectively unstructured grid) to support random
// access to cells. A serial iterator would be much more efficient.
vtkInformationKeyMacro(vtkHyperTreeGrid, LEVELS, Integer);
vtkInformationKeyMacro(vtkHyperTreeGrid, DIMENSION, Integer);
vtkInformationKeyRestrictedMacro(vtkHyperTreeGrid, SIZES, DoubleVector, 3 );
......@@ -729,7 +723,7 @@ public:
// Restore the initial state: only one node and one leaf: the root.
virtual void Initialize()
{
// Law: I believe that leaves are implicit (not node objects)
// NB: Leaves are implicit (not node objects)
// so why initialize a root node with one leaf?
// Does the root always have one child?
this->Nodes.resize(1);
......@@ -737,7 +731,7 @@ public:
int i=0;
while (i < N)
{
// Law: I assume that the root is a special node with only one child.
// It is assumed that the root is a special node with only one child.
// The other children flags are irrelavent, but set them as nodes for no good reason.
this->Nodes[0].SetLeafFlag(i, i==0 ); // First child is a leaf
this->Nodes[0].SetChild(i,0 );
......@@ -790,8 +784,7 @@ public:
//---------------------------------------------------------------------------
// Description:
// Public only for the vtkCompactHyperTreeCursor.
// Law:
// cursor (index ) appears to be different between nodes and leaves.
// NB: Cursor (index ) appears to be different between nodes and leaves.
// Different arrays => overlapping indexes.
// I am changing the name for clarity.
// This really returns the nodeIdx of the leafs parent.
......@@ -830,10 +823,10 @@ public:
// the leaf becomes a node and is not anymore a leaf.
cursor->SetIsLeaf( 0 ); // let the cursor knows about that change.
size_t nodeIndex=this->Nodes.size();
// Law: I believe that the node array does not include leaves (which are implicit).
// Bad interface "SetCursor" I would rather SetIndex.
// NB: Bad interface "SetCursor"; should rather SetIndex.
cursor->SetCursor(static_cast<int>( nodeIndex ) );
// Law: Add a node
// Nodes get constructed with leaf flags set to 1.
this->Nodes.resize( nodeIndex + 1 );
int parentNodeIdx = this->LeafParent[leafIndex];
......@@ -841,14 +834,15 @@ public:
// Change the parent: it has one less child as a leaf
vtkCompactHyperTreeNode<N> *parent=&( this->Nodes[parentNodeIdx] );
// Law: New nodes index in parents children array.
// New nodes index in parents children array.
int i = cursor->GetChildIndex();
assert( "check matching_child" && parent->GetChild( i ) == leafIndex );
parent->SetLeafFlag(i, false);
parent->SetChild(i,static_cast<int>( nodeIndex ) );
// The first new child
// Law: Recycle the leaf index we are deleting because it became a node.
// Recycle the leaf index we are deleting because it became a node.
// This avoids messy leaf parent array issues.
this->Nodes[nodeIndex].SetChild( 0, leafIndex );
this->LeafParent[leafIndex]=static_cast<int>( nodeIndex );
......@@ -884,7 +878,7 @@ public:
}
//---------------------------------------------------------------------------
// Law: Bad interface: This is really GetNumberOfLeaves.
// NB: Bad interface: This is really GetNumberOfLeaves.
int GetLeafParentSize()
{
return static_cast<int>( this->LeafParent.size() );
......@@ -972,10 +966,11 @@ protected:
this->Dimension = 3;
}
// Law: The root.
// The root.
this->Nodes.resize(1);
this->Nodes[0].SetParent( 0 );
// Law: Nodes default to have all children leaf flags equal true.
// Nodes default to have all children leaf flags equal true.
int i=0;
while( i < N )
{
......
......@@ -14,6 +14,7 @@
=========================================================================*/
// .NAME vtkHyperTreeGrid - A dataset structured as a tree where each node has
// exactly either 2^n or 3^n children.
//
// .SECTION Description
// An hypertree is a dataset where each node has either exactly 2^n or 3^n children
// or no child at all if the node is a leaf. `n' is the dimension of the
......@@ -109,10 +110,10 @@
// .SECTION Caveats
// It is not a spatial search object. If you are looking for this kind of
// octree see vtkCellLocator instead.
//
// .SECTION Thanks
// This class was written by Charles Law and Philippe Pebay, Kitware 2012
// This test was written by Philippe Pebay and Charles Law, Kitware 2012
// This work was supported in part by Commissariat a l'Energie Atomique (CEA/DIF)
#ifndef __vtkHyperTreeGrid_h
#define __vtkHyperTreeGrid_h
......
......@@ -21,7 +21,6 @@
#include "vtkHyperTreeGrid.h"
#include "vtkStreamingDemandDrivenPipeline.h"
//----------------------------------------------------------------------------
vtkHyperTreeGridAlgorithm::vtkHyperTreeGridAlgorithm()
{
......
......@@ -14,9 +14,9 @@
=========================================================================*/
// .NAME vtkHyperTreeGridAlgorithm - Superclass for algorithms that produce
// a hyper tree grid as output
//
// .SECTION Description
// vtkTreeGridAlgorithm is a convenience class to make writing algorithms
// vtkHyperTreeGridAlgorithm is a convenience class to make writing algorithms
// easier. It is also designed to help transition old algorithms to the new
// pipeline architecture. There are some assumptions and defaults made by this
// class you should be aware of. This class defaults such that your filter
......@@ -25,9 +25,10 @@
// constructor for the default. This class also provides a FillInputPortInfo
// method that by default says that all inputs will be HyperTreeGrid. If that
// isn't the case then please override this method in your subclass.
//
// .SECTION Thanks
// This class was written by Philippe Pebay, Kitware SAS 2012
// This test was written by Philippe Pebay and Charles Law, Kitware 2012
// This work was supported in part by Commissariat a l'Energie Atomique (CEA/DIF)
#ifndef __vtkHyperTreeGridAlgorithm_h
#define __vtkHyperTreeGridAlgorithm_h
......
cmake_minimum_required(VERSION 2.8)
project(HyperTreeGridDemonstrator)
if(NOT VTK_BINARY_DIR)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
endif(NOT VTK_BINARY_DIR)
link_directories(${VTK_LIBRARY_DIRS})
# Add example showing use use of vtkHyperTreeGrid along with various filters
add_executable(HyperTreeGridDemonstrator HyperTreeGridDemonstrator.cxx)
target_link_libraries(HyperTreeGridDemonstrator vtkCommonCore vtkCommonSystem vtkCommonDataModel vtkCommonExecutionModel vtkRenderingOpenGL vtkInteractionStyle vtkIOGeometry vtkFiltersCore vtkFiltersParallel vtkFiltersSources vtkFiltersHyperTree)
......@@ -4,8 +4,26 @@ Copyright (c) Kitware Inc.
All rights reserved.
=========================================================================*/
// .SECTION Description
// This program illustrates the use of various filters acting upon hyper
// tree grid data sets. It generates output files in VTK format.
//
// .SECTION Usage
// --branch-factor opt Branching factor of hyper tree grid
// --dimension opt Dimension of hyper tree grid
// --grid-size-X opt Size of hyper tree grid in X direction
// --grid-size-Y opt Size of hyper tree grid in Y direction
// --grid-size-Z opt Size of hyper tree grid in Z direction
// --max-level opt Maximum depth of hyper tree grid
// --skip-Axis-Cut Skip axis cut filter
// --skip-Contour Skip contour filter
// --skip-Cut Skip cut filter
// --skip-Geometry Skip geometry filter
// --skip-Shrink Skip shrink filter
//
// .SECTION Thanks
// This test was written by Charles Law and Philippe Pebay, Kitware 2012
// This example was written by Philippe Pebay and Charles Law, Kitware 2012
// This work was supported in part by Commissariat a l'Energie Atomique (CEA/DIF)
#include "vtkHyperTreeGrid.h"
#include "vtkHyperTreeGridAxisCut.h"
......@@ -23,14 +41,15 @@ All rights reserved.
#include "vtkShrinkFilter.h"
#include "vtkUnstructuredGrid.h"
#include "vtkUnstructuredGridWriter.h"
#include "vtkXMLUnstructuredGridWriter.h"
#include "vtksys/CommandLineArguments.hxx"
int TestHyperTreeGrid( int argc, char* argv[] )
int main( int argc, char* argv[] )
{
// Default parameters and options
int dim = 3;
int branch = 3;
int max = 3;
int nX = 3;
int nY = 4;
int nZ = 2;
......@@ -46,41 +65,49 @@ int TestHyperTreeGrid( int argc, char* argv[] )
clArgs.StoreUnusedArguments( false );
// Parse command line parameters and options
clArgs.AddArgument("--dimension",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&dim, "Dimension of hyper tree grid");
clArgs.AddArgument( "--dimension",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&dim, "Dimension of hyper tree grid" );
clArgs.AddArgument("--grid-size-X",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&nX, "Size of hyper tree grid in X direction");
clArgs.AddArgument( "--branch-factor",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&branch, "Branching factor of hyper tree grid" );
clArgs.AddArgument("--grid-size-Y",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&nY, "Size of hyper tree grid in Y direction");
clArgs.AddArgument( "--max-level",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&max, "Maximum depth of hyper tree grid" );
clArgs.AddArgument("--grid-size-Z",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&nZ, "Size of hyper tree grid in Z direction");
clArgs.AddArgument( "--grid-size-X",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&nX, "Size of hyper tree grid in X direction" );
clArgs.AddArgument("--skip-Axis-Cut",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipAxisCut, "Skip axis cut filter");
clArgs.AddArgument( "--grid-size-Y",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&nY, "Size of hyper tree grid in Y direction" );
clArgs.AddArgument("--skip-Contour",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipAxisCut, "Skip contour filter");
clArgs.AddArgument( "--grid-size-Z",
vtksys::CommandLineArguments::SPACE_ARGUMENT,
&nZ, "Size of hyper tree grid in Z direction" );
clArgs.AddArgument("--skip-Cut",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipCut, "Skip cut filter");
clArgs.AddArgument( "--skip-Axis-Cut",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipAxisCut, "Skip axis cut filter" );
clArgs.AddArgument("--skip-Geometry",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipGeometry, "Skip geometry filter");
clArgs.AddArgument( "--skip-Contour",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipAxisCut, "Skip contour filter" );
clArgs.AddArgument("--skip-Shrink",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipShrink, "Skip shrink filter");
clArgs.AddArgument( "--skip-Cut",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipCut, "Skip cut filter" );
clArgs.AddArgument( "--skip-Geometry",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipGeometry, "Skip geometry filter" );
clArgs.AddArgument( "--skip-Shrink",
vtksys::CommandLineArguments::NO_ARGUMENT,
&skipShrink, "Skip shrink filter" );
// If incorrect arguments were provided, provide some help and terminate in error.
if ( ! clArgs.Parse() )
......@@ -90,31 +117,67 @@ int TestHyperTreeGrid( int argc, char* argv[] )
<< "\n";
}
// Initialize return value of test
int testIntValue = 0;
// Create hyper tree grid source
vtkHyperTreeGridSource* fractal = vtkHyperTreeGridSource::New();
fractal->SetMaximumLevel( 3 );
fractal->DualOn();
if ( dim == 3 )
// Ensure that parsed dimensionality makes sense
if ( dim > 3 )
{
fractal->SetGridSize( nX, nY, nZ );
dim = 3;
}
else if ( dim == 2 )
else if ( dim < 1 )
{
fractal->SetGridSize( nX, nY, 1 );
dim = 1;
}
else if ( dim == 1 )
// Ensure that parsed branch factor makes sense
if ( branch > 3 )
{
fractal->SetGridSize( nX, 1, 1 );
branch = 3;
}
else
else if ( branch < 2 )
{
return 1;
branch = 2;
}
// Ensure that parsed maximum level makes sense
if ( max < 1 )
{
max = 1;
}
// Ensure that parsed grid sizes make sense
if ( nX < 1 )
{
nX = 1;
}
if ( nY < 1 )
{
nY = 1;
}
if ( nZ < 1 )
{
nZ = 1;
}
// Ensure that parsed grid sizes are consistent with dimensionality
if ( dim < 3 )
{
nZ = 1;
if ( dim < 2 )
{
nY = 1;
}
}
// Create hyper tree grid source
vtkNew<vtkHyperTreeGridSource> fractal;
fractal->SetMaximumLevel( max );
fractal->DualOn();
if ( dim == 3 )
{
fractal->SetGridSize( nX, nY, nZ );
}
fractal->SetGridSize( nX, nY, nZ );
fractal->SetDimension( dim );
fractal->SetAxisBranchFactor( 3 );
fractal->SetAxisBranchFactor( branch );
fractal->Update();
vtkHyperTreeGrid* htGrid = fractal->GetOutput();
......@@ -190,8 +253,5 @@ int TestHyperTreeGrid( int argc, char* argv[] )
writer3->Write();
}
// Clean up
fractal->Delete();
return testIntValue;
return 0;
}
......@@ -11,7 +11,6 @@ set(Module_SRCS
vtkHyperOctreeSampleFunction.cxx
vtkHyperOctreeSurfaceFilter.cxx
vtkHyperOctreeToUniformGridFilter.cxx
vtkHyperTreeGenerator.cxx
)
vtk_module_library(vtkFiltersHyperTree ${Module_SRCS})
create_test_sourcelist(Tests ${vtk-module}CxxTests.cxx
TestBinaryHyperTreeGrid.cxx
TestClipHyperOctree.cxx
TestHyperOctreeContourFilter.cxx
TestHyperOctreeCutter.cxx
TestHyperOctreeDual.cxx
TestHyperOctreeSurfaceFilter.cxx
TestHyperOctreeToUniformGrid.cxx
TestHyperTreeGrid.cxx
TestHyperTreeGridAxisCut.cxx
TestHyperTreeGridGeometry.cxx
TestHyperTreeGridTernary3DAxisCut.cxx
TestHyperTreeGridTernary3DGeometry.cxx
TestHyperTreeGridBinary2D.cxx
EXTRA_INCLUDE vtkTestDriver.h
)
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestQuadRotationalExtrusionMultiBlock.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .SECTION Thanks
// This test was written by Philippe Pebay, Kitware SAS 2012
#include "vtksys/CommandLineArguments.hxx"
#include "vtksys/Directory.hxx"
#include "vtksys/SystemTools.hxx"
#include "vtksys/Glob.hxx"
#include <vtksys/Process.h>
#include <string>
#include "vtkHyperTreeGrid.h"
#include "vtkHyperTreeGenerator.h"
#include "vtkContourFilter.h"
#include "vtkCutter.h"
#include "vtkDataSetMapper.h"
#include "vtkGeometryFilter.h"
#include "vtkNew.h"
#include "vtkPlane.h"
#include "vtkShrinkFilter.h"
#include "vtkPolyDataWriter.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkUnstructuredGridWriter.h"
#include "vtkXMLUnstructuredGridWriter.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDataSetWriter.h"
int TestBinaryHyperTreeGrid(int argc, char* argv[])
{
vtkNew<vtkHyperTreeGenerator> fractal;
fractal->SetMaximumLevel( 4 );
fractal->DualOn();
fractal->SetDimension( 3 );
fractal->SetAxisBranchFactor( 2 );
vtkHyperTreeGrid* tree = fractal->NewHyperTreeGrid();
vtkNew<vtkCutter> cut;
vtkNew<vtkPlane> plane;
plane->SetOrigin(0.5, 0.5, 0.3333333);
plane->SetNormal(0,0,1);
cut->SetInputData(tree);
cut->SetCutFunction(plane.GetPointer());
vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
writer->SetFileName("./binaryHyperTreeCut.vtk");
writer->SetInputConnection(cut->GetOutputPort());
writer->Write();
writer->Delete();
vtkNew<vtkContourFilter> contour;
contour->SetInputData( tree );
contour->SetNumberOfContours( 2 );
contour->SetValue( 0, 1.5 );
contour->SetValue( 1, 2.5 );
contour->SetInputArrayToProcess(
0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS,"Test");
vtkPolyDataWriter* writer2 = vtkPolyDataWriter::New();
writer2->SetFileName("./binaryHyperTreeContour.vtk");
writer2->SetInputConnection(contour->GetOutputPort());
writer2->Write();
writer2->Delete();
vtkNew<vtkShrinkFilter> shrink;
shrink->SetInputData(tree);
shrink->SetShrinkFactor( .8 );
vtkUnstructuredGridWriter* writer3 = vtkUnstructuredGridWriter::New();
writer3->SetFileName("./binaryHyperTreeShrink.vtk");
writer3->SetInputConnection(shrink->GetOutputPort());
writer3->Write();
writer3->Delete();
vtkNew<vtkDataSetMapper> treeMapper;
treeMapper->SetInputConnection( shrink->GetOutputPort() );
vtkNew<vtkActor> treeActor;
treeActor->SetMapper( treeMapper.GetPointer() );
// Create a renderer, add actors to it
vtkNew<vtkRenderer> ren1;
ren1->AddActor( treeActor.GetPointer() );
ren1->SetBackground( 1., 1., 1. );
// Create a renderWindow
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer( ren1.GetPointer() );
renWin->SetSize( 300, 300 );
renWin->SetMultiSamples( 0 );
// Create interactor
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow( renWin.GetPointer() );
// Render and test
renWin->Render();
int retVal = vtkRegressionTestImage( renWin.GetPointer() );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
tree->Delete();
return 0;
}
/*=========================================================================
Copyright (c) Kitware Inc.
All rights reserved.
=========================================================================*/
// .SECTION Thanks
// This test was written by Philippe Pebay and Charles Law, Kitware 2012
// This work was supported in part by Commissariat a l'Energie Atomique (CEA/DIF)
#include "vtkHyperTreeGridGeometry.h"
#include "vtkHyperTreeGridSource.h"
#include "vtkCamera.h"
#include "vtkCellData.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
int TestHyperTreeGridBinary2D( int argc, char* argv[] )
{
vtkNew<vtkHyperTreeGridSource> fractal;
fractal->SetMaximumLevel( 3 );
fractal->SetGridSize( 4, 3, 1 );
fractal->SetDimension( 2 );
fractal->SetAxisBranchFactor( 2 );
vtkNew<vtkHyperTreeGridGeometry> geometry;
geometry->SetInputConnection( fractal->GetOutputPort() );
geometry->Update();
vtkPolyData* pd = geometry->GetOutput();
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection( geometry->GetOutputPort() );
mapper->SetScalarRange( pd->GetCellData()->GetScalars()->GetRange() );
vtkNew<vtkActor> actor;
actor->SetMapper( mapper.GetPointer() );
// Create camera
double bd[6];
pd->GetBounds( bd );
vtkNew<vtkCamera> camera;
camera->SetClippingRange( 1., 100. );
camera->SetFocalPoint( pd->GetCenter() );
camera->SetPosition( .5 * bd[1], .5 * bd[3], 13 );
// Create a renderer, add actors to it
vtkNew<vtkRenderer> renderer;
renderer->SetActiveCamera( camera.GetPointer() );
renderer->SetBackground( 1., 1., 1. );
renderer->AddActor( actor.GetPointer() );
// Create a renderWindow
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer( renderer.GetPointer() );
renWin->SetSize( 300, 300 );
renWin->SetMultiSamples( 0 );
// Create interactor
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow( renWin.GetPointer() );
// Render and test
renWin->Render();
int retVal = vtkRegressionTestImage(