-
Notifications
You must be signed in to change notification settings - Fork 0
/
Display.cpp
1403 lines (1149 loc) · 41.3 KB
/
Display.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Created on: 10/03/2021
* Author: Ziniu Lu ([email protected])
*/
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include "Display.h"
#include "Settings.h"
BEGIN_PROJECT_NAMESPACE
//GuiDisplay::
GuiDisplay::GuiDisplay(IGL_Viewer* p_viewer, IGL_Gui* p_gui, std::vector<IglGeometry>* p_geoms)
{
this->Reset();
this->viewer = p_viewer;
this->gui = p_gui;
this->geoms = p_geoms;
}
void GuiDisplay::Draw(const char* title, bool* p_open)
{
ImGui::SetNextWindowPos(ImVec2(0.0f, 260.0f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(200.0f, 500.0f), ImGuiCond_FirstUseEver);
bool _viewer_menu_visible = true;
ImGui::Begin(title, &_viewer_menu_visible);
if (ImGui::CollapsingHeader("Viewing Options", ImGuiTreeNodeFlags_DefaultOpen))
{
// Select rotation type
int rotation_type = static_cast<int>(this->viewer->core().rotation_type);
static Eigen::Quaternionf trackball_angle = Eigen::Quaternionf::Identity();
static bool orthographic = true;
ImGui::PushItemWidth(100 * this->gui->menu_scaling());
if (ImGui::Combo("Camera Type", &rotation_type, "Trackball\0Two Axes\0002D Mode\0\0"))
{
using RT = igl::opengl::ViewerCore::RotationType;
auto new_type = static_cast<RT>(rotation_type);
if (new_type != this->viewer->core().rotation_type)
{
if (new_type == RT::ROTATION_TYPE_NO_ROTATION)
{
trackball_angle = this->viewer->core().trackball_angle;
orthographic = this->viewer->core().orthographic;
this->viewer->core().trackball_angle = Eigen::Quaternionf::Identity();
this->viewer->core().orthographic = true;
}
else if (this->viewer->core().rotation_type == RT::ROTATION_TYPE_NO_ROTATION)
{
this->viewer->core().trackball_angle = trackball_angle;
this->viewer->core().orthographic = orthographic;
}
this->viewer->core().set_rotation_type(new_type);
}
}
// Snap canonical view
//ImGui::PushItemWidth(130 * this->gui->menu_scaling());
//if (ImGui::Button("Snap canonical view"/*, ImVec2(-1, 0)*/))
//{
// this->viewer->snap_to_canonical_quaternion();
//}
// Zoom
ImGui::PushItemWidth(100 * this->gui->menu_scaling());
//ImGui::DragFloat("Shininess", &(my_viewer.data().shininess), 0.05f, 0.0f, 100.0f);
ImGui::DragFloat("Zoom", &(this->viewer->core().camera_zoom), 0.05f, 0.1f, 20.0f);
// Orthographic view
ImGui::Checkbox("Orthographic view", &(this->viewer->core().orthographic));
// Background
ImGui::ColorEdit4("Background", this->viewer->core().background_color.data(),
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_PickerHueWheel);
// Line Color
ImGui::ColorEdit4("Line color", this->viewer->data(this->viewer->selected_data_index).line_color.data(),
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_PickerHueWheel);
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.3f);
//ImGui::PopItemWidth();
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Geometry List", ImGuiTreeNodeFlags_DefaultOpen))
{
for (IglGeometry& geo : *(this->geoms))
{
size_t& geo_id = geo.id;
bool& geo_show = geo.show;
//make_checkbox(geo.name.c_str(), my_viewer.data().set_visible(geo_show, geo_id));
if (ImGui::Checkbox(geo.name.c_str(), &(geo_show)))
{
this->viewer->selected_data_index = geo_id;
this->viewer->data().set_visible(geo_show, this->viewer->core_list[0].id);
//std::cout << "set " << geo.name << std::boolalpha << " " << geo_show << std::endl;
}
if (geo.name == "skel_map")
{
ImGui::SameLine();
bool same = (geo.color_E.rows() == 1);
if (ImGui::Checkbox("same color", &(same)))
{
switch (same)
{
case true: // same color
{
geo.color_E.resize(1, 3);
geo.color_E << IglColor::green();
break;
}
case false: // random color
{
size_t v = geo.E(0, 0);
size_t rowE = geo.E.rows();
RVec_3d color = IglColor::random();
geo.color_E.resize(rowE, 3);
for (int row = 0; row < rowE; row++)
{
size_t my_v = geo.E(row, 0);
if (my_v != v)
{
v = my_v;
color = IglColor::random();
}
geo.color_E.row(row) << color;
}
break;
}
}
//extern Display* display;
display->update();
}
}
}
//ImGui::PopItemWidth();
}
ImGui::Separator();
// Set Parameter
if (ImGui::CollapsingHeader("Settings", ImGuiTreeNodeFlags_DefaultOpen))
{
//extern Settings* settings;
// Select rotation type
int active_geo = 0;
float active_line_width = settings->Viewer.line_width_skel;
//float active_line_color = 1;
static Eigen::Quaternionf trackball_angle = Eigen::Quaternionf::Identity();
static bool orthographic = true;
ImGui::PushItemWidth(100 * this->gui->menu_scaling());
if (ImGui::Combo("Set active geometry", &active_geo, "A\0B\000C\0\0"))
{
}
ImGui::PushItemWidth(100 * this->gui->menu_scaling());
ImGui::DragFloat("Line width", &this->viewer->data().line_width, 1.0f, 5.0f, 10.0f);
//ImGui::PopItemWidth();
}
ImGui::End();
}
//GuiControl::
GuiControl::GuiControl()
{
this->Reset();
}
void GuiControl::Draw(const char* title, bool* p_open)
{
ImGui::SetNextWindowPos(ImVec2(205.0f, 260.0f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(195.0f, 500.0f), ImGuiCond_FirstUseEver);
bool _viewer_menu_visible = true;
ImGui::Begin(title, &_viewer_menu_visible);
if (ImGui::Button("Reset ", ImVec2(-1, 0)))
{
//extern size_t process_nr;
//extern bool settings_loaded;
//extern bool is_triangle_mesh;
//extern Settings* settings;
//extern GuiConsole* gui_console;
//extern Mesh* mesh;
//extern Triangle_mesh* tmesh;
//extern Skel* skel;
//extern SkelGraph* skel_graph;
delete settings;
delete gui_console;
delete mesh;
delete skel_graph;
delete skel;
process_nr = 0;
settings_loaded = false;
is_triangle_mesh = false;
settings = new Settings();
gui_console = new GuiConsole();
mesh = new Mesh();
tmesh = NULL;
skel = new Skel();
skel_graph = new SkelGraph();
//extern Display* display;
display->erase(process_nr);
Print("All caches have been cleared.\n");
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Load File", ImGuiTreeNodeFlags_DefaultOpen))
{
if (ImGui::Button("Load Settings ", ImVec2(-1, 0)))
{
Print("[Button] Load Settings");
//extern Settings* settings;
//extern size_t print_to;
//extern size_t process_nr;
//extern bool settings_loaded;
if (process_nr == 0 && !settings_loaded)
{
settings->load(print_to);
if (settings->File.name.length() > 0)
{
settings_loaded = true;
process_nr = 1;
Print("\tdone.");
}
else
{
settings_loaded = false;
process_nr = 0;
Print("[error] Failed! Can not load \"Settings.csv\"!");
}
}
else
{
Print("If you want to reload file \"Settings.csv\", please click \"Reset\" button first.");
}
}
if (ImGui::Button("Isotropic Remeshing", ImVec2(-1, 0)))
{
Print("\n");
Print("[Button] Isotropic Remeshing");
//extern size_t process_nr;
if (process_nr >= 3)
{
Print("Please click \"Reset\" first!");
}
if (process_nr <= 0)
{
Print("Please load settings first!");
}
else if(process_nr == 1)
{
//extern bool settings_loaded;
if (settings_loaded)
{
//extern Settings* settings;
std::ostringstream t1;
t1 << "\tRemeshing " << settings->Remeshing.remeshing_out_suffix << " ...";
Print(t1.str());
std::ostringstream t2;
t2 << "\t - target_edge_length = " << settings->Remeshing.remeshing_edge_length << "\n"
<< "\t - number of iterations = " << settings->Remeshing.remeshing_nr_iter;
Print(t2.str());
std::string in_name = settings->File.name;
std::string in_path = settings->root_path + settings->File.folder_path + in_name;
size_t idx_dot = in_path.rfind('.');
std::string out_path = in_path.substr(0, idx_dot);
size_t idx_seg = out_path.rfind("_res");
if (idx_seg != out_path.npos) { out_path = out_path.substr(0, idx_seg); }
out_path += settings->Remeshing.remeshing_out_suffix;
MeshFile::isotropic_remeshing(in_path, out_path,
settings->Remeshing.remeshing_edge_length, settings->Remeshing.remeshing_nr_iter);
settings->File.name = in_name.substr(0, in_name.rfind('.')) + settings->Remeshing.remeshing_out_suffix;
Print("\tdone.");
}
}
else if (process_nr == 2)
{
//extern Mesh* mesh;
//extern Display* display;
//extern Settings* settings;
// reset loaded mesh -- similar to Reset
Print("\tRemoving current loaded mesh.\n");
process_nr = 1;
delete mesh;
mesh = NULL;
mesh = new Mesh();
display->erase(process_nr);
Print("\tdone.");
// isotropic remeshing -- same as process_nr == 1
std::ostringstream t1;
t1 << "\tRemeshing " << settings->Remeshing.remeshing_out_suffix << " ...";
Print(t1.str());
std::ostringstream t2;
t2 << "\t - target_edge_length = " << settings->Remeshing.remeshing_edge_length << "\n"
<< "\t - number of iterations = " << settings->Remeshing.remeshing_nr_iter;
Print(t2.str());
std::string in_name = settings->File.name;
std::string in_path = settings->root_path + settings->File.folder_path + in_name;
size_t idx_dot = in_path.rfind('.');
std::string out_path = in_path.substr(0, idx_dot);
size_t idx_seg = out_path.rfind("_res");
if (idx_seg != out_path.npos) { out_path = out_path.substr(0, idx_seg); }
out_path += settings->Remeshing.remeshing_out_suffix;
MeshFile::isotropic_remeshing(in_path, out_path,
settings->Remeshing.remeshing_edge_length, settings->Remeshing.remeshing_nr_iter);
settings->File.name = in_name.substr(0, in_name.rfind('.')) + settings->Remeshing.remeshing_out_suffix;
Print("\tdone.");
// reload mesh file -- same as Load Mesh File
Print("\tLoading mesh file ... ");
std::string path = settings->root_path + settings->File.folder_path + settings->File.name;
mesh->load(path);
if (mesh->is_triangle_mesh())
{
//extern bool is_triangle_mesh;
//extern Triangle_mesh* tmesh;
//extern Polyhedron* pmesh;
//extern Display* display;
is_triangle_mesh = true;
process_nr = 2;
//tmesh = &(mesh->get_tmesh());
pmesh = &(mesh->get_pmesh());
display->insert(*pmesh);
display->update();
}
Print("\tdone.");
}
}
if (ImGui::Button("Load Mesh File ", ImVec2(-1, 0)))
{
Print("\n");
Print("[Button] Load Mesh File");
//extern bool settings_loaded;
//extern size_t process_nr;
//extern Settings* settings;
//extern Mesh* mesh;
if (process_nr == 0)
{
Print("\tPlease load settings first!");
}
else if (process_nr >= 2)
{
Print("\tIf you want to reload mesh file, pleace click \"Reset\" button first!");
}
else if (process_nr == 1)
{
if (!settings_loaded)
{
Print("The settings load was not successful, please modify parameters in \"Settings.csv\" manually!");
}
else
{
Print("\tLoading mesh file ... ");
std::string path = settings->root_path + settings->File.folder_path + settings->File.name;
mesh->load(path);
if (mesh->is_triangle_mesh())
{
//extern bool is_triangle_mesh;
//extern Triangle_mesh* tmesh;
//extern Polyhedron* pmesh;
//extern Display* display;
is_triangle_mesh = true;
process_nr = 2;
//tmesh = &(mesh->get_tmesh());
pmesh = &(mesh->get_pmesh());
display->insert(*pmesh);
display->update();
}
Print("\tdone.");
}
} // process_nr == 1
} // if Button
} // group "Load File"
ImGui::Separator();
if (ImGui::CollapsingHeader("Skeletonization", ImGuiTreeNodeFlags_DefaultOpen))
{
if (ImGui::Button("Extract Skeleton ", ImVec2(-1, 0)))
{
Print("\n");
Print("[Button] Extract Skeleton");
//extern size_t process_nr;
//extern Display* display;
auto disp = display;
size_t& pro_nr = process_nr;
auto ins_skels = [disp, &pro_nr]()
{
//extern Settings* settings;
//extern Mesh* mesh;
//extern Skel* skel;
//extern SkelGraph* skel_graph;
skel->extract_to_end(*mesh);
if (skel_graph != NULL)
{
delete skel_graph;
skel_graph = NULL;
}
skel_graph = new SkelGraph(*skel, *mesh);
skel_graph->output_skel_graph_to_files(settings);
display->insert(*skel_graph);
display->update();
pro_nr = 3;
Print("\tdone.");
};
if (process_nr >= 4)
{
Print("If you want to re-extract the skeleton, please click \"Reset\" first!");
}
else if (process_nr <= 0)
{
Print("Please load settings first!");
}
else if (process_nr == 1)
{
Print("Please load mesh file first!");
}
else if (process_nr == 3)
{
Print("\tRe-extracting skeletons ...");
Print("\t\tclear all existing skeletons ...");
display->erase(process_nr);
Print("\t\tdone.");
ins_skels();
}
else if (process_nr == 2)
{
ins_skels();
}
}
if (ImGui::Button("Extract Segments", ImVec2(-1, 0)))
{
Print("[Button] Extract Segments");
//extern size_t process_nr;
//extern Display* display;
auto ins_segs = []()
{
//extern Settings* settings;
//extern Skel* skel;
//extern Polyhedron* pmesh;
//extern SkelGraph* skel_graph;
//extern Segmentation* segmentation;
//Skeleton& skeleton = skel->get_skeleton();
//std::string path = settings->root_path + settings->File.folder_path + settings->File.name;
segmentation->set_segments(*skel_graph, *pmesh);
display->insert(segmentation->get_segments());
display->update();
process_nr = 4;
};
switch (process_nr)
{
case 0:
{
Print("Please load settings first!");
break;
}
case 1:
{
Print("Please load mesh file first!");
break;
}
case 2:
{
Print("Please extract skeleton first!");
break;
}
case 3:
{
Print("\tRe-caculating segments ... ");
ins_segs();
Print("\t\tdone");
break;
}
case 4:
{
Print("\tRe-caculating segments ... ");
Print("\t\tclear all existing segments ... ");
display->erase(process_nr);
ins_segs();
Print("\t\tdone");
break;
}
default:
{
Print("\tPlease click \"Reset\" button first! ");
}
}
}
} // group "skeletonization"
ImGui::Separator();
if (ImGui::CollapsingHeader("Slicing", ImGuiTreeNodeFlags_DefaultOpen))
{
if (ImGui::Button("Get Next Stitch ", ImVec2(-1, 0)))
{
Print("[Button] Get Next Stitch");
std::cout << "" << std::endl;
}
if (ImGui::Button("Get Next layer ", ImVec2(-1, 0)))
{
Print("[Button] Get Next layer");
std::cout << "" << std::endl;
}
if (ImGui::Button("Slice To End ", ImVec2(-1, 0)))
{
Print("[Button] Slice To End");
std::cout << "" << std::endl;
}
}
ImGui::Separator();
// Set Parameter
if (ImGui::CollapsingHeader("Parameter", ImGuiTreeNodeFlags_DefaultOpen))
{
//extern Settings* settings;
// set para
ImGui::PushItemWidth(60);
ImGui::InputDouble("stitch_width ", &(settings->Stitch.stitch_width), 0, 0, "%.3f", 0);
ImGui::InputDouble("stitch_height", &(settings->Stitch.stitch_height), 0, 0, "%.3f", 0);
ImGui::InputDouble("obj_scale ", &(settings->Stitch.obj_scale), 0, 0, "%.3f", 0);
ImGui::InputDouble("layer0_offset", &(settings->Stitch.layer0_offset), 0, 0, "%.3f", 0);
ImGui::PopItemWidth();
}
ImGui::End();
}
// Display::
Display::Display() { }
Display::Display(std::string path) { this->insert(path); }
Display::Display(IglGeometry geometry) { this->insert(geometry); }
Display::Display(Triangle_mesh& tmesh) { this->insert_tmesh(tmesh); }
Display::Display(Skeleton& skeleton) { this->insert_skeleton(skeleton); }
Display::Display(Skel& skel) { this->insert_skel(skel); }
Display::Display(SkelGraph& skel_graph) { this->insert_skel_graph(skel_graph); }
Display::Display(Segment& segment) { this->insert_segment(segment); }
Display::Display(std::vector<Segment>& segments) { this->insert_segments(segments); }
Display::Display(Stitches& stitches) { this->insert_stitches(stitches); }
Display::Display(MAT_3d& V, MAT_2i& E, MAT_3i& F) { this->insert(V, E, F); }
Display::Display(MAT_3d& V, MAT_3i& F) { this->insert(V, F); }
Display::Display(MAT_3d& V, MAT_2i& E) { this->insert(V, E); }
Display::Display(MAT_3d& V, MAT_2i& E, MAT_3i& F, RVec_3d color_V, RVec_3d color_E, RVec_3d color_F)
{
this->insert(V, E, F, color_V, color_E, color_F);
}
Display::Display(MAT_3d& V, MAT_3i& F, RVec_3d color_V, RVec_3d color_F)
{
this->insert(V, F, color_V, color_F);
}
Display::Display(MAT_3d& V, MAT_2i& E, RVec_3d color_V, RVec_3d color_E)
{
this->insert(V, E, color_V, color_E);
}
// public
void Display::erase(size_t& process_nr)
{
std::vector<std::string> key_names = { "mesh", "skel", "segment"};
std::vector<size_t> idxs;
switch (process_nr)
{
case 2: // erase tmesh, skel x3
{
idxs.push_back(0);
idxs.push_back(1);
idxs.push_back(2);
break;
}
case 3: // erase skel x3
{
idxs.push_back(1);
idxs.push_back(2);
break;
}
case 4: // erase segment xN
{
idxs.push_back(2);
break;
}
default:
{
for (size_t i = 0; i < key_names.size(); i++)
{
idxs.push_back(i);
}
break;
}
} // switch
for (size_t i : idxs)
{
std::string& key_name = key_names[i];
size_t offset = 0;
while (true)
{
auto& geoms = this->igl_geoms;
size_t numGeo = geoms.size();
if (offset >= numGeo) { break; }
auto it_geoms_begin = geoms.begin();
auto it_geoms_end = geoms.end();
auto it_geoms = it_geoms_begin + offset;
std::string& geo_name = it_geoms->name;
auto pos = geo_name.find(key_name);
if (pos != geo_name.npos)
{
geoms.erase(it_geoms);
}
else
{
offset++;
}
} // while
} // for
this->update();
return;
}
void Display::update()
{
size_t id_max = this->viewer.data_list.size() - 1;
for (; id_max > 0; --id_max)
{
this->viewer.erase_mesh(id_max);
}
this->viewer.data().clear();
size_t idx = 0;
for (IglGeometry& my_geom : this->igl_geoms)
{
size_t numV = my_geom.V.rows();
size_t numE = my_geom.E.rows();
size_t numF = my_geom.F.rows();
if (numV <= 0) continue;
if (idx > 0)
{
this->viewer.append_mesh();
}
this->viewer.data().clear();
set_parameter(my_geom.name);
if (numE > 0 && numF == 0)
{
//this->viewer.data().set_vertices(my_geom.V);
this->viewer.data().set_edges(my_geom.V, my_geom.E, my_geom.color_E);
//MAT_3d colors_V;
//my_geom.get_colors_V(colors_V);
//this->viewer.data().set_colors(colors_V);
}
else if (numE == 0 && numF > 0)
{
this->viewer.data().set_mesh(my_geom.V, my_geom.F);
MAT_3d colors_V;
MAT_3d colors_F;
my_geom.get_colors_V(colors_V);
my_geom.get_colors_F(colors_F);
this->viewer.data().set_colors(colors_V);
this->viewer.data().set_colors(colors_F);
}
else if (numE > 0 && numF > 0)
{
this->viewer.data().set_mesh(my_geom.V, my_geom.F);
this->viewer.data().set_edges(my_geom.V, my_geom.E, my_geom.color_E);
MAT_3d colors_V;
MAT_3d colors_F;
my_geom.get_colors_V(colors_V);
my_geom.get_colors_F(colors_F);
this->viewer.data().set_colors(colors_V);
this->viewer.data().set_colors(colors_F);
}
else
{
this->viewer.data().set_vertices(my_geom.V);
MAT_3d colors_V;
my_geom.get_colors_V(colors_V);
this->viewer.data().set_colors(colors_V);
}
idx++;
}
//this->viewer.data().show_overlay_depth = false;
this->set_camera_zoom();
}
// private
void Display::insert_obj(std::string path)
{
std::ifstream input;
input.open(path, std::ios::in);
if (!input.is_open())
{
std::cout << "Cannot open file \"" << path << "\"!";
return;
}
std::string line = "";
std::vector<std::string> buf;
std::vector<std::vector<double>> v;
std::vector<std::vector<int>> e;
std::vector<std::vector<int>> f;
while (std::getline(input, line))
{
buf.clear();
// divide elements in each line
std::stringstream inputL(line);
std::string str;
while (inputL >> str)
{
buf.push_back(str);
}
if (buf.size() == 0) { continue; }
auto it_buf_begin = buf.begin();
std::string line_type = *it_buf_begin;
if (line_type == "v")
{
std::vector<double> v_;
v_.resize(3);
v_[0] = stod(*(it_buf_begin + 1));
v_[1] = stod(*(it_buf_begin + 2));
v_[2] = stod(*(it_buf_begin + 3));
v.push_back(v_);
}
else if (line_type == "l")
{
std::vector<int> e_;
e_.resize(2);
e_[0] = stoi(*(it_buf_begin + 1)) - 1;
e_[1] = stoi(*(it_buf_begin + 2)) - 1;
e.push_back(e_);
}
else if (line_type == "f")
{
std::vector<int> f_;
f_.resize(3);
f_[0] = stoi(*(it_buf_begin + 1)) - 1;
f_[1] = stoi(*(it_buf_begin + 2)) - 1;
f_[2] = stoi(*(it_buf_begin + 3)) - 1;
f.push_back(f_);
}
}
input.close();
int numV = v.size();
int numE = e.size();
int numF = f.size();
IglGeometry my_geom;
my_geom.name = path.substr(path.rfind("/"));
my_geom.id = this->igl_geoms.size();
MAT_3d& my_V = my_geom.V;
MAT_2i& my_E = my_geom.E;
MAT_3i& my_F = my_geom.F;
if (numV > 0)
{
my_geom.color_V = IglColor::black();
my_V.resize(numV, 3);
for (int i = 0; i < numV; i++)
{
my_V.row(i) << v[i][0], v[i][1], v[i][2];
}
}
if (numE > 0)
{
my_geom.color_E = IglColor::black();
my_E.resize(numE, 2);
for (int i = 0; i < numE; i++)
{
my_E.row(i) << e[i][0], e[i][1];
}
}
if (numF > 0)
{
my_geom.color_F = IglColor::yellow();
my_F.resize(numF, 3);
for (int i = 0; i < numF; i++)
{
my_F.row(i) << f[i][0], f[i][1], f[i][2];
}
}
this->insert_geometry(my_geom);
}
void Display::insert_off(std::string path)
{
IglGeometry my_geom;
my_geom.name = path.substr(path.rfind("/"));
my_geom.id = this->igl_geoms.size();
my_geom.color_V = IglColor::white();
my_geom.color_F = IglColor::yellow();
MAT_3d& my_V = my_geom.V;
MAT_3i& my_F = my_geom.F;
igl::readOFF(path, my_V, my_F);
this->insert_geometry(my_geom);
}
void Display::insert_stl(std::string path)
{
std::ifstream input(path);
IglGeometry my_geom;
my_geom.name = path.substr(path.rfind("/"));
my_geom.id = this->igl_geoms.size();
my_geom.color_V = IglColor::black();
my_geom.color_F = IglColor::yellow();
MAT_3d& my_V = my_geom.V;
MAT_3i& my_F = my_geom.F;
MAT_3d N;
igl::readSTL(input, my_V, my_F, N);
this->insert_geometry(my_geom);
}
void Display::insert_skel_graph(SkelGraph& skel_graph)
{
const std::vector<SkelNode>& skel_nodes = skel_graph.get_skel_nodes();
const std::vector<SkelEdge>& skel_edges = skel_graph.get_skel_edges();
const std::vector<SkelExtn>& skel_extns = skel_graph.get_skel_extns();
const auto ins_skeleton = [&skel_nodes, &skel_edges, this]()
{
size_t numV = skel_nodes.size();
size_t numE = skel_edges.size();
MAT_3d my_V;
MAT_2i my_E;
my_V.resize(numV, 3);
my_E.resize(numE, 2);
size_t v_i = 0;
for (SkelNode nd : skel_nodes)
{
const Point& p = nd.point();
my_V.row(v_i) << p.x(), p.y(), p.z();
v_i++;
}
size_t e_i = 0;
for (SkelEdge eg : skel_edges)
{
my_E.row(e_i) << eg.source() - 1, eg.target() - 1;
e_i++;
}
size_t id = this->igl_geoms.size();
return IglGeometry("skel", id, my_V, my_E, IglColor::yellow(), IglColor::yellow());
};
const auto ins_extension = [&skel_extns, this]()
{
MAT_3d my_V;
MAT_2i my_E;
size_t numE = skel_extns.size();
size_t numV = 2 * numE;
my_V.resize(numV, 3);
my_E.resize(numE, 2);
size_t v_i = 0;
size_t e_i = 0;
for (SkelExtn my_extn : skel_extns)
{
const Point& top_node = my_extn.get_skel_node().point();
const Point& extn_point = my_extn.get_extn_point();
my_V.row(v_i) << top_node.x(), top_node.y(), top_node.z();
my_V.row(v_i + 1) << extn_point.x(), extn_point.y(), extn_point.z();
my_E.row(e_i) << v_i, v_i + 1;
v_i += 2;
e_i++;
}
size_t id = this->igl_geoms.size();