6
6
#include " ../src/bni_normal_integration.h"
7
7
#include " ../src/flatnormals.h"
8
8
9
+ #include < assm/Grid.h>
10
+ #include < assm/algorithms/PhotometricRemeshing.h>
11
+ #include < assm/algorithms/Integration.h>
12
+
9
13
#include < Eigen/Eigen>
10
14
#include < Eigen/Core>
11
15
#include < Eigen/Dense>
@@ -129,6 +133,10 @@ void NormalsTask::run() {
129
133
bool proceed = progressed (" Integrating normals..." , 0 );
130
134
if (!proceed)
131
135
return ;
136
+ QString filename = output.left (output.size () -4 ) + " .obj" ;
137
+
138
+ float precision = 0 .1f ;
139
+ assm (filename, normals, precision);
132
140
std::vector<float > z;
133
141
bni_integrate (callback, imageset.width , imageset.height , normals, z, bni_k);
134
142
if (z.size () == 0 ) {
@@ -137,14 +145,60 @@ void NormalsTask::run() {
137
145
return ;
138
146
}
139
147
// TODO remove extension properly
140
- QString filename = output.left (output.size () -4 ) + " .ply" ;
141
148
142
149
progressed (" Saving surface..." , 99 );
150
+ filename = output.left (output.size () -4 ) + " .ply" ;
143
151
savePly (filename, imageset.width , imageset.height , z);
144
152
}
145
153
progressed (" Done" , 100 );
146
154
}
147
155
156
+ bool saveObj (const char *filename, pmp::SurfaceMesh &mesh) {
157
+ FILE *fp = fopen (filename, " wb" );
158
+ if (!fp) {
159
+ // cerr << "Could not open file: " << filename << endl;
160
+ return false ;
161
+ }
162
+ int nvertices = 0 ;
163
+ for (auto vertex: mesh.vertices ()) {
164
+ auto p = mesh.position (vertex);
165
+ fprintf (fp, " v %f %f %f\n " , p[0 ], p[1 ], p[2 ]);
166
+ nvertices++;
167
+ }
168
+ for (auto face : mesh.faces ()) {
169
+ int indexes[3 ];
170
+ int count =0 ;
171
+ for (auto vertex : mesh.vertices (face)) {
172
+ auto p = mesh.position (vertex);
173
+ int v = indexes[count++] = vertex.idx () + 1 ;
174
+ assert (v > 0 && v <= nvertices);
175
+ }
176
+ fprintf (fp, " f %d %d %d\n " , indexes[0 ], indexes[1 ], indexes[2 ]);
177
+ }
178
+ fclose (fp);
179
+ return true ;
180
+ }
181
+
182
+ void NormalsTask::assm (QString filename, std::vector<float > &_normals, float approx_error) {
183
+ Grid<Eigen::Vector3f> normals (imageset.width , imageset.height , Eigen::Vector3f (0 .0f , 0 .0f , 0 .0f ));
184
+ for (int i = 0 ; i < _normals.size ()/3 ; i++) {
185
+ normals[i] = Eigen::Vector3f (_normals[i*3 ], _normals[i*3 +1 ], _normals[i*3 +2 ]);
186
+ }
187
+ Grid<unsigned char > mask (imageset.width , imageset.height , 0 );
188
+ mask.fill (255 );
189
+
190
+ float l_min = 1 ;
191
+ float l_max = 100 ;
192
+
193
+ PhotometricRemeshing<pmp::Orthographic> remesher (normals, mask);
194
+ remesher.run (l_min, l_max, approx_error);
195
+
196
+ pmp::Integration<double , pmp::Orthographic> integrator (remesher.mesh (), normals, mask);
197
+ integrator.run ();
198
+
199
+ saveObj (filename.toStdString ().c_str (), remesher.mesh ());
200
+ }
201
+
148
202
149
203
void NormalsWorker::run () {
150
204
switch (solver)
0 commit comments