NOVCAGraph
Description¶

-
This example shows how to construct a graph to visualize it in ParaView/VisIt using the VTK output file testVertex.vtu.
-
Contributed by Sanjaya Gajurel, Case Western Reserve University
Other languages
See (Python)
Question
If you have a simple question about this example contact us at VTKExProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum
Code¶
NOVCAGraph.cxx
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkPolyLine.h>
#include <vtkTriangle.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLUnstructuredGridWriter.h>
#include <vtkSmartPointer.h>
int main ( int, char *[] )
{
// Create 8 Vertices.
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
for ( unsigned int i = 0; i < 2; ++i )
for ( unsigned int j = 0; j < 4; ++j )
points->InsertNextPoint( i, j, 0);
//Create Edges
vtkSmartPointer<vtkPolyLine> line =
vtkSmartPointer<vtkPolyLine>::New();
line->GetPointIds()->SetNumberOfIds(8);
for ( unsigned int i = 0; i < 8; ++i )
line->GetPointIds()->SetId(i,i);
vtkSmartPointer<vtkCellArray> cellArray =
vtkSmartPointer<vtkCellArray>::New();
cellArray->InsertNextCell(line);
// Create a Graph with Vertices and Edges.
vtkSmartPointer<vtkUnstructuredGrid> grid =
vtkSmartPointer<vtkUnstructuredGrid>::New();
grid->SetPoints(points);
grid->SetCells(VTK_POLY_LINE,cellArray);
// Write the file
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName("testVertex.vtu");
writer->SetInputData(grid);
writer->Write();
return EXIT_SUCCESS;
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(NOVCAGraph)
find_package(VTK COMPONENTS
vtkvtkCommonCore
vtkvtkCommonDataModel
vtkvtkIOXML QUIET)
if (NOT VTK_FOUND)
message("Skipping NOVCAGraph: ${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(NOVCAGraph MACOSX_BUNDLE NOVCAGraph.cxx )
target_link_libraries(NOVCAGraph PRIVATE ${VTK_LIBRARIES})
else ()
# include all components
add_executable(NOVCAGraph MACOSX_BUNDLE NOVCAGraph.cxx )
target_link_libraries(NOVCAGraph PRIVATE ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS NOVCAGraph
MODULES ${VTK_LIBRARIES}
)
endif ()
Download and Build NOVCAGraph¶
Click here to download NOVCAGraph and its CMakeLists.txt file. Once the tarball NOVCAGraph.tar has been downloaded and extracted,
cd NOVCAGraph/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:
./NOVCAGraph
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.