add build option to disable the viewer and use the system vtk
This commit is contained in:
parent
357068d1b8
commit
b8886676fe
@ -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()
|
||||
|
66
src/main.cc
66
src/main.cc
@ -5,8 +5,12 @@
|
||||
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
#include <vtkCamera.h>
|
||||
#include <vtkUnstructuredGridReader.h>
|
||||
#include <vtkUnstructuredGridWriter.h>
|
||||
|
||||
#ifdef USE_VIEWER
|
||||
#include <vtkNamedColors.h>
|
||||
#include <vtkCamera.h>
|
||||
#include <vtkVolumeProperty.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
@ -14,9 +18,8 @@
|
||||
#include <vtkVolumeMapper.h>
|
||||
#include <vtkVolume.h>
|
||||
#include <vtkOpenGLProjectedTetrahedraMapper.h>
|
||||
#include <vtkUnstructuredGridReader.h>
|
||||
#include <vtkUnstructuredGridWriter.h>
|
||||
#include <vtkPiecewiseFunction.h>
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
|
||||
@ -92,34 +95,35 @@ int main(int argc, char **argv) {
|
||||
writer->SetFileName("out.vtk");
|
||||
writer->Write();
|
||||
|
||||
// /* Volume rendering properties */
|
||||
// vtkNew<vtkOpenGLProjectedTetrahedraMapper> volumeMapper;
|
||||
// volumeMapper->SetInputConnection(externalPointsFilter->GetOutputPort());
|
||||
// vtkNew<vtkVolume> volume;
|
||||
// volume->SetMapper(volumeMapper);
|
||||
// vtkNew<vtkPiecewiseFunction> transferFunction;
|
||||
// transferFunction->AddPoint(-1, 0);
|
||||
// transferFunction->AddPoint(1, 1);
|
||||
// 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();
|
||||
#ifdef USE_VIEWER
|
||||
/* Volume rendering properties */
|
||||
vtkNew<vtkOpenGLProjectedTetrahedraMapper> volumeMapper;
|
||||
volumeMapper->SetInputConnection(externalPointsFilter->GetOutputPort());
|
||||
vtkNew<vtkVolume> volume;
|
||||
volume->SetMapper(volumeMapper);
|
||||
vtkNew<vtkPiecewiseFunction> transferFunction;
|
||||
transferFunction->AddPoint(-1, 0);
|
||||
transferFunction->AddPoint(1, 1);
|
||||
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();
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user