pfe/src/main.cc

75 lines
2.2 KiB
C++
Raw Normal View History

2022-01-31 16:55:32 +01:00
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCylinderSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
2022-02-10 19:38:48 +01:00
#include <vtkVolumeProperty.h>
2022-01-31 16:55:32 +01:00
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
2022-02-09 16:24:57 +01:00
#include <vtkVolumeMapper.h>
#include <vtkVolume.h>
2022-02-10 19:38:48 +01:00
#include <vtkOpenGLProjectedTetrahedraMapper.h>
#include <vtkUnstructuredGridReader.h>
2022-02-09 16:24:57 +01:00
#include <vtkPolyDataReader.h>
#include <vtkXMLPolyDataReader.h>
2022-02-10 19:38:48 +01:00
#include <vtkPiecewiseFunction.h>
2022-01-31 16:55:32 +01:00
#include <array>
2022-02-09 16:24:57 +01:00
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " FILE.vtk" << std::endl;
return EXIT_FAILURE;
}
2022-01-31 16:55:32 +01:00
vtkNew<vtkNamedColors> colors;
std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
colors->SetColor("BkgColor", bkg.data());
2022-02-10 19:38:48 +01:00
// vtkNew<vtkXMLPolyDataReader> reader;
vtkNew<vtkUnstructuredGridReader> reader;
2022-02-09 16:24:57 +01:00
reader->SetFileName(argv[1]);
2022-02-10 19:38:48 +01:00
vtkNew<vtkOpenGLProjectedTetrahedraMapper> volumeMapper;
volumeMapper->SetInputConnection(reader->GetOutputPort());
// vtkNew<vtkPolyDataMapper> mapper;
// mapper->SetInputConnection(reader->GetOutputPort());
2022-01-31 16:55:32 +01:00
2022-02-10 19:38:48 +01:00
vtkNew<vtkVolume> volume;
volume->SetMapper(volumeMapper);
vtkNew<vtkPiecewiseFunction> transferFunction;
transferFunction->AddPoint(-1, 100);
transferFunction->AddPoint(0, .5);
// transferFunction->AddPoint(1, 1);
volume->GetProperty()->SetScalarOpacity(transferFunction);
volume->GetProperty()->SetColor(transferFunction);
// vtkNew<vtkActor> actor;
// actor->SetMapper(mapper);
2022-01-31 16:55:32 +01:00
2022-02-10 19:38:48 +01:00
// actor->GetProperty()->SetColor(
// colors->GetColor4d("Tomato").GetData());
// actor->RotateX(30.0);
// actor->RotateY(-45.0);
2022-01-31 16:55:32 +01:00
vtkNew<vtkRenderer> renderer;
2022-02-10 19:38:48 +01:00
// renderer->AddActor(actor);
renderer->AddVolume(volume);
2022-01-31 16:55:32 +01:00
renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.5);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(300, 300);
renderWindow->AddRenderer(renderer);
2022-02-10 19:38:48 +01:00
renderWindow->SetWindowName("PFE");
2022-01-31 16:55:32 +01:00
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}