In a very simple case, VTK window doesn’t show up?!.. Any clue why?
Here the sample:
>> cat vtkTest.cpp
// STL.
#include <iostream> // cout
#include <stdexcept> // exception
// VTK.
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkPointData.h>
#include <vtkUnsignedCharArray.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballActor.h>
int run() {
// Create data to render.
vtkNew<vtkPolyData> polyData;
// Create points.
vtkNew<vtkPoints> points;
points->InsertNextPoint(0.0, 0.0, 0.0);
points->InsertNextPoint(1.0, 0.0, 0.0);
points->InsertNextPoint(0.0, 1.0, 0.0);
points->InsertNextPoint(0.0, 0.0, 1.0);
polyData->SetPoints(points);
// Setup colors.
vtkNew<vtkUnsignedCharArray> colors;
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
unsigned char black[3] = {0, 0, 0};
unsigned char red[3] = {255, 0, 0};
unsigned char green[3] = {0, 255, 0};
unsigned char blue[3] = {0, 0, 255};
colors->InsertNextTypedTuple(black);
colors->InsertNextTypedTuple(red);
colors->InsertNextTypedTuple(green);
colors->InsertNextTypedTuple(blue);
vtkPointData * pointData = polyData->GetPointData();
if (pointData) {
pointData->SetScalars(colors);
}
// Setup filter.
vtkNew<vtkVertexGlyphFilter> vertexFilter;
vertexFilter->SetInputData(polyData);
// Setup mapper.
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(vertexFilter->GetOutputPort());
// Setup actor.
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
vtkProperty * prop = actor->GetProperty();
if (prop) {
prop->SetPointSize(10);
}
// Setup renderer.
vtkNew<vtkRenderer> renderer;
renderer->AddActor(actor);
renderer->SetBackground(1., 1., 1.);
// Setup window.
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("vtkTest");
// Setup interactor.
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
vtkNew<vtkInteractorStyleTrackballActor> style;
renderWindowInteractor->SetInteractorStyle(style);
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
// Render scene.
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}
int main() {
int rc = 1;
try {
rc = run();
}
catch(std::exception & e) {
std::cerr << "Error - " << e.what() << std::endl;
rc = 1;
}
std::cout << "Main thread: exiting..." << std::endl;
return rc;
}
>> cat CMakeLists.txt
cmake_minimum_required (VERSION 3.20)
# Define project
project(vtkTest C CXX)
# Get VTK targets to compile / link with.
find_package(VTK
COMPONENTS
CommonCore
CommonDataModel
FiltersGeneral
InteractionStyle
RenderingCore
REQUIRED)
message(STATUS "VTK VERSION=${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}")
# Define binary
add_executable(vtkTest vtkTest.cpp)
vtk_module_autoinit(TARGETS vtkTest MODULES "${VTK_LIBRARIES}")
target_include_directories(vtkTest PRIVATE "${VTK_INCLUDE_DIRS}")
target_link_libraries(vtkTest PRIVATE "${VTK_LIBRARIES}")
Now, build seems OK:
>> cd build/
>> cmake ..
-- VTK VERSION=9.1
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/vtkTest/build
>> make VERBOSE=1
[ 50%] Building CXX object CMakeFiles/vtkTest.dir/vtkTest.cpp.o
/usr/bin/c++ -Dkiss_fft_scalar=double -DvtkRenderingCore_AUTOINIT_INCLUDE=\"/tmp/vtkTest/build/CMakeFiles/vtkModuleAutoInit_9b5895f873bcba09752b0c704bf968d6.h\" -I/tmp/vtkTest -isystem /usr/include/vtk-9.1 -MD -MT CMakeFiles/vtkTest.dir/vtkTest.cpp.o -MF CMakeFiles/vtkTest.dir/vtkTest.cpp.o.d -o CMakeFiles/vtkTest.dir/vtkTest.cpp.o -c /tmp/vtkTest/vtkTest.cpp
[100%] Linking CXX executable vtkTest
/usr/bin/cmake -E cmake_link_script CMakeFiles/vtkTest.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/vtkTest.dir/vtkTest.cpp.o -o vtkTest /usr/lib/x86_64-linux-gnu/libvtkInteractionStyle-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkRenderingCore-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkFiltersGeneral-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkFiltersCore-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonExecutionModel-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonDataModel-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonTransforms-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonMisc-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonMath-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkkissfft-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonCore-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libtbb.so.12.8 /usr/lib/x86_64-linux-gnu/libvtksys-9.1.so.9.1.0 -ldl
… But, the application doesn’t open any VTK window and returns?!..
>> ./vtkTest
Main thread: exiting...
This is happening on debian/testing with apt-install vtk:
>> cmake --debug-find ..
...
find_package considered the following locations for VTK's Config module:
The file was found at
/usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake
>> apt-file search /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake
libvtk9-dev: /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake
>> dpkg -l libvtk9-dev
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-=========================-============-=================================
ii libvtk9-dev 9.1.0+really9.1.0+dfsg2-5 amd64 VTK header files
Any clue on why the window doesn’t pop up?!..