add build option to disable the viewer and use the system vtk

This commit is contained in:
ccolin 2022-02-23 14:00:48 +01:00
parent 357068d1b8
commit b8886676fe
2 changed files with 71 additions and 47 deletions

View File

@ -2,7 +2,37 @@ cmake_minimum_required(VERSION 3.15)
project(pfe) project(pfe)
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) add_subdirectory(external/vtk)
endif()
add_executable(pfe) add_executable(pfe)
@ -19,18 +49,8 @@ target_sources(pfe PRIVATE
src/external_points_filter.cc src/external_points_filter.cc
src/external_points_filter.h) src/external_points_filter.h)
target_link_libraries(pfe PRIVATE target_link_libraries(pfe PRIVATE ${VTK_COMPONENTS})
VTK::CommonCore
VTK::ViewsCore if(ENABLE_VIEWER)
VTK::RenderingCore target_compile_definitions(pfe PRIVATE ENABLE_VIEWER)
VTK::IOCore endif()
VTK::FiltersCore
VTK::CommonColor
VTK::GUISupportQt
VTK::RenderingQt
VTK::ViewsQt
VTK::RenderingVolume
VTK::CommonDataModel
VTK::IOLegacy
VTK::IOXML
VTK::RenderingVolumeOpenGL2)

View File

@ -5,8 +5,12 @@
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkUnstructuredGrid.h> #include <vtkUnstructuredGrid.h>
#include <vtkCamera.h> #include <vtkUnstructuredGridReader.h>
#include <vtkUnstructuredGridWriter.h>
#ifdef USE_VIEWER
#include <vtkNamedColors.h> #include <vtkNamedColors.h>
#include <vtkCamera.h>
#include <vtkVolumeProperty.h> #include <vtkVolumeProperty.h>
#include <vtkRenderWindow.h> #include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h> #include <vtkRenderWindowInteractor.h>
@ -14,9 +18,8 @@
#include <vtkVolumeMapper.h> #include <vtkVolumeMapper.h>
#include <vtkVolume.h> #include <vtkVolume.h>
#include <vtkOpenGLProjectedTetrahedraMapper.h> #include <vtkOpenGLProjectedTetrahedraMapper.h>
#include <vtkUnstructuredGridReader.h>
#include <vtkUnstructuredGridWriter.h>
#include <vtkPiecewiseFunction.h> #include <vtkPiecewiseFunction.h>
#endif
#include <array> #include <array>
@ -92,34 +95,35 @@ int main(int argc, char **argv) {
writer->SetFileName("out.vtk"); writer->SetFileName("out.vtk");
writer->Write(); writer->Write();
// /* Volume rendering properties */ #ifdef USE_VIEWER
// vtkNew<vtkOpenGLProjectedTetrahedraMapper> volumeMapper; /* Volume rendering properties */
// volumeMapper->SetInputConnection(externalPointsFilter->GetOutputPort()); vtkNew<vtkOpenGLProjectedTetrahedraMapper> volumeMapper;
// vtkNew<vtkVolume> volume; volumeMapper->SetInputConnection(externalPointsFilter->GetOutputPort());
// volume->SetMapper(volumeMapper); vtkNew<vtkVolume> volume;
// vtkNew<vtkPiecewiseFunction> transferFunction; volume->SetMapper(volumeMapper);
// transferFunction->AddPoint(-1, 0); vtkNew<vtkPiecewiseFunction> transferFunction;
// transferFunction->AddPoint(1, 1); transferFunction->AddPoint(-1, 0);
// volume->GetProperty()->SetScalarOpacity(transferFunction); transferFunction->AddPoint(1, 1);
// volume->GetProperty()->SetColor(transferFunction); volume->GetProperty()->SetScalarOpacity(transferFunction);
volume->GetProperty()->SetColor(transferFunction);
// /* Renderer */
// vtkNew<vtkNamedColors> colors;
// std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
// colors->SetColor("BkgColor", bkg.data());
// vtkNew<vtkRenderer> renderer;
// renderer->AddVolume(volume);
// renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
// renderer->ResetCamera();
// renderer->GetActiveCamera()->Zoom(1.5);
// vtkNew<vtkRenderWindow> renderWindow;
// renderWindow->SetSize(300, 300);
// renderWindow->AddRenderer(renderer);
// renderWindow->SetWindowName("PFE");
// vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
// renderWindowInteractor->SetRenderWindow(renderWindow);
// renderWindow->Render();
// renderWindowInteractor->Start();
/* Renderer */
vtkNew<vtkNamedColors> colors;
std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
colors->SetColor("BkgColor", bkg.data());
vtkNew<vtkRenderer> renderer;
renderer->AddVolume(volume);
renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.5);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(300, 300);
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("PFE");
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindow->Render();
renderWindowInteractor->Start();
#endif
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }