/
CurvatureMain.cpp
164 lines (146 loc) · 6.17 KB
/
CurvatureMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "../MeshAnalyser.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
void print_help()
{
printf(
"Usage: CurvatureMain [Options] InputVTKMesh MeanCurvatureOutput\n"
"Options: \n"
" -m Method: set the method used to compute curvature(s) (default 0)\n"
" 0 -- Use ComputePrincipalCurvatures() function to compute both mean and Gaussian curvatures based on the relative direction of the normal vectors in a small neighborhood\n"
" 1 -- Use ComputeBothCurvatures() function to compute both mean and Gaussian curvatures based on the local ratios between a filtered surface and the original surface area\n"
" 2 -- Use ComputeCurvature() function to compute the mean curvature based on the direction of the displacement vectors during a Laplacian filtering\n"
" -n Neighborhood: set the neighborhood size for computing curvature (default 0.7)\n"
" -g GaussianCurvVTK: set the output file to save Gaussian curvature (no default)\n"
" -x MaxCurvVTK: set the output file to save maximum curvature (no default)\n"
" -i MinCurvVTK: set the output file to save minimum curvature (no default)\n"
" -d DirectionVTK: set the output file to save minimal curvature's direction (no default)\n"
"Example: CurvatureMain -m 0 -n 0.75 -i lh.min_curv.vtk -x lh.max_curv.vtk -g lh.gaussian_curv.vtk -d lh.min_dir.vtk lh.pial.vtk lh.mean_curv.vtk \n"
);
}
int main(int argc, char** argv)
{
cout<<endl;
time_t start= time(NULL);
if(argc < 3)
{
print_help();
return -1;
}
/* Default values for options */
int Method=0; // using ComputePrincipalCurvatures()
bool Gaussian=false, Max=false, Min=false, MinDir=false; // whether output Gaussian, max and min curvatures, and directions of minimal curvature
char * GaussianVTK, * MaxVTK, * MinVTK, * MinDirVTK; // files to save Gaussian, max and min curvatures, and directions of minimal curvature
double NeighborhoodSize = 0.7; // default neighborhood size for computing curvature
/*Check whether we have mandatory I/Os*/
int Mandatory = 0; // number of mandatory I/O (input mesh and mean curvature VTK) available
for (int i=1;i<argc;i++) // we may need to use getopt or getlongopt later - Forrest, 2012/05/29
{
if (argv[i][0] != '-')
{
Mandatory++;
}
else
i++; // skip the value after a flag
}
if (Mandatory < 2)
{
cout<<"[ERROR] Not sufficient mandatory I/Os. Check usage please. "<<endl;
print_help();
return -4;
}
/* Processing options and arguments */
for (int i=1;i<argc;i++) // we may need to use getopt or getlongopt later - Forrest, 2012/05/29
{
if (argv[i][0] != '-')
continue; // no more options
switch (argv[i][1])
{
case 'm' : // select curvature computation method
Method = atoi(argv[i+1]);
cout<<"Using method "<<Method<<" to compute curvature(s)..."<<endl;
break;
case 'g' : // whether output Gaussian curvature
if (Method==2)
{
cout<<"[ERROR]: Method 2 does NOT compute Gaussian curvature."<<endl;
return -2;
}
Gaussian = true;
GaussianVTK = argv[i+1];
break;
case 'x' : // whether output max curvature
Max = true;
MaxVTK = argv[i+1];
break;
case 'i' : // whether output min curvature
Min = true;
MinVTK = argv[i+1];
break;
case 'n': //set neighborhood size for computing curvature
// if (Method==0)
// cout <<"[Warning]: Method 0 does not need neighborhood size though you provided it."<<endl;
NeighborhoodSize = atof(argv[i+1]);
break;
case 'd': // whether output directions of min curvature
if ((Method==2) || (Method==1))
{
cout<<"[ERROR]: Method 2 or 1 does NOT compute directions of minimal curvature. Remove flag -d and its argument please."<<endl;
return -3;
}
MinDir = true;
MinDirVTK = argv[i+1];
break;
default:
cout<<"[ERROR] Unrecognized argument flag or option. Check usage. ";
print_help();
} // end of switch
} // end of looping thru arguments
/*Compute curvatures*/
MeshAnalyser* ma = new MeshAnalyser(argv[argc-2]); // the second last input is the inputVTK
switch (Method)
{
case 2:
ma->ComputeCurvature(NeighborhoodSize, 20);
break;
case 1:
ma->ComputeBothCurvatures(NeighborhoodSize);
break;
default: // =0
vtkDoubleArray* minDirections= ma->ComputePrincipalCurvatures(NeighborhoodSize);
if(MinDir)
{
cout<<"Saving directions of minimal curvature into file "<<MinDirVTK<<endl;
double dir[3];
ofstream myfile(MinDirVTK);
myfile.clear();
for(int i = 0; i<minDirections->GetNumberOfTuples() ; i++)
{
minDirections->GetTuple(i,dir);
myfile<<dir[0]<<" "<<dir[1]<<" "<<dir[2]<<endl;
}
myfile.close();
}
break;
}
/*Write results into VTK files*/
ma->WriteIntoFile(argv[argc-1], (char*)"curv"); // the very last input is the VTK for mean curv
if(Gaussian)
{
cout<<"Saving Gaussian curvature into file "<<GaussianVTK<<endl;
ma->WriteIntoFile(GaussianVTK, (char*)"gCurv");
}
if(Max)
{
cout<<"Saving maximum curvature into file "<<MaxVTK<<endl;
ma->WriteIntoFile(MaxVTK, (char*)"curv1");
}
if(Min)
{
cout<<"Saving minimum curvature into file "<<MinVTK<<endl;
ma->WriteIntoFile(MinVTK, (char*)"curv2");
}
cout<<"Elapsed time: "<<time(NULL)-start<<" s"<<endl;
return 0;
}