|
| 1 | +#include "GetCurvaturesCLP.h" |
| 2 | + |
| 3 | +// VTK Includes |
| 4 | +#include "vtkXMLPolyDataWriter.h" |
| 5 | +#include "vtkXMLPolyDataReader.h" |
| 6 | +#include "vtkSmartPointer.h" |
| 7 | +#include "vtkPolyData.h" |
| 8 | +#include "vtkNew.h" |
| 9 | +#include "vtkTransformFilter.h" |
| 10 | +#include "vtkTransform.h" |
| 11 | +#include "vtkPoints.h" |
| 12 | +#include "vtkCurvatures.h" |
| 13 | +#include "vtkPointData.h" |
| 14 | +#include "vtkDoubleArray.h" |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +int main (int argc, char * argv[]) |
| 19 | + { |
| 20 | + PARSE_ARGS; |
| 21 | + |
| 22 | + try{ |
| 23 | + |
| 24 | + |
| 25 | + vtkSmartPointer<vtkPolyData> polyData; |
| 26 | + |
| 27 | + |
| 28 | + // Read the file |
| 29 | + vtkNew<vtkXMLPolyDataReader> reader; |
| 30 | + reader->SetFileName(inputVolume.c_str()); |
| 31 | + reader->Update(); |
| 32 | + polyData = reader->GetOutput(); |
| 33 | + |
| 34 | + vtkNew<vtkCurvatures> curveMax; |
| 35 | + curveMax->SetInputData(polyData); |
| 36 | + curveMax->SetCurvatureTypeToMaximum(); |
| 37 | + curveMax->Update(); |
| 38 | + |
| 39 | + vtkSmartPointer<vtkPolyData> polyDataCurveMax = curveMax->GetOutput(); |
| 40 | + |
| 41 | + vtkNew<vtkCurvatures> curveMin; |
| 42 | + curveMin->SetInputData(polyData); |
| 43 | + curveMin->SetCurvatureTypeToMinimum(); |
| 44 | + curveMin->Update(); |
| 45 | + vtkSmartPointer<vtkPolyData> polyDataCurveMin = curveMin->GetOutput(); |
| 46 | + |
| 47 | + unsigned int nPoints = polyDataCurveMax->GetNumberOfPoints(); |
| 48 | + vtkSmartPointer<vtkDoubleArray> ArrayCurveMax = vtkDoubleArray::SafeDownCast( |
| 49 | + polyDataCurveMax->GetPointData()->GetScalars() |
| 50 | + ); |
| 51 | + vtkSmartPointer<vtkDoubleArray> ArrayCurveMin = vtkDoubleArray::SafeDownCast( |
| 52 | + polyDataCurveMin->GetPointData()->GetScalars() |
| 53 | + ); |
| 54 | + |
| 55 | + std::ofstream curvedness(outputCurve); |
| 56 | + std::ofstream shapeIndex(outputShape); |
| 57 | + std::ofstream gauss(outputGauss); |
| 58 | + std::ofstream mean(outputMean); |
| 59 | + |
| 60 | + curvedness << "NUMBER_OF_POINTS=" << nPoints << std::endl; |
| 61 | + curvedness << "DIMENSION=1" << std::endl << "TYPE=Scalar" << std::endl; |
| 62 | + |
| 63 | + shapeIndex << "NUMBER_OF_POINTS=" << nPoints << std::endl; |
| 64 | + shapeIndex << "DIMENSION=1" << std::endl << "TYPE=Scalar" << std::endl; |
| 65 | + |
| 66 | + gauss << "NUMBER_OF_POINTS=" << nPoints << std::endl; |
| 67 | + gauss << "DIMENSION=1" << std::endl << "TYPE=Scalar" << std::endl; |
| 68 | + |
| 69 | + mean << "NUMBER_OF_POINTS=" << nPoints << std::endl; |
| 70 | + mean << "DIMENSION=1" << std::endl << "TYPE=Scalar" << std::endl; |
| 71 | + |
| 72 | + if( ArrayCurveMax && ArrayCurveMin ) |
| 73 | + { |
| 74 | + |
| 75 | + for( unsigned int i = 0; i < nPoints; i++ ) |
| 76 | + { |
| 77 | + |
| 78 | + float curvmax, curvmin; |
| 79 | + curvmax = ArrayCurveMax->GetValue(i); |
| 80 | + curvmin = ArrayCurveMin->GetValue(i); |
| 81 | + |
| 82 | + float aux = sqrt( (pow(curvmax, 2) + pow(curvmin, 2) ) / 2); |
| 83 | + curvedness << aux << std::endl; |
| 84 | + |
| 85 | + aux = (2 / M_PI) * (atan( (curvmax + curvmin) / (curvmax - curvmin) ) ); |
| 86 | + if( aux != aux ) |
| 87 | + { |
| 88 | + aux = 0; |
| 89 | + } |
| 90 | + shapeIndex << aux << std::endl; |
| 91 | + |
| 92 | + aux = curvmax * curvmin; |
| 93 | + gauss << aux << std::endl; |
| 94 | + |
| 95 | + aux = (curvmax + curvmin) / 2; |
| 96 | + mean << aux << std::endl; |
| 97 | + // std::cout << "Curvature: " << curv << std::endl; |
| 98 | + } |
| 99 | + } |
| 100 | + else |
| 101 | + { |
| 102 | + // std::cout << "Got no array?" << std::endl; |
| 103 | + |
| 104 | + curvedness.close(); |
| 105 | + } |
| 106 | + |
| 107 | + curvedness.close(); |
| 108 | + shapeIndex.close(); |
| 109 | + gauss.close(); |
| 110 | + mean.close(); |
| 111 | + |
| 112 | + //Write to file |
| 113 | + //vtkNew<vtkXMLPolyDataWriter> writer; |
| 114 | + //writer->SetFileName(outputVolume.c_str()); |
| 115 | + //writer->SetInputData(polyData); |
| 116 | + //writer->Update(); |
| 117 | + } |
| 118 | + catch (int e) |
| 119 | + { |
| 120 | + cout << "An exception occurred. Exception Nr. " << e << '\n'; |
| 121 | + return EXIT_FAILURE; |
| 122 | + } |
| 123 | + |
| 124 | + return EXIT_SUCCESS; |
| 125 | + |
| 126 | + } |
0 commit comments