182 lines
5.6 KiB
C++
182 lines
5.6 KiB
C++
#include "angles_filter.h"
|
|
#include "aspect_ratio_filter.h"
|
|
#include "dihedral_angles_filter.h"
|
|
#include "surface_points_filter.h"
|
|
#include "project_surface_points_on_poly.h"
|
|
#include "mesh_fit_filter.h"
|
|
#include "point_tris_dist.h"
|
|
|
|
#include <vtkCellData.h>
|
|
#include <vtkUnstructuredGrid.h>
|
|
#include <vtkUnstructuredGridReader.h>
|
|
#include <vtkUnstructuredGridWriter.h>
|
|
#include <vtkPolyData.h>
|
|
#include <vtkCellArrayIterator.h>
|
|
#include <vtkXMLPolyDataReader.h>
|
|
|
|
#ifdef USE_VIEWER
|
|
#include <vtkNamedColors.h>
|
|
#include <vtkCamera.h>
|
|
#include <vtkVolumeProperty.h>
|
|
#include <vtkRenderWindow.h>
|
|
#include <vtkRenderWindowInteractor.h>
|
|
#include <vtkRenderer.h>
|
|
#include <vtkVolumeMapper.h>
|
|
#include <vtkVolume.h>
|
|
#include <vtkOpenGLProjectedTetrahedraMapper.h>
|
|
#include <vtkPiecewiseFunction.h>
|
|
#endif
|
|
|
|
#include <array>
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc != 3) {
|
|
std::cerr << "Usage: " << argv[0] << " tetmesh polydata" << std::endl;
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
/* Reader */
|
|
vtkNew<vtkUnstructuredGridReader> reader;
|
|
reader->SetFileName(argv[1]);
|
|
|
|
|
|
/* Angles filter */
|
|
vtkNew<AnglesFilter> anglesFilter;
|
|
anglesFilter->SetInputConnection(reader->GetOutputPort());
|
|
|
|
/* Display angles in console. */
|
|
// anglesFilter->Update();
|
|
// vtkUnstructuredGrid *grid = anglesFilter->GetOutput();
|
|
// auto *angles = grid->GetCellData()->GetArray("angles");
|
|
// for (ssize_t i = 0; i < angles->GetNumberOfTuples(); i++) {
|
|
// std::cerr << "cell " << i << ": ";
|
|
// for (ssize_t j = 0; j < angles->GetNumberOfComponents(); j++) {
|
|
// std::cerr << angles->GetTuple(i)[j] << ", ";
|
|
// }
|
|
// std::cerr << "\b\b \n";
|
|
// }
|
|
|
|
/* Aspect ratio */
|
|
vtkNew<AspectRatioFilter> aspectRatioFilter;
|
|
aspectRatioFilter->SetInputConnection(anglesFilter->GetOutputPort());
|
|
|
|
/* Display aspect ratios in console. */
|
|
// aspectRatioFilter->Update();
|
|
// grid = aspectRatioFilter->GetOutput();
|
|
// auto *aspectRatios = grid->GetCellData()->GetArray("aspect_ratio");
|
|
// for (ssize_t i = 0; i < aspectRatios->GetNumberOfTuples(); i++) {
|
|
// std::cerr << "cell " << i << ": "
|
|
// << aspectRatios->GetTuple1(i) << "\n";
|
|
// }
|
|
|
|
/* Dihedral angles filter */
|
|
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
|
|
dihedralAnglesFilter->SetInputConnection(aspectRatioFilter->GetOutputPort());
|
|
|
|
/* Display dihedral angles in console. */
|
|
// dihedralAnglesFilter->Update();
|
|
// grid = dihedralAnglesFilter->GetOutput();
|
|
// auto dihedralAngles = grid->GetCellData()->GetArray("dihedral_angles");
|
|
// for (vtkIdType i = 0; i < grid->GetNumberOfCells(); i++) {
|
|
// std::cerr << "dihedral angles ";
|
|
// for (vtkIdType j = 0; j < 6; j++) {
|
|
// std::cerr << dihedralAngles->GetTuple(i)[j] << ", ";
|
|
// }
|
|
// std::cerr << "\b\b\n";
|
|
// }
|
|
|
|
/* External faces filter. */
|
|
// vtkNew<vtkmExternalFaces> externalFacesFilter;
|
|
// externalFacesFilter->DebugOn();
|
|
// externalFacesFilter->SetInputConnection(dihedralAnglesFilter->GetOutputPort());
|
|
|
|
/* Surface points filter. */
|
|
vtkNew<SurfacePointsFilter> surfacePointsFilter;
|
|
surfacePointsFilter->SetInputConnection(dihedralAnglesFilter->GetOutputPort());
|
|
|
|
|
|
// vtkNew<MeshFitFilter> meshFitFilter;
|
|
// meshFitFilter->SetInputConnection(surfacePointsFilter->GetOutputPort());
|
|
|
|
vtkNew<vtkXMLPolyDataReader> pdReader;
|
|
pdReader->SetFileName(argv[2]);
|
|
|
|
vtkNew<ProjectSurfacePointsOnPoly> project;
|
|
project->SetInputConnection(0, surfacePointsFilter->GetOutputPort());
|
|
project->SetInputConnection(1, pdReader->GetOutputPort());
|
|
|
|
|
|
vtkNew<vtkUnstructuredGridWriter> writer;
|
|
writer->SetInputConnection(project->GetOutputPort());
|
|
writer->SetFileTypeToASCII();
|
|
writer->SetFileName("out.vtk");
|
|
writer->Write();
|
|
|
|
|
|
// vtkNew<vtkPoints> points;
|
|
// points->InsertPoint(0, 0., 0., 0.);
|
|
// points->InsertPoint(1, 1., 0., 0.);
|
|
// points->InsertPoint(2, 1., 1., 0.);
|
|
|
|
// vtkNew<vtkCellArray> strips;
|
|
// strips->InsertNextCell(3);
|
|
// strips->InsertCellPoint(0);
|
|
// strips->InsertCellPoint(1);
|
|
// strips->InsertCellPoint(2);
|
|
|
|
// vtkNew<vtkPolyData> profile;
|
|
// profile->SetPoints(points);
|
|
// profile->SetStrips(strips);
|
|
|
|
// vtkCell *cell = profile->GetCell(0);
|
|
// // vtkTriangle *triangle = vtkTriangle::SafeDownCast(cell);
|
|
// // vtkTriangle *triangle = (vtkTriangle *) cell;
|
|
|
|
// double direction[3];// = {0, 0, 0};
|
|
// double point[3] = {0, 1, 0};
|
|
|
|
// double d = pointTriangleDistance(point, cell, direction);
|
|
// //double d = 5;
|
|
|
|
// std::cout << "[" << point[0]
|
|
// << ", " << point[1]
|
|
// << ", " << point[2]
|
|
// << "] (" << d << ")"
|
|
// << "[" << direction[0]
|
|
// << ", " << direction[1]
|
|
// << ", " << direction[2] << "]\n";
|
|
|
|
#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;
|
|
}
|