Actor2D
VTKExamples/Cxx/Images/Actor2D
Other Languages
See (Java)
Code¶
Actor2D.cxx
#include <vtkSmartPointer.h> #include <vtkCubeSource.h> #include <vtkPolyData.h> #include <vtkPoints.h> #include <vtkVertexGlyphFilter.h> #include <vtkRenderWindow.h> #include <vtkRenderer.h> #include <vtkRenderWindowInteractor.h> #include <vtkActor2D.h> #include <vtkPolyDataMapper2D.h> #include <vtkProperty2D.h> int main(int, char *[]) { vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); points->InsertNextPoint(10,10,0); points->InsertNextPoint(100,100,0); points->InsertNextPoint(200,200,0); vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New(); polydata->SetPoints(points); vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New(); glyphFilter->SetInputData(polydata); glyphFilter->Update(); vtkSmartPointer<vtkPolyDataMapper2D> mapper = vtkSmartPointer<vtkPolyDataMapper2D>::New(); mapper->SetInputConnection(glyphFilter->GetOutputPort()); mapper->Update(); vtkSmartPointer<vtkActor2D> actor = vtkSmartPointer<vtkActor2D>::New(); actor->SetMapper(mapper); // Create a renderer, render window, and interactor vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow); // Add the actor to the scene renderer->AddActor(actor); renderWindow->SetSize(300,300); actor->GetProperty()->SetColor(0,1,0); actor->GetProperty()->SetPointSize(3); // Render and interact renderWindow->Render(); renderWindowInteractor->Start(); return EXIT_SUCCESS; }
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(Actor2D) find_package(VTK COMPONENTS vtkCommonCore vtkCommonDataModel vtkFiltersGeneral vtkFiltersSources vtkInteractionStyle vtkRenderingCore vtkRenderingFreeType vtkRenderingOpenGL2 QUIET) if (NOT VTK_FOUND) message("Skipping Actor2D: ${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(Actor2D MACOSX_BUNDLE Actor2D.cxx ) target_link_libraries(Actor2D PRIVATE ${VTK_LIBRARIES}) else () # include all components add_executable(Actor2D MACOSX_BUNDLE Actor2D.cxx ) target_link_libraries(Actor2D PRIVATE ${VTK_LIBRARIES}) # vtk_module_autoinit is needed vtk_module_autoinit( TARGETS Actor2D MODULES ${VTK_LIBRARIES} ) endif ()
Download and Build Actor2D¶
Click here to download Actor2D and its CMakeLists.txt file. Once the tarball Actor2D.tar has been downloaded and extracted,
cd Actor2D/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:
./Actor2D
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.