15
15
#include < util/system.h>
16
16
#include < util/file_system.h>
17
17
#include < core/mesh_io_ply.h>
18
+ #include < core/image_tools.h>
19
+ #include < core/image_drawing.h>
20
+ #include " core/image_io.h"
18
21
19
22
#include " texturing/util.h"
20
23
#include " texturing/timer.h"
@@ -65,7 +68,6 @@ int main(int argc, char **argv) {
65
68
tex::prepare_mesh (vertex_infos, mesh);
66
69
67
70
68
-
69
71
// =================================Geneatring texture views=====================//
70
72
std::size_t const num_faces = mesh->get_faces ().size () / 3 ;
71
73
std::cout << " Generating texture views: " << std::endl;
@@ -76,16 +78,12 @@ int main(int argc, char **argv) {
76
78
77
79
78
80
// ===============================Building adjacency graph=======================//
79
- std::cout << " Building adjacency graph: " << std::endl;
81
+ std::cout << " Building adjacency graph: " << std::endl; // each facet is corresponding a facet
80
82
tex::Graph graph (num_faces);
81
83
tex::build_adjacency_graph (mesh, vertex_infos, &graph);
82
84
wtimer.reset ();
83
85
84
86
85
- /* ***** 2015/12/11 yangliang *************/
86
-
87
-
88
-
89
87
// ===============================View Selection ================================//
90
88
// if labeling file does not exist, compute a view label for each facet via MRF
91
89
if (conf.labeling_file .empty ()) {
@@ -154,8 +152,62 @@ int main(int argc, char **argv) {
154
152
std::cout << " done." << std::endl;
155
153
}
156
154
std::cout << " \t Took: " << wtimer.get_elapsed_sec () << " s" << std::endl;
155
+ // todo rendering the mesh with different colors
156
+ {
157
+ std::vector<std::size_t > labeling (graph.num_nodes ());
158
+ for (std::size_t i = 0 ; i < graph.num_nodes (); ++i) {
159
+ labeling[i] = graph.get_label (i);
160
+ }
161
+ std::vector<std::size_t >::iterator max_iter = std::max_element (labeling.begin (), labeling.end ());
162
+ int n_labels = *max_iter + 1 ;
163
+ std::vector<math::Vec3f> colors (n_labels);
164
+ colors[0 ][0 ] = 0 ;
165
+ colors[0 ][1 ] = 0 ;
166
+ colors[0 ][2 ] = 0 ;
167
+
168
+ for (int i=1 ; i< colors.size (); i++){
169
+ colors[i][0 ] = rand ()&255 ;
170
+ colors[i][1 ] = rand ()&255 ;
171
+ colors[i][2 ] = rand ()&255 ;
172
+ }
157
173
174
+ std::ofstream out (" ./examples/task7/view_selection_result.ply" );
175
+ assert (out.is_open ());
176
+ out<<" ply" <<std::endl;
177
+ out<<" format ascii 1.0" <<std::endl;
178
+ out<<" element vertex " <<mesh->get_vertices ().size ()<<std::endl;
179
+ out<<" property float x" <<std::endl;
180
+ out<<" property float y" <<std::endl;
181
+ out<<" property float z" <<std::endl;
182
+ out<<" element face " <<mesh->get_faces ().size ()/3 <<std::endl;
183
+ out<<" property list uchar int vertex_indices" <<std::endl;
184
+ out<<" property uchar red" <<std::endl;
185
+ out<<" property uchar green" <<std::endl;
186
+ out<<" property uchar blue" <<std::endl;
187
+ out<<" end_header" <<std::endl;
188
+
189
+ // Face List
190
+ core::TriangleMesh::FaceList const & mesh_faces = mesh->get_faces ();
191
+ // Vertices
192
+ core::TriangleMesh::VertexList const & vertices = mesh->get_vertices ();
193
+ for (int i=0 ; i< vertices.size (); i++){
194
+ out<<vertices[i][0 ]<<" " <<vertices[i][1 ]<<" " <<vertices[i][2 ]<<std::endl;
195
+ }
158
196
197
+ std::cout<<" labeling size: " <<labeling.size ()<<" faces size: " <<num_faces<<std::endl;
198
+ for (int i=0 ; i< labeling.size (); i++){
199
+ int label = labeling[i];
200
+ assert (label>=0 && label <labeling.size ());
201
+ int v0 = mesh_faces[3 *i + 0 ];
202
+ int v1 = mesh_faces[3 *i + 1 ];
203
+ int v2 = mesh_faces[3 *i + 2 ];
204
+ int r = colors[label][0 ];
205
+ int g = colors[label][1 ];
206
+ int b = colors[label][2 ];
207
+ out<<" 3 " <<v0<<" " <<v1<<" " <<v2<<" " <<r<<" " <<g<<" " <<b<<std::endl;
208
+ }
209
+ out.close ();
210
+ }
159
211
160
212
// =============================================texture_atlases====================================================//
161
213
tex::TextureAtlases texture_atlases;
@@ -171,6 +223,44 @@ int main(int argc, char **argv) {
171
223
&vertex_projection_infos,
172
224
&texture_patches);
173
225
226
+ // todo save texturePatches and the projection of facets
227
+ {
228
+ for (int i=0 ; i< texture_patches.size (); i++)
229
+ {
230
+ if (texture_patches[i]->get_faces ().size ()<10000 )continue ;
231
+
232
+ char image_name[255 ];
233
+ char validity_mask_name[255 ];
234
+ char blending_mask_name[255 ];
235
+
236
+ sprintf (image_name," examples/task7/texture_patches_init/texture_patch%d.jpg" , i);
237
+ sprintf (blending_mask_name," examples/task7/texture_patches_init/blending_mask%d.jpg" , i);
238
+ sprintf (validity_mask_name," examples/task7/texture_patches_init/validity_mask%d.jpg" , i);
239
+
240
+ core::FloatImage::Ptr image = texture_patches[i]->get_image ()->duplicate ();
241
+ core::ByteImage::Ptr validity_mask = texture_patches[i]->get_validity_mask ()->duplicate ();
242
+ core::ByteImage::Ptr blending_mask = texture_patches[i]->get_blending_mask ()->duplicate ();
243
+
244
+ float color[3 ]={255 , 0 ,0 };
245
+ std::vector<math::Vec2f> texcoords = texture_patches[i]->get_texcoords ();
246
+ for (int i=0 ; i< texcoords.size (); i+=3 ){
247
+ math::Vec2f v0 = texcoords[i+0 ];
248
+ math::Vec2f v1 = texcoords[i+1 ];
249
+ math::Vec2f v2 = texcoords[i+2 ];
250
+
251
+ core::image::draw_line<float >(*image, int (v0[0 ]), int (v0[1 ]), int (v1[0 ]), int (v1[1 ]), color);
252
+ core::image::draw_line<float >(*image, int (v1[0 ]), int (v1[1 ]), int (v2[0 ]), int (v2[1 ]), color);
253
+ core::image::draw_line<float >(*image, int (v0[0 ]), int (v0[1 ]), int (v2[0 ]), int (v2[1 ]), color);
254
+
255
+ }
256
+
257
+ core::image::save_file (core::image::float_to_byte_image (image), image_name);
258
+ core::image::save_file (validity_mask, validity_mask_name);
259
+ core::image::save_file (blending_mask, blending_mask_name);
260
+
261
+ }
262
+ }
263
+
174
264
// Global seam leveling
175
265
if (conf.settings .global_seam_leveling ) {
176
266
std::cout << " Running global seam leveling:" << std::endl;
@@ -180,6 +270,44 @@ int main(int argc, char **argv) {
180
270
vertex_projection_infos,
181
271
&texture_patches);
182
272
timer.measure (" Running global seam leveling" );
273
+
274
+ {
275
+ for (int i=0 ; i< texture_patches.size (); i++)
276
+ {
277
+ if (texture_patches[i]->get_faces ().size ()<10000 )continue ;
278
+
279
+ char image_name[255 ];
280
+ char validity_mask_name[255 ];
281
+ char blending_mask_name[255 ];
282
+
283
+ sprintf (image_name," examples/task7/texture_pathes_color_adjustment/texture_patch%d.jpg" , i);
284
+ sprintf (blending_mask_name," examples/task7/texture_pathes_color_adjustment/blending_mask%d.jpg" , i);
285
+ sprintf (validity_mask_name," examples/task7/texture_pathes_color_adjustment/validity_mask%d.jpg" , i);
286
+
287
+ core::FloatImage::Ptr image = texture_patches[i]->get_image ()->duplicate ();
288
+ core::ByteImage::Ptr validity_mask = texture_patches[i]->get_validity_mask ()->duplicate ();
289
+ core::ByteImage::Ptr blending_mask = texture_patches[i]->get_blending_mask ()->duplicate ();
290
+
291
+ float color[3 ]={255 , 0 ,0 };
292
+ std::vector<math::Vec2f> texcoords = texture_patches[i]->get_texcoords ();
293
+ for (int i=0 ; i< texcoords.size (); i+=3 ){
294
+ math::Vec2f v0 = texcoords[i+0 ];
295
+ math::Vec2f v1 = texcoords[i+1 ];
296
+ math::Vec2f v2 = texcoords[i+2 ];
297
+
298
+ core::image::draw_line<float >(*image, int (v0[0 ]), int (v0[1 ]), int (v1[0 ]), int (v1[1 ]), color);
299
+ core::image::draw_line<float >(*image, int (v1[0 ]), int (v1[1 ]), int (v2[0 ]), int (v2[1 ]), color);
300
+ core::image::draw_line<float >(*image, int (v0[0 ]), int (v0[1 ]), int (v2[0 ]), int (v2[1 ]), color);
301
+
302
+ }
303
+
304
+ core::image::save_file (core::image::float_to_byte_image (image), image_name);
305
+ core::image::save_file (validity_mask, validity_mask_name);
306
+ core::image::save_file (blending_mask, blending_mask_name);
307
+
308
+ }
309
+ }
310
+
183
311
} else {
184
312
ProgressCounter texture_patch_counter (" Calculating validity masks for texture patches" , texture_patches.size ());
185
313
#pragma omp parallel for schedule(dynamic)
@@ -193,6 +321,7 @@ int main(int argc, char **argv) {
193
321
timer.measure (" Calculating texture patch validity masks" );
194
322
}
195
323
324
+
196
325
// ======================================local seam leveling===========================//
197
326
// Local seam leveling (Poisson Editing???)
198
327
if (conf.settings .local_seam_leveling ) {
@@ -203,7 +332,6 @@ int main(int argc, char **argv) {
203
332
204
333
205
334
// ====================================Generating textgure atlases====================//
206
- // Generate texture atlases
207
335
/* Generate texture atlases. */
208
336
std::cout << " Generating texture atlases:" << std::endl;
209
337
tex::generate_texture_atlases (&texture_patches, &texture_atlases);
0 commit comments