-
Notifications
You must be signed in to change notification settings - Fork 25
/
example.cpp
244 lines (214 loc) · 11.9 KB
/
example.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/IO/reader/OBJReader.hh>
#include <OpenMesh/Core/IO/writer/OBJWriter.hh>
#include <iostream>
#include <Eigen/Dense>
#include <stdio.h>
#include <math.h>
#include "meshmonk.hpp"
using namespace std;
typedef OpenMesh::DefaultTraits MyTraits;
typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits> TriMesh;
typedef Eigen::Matrix< int, Eigen::Dynamic, 3> FacesMat; //matrix Mx3 of type unsigned int
typedef Eigen::VectorXf VecDynFloat;
typedef Eigen::Matrix< float, Eigen::Dynamic, 6> FeatureMat; //matrix Mx6 of type float
int main()
{
/*
############################################################################
############################## INPUT #####################################
############################################################################
*/
//# IO variables
//const string floatingDir = "/home/jonatan/projects/meshmonk/examples/data/karlijne/Normaal/Cleaned/CL0009A_Clean.obj";
// const string floatingDir = "/home/jonatan/projects/meshmonk/examples/data/karlijne/Normaal/Cleaned/rigidResult.obj";
// const string targetDir = "/home/jonatan/projects/meshmonk/examples/data/karlijne/Normaal/Cleaned/CL0013A_Clean.obj";
// const string floatingDir = "/home/jonatan/projects/meshmonk/examples/faceTemplate.obj";
// const string targetDir = "/home/jonatan/projects/meshmonk/examples/faceTarget.obj";
// const string resultDir = "/home/jonatan/projects/meshmonk/examples/data/karlijne/Normaal/Cleaned/resultexample.obj";
// const string floatingDir = "/home/jonatan/projects/meshmonk/examples/data/bunny.obj";
// const string targetDir = "/home/jonatan/projects/meshmonk/examples/data/bunny2.obj";
// const string resultDir = "/home/jonatan/projects/meshmonk/examples/data/bunnyResult.obj";
//# My Matlab Data
// const string floatingDir = "/home/jonatan/projects/meshmonk/examples/faceTemplate.obj";
// const string targetDir = "/home/jonatan/projects/meshmonk/examples/faceTarget.obj";
//# Peter's Matlab Data
const string floatingDir = "/Users/maartenhuijsmans/GitProjects/meshmonk/meshmonk/floating.obj";
const string targetDir = "/Users/maartenhuijsmans/GitProjects/meshmonk/meshmonk/target.obj";
const string resultDir = "/home/jonatan/projects/meshmonk/examples/matlabResult.obj";
//# Load meshes and convert to feature matrices
FeatureMat floatingFeatures;
FeatureMat targetFeatures;
FacesMat floatingFaces;
FacesMat targetFaces;
meshmonk::read_obj_files(floatingDir, targetDir,
floatingFeatures, targetFeatures,
floatingFaces, targetFaces);
const size_t numFloatingVertices = floatingFeatures.rows();
const size_t numTargetVertices = targetFeatures.rows();
VecDynFloat floatingFlags = VecDynFloat::Ones(numFloatingVertices);
VecDynFloat targetFlags = VecDynFloat::Ones(numTargetVertices);
//
//
//
// /*
// ############################################################################
// ############################## REGISTRATION ##############################
// ############################################################################
//// */
//# Parameters
//## Pyramid
const size_t numIterations = 60;
const size_t numRigidIterations = 20;
const size_t numPyramidLayers = 1;
const float downsampleFloatStart = 0;
const float downsampleTargetStart = 0;
const float downsampleFloatEnd = 0;
const float downsampleTargetEnd = 0;
//## Correspondences
const bool correspondencesSymmetric = true;
const size_t correspondencesNumNeighbours = 5;
//## Inliers
const float inlierKappa = 4.0f;
const bool inlierUseOrientation = false;
//## Transformation
const float transformSigma = 3.0f;
const size_t transformNumViscousIterationsStart = 55;
const size_t transformNumViscousIterationsEnd = 2;
const size_t transformNumElasticIterationsStart = 56;
const size_t transformNumElasticIterationsEnd = 3;
//# Rigid registration
//meshmonk::rigid_registration(floatingFeatures, targetFeatures, floatingFaces, targetFaces,
// floatingFlags, targetFlags, numRigidIterations,
// correspondencesSymmetric, correspondencesNumNeighbours, inlierKappa);
//
//
//DEBUG
std::cout << " -- Floating Features --\n" << floatingFeatures.topRows(10) << std::endl;
std::cout << " -- Target Features --\n" << targetFeatures.topRows(10) << std::endl;
std::cout << " -- Floating Faces --\n" << floatingFaces.topRows(10) << std::endl;
std::cout << " -- Target Faces --\n" << targetFaces.topRows(10) << std::endl;
std::cout << " -- Floating Flags --\n" << floatingFlags.topRows(10) << std::endl;
std::cout << " -- Target Flags --\n" << targetFlags.topRows(10) << std::endl;
//END DEBUG
//# Call pyramid_registration()
//DEBUG
std::cout << "Num Floating Elements - " << floatingFeatures.rows() << std::endl;
std::cout << "Num Target Elements - " << targetFeatures.rows() << std::endl;
std::cout << "Num Floating Faces - " << floatingFaces.rows() << std::endl;
std::cout << "Num Target Faces - " << targetFaces.rows() << std::endl;
std::cout << "Num Iterations - " << numIterations << std::endl;
std::cout << "Num Pyramid Layers - " << numPyramidLayers << std::endl;
std::cout << "Downsample Float Start - " << downsampleFloatStart << std::endl;
std::cout << "Downsample Target Start - " << downsampleTargetStart << std::endl;
std::cout << "Downsample Float End - " << downsampleFloatEnd << std::endl;
std::cout << "Downsample Target End - " << downsampleTargetEnd << std::endl;
std::cout << "Symmetric Correspondences - " << correspondencesSymmetric << std::endl;
std::cout << "Num Neighbours - " << correspondencesNumNeighbours << std::endl;
std::cout << "Inlier Kappa - " << inlierKappa << std::endl;
std::cout << "Transform Sigma - " << transformSigma << std::endl;
std::cout << "transformNumViscousIterationsStart - " << transformNumViscousIterationsStart << std::endl;
std::cout << "transformNumViscousIterationsEnd - " << transformNumViscousIterationsEnd << std::endl;
std::cout << "transformNumElasticIterationsStart - " << transformNumElasticIterationsStart << std::endl;
std::cout << "transformNumElasticIterationsEnd - " << transformNumElasticIterationsEnd << std::endl;
//END DEBUG
//
//
//# Nonrigid registration
//DEBUG
//## Initialize variables
// floatingFeatures = FeatureMat::Zero(3,6);
// floatingFeatures << 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
// 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
// 1.0, 0.0, 0.0, 1.0, 0.0, 0.0;
// targetFeatures = FeatureMat::Zero(3,6);
// targetFeatures << 1.1, 1.0, 1.0, 1.0, 0.0, 0.0,
// 0.9, 1.0, 0.0, 1.0, 0.0, 0.0,
// 1.2, 0.0, 0.0, 1.0, 0.0, 0.0;
// floatingFaces = FacesMat::Zero(1,3);
// floatingFaces << 0, 1, 2;
// targetFaces = FacesMat::Zero(1,3);
// targetFaces << 0, 1, 2;
// floatingFlags = VecDynFloat::Ones(3);
// targetFlags = VecDynFloat::Ones(3);
//
//
// std::cout << "floatingFeatures: " << floatingFeatures << std::endl;
// std::cout << "targetFeatures: " << targetFeatures << std::endl;
// std::cout << "floatingFaces: " << floatingFaces << std::endl;
// std::cout << "targetFaces: " << targetFaces << std::endl;
// std::cout << "floatingFlags: " << floatingFlags << std::endl;
// std::cout << "targetFlags: " << targetFlags << std::endl;
//
// //## Convert to arrays
// float floatingFeaturesArray[18];
// Eigen::Map<FeatureMat>(floatingFeaturesArray, floatingFeatures.rows(), floatingFeatures.cols()) = floatingFeatures;
// float targetFeaturesArray[18];
// Eigen::Map<FeatureMat>(targetFeaturesArray, targetFeatures.rows(), targetFeatures.cols()) = targetFeatures;
//
// int floatingFacesArray[18];
// Eigen::Map<FacesMat>(floatingFacesArray, floatingFaces.rows(), floatingFaces.cols()) = floatingFaces;
// int targetFacesArray[18];
// Eigen::Map<FacesMat>(targetFacesArray, targetFaces.rows(), targetFaces.cols()) = targetFaces;
//
// float floatingFlagsArray[18];
// Eigen::Map<VecDynFloat>(floatingFlagsArray, floatingFlags.rows(), floatingFlags.cols()) = floatingFlags;
// float targetFlagsArray[18];
// Eigen::Map<VecDynFloat>(targetFlagsArray, targetFlags.rows(), targetFlags.cols()) = targetFlags;
//
//
//
// std::cout << "floatingFeaturesArray: " << std::endl;
// for (int i = 0 ; i < 3 ; i++){
// for (int j = 0 ; j < 6 ; j++) {
// std::cout << floatingFeaturesArray[6*i + j] << " | ";
// }
// std::cout << std::endl;
// }
//
// std::cout << "targetFeaturesArray: " << targetFeaturesArray << std::endl;
// std::cout << "floatingFacesArray: " << floatingFacesArray << std::endl;
// std::cout << "targetFacesArray: " << targetFacesArray << std::endl;
// std::cout << "floatingFlagsArray: " << floatingFlagsArray << std::endl;
// std::cout << "targetFlagsArray: " << targetFlagsArray << std::endl;
//END DEBUG
meshmonk::pyramid_registration(floatingFeatures, targetFeatures,
floatingFaces, targetFaces,
floatingFlags, targetFlags,
numIterations, numPyramidLayers,
downsampleFloatStart, downsampleTargetStart,
downsampleFloatEnd, downsampleTargetEnd,
correspondencesSymmetric, correspondencesNumNeighbours,
inlierKappa, inlierUseOrientation,
transformSigma,
transformNumViscousIterationsStart, transformNumViscousIterationsEnd,
transformNumElasticIterationsStart, transformNumElasticIterationsEnd);
// meshmonk::nonrigid_registration_mex(floatingFeaturesArray, targetFeaturesArray,
// 3, 3,
// floatingFacesArray, targetFacesArray,
// 1, 1,
// floatingFlagsArray, targetFlagsArray,
// numIterations,
// correspondencesSymmetric, correspondencesNumNeighbours,
// inlierKappa, inlierUseOrientation,
// transformSigma,
// transformNumViscousIterationsStart, transformNumViscousIterationsEnd,
// transformNumElasticIterationsStart, transformNumElasticIterationsEnd);
// /*
// ############################################################################
// ############################## OUTPUT #####################################
// ############################################################################
// */
// //# Write result to file
// std::cout << "Writing results to file..." << std::endl;
// //DEBUG
// std::cout << "Num Floating Elements - " << floatingFeatures.rows() << std::endl;
// std::cout << "Num Target Elements - " << targetFeatures.rows() << std::endl;
// std::cout << "Num Floating Faces - " << floatingFaces.rows() << std::endl;
// std::cout << "Num Target Faces - " << targetFaces.rows() << std::endl;
// //END DEBUG
// meshmonk::write_obj_files(floatingFeatures,floatingFaces, resultDir);
// std::cout << "Process finished." << std::endl;
return 0;
}