# HyperTreeGridSource

VTKExamples/Cxx/HyperTreeGrid/HyperTreeGridSource

Other Languages

See (Python), (Java)

### Code

HyperTreeGridSource.cxx

    #include <vtkHyperTreeGridSource.h>

    #include <vtkShrinkFilter.h>

    #include <vtkActor.h>
    #include <vtkCamera.h>
    #include <vtkProperty.h>
    #include <vtkDataSetMapper.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkRenderer.h>
    #include <vtkNamedColors.h>

    int main( int, char*[] )
    {
      // Create hyper tree grid source
      vtkSmartPointer<vtkHyperTreeGridSource> source =
        vtkSmartPointer<vtkHyperTreeGridSource>::New();
      source->SetMaximumLevel( 6 );
      source->SetGridSize( 3, 3, 2 );
      source->SetGridScale( 1.5, 1., .7 );
      source->SetDimension( 3 );
      source->SetBranchFactor( 4 );
      source->SetDescriptor( "RRR .R. .RR ..R ..R .R.|R.......................... ........................... ........................... .............R............. ....RR.RR........R......... .....RRRR.....R.RR......... ........................... ........................... ...........................|........................... ........................... ........................... ...RR.RR.......RR.......... ........................... RR......................... ........................... ........................... ........................... ........................... ........................... ........................... ........................... ............RRR............|........................... ........................... .......RR.................. ........................... ........................... ........................... ........................... ........................... ........................... ........................... ...........................|........................... ..........................." );
      source->Update();

      vtkSmartPointer<vtkShrinkFilter> shrink =
        vtkSmartPointer<vtkShrinkFilter>::New();
      shrink->SetInputConnection(source->GetOutputPort());
      shrink->SetShrinkFactor( .8 );

      vtkSmartPointer<vtkDataSetMapper> mapper =
        vtkSmartPointer<vtkDataSetMapper>::New();
      mapper->SetInputConnection(shrink->GetOutputPort());
      mapper->ScalarVisibilityOff();

      vtkSmartPointer<vtkNamedColors> colors =
        vtkSmartPointer<vtkNamedColors>::New();

      vtkSmartPointer<vtkActor> actor =
        vtkSmartPointer<vtkActor>::New();
      actor->SetMapper(mapper);
      actor->GetProperty()->SetDiffuseColor(colors->GetColor3d("Burlywood").GetData());

    // Create the RenderWindow, Renderer and both Actors
    //
      vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
      renderWindow->AddRenderer(renderer);
      vtkSmartPointer<vtkRenderWindowInteractor> interactor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      interactor->SetRenderWindow(renderWindow);

      renderer->SetBackground(colors->GetColor3d("SlateGray").GetData());
      renderer->AddActor(actor);
      renderer->ResetCamera();
      renderer->GetActiveCamera()->Azimuth(150);
      renderer->GetActiveCamera()->Elevation(30);
      renderer->ResetCameraClippingRange();

      renderWindow->SetSize(640, 480);
      interactor->Start();
      return EXIT_SUCCESS;
      }

### CMakeLists.txt

    cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

    project(HyperTreeGridSource)

    find_package(VTK COMPONENTS
      vtkCommonColor
      vtkFiltersGeneral
      vtkFiltersSources
      vtkInteractionStyle
      vtkRenderingCore
      vtkRenderingFreeType
      vtkRenderingOpenGL2 QUIET)
    if (NOT VTK_FOUND)
      message("Skipping HyperTreeGridSource: ${VTK_NOT_FOUND_MESSAGE}")
      return ()
    endif()
    message (STATUS "VTK_VERSION: ${VTK_VERSION}")
    if (VTK_VERSION VERSION_LESS "8.90.0")
      # old system
      include(${VTK_USE_FILE})
      add_executable(HyperTreeGridSource MACOSX_BUNDLE HyperTreeGridSource.cxx )
      target_link_libraries(HyperTreeGridSource PRIVATE ${VTK_LIBRARIES})
    else ()
      # include all components
      add_executable(HyperTreeGridSource MACOSX_BUNDLE HyperTreeGridSource.cxx )
      target_link_libraries(HyperTreeGridSource PRIVATE ${VTK_LIBRARIES})
      # vtk_module_autoinit is needed
      vtk_module_autoinit(
        TARGETS HyperTreeGridSource
        MODULES ${VTK_LIBRARIES}
        )
    endif ()

### Download and Build HyperTreeGridSource

Click here to download HyperTreeGridSource and its CMakeLists.txt file. Once the tarball HyperTreeGridSource.tar has been downloaded and extracted,

    cd HyperTreeGridSource/build

If VTK is installed:

    cmake ..

If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:

    cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

    make

and run it:

    ./HyperTreeGridSource

WINDOWS USERS

Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.