From b8886676fee9fc0484d8b9def91cb37dd79adebe Mon Sep 17 00:00:00 2001 From: ccolin Date: Wed, 23 Feb 2022 14:00:48 +0100 Subject: [PATCH] add build option to disable the viewer and use the system vtk --- CMakeLists.txt | 52 +++++++++++++++++++++++++++------------ src/main.cc | 66 ++++++++++++++++++++++++++------------------------ 2 files changed, 71 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f34243f..9ae03ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,37 @@ cmake_minimum_required(VERSION 3.15) project(pfe) -add_subdirectory(external/vtk) +set(VTK_COMPONENTS + VTK::CommonCore + VTK::IOCore + VTK::FiltersCore + VTK::CommonColor + VTK::CommonDataModel + VTK::IOLegacy + VTK::IOXML) +set(ENABLE_VIEWER OFF CACHE BOOL "Enable the 3D viewer, depends on Qt.") +if(ENABLE_VIEWER) + list(APPEND VTK_COMPONENTS + VTK::RenderingCore + VTK::ViewsCore + VTK::GUISupportQt + VTK::RenderingQt + VTK::ViewsQt + VTK::RenderingVolume + VTK::RenderingVolumeOpenGL2) +endif() + +set(USE_SYSTEM_VTK NO CACHE BOOL + "Use the version of vtk installed in the system instead of downloading and compiling it ourselves.") +if(USE_SYSTEM_VTK) + list(TRANSFORM VTK_COMPONENTS REPLACE "VTK::" "" + OUTPUT_VARIABLE VTK_PACKAGE_COMPONENTS) + message("VTK_COMPONENTS: ${VTK_COMPONENTS}") + message("VTK_PACKAGE_COMPONENTS: ${VTK_PACKAGE_COMPONENTS}") + find_package(VTK COMPONENTS ${VTK_PACKAGE_COMPONENTS}) +else() + add_subdirectory(external/vtk) +endif() add_executable(pfe) @@ -19,18 +49,8 @@ target_sources(pfe PRIVATE src/external_points_filter.cc src/external_points_filter.h) -target_link_libraries(pfe PRIVATE - VTK::CommonCore - VTK::ViewsCore - VTK::RenderingCore - VTK::IOCore - VTK::FiltersCore - VTK::CommonColor - VTK::GUISupportQt - VTK::RenderingQt - VTK::ViewsQt - VTK::RenderingVolume - VTK::CommonDataModel - VTK::IOLegacy - VTK::IOXML - VTK::RenderingVolumeOpenGL2) +target_link_libraries(pfe PRIVATE ${VTK_COMPONENTS}) + +if(ENABLE_VIEWER) + target_compile_definitions(pfe PRIVATE ENABLE_VIEWER) +endif() diff --git a/src/main.cc b/src/main.cc index 857e8d0..b2f7f35 100644 --- a/src/main.cc +++ b/src/main.cc @@ -5,8 +5,12 @@ #include #include -#include +#include +#include + +#ifdef USE_VIEWER #include +#include #include #include #include @@ -14,9 +18,8 @@ #include #include #include -#include -#include #include +#endif #include @@ -92,34 +95,35 @@ int main(int argc, char **argv) { writer->SetFileName("out.vtk"); writer->Write(); - // /* Volume rendering properties */ - // vtkNew volumeMapper; - // volumeMapper->SetInputConnection(externalPointsFilter->GetOutputPort()); - // vtkNew volume; - // volume->SetMapper(volumeMapper); - // vtkNew transferFunction; - // transferFunction->AddPoint(-1, 0); - // transferFunction->AddPoint(1, 1); - // volume->GetProperty()->SetScalarOpacity(transferFunction); - // volume->GetProperty()->SetColor(transferFunction); - - // /* Renderer */ - // vtkNew colors; - // std::array bkg{{26, 51, 102, 255}}; - // colors->SetColor("BkgColor", bkg.data()); - // vtkNew renderer; - // renderer->AddVolume(volume); - // renderer->SetBackground(colors->GetColor3d("BkgColor").GetData()); - // renderer->ResetCamera(); - // renderer->GetActiveCamera()->Zoom(1.5); - // vtkNew renderWindow; - // renderWindow->SetSize(300, 300); - // renderWindow->AddRenderer(renderer); - // renderWindow->SetWindowName("PFE"); - // vtkNew renderWindowInteractor; - // renderWindowInteractor->SetRenderWindow(renderWindow); - // renderWindow->Render(); - // renderWindowInteractor->Start(); +#ifdef USE_VIEWER + /* Volume rendering properties */ + vtkNew volumeMapper; + volumeMapper->SetInputConnection(externalPointsFilter->GetOutputPort()); + vtkNew volume; + volume->SetMapper(volumeMapper); + vtkNew transferFunction; + transferFunction->AddPoint(-1, 0); + transferFunction->AddPoint(1, 1); + volume->GetProperty()->SetScalarOpacity(transferFunction); + volume->GetProperty()->SetColor(transferFunction); + /* Renderer */ + vtkNew colors; + std::array bkg{{26, 51, 102, 255}}; + colors->SetColor("BkgColor", bkg.data()); + vtkNew renderer; + renderer->AddVolume(volume); + renderer->SetBackground(colors->GetColor3d("BkgColor").GetData()); + renderer->ResetCamera(); + renderer->GetActiveCamera()->Zoom(1.5); + vtkNew renderWindow; + renderWindow->SetSize(300, 300); + renderWindow->AddRenderer(renderer); + renderWindow->SetWindowName("PFE"); + vtkNew renderWindowInteractor; + renderWindowInteractor->SetRenderWindow(renderWindow); + renderWindow->Render(); + renderWindowInteractor->Start(); +#endif return EXIT_SUCCESS; }