2022-02-17 14:02:20 +01:00
|
|
|
#include "angles_filter.h"
|
|
|
|
|
2022-02-15 14:41:02 +01:00
|
|
|
#include <vtkCellData.h>
|
|
|
|
#include <vtkUnstructuredGrid.h>
|
2022-01-31 16:55:32 +01:00
|
|
|
#include <vtkCamera.h>
|
|
|
|
#include <vtkNamedColors.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>
|
|
|
|
#include <vtkPiecewiseFunction.h>
|
2022-02-15 14:41:02 +01:00
|
|
|
#include <vtkDoubleArray.h>
|
2022-01-31 16:55:32 +01:00
|
|
|
|
|
|
|
#include <array>
|
2022-02-15 12:55:12 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
2022-02-17 14:02:20 +01:00
|
|
|
// template <typename T>
|
|
|
|
// T average(const std::vector<T> &data) {
|
|
|
|
// T avg = 0;
|
|
|
|
// for (const T &t : data) {
|
|
|
|
// avg += t;
|
|
|
|
// }
|
|
|
|
// return avg / data.size();
|
|
|
|
// }
|
2022-02-15 14:41:02 +01:00
|
|
|
|
|
|
|
|
2022-02-17 14:02:20 +01:00
|
|
|
// template <typename T>
|
|
|
|
// T standard_deviation(const std::vector<T> &data) {
|
|
|
|
// T avg = average(data);
|
|
|
|
// T stddev = 0;
|
|
|
|
// for (const T &t : data) {
|
|
|
|
// stddev += (t - avg) * (t - avg);
|
|
|
|
// }
|
|
|
|
// return std::sqrt(stddev / data.size());
|
|
|
|
// }
|
2022-02-15 14:41:02 +01:00
|
|
|
|
|
|
|
|
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-15 14:41:02 +01:00
|
|
|
// reader->Update();
|
2022-02-17 14:02:20 +01:00
|
|
|
vtkNew<AnglesFilter> anglesFilter;
|
|
|
|
anglesFilter->SetInputConnection(reader->GetOutputPort());
|
|
|
|
anglesFilter->Update();
|
|
|
|
vtkUnstructuredGrid *grid = anglesFilter->GetOutput();
|
2022-02-15 14:41:02 +01:00
|
|
|
auto *angles = vtkDoubleArray::SafeDownCast(grid->GetCellData()->GetArray("angles"));
|
|
|
|
for (ssize_t i = 0; i < angles->GetNumberOfTuples(); i++) {
|
|
|
|
std::cout << "cell " << i << ": ";
|
|
|
|
for (ssize_t j = 0; j < angles->GetNumberOfComponents(); j++) {
|
|
|
|
std::cout << angles->GetTuple(i)[j] << ", ";
|
|
|
|
}
|
|
|
|
std::cout << "\b\b \n";
|
2022-02-15 12:55:12 +01:00
|
|
|
}
|
2022-02-15 14:41:02 +01:00
|
|
|
// std::cout << "avg: " << average(angles)
|
|
|
|
// << ", stddev: " << standard_deviation(angles)
|
|
|
|
// << ", min: " << *std::min_element(angles.begin(), angles.end())
|
|
|
|
// << ", max: " << *std::max_element(angles.begin(), angles.end()) << std::endl;
|
2022-02-09 16:24:57 +01:00
|
|
|
|
2022-02-10 19:38:48 +01:00
|
|
|
vtkNew<vtkOpenGLProjectedTetrahedraMapper> volumeMapper;
|
2022-02-17 14:02:20 +01:00
|
|
|
volumeMapper->SetInputConnection(anglesFilter->GetOutputPort());
|
2022-02-10 19:38:48 +01:00
|
|
|
// 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;
|
2022-02-15 12:55:12 +01:00
|
|
|
transferFunction->AddPoint(-1, 0);
|
|
|
|
transferFunction->AddPoint(1, 1);
|
2022-02-10 19:38:48 +01:00
|
|
|
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;
|
|
|
|
}
|