The article shows how to create a simple vtk render window project. We need cmake and the visualization toolkit installed. This example uses C plus plus programming language to create and show a cone in the 3D world. CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

project(mytest)

find_package( VTK REQUIRED )
include( ${VTK_USE_FILE} )

add_executable(${PROJECT_NAME} "main.cpp")

target_link_libraries( ${PROJECT_NAME} ${VTK_LIBRARIES} )

main.cpp

#include <iostream>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>

#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();

using namespace std;

int main()
{
    vtkSPtrNew( cone, vtkConeSource );
    vtkSPtrNew( mapper, vtkPolyDataMapper );
    mapper->SetInputConnection( cone->GetOutputPort() );

    vtkSPtrNew( actor, vtkActor );
    actor->SetMapper( mapper );

    vtkSPtrNew( renderer, vtkRenderer );
    renderer->AddActor(actor);
    renderer->SetBackground( 0, 0, 0 );

    vtkSPtrNew( renderWindow, vtkRenderWindow );
    renderWindow->AddRenderer( renderer );

    vtkSPtrNew( renderWindowInteractor, vtkRenderWindowInteractor );
    renderWindowInteractor->SetRenderWindow( renderWindow );

    renderer->ResetCamera();
    renderWindow->Render();
    renderWindowInteractor->Start();
    return 0;
}



 

 


2 Comments

VTK – A Simple Example Written In Python Script – theArcticOcean · 2019年7月31日 at am9:55

[…] post is similar to 【VTK】A SIMPLE EXAMPLE WRITTEN IN C++ We use python script to do the same thing: create and show a cone in 3D world with the […]

VTK – A Simple Example Written In Tcl Script – theArcticOcean · 2019年7月31日 at am9:55

[…] post is similar to 【VTK】A SIMPLE EXAMPLE WRITTEN IN C++ We use TCL script to do the same thing: create and show cone in the 3D world with the […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page