# StructuredGridOutline

VTKExamples/Cxx/StructuredGrid/StructuredGridOutline

### Description¶

Visualize the outline of a structured grid.

Other Languages

See (Java)

Question

### Code¶

StructuredGridOutline.cxx

#include <vtkSmartPointer.h>
#include <vtkStructuredGrid.h>
#include <vtkXMLStructuredGridWriter.h>
#include <vtkMath.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkStructuredGridOutlineFilter.h>

int main(int, char *[])
{
// Create a grid
vtkSmartPointer<vtkStructuredGrid> structuredGrid =
vtkSmartPointer<vtkStructuredGrid>::New();

vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
unsigned int numi = 2;
unsigned int numj = 3;
unsigned int numk = 2;

for(unsigned int k = 0; k < numk; k++)
{
for(unsigned int j = 0; j < numj; j++)
{
for(unsigned int i = 0; i < numi; i++)
{
points->InsertNextPoint(i, j, k);
}
}
}

//specify the dimensions of the grid
structuredGrid->SetDimensions(numi, numj, numk);
structuredGrid->SetPoints(points);

std::cout << "There are " << structuredGrid->GetNumberOfPoints() << " points." << std::endl;
std::cout << "There are " << structuredGrid->GetNumberOfCells() << " cells." << std::endl;

vtkSmartPointer<vtkStructuredGridOutlineFilter> outlineFilter =
vtkSmartPointer<vtkStructuredGridOutlineFilter>::New();
outlineFilter->SetInputData(structuredGrid);
outlineFilter->Update();

// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(outlineFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

// Visualize
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

//renderer->SetBackground(1,1,1); // Background color white

renderWindow->Render();
renderWindowInteractor->Start();

return EXIT_SUCCESS;
}


### CMakeLists.txt¶

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(StructuredGridOutline)

find_package(VTK COMPONENTS
vtkCommonCore
vtkCommonDataModel
vtkFiltersCore
vtkIOXML
vtkInteractionStyle
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingOpenGL2 QUIET)
if (NOT VTK_FOUND)
message("Skipping StructuredGridOutline: ${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(StructuredGridOutline MACOSX_BUNDLE StructuredGridOutline.cxx ) target_link_libraries(StructuredGridOutline PRIVATE${VTK_LIBRARIES})
else ()
# include all components
target_link_libraries(StructuredGridOutline PRIVATE ${VTK_LIBRARIES}) # vtk_module_autoinit is needed vtk_module_autoinit( TARGETS StructuredGridOutline MODULES${VTK_LIBRARIES}
)
endif ()


cd StructuredGridOutline/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:

./StructuredGridOutline


WINDOWS USERS

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