18 #include <CGAL/boost/graph/Euler_operations.h>
19 #include <CGAL/boost/graph/helpers.h>
20 #include <CGAL/boost/graph/copy_face_graph.h>
21 #include <CGAL/circulator.h>
22 #include <Eigen/Dense>
37 #pragma warning(disable : 4244) // for VS-2015
38 #pragma warning(disable : 4267)
43 #define COLOR_NUMBER 10000
44 #define USE_COLOR_METRIC
45 #define AC_BUFFER 1024 * 10000
53 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
58 VertexColorMap *_v_cm,
59 const std::string &_Input_File_Name,
60 const std::string &_File_Name,
62 const int &_NVertices,
63 const bool _Normal_flipping,
64 const bool _Use_metric,
65 const float &_Metric_thread,
66 const bool _Use_forget_metric,
67 const int &_Forget_value,
68 const bool _Compression_selected,
69 const bool _Adaptive_quantization,
70 const bool _Is_bijection_selected)
72 #ifdef DBG_Main_Function
74 DBG_print_mesh_geometry(_pMesh, _pm,
"beginning of Main_Function()");
75 DBG_print_mesh_vertexcolor(_pMesh, _v_cm,
"beginning of Main_Function()");
80 return "Some faces of the mesh are not triangles. No compression was done.";
84 FEVV::make_vertex_property_map< HalfedgeGraph, Color_Unit >(_pMesh);
86 FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
87 vertex_Component_Number =
88 FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
89 Vertex_Flag = FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
90 Vertex_Number = FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
91 Vertex_Sign = FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
93 FEVV::make_vertex_property_map< HalfedgeGraph, Vector >(_pMesh);
94 vertex_Q_Index = FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
95 vertex_Region_Number =
96 FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
97 vertex_Removal_Order =
98 FEVV::make_vertex_property_map< HalfedgeGraph, int >(_pMesh);
100 facet_tag = FEVV::make_face_property_map< HalfedgeGraph, int >(_pMesh);
101 facet_Component_Number =
102 FEVV::make_face_property_map< HalfedgeGraph, int >(_pMesh);
103 Facet_Flag = FEVV::make_face_property_map< HalfedgeGraph, int >(_pMesh);
104 facet_normal = FEVV::make_face_property_map< HalfedgeGraph, Vector >(_pMesh);
110 compute_normals(_pMesh, _pm);
113 auto time_start = std::chrono::steady_clock::now();
116 if(FILE *file = fopen(_Input_File_Name.c_str(),
"r"))
118 fseek(file, 0, SEEK_END);
119 this->Initial_file_size = ftell(file);
123 this->Initial_file_size = 0;
126 this->Is_Bijection_Enabled = _Is_bijection_selected;
131 this->Global_Initialization(_pMesh, _Qbit, _File_Name.c_str(), _pm, _v_cm);
133 #ifdef DBG_Main_Function
134 DBG_print_mesh_vertexcolor(
135 _pMesh, _v_cm,
"in Main_Function() after Global_Initialization()");
139 if(_Adaptive_quantization)
141 this->Adaptive_Quantization(_pMesh,
154 this->Simplification(_pMesh,
164 unsigned Connectivity_size = 0, Color_size = 0, Total_size = 0;
167 if(_Compression_selected)
169 this->Compression(_pMesh,
178 unsigned Number_layers = this->GlobalCountOperation;
182 auto time_end = std::chrono::steady_clock::now();
183 std::chrono::duration< double > time_diff = time_end - time_start;
186 double Connectivity_rate = (double)Connectivity_size / Init_number_vertices;
187 double Color_rate = (double)Color_size / Init_number_vertices;
188 double Total_rate = (double)Total_size * 8 / Init_number_vertices;
189 double Geometry_rate = Total_rate - Connectivity_rate - Color_rate;
191 std::ostringstream Res_tmp;
192 Res_tmp <<
"Base mesh : " << std::setw(3) << Final_number_vertices
194 Res_tmp <<
"Connectivity : " << float(Connectivity_rate) <<
" b/v \n";
195 Res_tmp <<
"Geometry : " << float(Geometry_rate) <<
" b/v\n";
196 Res_tmp <<
"Color : " << float(Color_rate) <<
" b/v\n";
197 Res_tmp <<
"Total size : " << float(Total_rate) <<
" b/v\n";
198 if(this->Initial_file_size != 0)
199 Res_tmp <<
"Ratio : " << (float)Total_size / this->Initial_file_size * 100
202 Res_tmp <<
"Ratio : "
204 Res_tmp <<
"Number of layers : " << Number_layers <<
"\n";
205 Res_tmp <<
"Calculation time : " << (float)time_diff.count() <<
" seconds \n";
206 std::string Res = Res_tmp.str();
209 std::cout << Res << std::endl;
210 #ifdef DBG_Main_Function
211 DBG_print_mesh_geometry(_pMesh, _pm,
"end of Main_Function()");
212 DBG_print_mesh_vertexcolor(_pMesh, _v_cm,
"end of Main_Function()");
221 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
228 VertexColorMap *v_cm)
236 this->Color_Initialization(_pMesh, v_cm);
240 this->Multiple_Components_Initialization(_pMesh, pm, _Qbit);
243 this->Quantization(_pMesh, pm);
249 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
256 typedef boost::graph_traits< HalfedgeGraph >
GraphTraits;
264 auto vertex_iterator_pair =
vertices(_pMesh);
267 for(; pVertex != pVertex_end; ++pVertex)
270 put(this->vertex_Component_Number, *pVertex, -1);
280 auto face_iterator_pair =
faces(_pMesh);
283 for(
face_iterator pFacet = pFacet_beg; pFacet != pFacet_end; ++pFacet)
285 put(this->facet_tag, *pFacet, -1);
288 int Component_index = 0;
290 for(
face_iterator pFacet = pFacet_beg; pFacet != pFacet_end; ++pFacet)
293 if(
get(this->facet_tag, *pFacet) == -1)
295 bool Is_closed =
true;
296 bool Is_seed_edge_found =
false;
298 float xmin = 50000., ymin = 50000., zmin = 50000.;
299 float xmax = -50000., ymax = -50000., zmax = -50000.;
301 int Number_vertices = 0;
303 put(this->facet_tag, *pFacet, Component_index);
305 std::list< face_descriptor > facets;
306 facets.push_front(*pFacet);
308 while(!facets.empty())
313 put(this->facet_tag,
F, Component_index);
316 put(this->facet_Component_Number,
F, Component_index);
318 area += Area_Facet_Triangle(
halfedge(
F, _pMesh), _pMesh, pm);
321 CGAL::Halfedge_around_face_circulator< HalfedgeGraph > pHalfedge(
323 CGAL::Halfedge_around_face_circulator< HalfedgeGraph > end(pHalfedge);
327 if(
get(this->vertex_Component_Number,
target(*pHalfedge, _pMesh)) ==
330 put(this->vertex_Component_Number,
331 target(*pHalfedge, _pMesh),
357 if(CGAL::is_border_edge(*pHalfedge, _pMesh))
360 if(!Is_seed_edge_found)
362 if(((!CGAL::is_border_edge(*pHalfedge, _pMesh)) &&
363 (!Is_Border_Vertex(*pHalfedge, _pMesh)) &&
364 (!Is_Border_Vertex(
opposite(*pHalfedge, _pMesh), _pMesh))) ||
368 Is_seed_edge_found =
true;
371 put(this->vertex_Seed_Edge,
372 target(*pHalfedge, _pMesh),
373 2 * Component_index);
374 put(this->vertex_Seed_Edge,
376 2 * Component_index + 1);
381 if(pNFacet != boost::graph_traits< HalfedgeGraph >::null_face() &&
382 get(this->facet_tag, pNFacet) == -1)
384 facets.push_front(pNFacet);
385 put(this->facet_tag, pNFacet, Component_index);
386 put(this->facet_Component_Number, pNFacet, Component_index);
388 }
while(++pHalfedge != end);
391 this->xmin.push_back(xmin);
392 this->ymin.push_back(ymin);
393 this->zmin.push_back(zmin);
395 this->xmax.push_back(xmax);
396 this->ymax.push_back(ymax);
397 this->zmax.push_back(zmax);
399 double HighestBB = -5000;
400 if(xmax - xmin > HighestBB)
401 HighestBB = xmax - xmin;
402 if(ymax - ymin > HighestBB)
403 HighestBB = ymax - ymin;
404 if(zmax - zmin > HighestBB)
405 HighestBB = zmax - zmin;
407 this->HighestLengthBB.push_back(HighestBB);
410 Vector e1(xmax - xmin, 0., 0.);
411 Vector e2(0., ymax - ymin, 0.);
417 double volume = base_area * (zmax - zmin);
422 volume *= std::pow(((
double)10.0 / (
double)HighestBB), 3.0);
423 area *= std::pow(((
double)10.0 / (
double)HighestBB), 2.0);
426 this->ComponentVolume.push_back(volume);
427 this->ComponentArea.push_back(area);
428 this->ComponentNumberVertices.push_back(Number_vertices);
431 this->IsClosed.push_back(Is_closed);
437 this->NumberComponents = Component_index;
440 std::list< Point_Int > pi;
441 std::list< Color_Unit > cu;
444 for(
int i = 0; i < this->NumberComponents; i++)
447 this->ListOperation.push_back(li);
450 this->Connectivity.push_back(li);
453 this->Geometry.push_back(pi);
456 this->VertexColor.push_back(cu);
459 this->NumberSymbol.push_back(li);
460 this->NumberVertices.push_back(li);
463 this->AlphaRange.push_back(li);
464 this->AlphaOffset.push_back(li);
465 this->GammaRange.push_back(li);
466 this->GammaOffset.push_back(li);
469 this->ComponentOperations.push_back(0);
472 this->NumberDecimation.push_back(0);
475 this->NumberChangeQuantization.push_back(0);
476 this->NumberColorQuantization.push_back(0);
479 this->Qbit.push_back(_Qbit);
482 this->QuantizationCorrectVector.push_back(li);
485 this->NumberQuantizationLayer.push_back(li);
488 this->NumberProcessedVertices.push_back(li);
489 this->ColorChildcellIndex.push_back(li);
490 this->ColorEncoderIndex.push_back(li);
493 #ifdef DBG_Multiple_Components_Initialization
496 <<
"--- function " << __func__ << std::endl;
498 <<
"this->NumberComponents=" << this->NumberComponents
503 <<
"vertex->Seed_Edge=" << std::endl;
505 auto vertex_iterator_pair =
vertices(_pMesh);
508 for(; pVertex != pVertex_end; ++pVertex)
510 auto s =
get(this->vertex_Seed_Edge, *pVertex);
511 std::cout <<
"DBG " << s << std::endl;
517 <<
"vertex->Component_Number=" << std::endl;
519 auto vertex_iterator_pair =
vertices(_pMesh);
522 for(; pVertex != pVertex_end; ++pVertex)
524 auto n =
get(this->vertex_Component_Number, *pVertex);
525 std::cout <<
"DBG " << n << std::endl;
531 <<
"face->tag=" << std::endl;
533 auto face_iterator_pair =
faces(_pMesh);
536 for(; pFacet != pFacet_end; ++pFacet)
538 auto t =
get(this->facet_tag, *pFacet);
539 std::cout <<
"DBG " << t << std::endl;
545 <<
"face->Component_Number=" << std::endl;
547 auto face_iterator_pair =
faces(_pMesh);
550 for(; pFacet != pFacet_end; ++pFacet)
552 auto n =
get(this->facet_Component_Number, *pFacet);
553 std::cout <<
"DBG " << n << std::endl;
565 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
570 typedef boost::graph_traits< HalfedgeGraph >
GraphTraits;
575 for(
int i = 0; i < this->NumberComponents; i++)
577 float max = this->xmax[i] - this->xmin[i];
579 if(this->ymax[i] - this->ymin[i] > max)
580 max = this->ymax[i] - this->ymin[i];
582 if(this->zmax[i] - this->zmin[i] > max)
583 max = this->zmax[i] - this->zmin[i];
585 int NbInteraval = std::pow(2., (
int)this->Qbit[i]);
587 float Q_Step = max / (float)NbInteraval;
588 this->Quantization_Step.push_back(Q_Step);
592 auto vertex_iterator_pair =
vertices(_pMesh);
607 float xtmp = point[0];
608 float ytmp = point[1];
609 float ztmp = point[2];
615 int Component_ID =
get(this->vertex_Component_Number, *pVert);
617 int Qx = (int)(ceil((x - (
double)this->xmin[Component_ID]) /
618 (
double)this->Quantization_Step[Component_ID])) -
622 int Qy = (int)(ceil((y - (
double)this->ymin[Component_ID]) /
623 (double)this->Quantization_Step[Component_ID])) -
627 int Qz = (int)(ceil((z - (
double)this->zmin[Component_ID]) /
628 (
double)this->Quantization_Step[Component_ID])) -
635 Point3d(this->xmin[Component_ID] +
636 (Qx + 0.5) * this->Quantization_Step[Component_ID],
637 this->ymin[Component_ID] +
638 (Qy + 0.5) * this->Quantization_Step[Component_ID],
639 this->zmin[Component_ID] +
640 (Qz + 0.5) * this->Quantization_Step[Component_ID]));
643 #ifdef DBG_Quantization
646 <<
"--- function " << __func__ << std::endl;
649 std::cout <<
"DBG " << __func__ <<
" "
650 <<
"vertex->point()=" << std::endl;
652 auto vertex_iterator_pair =
vertices(_pMesh);
655 for(; pVertex != pVertex_end; ++pVertex)
657 auto p3d =
get(*pm, *pVertex);
658 std::cout <<
"DBG " << __func__ <<
" " << p3d[0] <<
" " << p3d[1] <<
" "
659 << p3d[2] << std::endl;
669 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
674 typedef boost::graph_traits< HalfedgeGraph >
GraphTraits;
676 typedef typename boost::property_traits< VertexColorMap >::value_type Color;
682 this->IsColored =
true;
684 auto vertex_iterator_pair =
vertices(_pMesh);
689 Color c =
get(*v_cm, *vi);
690 this->OnlyColor[0] = c[0];
691 this->OnlyColor[1] = c[1];
692 this->OnlyColor[2] = c[2];
695 this->IsOneColor =
true;
696 for(; vi != vi_end; ++vi)
698 Color c =
get(*v_cm, *vi);
699 if(c[0] != this->OnlyColor[0] || c[1] != this->OnlyColor[1] ||
700 c[2] != this->OnlyColor[2])
702 this->IsOneColor =
false;
710 if((this->IsColored) && (!this->IsOneColor))
714 float C0_min = 5000, C1_min = 5000, C2_min = 5000;
715 float C0_max = -5000, C1_max = -5000, C2_max = -5000;
718 auto vertex_iterator_pair =
vertices(_pMesh);
721 for(; pVertex != pVertex_end; ++pVertex)
723 Color c =
get(*v_cm, *pVertex);
724 Temp_color[0] = c[0];
725 Temp_color[1] = c[1];
726 Temp_color[2] = c[2];
730 RGB_To_LAB(Temp_color[0], Temp_color[1], Temp_color[2], New_color);
733 put(*v_cm, *pVertex, Color(New_color[0], New_color[1], New_color[2]));
736 if(New_color[0] > C0_max)
737 C0_max = New_color[0];
738 if(New_color[0] < C0_min)
739 C0_min = New_color[0];
741 if(New_color[1] > C1_max)
742 C1_max = New_color[1];
743 if(New_color[1] < C1_min)
744 C1_min = New_color[1];
746 if(New_color[2] > C2_max)
747 C2_max = New_color[2];
748 if(New_color[2] < C2_min)
749 C2_min = New_color[2];
754 float Color_max = C0_max - C0_min;
755 if(C1_max - C1_min > Color_max)
756 Color_max = C1_max - C1_min;
757 if(C2_max - C2_min > Color_max)
758 Color_max = C2_max - C2_min;
761 this->C0_Min = C0_min;
762 this->C1_Min = C1_min;
763 this->C2_Min = C2_min;
766 this->Color_Quantization_Step = (float)((Color_max) / Nb_interaval);
771 float New_vertex_color[3];
772 float Reconstructed_color[3];
775 pVertex = vertex_iterator_pair.first;
776 for(; pVertex != pVertex_end; ++pVertex)
778 Color c =
get(*v_cm, *pVertex);
779 Temp_color[0] = c[0];
780 Temp_color[1] = c[1];
781 Temp_color[2] = c[2];
783 int Qc0 = (int)(floor(
784 (Temp_color[0] - C0_min) / this->Color_Quantization_Step + 0.5));
785 int Qc1 = (int)(floor(
786 (Temp_color[1] - C1_min) / this->Color_Quantization_Step + 0.5));
787 int Qc2 = (int)(floor(
788 (Temp_color[2] - C2_min) / this->Color_Quantization_Step + 0.5));
790 Resulting_color.
c0 = Qc0;
791 Resulting_color.
c1 = Qc1;
792 Resulting_color.
c2 = Qc2;
793 put(this->vertex_color_int,
796 Resulting_color.
c0, Resulting_color.
c1, Resulting_color.
c2));
798 New_vertex_color[0] =
799 this->C0_Min + Resulting_color.
c0 * this->Color_Quantization_Step;
800 New_vertex_color[1] =
801 this->C1_Min + Resulting_color.
c1 * this->Color_Quantization_Step;
802 New_vertex_color[2] =
803 this->C2_Min + Resulting_color.
c2 * this->Color_Quantization_Step;
808 Reconstructed_color);
809 for(
int i = 0; i < 3; i++)
811 if(Reconstructed_color[i] < 0.)
812 Reconstructed_color[i] = 0.;
813 if(Reconstructed_color[i] > 1.)
814 Reconstructed_color[i] = 1.;
821 Color(Reconstructed_color[0],
822 Reconstructed_color[1],
823 Reconstructed_color[2]));
827 #ifdef DBG_Color_Initialization
830 <<
"--- function " << __func__ << std::endl;
832 <<
"this->IsColored=" << this->IsColored << std::endl;
834 <<
"this->IsOneColor=" << this->IsOneColor << std::endl;
839 <<
"vertex->color()=" << std::endl;
841 auto vertex_iterator_pair =
vertices(_pMesh);
844 for(; pVertex != pVertex_end; ++pVertex)
846 Color c =
get(*v_cm, *pVertex);
847 std::cout <<
"DBG " << c[0] <<
" " << c[1] <<
" " << c[2]
852 if((this->IsColored) && (!this->IsOneColor))
855 <<
"vertex->color_int()=" << std::endl;
857 auto vertex_iterator_pair =
vertices(_pMesh);
860 for(; pVertex != pVertex_end; ++pVertex)
863 std::cout <<
"DBG " << c.
c0 <<
" " << c.
c1 <<
" " << c.
c2
872 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
877 VertexColorMap *_v_cm,
878 const int &_NVertices,
879 const bool _Normal_flipping,
880 const bool _Use_metric,
881 const float &_Metric_thread,
882 const bool _Use_forget_metric,
883 const int &_Forget_value,
891 unsigned Last_Number = 0;
893 int Operation_choice = -1;
900 Last_Number = Current_Number;
903 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
908 if(this->ComponentOperations[Component_ID] ==
909 this->GlobalCountOperation)
914 this->Recalculate_Component_Area(_pMesh, _pm, Component_ID, temp);
917 int QG = Estimate_Geometry_Quantization(
918 this->ComponentVolume[Component_ID],
919 this->ComponentArea[Component_ID],
920 this->ComponentNumberVertices[Component_ID]);
927 if(QG < (
int)this->Qbit[Component_ID])
930 Operation_choice = 1;
933 this->Diminush_Geometry_Quantization_Precision(
934 _pMesh, Component_ID, _pm);
936 this->Qbit[Component_ID]--;
937 this->NumberChangeQuantization[Component_ID]++;
939 this->ComponentOperations[Component_ID]++;
940 this->ListOperation[Component_ID].push_front(Operation_choice);
945 Operation_choice = 0;
950 this->Decimation_Conquest(_pMesh,
958 this->Regulation(_pMesh,
967 this->NumberDecimation[Component_ID] += 1;
968 this->ComponentOperations[Component_ID] += 1;
969 this->ListOperation[Component_ID].push_front(Operation_choice);
971 unsigned Diff_number_vertices =
973 this->ComponentNumberVertices[Component_ID] += Diff_number_vertices;
975 if(Diff_number_vertices == 0)
976 this->Remove_Last_Phase_Elements(Component_ID);
987 this->GlobalCountOperation++;
990 if(Current_Number < (
unsigned)_NVertices)
993 }
while((Current_Number != Last_Number) || (Continue));
995 compute_normals(_pMesh, _pm);
1001 FILE *Operation_order = fopen(
"Operation_order.txt",
"w");
1002 fclose(Operation_order);
1005 unsigned Last_Number = 0;
1007 int Operation_choice = -1;
1009 std::vector< int > QC_Initials;
1010 std::vector< int > QC_Finals;
1013 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
1016 double Max_color, Mean_color;
1017 int Number_vertices = 0;
1020 this->Calculate_Edge_Color_Difference(
1021 _pMesh, Component_ID, Max_color, Mean_color, Number_vertices);
1022 double Mean_Max = Mean_color / Max_color;
1028 int QC_init = floor(-57.966 * Mean_Max * Mean_Max + 5.311 * Mean_Max +
1030 int QC_fin = floor(84.548 * Mean_Max * Mean_Max - 33.723 * Mean_Max +
1033 QC_Initials.push_back(QC_init);
1034 QC_Finals.push_back(QC_fin);
1041 Last_Number = Current_Number;
1044 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
1049 if(this->ComponentOperations[Component_ID] ==
1050 this->GlobalCountOperation)
1053 this->Recalculate_Component_Area(_pMesh, _pm, Component_ID, temp);
1054 int Number_of_vertices = 0;
1055 double Max_color = 0., Mean_color = 0.;
1056 this->Calculate_Edge_Color_Difference(
1057 _pMesh, Component_ID, Max_color, Mean_color, Number_of_vertices);
1058 double Mean_Max = Mean_color / Max_color;
1062 floor(-1.181 * log(Mean_Max * this->ComponentArea[Component_ID] /
1063 (
double)Number_of_vertices) +
1065 int QG = Estimate_Geometry_Quantization(
1066 this->ComponentVolume[Component_ID],
1067 this->ComponentArea[Component_ID],
1068 this->ComponentNumberVertices[Component_ID]);
1072 if((8 - this->NumberColorQuantization[Component_ID] >
1073 QC_Initials[Component_ID]) &&
1074 (!this->IsOneColor))
1077 Operation_choice = 2;
1081 this->Diminush_Color_Quantization_Precision(
1082 _pMesh, Component_ID, _v_cm);
1084 this->NumberColorQuantization[Component_ID]++;
1085 this->ComponentOperations[Component_ID]++;
1086 this->ListOperation[Component_ID].push_front(Operation_choice);
1090 else if(((8 - this->NumberColorQuantization[Component_ID] > QC) &&
1091 (QC >= QC_Finals[Component_ID])) &&
1092 (!this->IsOneColor))
1094 Operation_choice = 2;
1098 this->Diminush_Color_Quantization_Precision(
1099 _pMesh, Component_ID, _v_cm);
1101 this->NumberColorQuantization[Component_ID]++;
1102 this->ComponentOperations[Component_ID]++;
1103 this->ListOperation[Component_ID].push_front(Operation_choice);
1107 else if(((
int)this->Qbit[Component_ID] > QG) && (QG >= 5))
1110 Operation_choice = 1;
1113 this->Diminush_Geometry_Quantization_Precision(
1114 _pMesh, Component_ID, _pm);
1116 this->Qbit[Component_ID]--;
1117 this->NumberChangeQuantization[Component_ID]++;
1119 this->ComponentOperations[Component_ID]++;
1120 this->ListOperation[Component_ID].push_front(Operation_choice);
1126 Operation_choice = 0;
1131 this->Decimation_Conquest(_pMesh,
1139 this->Regulation(_pMesh,
1148 this->NumberDecimation[Component_ID] += 1;
1149 unsigned Diff_number_vertices =
1152 this->ComponentOperations[Component_ID] += 1;
1153 this->ListOperation[Component_ID].push_front(Operation_choice);
1155 this->ComponentNumberVertices[Component_ID] += Diff_number_vertices;
1157 if(Diff_number_vertices == 0)
1158 this->Remove_Last_Phase_Elements(Component_ID);
1163 FILE *Operation_order = fopen(
"Operation_order.txt",
"a");
1164 fprintf(Operation_order,
1165 "Component_ID = %d Operation = %d \n",
1168 fclose(Operation_order);
1175 this->GlobalCountOperation++;
1178 if(Current_Number < (
unsigned)_NVertices)
1181 }
while((Current_Number != Last_Number) || (Continue));
1183 compute_normals(_pMesh, _pm);
1188 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1191 HalfedgeGraph &mesh)
1193 typedef boost::graph_traits< HalfedgeGraph >
GraphTraits;
1200 auto vertex_iterator_pair =
vertices(mesh);
1206 put(this->Vertex_Flag, *pVertex,
FREE);
1207 put(this->Vertex_Number, *pVertex, i);
1208 put(this->Vertex_Sign, *pVertex,
NOSIGN);
1212 auto face_iterator_pair =
faces(mesh);
1215 for(
face_iterator pFacet = pFacet_beg; pFacet != pFacet_end; ++pFacet)
1217 put(this->Facet_Flag, *pFacet,
FREE);
1222 #if 1 // DBG-ELO+beg
1223 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1228 const HalfedgeGraph &_pMesh,
1229 const PointMap *_pm)
1237 std::cout << title <<
" :" << std::endl;
1238 std::cout <<
" psource = " << psource[0] <<
", " << psource[1] <<
", "
1239 << psource[2] << std::endl;
1240 std::cout <<
" ptarget = " << ptarget[0] <<
", " << ptarget[1] <<
", "
1241 << ptarget[2] << std::endl;
1242 bool is_border_edge =
1243 (
face(h, _pMesh) == boost::graph_traits< HalfedgeGraph >::null_face());
1244 std::cout <<
" is_border = " << std::boolalpha << is_border_edge
1248 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1253 const PointMap *_pm)
1256 std::cout << title <<
" = " << p[0] <<
", " << p[1] <<
", " << p[2]
1260 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1266 std::ostringstream s;
1267 s <<
"(" << p[0] <<
", " << p[1] <<
", " << p[2] <<
")";
1270 #endif // DBG-ELO+end
1273 #if 1 // DBG-ELO+beg
1274 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1278 const HalfedgeGraph &_pMesh,
1279 const PointMap *_pm)
1284 std::ostringstream s;
1285 s << vertex_to_string(vsource, _pm) <<
"->" << vertex_to_string(vtarget, _pm);
1288 #endif // DBG-ELO+end
1291 #if 1 // DBG-ELO+beg
1292 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1297 const PointMap *_pm)
1304 else if((p1[0] == p2[0]) && (p1[1] < p2[1]))
1306 else if((p1[0] == p2[0]) && (p1[1] == p2[1]) && (p1[2] < p2[2]))
1312 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1316 const HalfedgeGraph &_pMesh,
1317 const PointMap *_pm)
1322 std::ostringstream s;
1323 if(v_inf_to_v(vsource, vtarget, _pm))
1324 s << vertex_to_string(vsource, _pm) <<
"->"
1325 << vertex_to_string(vtarget, _pm);
1327 s << vertex_to_string(vtarget, _pm) <<
"->"
1328 << vertex_to_string(vsource, _pm);
1332 #endif // DBG-ELO+end
1339 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
1343 const PointMap *_pm,
1344 const bool Normal_flipping,
1345 const bool Use_metric,
1346 const float &Metric_thread,
1347 const bool Use_forget_metric,
1348 const int &Forget_value,
1349 const int &Component_ID)
1351 typedef boost::graph_traits< HalfedgeGraph >
GraphTraits;
1354 #ifdef DBG_Decimation_Conquest
1355 static unsigned int Decimation_Conquest_call_cnt = 0;
1356 Decimation_Conquest_call_cnt++;
1357 std::cout <<
"Decimation_Conquest_call_cnt = " << Decimation_Conquest_call_cnt
1362 double Max_color, Mean_color;
1365 this->Calculate_Edge_Color_Difference(
1366 _pMesh, Component_ID, Max_color, Mean_color, Temp_NV);
1367 this->Recalculate_Component_Area(_pMesh, _pm, Component_ID, Number_facets);
1369 (double)this->ComponentArea[Component_ID] / (
double)Number_facets;
1377 int Number_vertices = 0;
1378 int Number_symbol = 0;
1381 auto halfedge_iterator_pair = halfedges(_pMesh);
1385 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * Component_ID) ||
1387 2 * Component_ID + 1))
1391 #ifdef DBG_Decimation_Conquest
1392 std::cout <<
"marker #1" << std::endl;
1394 int loop_counter = 0;
1399 put(this->Vertex_Flag,
1404 put(this->Vertex_Sign,
target(First_halfedge, _pMesh),
PLUS);
1405 put(this->Vertex_Sign,
1409 std::queue< halfedge_descriptor > Halfedges;
1410 Halfedges.push(First_halfedge);
1415 while(!Halfedges.empty())
1417 #ifdef DBG_Decimation_Conquest
1418 std::cout <<
"marker #2" << std::endl;
1419 std::cout <<
"loop " << ++loop_counter << std::endl;
1421 h = Halfedges.front();
1422 #ifdef DBG_Decimation_Conquest
1432 if(CGAL::is_border(h, _pMesh) ==
true)
1434 #ifdef DBG_Decimation_Conquest
1435 std::cout <<
"marker #3" << std::endl;
1436 std::cout <<
"(h->next()->vertex()->Vertex_Flag == FREE)"
1437 << (
get(this->Vertex_Flag,
target(
next(h, _pMesh), _pMesh)) ==
1440 std::cout <<
"(valence >= 3)" << (valence >= 3) << std::endl;
1441 std::cout <<
"(valence <= 4)" << (valence <= 4) << std::endl;
1442 std::cout <<
"(Is_Border_Vertex(h->next()) == true)"
1443 << (Is_Border_Vertex(
next(h, _pMesh), _pMesh) ==
true)
1451 #ifdef DBG_Decimation_Conquest
1452 std::cout <<
"marker #4" << std::endl;
1459 (valence >= 3) && (valence <= 6) &&
1460 (!Is_Border_Vertex(
next(h, _pMesh), _pMesh)))
1462 #ifdef DBG_Decimation_Conquest
1463 std::cout <<
"marker #5" << std::endl;
1466 type = Find_Type(_pMesh, h, valence);
1469 bool Manifold_condition =
1470 Is_Manifold_Property_Violated(_pMesh, h, type, valence);
1472 bool Normal_flipping_condition =
false;
1475 Normal_flipping_condition =
1476 Is_Normal_Flipping_Occured(_pMesh, _pm, h, valence);
1480 bool Geometric_metric_condition =
false;
1484 if(Use_forget_metric)
1487 Geometric_metric_condition =
false;
1489 Geometric_metric_condition = Is_Geometric_Metric_Violated(
1490 _pMesh, _pm, h, type, valence, Metric_thread);
1493 Geometric_metric_condition = Is_Geometric_Metric_Violated(
1494 _pMesh, _pm, h, type, valence, Metric_thread);
1496 bool Is_Color_Too_Important =
false;
1498 #ifdef USE_COLOR_METRIC
1500 Is_Color_Too_Important = this->Error_Projected_Surface(
1501 _pMesh, _pm, h, Component_ID, Mean_color, Mean_area);
1503 #ifdef DBG_Decimation_Conquest
1504 std::cout <<
"Is_Color_Too_Important = " << Is_Color_Too_Important
1510 bool Check_all_condition =
false;
1512 if((!Manifold_condition) && (!Geometric_metric_condition) &&
1513 (!Normal_flipping_condition) && (!Is_Color_Too_Important))
1514 Check_all_condition =
true;
1516 if(Check_all_condition)
1519 #ifdef DBG_Decimation_Conquest
1520 std::cout <<
"marker #6" << std::endl;
1529 Point3d Coordinates_removed_vertex =
1532 Change_Real_Int(Coordinates_removed_vertex, Component_ID);
1535 if((this->IsColored) && (!this->IsOneColor))
1538 Removed_vertex_color = Get_Vertex_Color(
next(g, _pMesh), _pMesh);
1542 Average_color = Get_Average_Vertex_Color_Lee(g, valence, _pMesh);
1546 Color_Unit Color_diff = Removed_vertex_color - Average_color;
1547 this->InterVertexColor.push_front(Color_diff);
1552 this->InterConnectivity.push_front(valence - 3);
1555 Point3d Barycenter = Barycenter_Patch_Before_Removal(g, _pMesh, _pm);
1557 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
1560 #ifdef DBG_Decimation_Conquest
1563 CGAL::Euler::remove_center_vertex(
next(g, _pMesh), _pMesh);
1569 for(
int j = 0; j < (valence - 1); j++)
1571 g =
next(g, _pMesh);
1574 put(this->Vertex_Flag,
1578 if(!(CGAL::is_border_edge(g, _pMesh)))
1579 Halfedges.push(
opposite(g, _pMesh));
1583 Retriangulation(_pMesh, g, valence, 0, Component_ID, _pm);
1585 Vector normal = Normal_Patch(g, valence, _pMesh, _pm);
1587 Vector T1 = Calculate_T1_T2(h, normal, T2, _pMesh, _pm);
1589 if(normal ==
Vector(0.0, 0.0, 0.0))
1593 normal =
Vector(0., 0., 1.);
1595 else if(T1 ==
Vector(0.0, 0.0, 0.0))
1599 normal =
Vector(0., 0., 1.);
1601 else if(T2 ==
Vector(0.0, 0.0, 0.0))
1605 normal =
Vector(0., 0., 1.);
1611 if(this->Is_Bijection_Enabled)
1612 Frenet_Coordinates = Frenet_Rotation(Dist, T1, T2, normal);
1614 Frenet_Coordinates = Dist;
1616 this->InterGeometry.push_front(Frenet_Coordinates);
1622 #ifdef DBG_Decimation_Conquest
1623 std::cout <<
"marker #7" << std::endl;
1626 this->InterConnectivity.push_front(4);
1646 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
1661 if(!CGAL::is_border_edge(
next(h, _pMesh), _pMesh))
1664 if(!CGAL::is_border_edge(
prev(h, _pMesh), _pMesh))
1672 (valence >= 3) && (valence <= 4) &&
1673 (Is_Border_Vertex(
next(h, _pMesh), _pMesh) ==
true))
1675 #ifdef DBG_Decimation_Conquest
1676 std::cout <<
"marker #8" << std::endl;
1683 type = Find_Type(_pMesh, h, valence);
1684 #ifdef DBG_Decimation_Conquest
1690 bool Check_border_structure =
true;
1697 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
1699 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
1701 int Number_neighboring_border_vertices = 0;
1702 CGAL_For_all(Hvc, Hvc_end)
1707 if(Is_Border_Vertex(
opposite(*Hvc, _pMesh), _pMesh))
1709 Number_neighboring_border_vertices++;
1712 if(CGAL::is_border(*Hvc, _pMesh))
1714 First_border_edge = *Hvc;
1717 #ifdef DBG_Decimation_Conquest
1718 print_halfedge(
"First_border_edge", First_border_edge, _pMesh, _pm);
1719 std::cout <<
"Number_neighboring_border_vertices = "
1720 << Number_neighboring_border_vertices << std::endl;
1723 if(Number_neighboring_border_vertices > 2)
1724 Check_border_structure =
false;
1726 if(Is_Manifold_Property_Violated(_pMesh, g, type, valence))
1727 Check_border_structure =
false;
1730 if(Check_border_structure)
1732 #ifdef DBG_Decimation_Conquest
1733 std::cout <<
"marker #9" << std::endl;
1735 print_halfedge(
"First_border_edge", First_border_edge, _pMesh, _pm);
1740 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > vh_it =
1741 CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(vh1,
1743 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > vh_it_end =
1748 CGAL_For_all(vh_it, vh_it_end)
1752 Check_border_structure =
false;
1756 #ifdef DBG_Decimation_Conquest
1757 std::cout <<
"Check_border_structure = " << std::boolalpha
1758 << Check_border_structure << std::endl;
1765 int Count_border_edges = 1;
1766 Standard_edge = First_border_edge;
1767 First_border_edge =
next(First_border_edge, _pMesh);
1769 for(; First_border_edge != Standard_edge;
1770 First_border_edge =
next(First_border_edge, _pMesh))
1772 Count_border_edges++;
1773 if(Count_border_edges > 5)
1777 if(Count_border_edges <= 3)
1778 Check_border_structure =
false;
1781 if(Count_border_edges == 4)
1785 Check_border_structure =
false;
1806 if(Check_border_structure)
1808 #ifdef DBG_Decimation_Conquest
1809 std::cout <<
"marker #10" << std::endl;
1816 this->InterConnectivity.push_front(valence + 2);
1818 Point3d Real_vertex_position =
1821 Change_Real_Int(Real_vertex_position, Component_ID);
1825 if((this->IsColored) && (!this->IsOneColor))
1827 Removed_vertex_color = Get_Vertex_Color(
next(h, _pMesh), _pMesh);
1831 std::vector< halfedge_descriptor > Border_edges;
1832 int Number_jump = 0;
1834 while(CGAL::is_border_edge(
next(g, _pMesh), _pMesh) ==
false)
1840 Border_edges.push_back(
opposite(g, _pMesh));
1841 #ifdef DBG_Decimation_Conquest
1843 "Border_edges.push_back 1",
opposite(g, _pMesh), _pMesh, _pm);
1845 for(
int i = 0; i < (valence - 2); i++)
1848 Border_edges.push_back(
opposite(g, _pMesh));
1849 #ifdef DBG_Decimation_Conquest
1851 "Border_edges.push_back 2",
opposite(g, _pMesh), _pMesh, _pm);
1855 for(
int i = 0; i < (valence - 1); i++)
1860 CGAL_assertion(!CGAL::is_border(Temp, _pMesh));
1861 #ifdef DBG_Decimation_Conquest
1862 std::cout <<
"remove face" << std::endl;
1869 #ifdef DBG_Decimation_Conquest
1870 std::cout <<
"marker #11" << std::endl;
1873 prev(
opposite(Border_edges[valence - 2], _pMesh), _pMesh);
1877 #ifdef DBG_Decimation_Conquest
1879 bool is_border_Retriangulation_edge =
1880 (
face(Retriangulation_edge, _pMesh) ==
1881 boost::graph_traits< HalfedgeGraph >::null_face());
1884 Border_edges[valence - 2],
1888 "Retriangulation_edge", Retriangulation_edge, _pMesh, _pm);
1890 std::cout <<
"add face" << std::endl;
1892 CGAL::Euler::add_face_to_border(
1893 Retriangulation_edge,
opposite(Border_edges[0], _pMesh), _pMesh);
1896 opposite(Border_edges[Number_jump], _pMesh);
1900 put(this->Vertex_Flag,
1904 if((type == 1) || (type == 2) || (type == 4))
1906 if(
get(this->Vertex_Sign,
1908 put(this->Vertex_Sign,
1914 if(
get(this->Vertex_Sign,
1916 put(this->Vertex_Sign,
1923 Barycenter_Patch_After_Removal(Input_gate, valence, _pMesh, _pm);
1924 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
1926 if((this->IsColored) && (!this->IsOneColor))
1930 Average_color = Get_Average_Vertex_Color_After_Removal(
1931 g, valence, _pMesh);
1932 Color_Unit Color_diff = Removed_vertex_color - Average_color;
1934 this->InterVertexColor.push_front(Color_diff);
1938 Vector normal = Normal_Patch(g, valence, _pMesh, _pm);
1941 Vector T1 = Calculate_T1_T2(g, normal, T2, _pMesh, _pm);
1943 if(normal ==
Vector(0.0, 0.0, 0.0))
1945 normal =
Vector(0, 0, 1);
1955 if(this->Is_Bijection_Enabled)
1956 Frenet_Coordinates = Frenet_Rotation(Dist, T1, T2, normal);
1958 Frenet_Coordinates = Dist;
1963 this->InterGeometry.push_front(Frenet_Coordinates);
1965 if(Number_jump == 0)
1966 Halfedges.push(Border_edges[1]);
1968 Halfedges.push(Border_edges[0]);
1971 else if(valence == 4)
1973 #ifdef DBG_Decimation_Conquest
1974 std::cout <<
"marker #12" << std::endl;
1977 prev(
opposite(Border_edges[valence - 2], _pMesh), _pMesh);
1979 if(((Number_jump == 0) && ((type == 5) || (type == 8))) ||
1980 ((Number_jump == 1) && ((type == 6) || (type == 7))) ||
1981 ((Number_jump == 2) && ((type == 5) || (type == 8))))
1984 #ifdef DBG_Decimation_Conquest
1985 std::cout <<
"add face" << std::endl;
1987 CGAL::Euler::add_face_to_border(Retriangulation_edge,
1990 put(this->Facet_Flag,
1994 #ifdef DBG_Decimation_Conquest
1995 std::cout <<
"add face" << std::endl;
1997 CGAL::Euler::add_face_to_border(Retriangulation_edge,
2000 put(this->Facet_Flag,
2005 else if(((Number_jump == 0) && ((type == 6) || (type == 7))) ||
2006 ((Number_jump == 1) && ((type == 5) || (type == 8))) ||
2007 ((Number_jump == 2) && ((type == 6) || (type == 7))))
2009 #ifdef DBG_Decimation_Conquest
2010 std::cout <<
"add face" << std::endl;
2012 CGAL::Euler::add_face_to_border(
opposite(Border_edges[2], _pMesh),
2015 put(this->Facet_Flag,
2021 #ifdef DBG_Decimation_Conquest
2022 std::cout <<
"add face" << std::endl;
2024 CGAL::Euler::add_face_to_border(
2025 Retriangulation_edge, Temp_border, _pMesh);
2026 put(this->Facet_Flag,
2032 opposite(Border_edges[Number_jump], _pMesh);
2036 if((type == 5) || (type == 8))
2046 else if((type == 6) || (type == 7))
2054 put(this->Vertex_Sign,
2060 for(
int i = 0; i < valence - 1; i++)
2063 put(this->Vertex_Flag,
2067 if((
unsigned)i != (
unsigned)Number_jump)
2068 Halfedges.push(Border_edges[i]);
2071 if((this->IsColored) && (!this->IsOneColor))
2076 Get_Vertex_Color(
opposite(Border_edges[0], _pMesh), _pMesh);
2077 Color_Unit Color_1 = Get_Vertex_Color(Border_edges[0], _pMesh);
2078 Color_Unit Color_2 = Get_Vertex_Color(Border_edges[1], _pMesh);
2079 Color_Unit Color_3 = Get_Vertex_Color(Border_edges[2], _pMesh);
2081 (int)(Color_0.
c0 + Color_1.
c0 + Color_2.
c0 + Color_3.
c0) / 4.0;
2083 (int)(Color_0.
c1 + Color_1.
c1 + Color_2.
c1 + Color_3.
c1) / 4.0;
2085 (int)(Color_0.
c2 + Color_1.
c2 + Color_2.
c2 + Color_3.
c2) / 4.0;
2087 Color_Unit Color_diff = Removed_vertex_color - Average_color;
2089 this->InterVertexColor.push_front(Color_diff);
2097 P1 =
get(*_pm,
target(Border_edges[0], _pMesh));
2098 P2 =
get(*_pm,
target(Border_edges[1], _pMesh));
2099 P3 =
get(*_pm,
target(Border_edges[2], _pMesh));
2101 Point3d Barycenter((P0[0] + P1[0] + P2[0] + P3[0]) / 4,
2102 (P0[1] + P1[1] + P2[1] + P3[1]) / 4,
2103 (P0[2] + P1[2] + P2[2] + P3[2]) / 4);
2105 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
2108 Vector normal = Normal_Patch(g, valence, _pMesh, _pm);
2111 Vector T1 = Calculate_T1_T2(g, normal, T2, _pMesh, _pm);
2113 if(normal ==
Vector(0.0, 0.0, 0.0))
2117 normal =
Vector(0, 0, 1);
2122 if(this->Is_Bijection_Enabled)
2123 Frenet_Coordinates = Frenet_Rotation(Dist, T1, T2, normal);
2125 Frenet_Coordinates = Dist;
2127 this->InterGeometry.push_front(Frenet_Coordinates);
2133 #ifdef DBG_Decimation_Conquest
2134 std::cout <<
"marker #13" << std::endl;
2137 this->InterConnectivity.push_front(4);
2156 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
2171 if(!CGAL::is_border_edge(
next(h, _pMesh), _pMesh))
2174 if(!CGAL::is_border_edge(
prev(h, _pMesh), _pMesh))
2183 #ifdef DBG_Decimation_Conquest
2184 std::cout <<
"marker #14" << std::endl;
2187 this->InterConnectivity.push_front(4);
2192 put(this->Vertex_Flag,
2209 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
2225 if(CGAL::is_border_edge(
next(h, _pMesh), _pMesh) ==
false)
2228 if(CGAL::is_border_edge(
prev(h, _pMesh), _pMesh) ==
false)
2232 if((this->IsColored) && (!this->IsOneColor))
2234 #ifdef DBG_Decimation_Conquest
2235 std::cout <<
"marker #15" << std::endl;
2237 while(!this->InterVertexColor.empty())
2239 Color_Unit Col = this->InterVertexColor.front();
2240 this->InterVertexColor.pop_front();
2241 this->VertexColor[Component_ID].push_front(Col);
2246 while(!InterConnectivity.empty())
2248 #ifdef DBG_Decimation_Conquest
2249 std::cout <<
"marker #16" << std::endl;
2251 int Symbol = InterConnectivity.front();
2252 InterConnectivity.pop_front();
2253 this->Connectivity[Component_ID].push_front(Symbol);
2257 while(!InterGeometry.empty())
2259 #ifdef DBG_Decimation_Conquest
2260 std::cout <<
"marker #17" << std::endl;
2263 InterGeometry.pop_front();
2264 this->Geometry[Component_ID].push_front(Geo);
2267 this->NumberVertices[Component_ID].push_front(Number_vertices);
2268 this->NumberSymbol[Component_ID].push_front(Number_symbol);
2272 this->DumpSymbolDecimation = Number_symbol;
2275 return Number_vertices;
2280 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
2285 const int &Component_ID,
2287 VertexColorMap *_v_cm)
2294 std::queue< halfedge_descriptor > Halfedges;
2297 this->Qbit[Component_ID] + this->NumberChangeQuantization[Component_ID];
2299 int Alpha_range = Decoder.
get_bits(Qbit + 1);
2300 int Alpha_offset = Decoder.
get_bits(Qbit + 1);
2301 int Gamma_range = Decoder.
get_bits(Qbit + 1);
2302 int Gamma_offset = Decoder.
get_bits(Qbit + 1);
2304 if(this->Smallest_Alpha < 0)
2305 Alpha_offset = Alpha_offset + this->Smallest_Alpha;
2307 if(this->Smallest_Gamma < 0)
2308 Gamma_offset = Gamma_offset + this->Smallest_Gamma;
2310 bool check_alpha =
false;
2311 bool check_gamma =
false;
2313 if((Alpha_range == 0) || (Alpha_range == 1))
2319 if((Gamma_range == 0) || (Gamma_range == 1))
2325 float Color_step = 0.0;
2326 if(this->NumberColorQuantization[Component_ID] == 0)
2327 Color_step = this->Color_Quantization_Step;
2329 Color_step = this->Color_Quantization_Step *
2330 std::pow(2.0, this->NumberColorQuantization[Component_ID]);
2336 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * Component_ID) ||
2338 2 * Component_ID + 1))
2343 Halfedges.push(*hi);
2347 while(!Halfedges.empty())
2349 h = Halfedges.front();
2353 (
get(this->Facet_Flag,
face(h, _pMesh)) ==
2358 int valence = Decoder.
decode(Connectivity) + 3;
2368 std::vector< Point3d > Vertices;
2369 Point3d Barycenter = Barycenter_Patch_After_Removal(pass, 3, _pMesh, _pm);
2370 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
2372 Vector normal = Triangle_Normal(_pMesh, _pm, pass);
2374 Vector T1 = Calculate_T1_T2(pass, normal, T2, _pMesh, _pm);
2376 if(T1 ==
Vector(0.0, 0.0, 0.0))
2380 normal =
Vector(0, 0, 1);
2383 else if(normal ==
Vector(0.0, 0.0, 0.0))
2387 normal =
Vector(0, 0, 1);
2389 else if(T2 ==
Vector(0.0, 0.0, 0.0))
2393 normal =
Vector(0, 0, 1);
2398 if(check_alpha ==
false)
2400 Frenet.
x = Decoder.
decode(alpha);
2401 Frenet.
y = Decoder.
decode(alpha);
2409 if(check_gamma ==
false)
2410 Frenet.
z = Decoder.
decode(gamma);
2415 Frenet.
x -= Alpha_offset;
2416 Frenet.
y -= Alpha_offset;
2417 Frenet.
z -= Gamma_offset;
2420 if(this->Is_Bijection_Enabled)
2421 Diff = Inverse_Frenet_Rotation(Frenet, T1, T2, normal);
2426 Point3d Center_vertex = this->Change_Int_Real(Center, Component_ID);
2432 int Selected_region = 500000;
2434 std::vector< int > T_Bin;
2435 std::vector< int > T_Number;
2437 for(
int i = 0; i < valence; i++)
2439 int N1 =
get(this->vertex_Region_Number,
target(reg, _pMesh));
2440 bool Is_existed =
false;
2441 for(
unsigned int j = 0; j < T_Bin.size(); j++)
2451 T_Bin.push_back(N1);
2452 T_Number.push_back(1);
2454 reg =
next(reg, _pMesh);
2457 for(
unsigned int i = 0; i < T_Number.size(); i++)
2459 if(T_Number[i] > Max)
2462 std::vector< int > T_possible_bin;
2463 for(
unsigned int i = 0; i < T_Number.size(); i++)
2465 if(T_Number[i] == Max)
2466 T_possible_bin.push_back(T_Bin[i]);
2469 if(T_possible_bin.size() == 1)
2471 Selected_region = T_possible_bin[0];
2475 Selected_region = 5000;
2476 for(
unsigned int i = 0; i < T_possible_bin.size(); i++)
2478 if(T_possible_bin[i] < Selected_region)
2479 Selected_region = T_possible_bin[i];
2485 g = CGAL::Euler::add_center_vertex(g, _pMesh);
2486 init_vertex_attributes(
target(g, _pMesh));
2488 put(*_pm,
target(g, _pMesh), Center_vertex);
2489 put(this->vertex_Seed_Edge,
target(g, _pMesh), -1);
2491 int RO = this->GlobalCountOperation - Decompress_count;
2493 put(this->vertex_Removal_Order,
target(g, _pMesh), RO);
2495 put(this->vertex_Region_Number,
target(g, _pMesh), Selected_region);
2497 if(Selected_region != -1)
2498 this->m_Number_Vertices_Per_Regions[Selected_region]++;
2504 g =
next(g, _pMesh);
2508 if(!CGAL::is_border_edge(
prev(g, _pMesh), _pMesh))
2513 if(!CGAL::is_border_edge(
next(h1, _pMesh), _pMesh))
2515 if(!CGAL::is_border_edge(
prev(h1, _pMesh), _pMesh))
2521 if(!CGAL::is_border_edge(
prev(g, _pMesh), _pMesh))
2526 if(!CGAL::is_border_edge(
next(h2, _pMesh), _pMesh))
2528 if(!CGAL::is_border_edge(
prev(h2, _pMesh), _pMesh))
2533 if((this->IsColored) && (!this->IsOneColor))
2539 Predicted_color = Get_Average_Vertex_Color_Lee(g, valence, _pMesh);
2542 Color_difference.
c0 =
2543 this->Decoder.
decode(this->Color_0_Model) + this->Smallest_C0;
2544 Color_difference.
c1 =
2545 this->Decoder.
decode(this->Color_1_Model) + this->Smallest_C1;
2546 Color_difference.
c2 =
2547 this->Decoder.
decode(this->Color_2_Model) + this->Smallest_C2;
2549 Color_Unit CV = Predicted_color + Color_difference;
2551 put(this->vertex_color_int,
2556 LAB[0] = this->C0_Min + CV.
c0 * Color_step;
2557 LAB[1] = this->C1_Min + CV.
c1 * Color_step;
2558 LAB[2] = this->C2_Min + CV.
c2 * Color_step;
2564 typename boost::property_traits< VertexColorMap >::value_type Color;
2567 Color(RGB[0], RGB[1], RGB[2]));
2570 if((this->IsColored) && (this->IsOneColor))
2572 g =
next(h, _pMesh);
2574 typename boost::property_traits< VertexColorMap >::value_type Color;
2577 Color(this->OnlyColor[0], this->OnlyColor[1], this->OnlyColor[2]));
2585 if(!CGAL::is_border_edge(
next(h, _pMesh), _pMesh))
2587 if(!CGAL::is_border_edge(
prev(h, _pMesh), _pMesh))
2597 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
2602 const int &Component_ID,
2604 VertexColorMap *_v_cm)
2606 #ifdef DBG_Un_Decimation_Conquest
2607 static unsigned int Un_Decimation_Conquest_call_cnt = 0;
2608 std::cout <<
"__func__"
2609 <<
" Un_Decimation_Conquest_call_cnt = "
2610 << ++Un_Decimation_Conquest_call_cnt << std::endl;
2615 int Number_connectivity_symbols;
2616 if(this->IsClosed[Component_ID])
2617 Number_connectivity_symbols = 5;
2619 Number_connectivity_symbols = 7;
2624 std::queue< halfedge_descriptor > Halfedges;
2627 this->Qbit[Component_ID] + this->NumberChangeQuantization[Component_ID];
2629 int Alpha_range = Decoder.
get_bits(Qbit + 1);
2630 int Alpha_offset = Decoder.
get_bits(Qbit + 1);
2631 int Gamma_range = Decoder.
get_bits(Qbit + 1);
2632 int Gamma_offset = Decoder.
get_bits(Qbit + 1);
2634 if(this->Smallest_Alpha < 0)
2635 Alpha_offset = Alpha_offset + this->Smallest_Alpha;
2637 if(this->Smallest_Gamma < 0)
2638 Gamma_offset = Gamma_offset + this->Smallest_Gamma;
2640 bool check_alpha =
false;
2641 bool check_gamma =
false;
2643 if((Alpha_range == 0) || (Alpha_range == 1))
2649 if((Gamma_range == 0) || (Gamma_range == 1))
2656 float Color_step = 0.0;
2657 if(this->NumberColorQuantization[Component_ID] == 0)
2658 Color_step = this->Color_Quantization_Step;
2660 Color_step = this->Color_Quantization_Step *
2661 std::pow(2.0, this->NumberColorQuantization[Component_ID]);
2668 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * Component_ID) ||
2670 2 * Component_ID + 1))
2682 Halfedges.push(*hi);
2686 #ifdef DBG_Un_Decimation_Conquest
2687 int dbg_loop_counter = 0;
2690 while(!Halfedges.empty())
2692 #ifdef DBG_Un_Decimation_Conquest
2693 std::cout << __func__ <<
" marker #2"
2694 <<
" loop " << ++dbg_loop_counter << std::endl;
2695 std::cout << __func__ <<
" Halfedges.size()=" << Halfedges.size()
2699 h = Halfedges.front();
2702 #ifdef DBG_Un_Decimation_Conquest
2703 if(Un_Decimation_Conquest_call_cnt == 2)
2707 unsigned int valence = 0, type = 0;
2709 if(CGAL::is_border(h, _pMesh) ==
true)
2717 valence = Decoder.
decode(Connectivity) + 3;
2720 if((valence >= 3) && (valence <= 6))
2722 type = Find_Type(_pMesh, h, valence);
2729 Vector normal = Normal_Patch(pass, valence, _pMesh, _pm);
2731 Vector T1 = Calculate_T1_T2(h, normal, T2, _pMesh, _pm);
2733 if(T1 ==
Vector(0.0, 0.0, 0.0))
2737 normal =
Vector(0, 0, 1);
2740 else if(normal ==
Vector(0.0, 0.0, 0.0))
2744 normal =
Vector(0, 0, 1);
2746 else if(T2 ==
Vector(0.0, 0.0, 0.0))
2750 normal =
Vector(0, 0, 1);
2754 bool Check_Validity = Remove_Edges(_pMesh, g, type);
2755 Check_Validity =
false;
2758 if(Check_Validity ==
false)
2760 #ifdef DBG_Un_Decimation_Conquest
2761 if(Un_Decimation_Conquest_call_cnt == 9 && dbg_loop_counter == 1044)
2762 bool dbg_dummy =
true;
2767 std::vector< Point3d > Vertices;
2769 Barycenter_Patch_After_Removal(pass, valence, _pMesh, _pm);
2770 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
2773 if(check_alpha ==
false)
2775 Frenet.
x = Decoder.
decode(alpha);
2776 Frenet.
y = Decoder.
decode(alpha);
2778 else if(check_alpha ==
true)
2783 if(check_gamma ==
false)
2784 Frenet.
z = Decoder.
decode(gamma);
2785 else if(check_gamma ==
true)
2788 Frenet.
x -= Alpha_offset;
2789 Frenet.
y -= Alpha_offset;
2790 Frenet.
z -= Gamma_offset;
2793 if(this->Is_Bijection_Enabled)
2794 Diff = Inverse_Frenet_Rotation(Frenet, T1, T2, normal);
2802 Point3d Center_vertex = this->Change_Int_Real(Center, Component_ID);
2807 int Selected_region = 500000;
2809 std::vector< int > T_Bin;
2810 std::vector< int > T_Number;
2812 for(
int i = 0; i < (int)valence; i++)
2814 int N1 =
get(this->vertex_Region_Number,
target(reg, _pMesh));
2815 bool Is_existed =
false;
2816 for(
unsigned int j = 0; j < T_Bin.size(); j++)
2826 T_Bin.push_back(N1);
2827 T_Number.push_back(1);
2829 reg =
next(reg, _pMesh);
2832 for(
unsigned int i = 0; i < T_Number.size(); i++)
2834 if(T_Number[i] > Max)
2837 std::vector< int > T_possible_bin;
2838 for(
unsigned int i = 0; i < T_Number.size(); i++)
2840 if(T_Number[i] == Max)
2841 T_possible_bin.push_back(T_Bin[i]);
2844 if(T_possible_bin.size() == 1)
2846 Selected_region = T_possible_bin[0];
2850 Selected_region = 5000;
2851 for(
unsigned int i = 0; i < T_possible_bin.size(); i++)
2853 if(T_possible_bin[i] < Selected_region)
2854 Selected_region = T_possible_bin[i];
2858 g = CGAL::Euler::add_center_vertex(g, _pMesh);
2859 init_vertex_attributes(
target(g, _pMesh));
2860 put(*_pm,
target(g, _pMesh), Center_vertex);
2861 #ifdef DBG_Un_Decimation_Conquest
2862 std::cout << __func__ <<
" marker PM#1"
2863 <<
" loop " << dbg_loop_counter << std::endl;
2864 std::cout << __func__
2865 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
2869 put(this->vertex_Region_Number,
target(g, _pMesh), Selected_region);
2871 if(Selected_region != -1)
2872 this->m_Number_Vertices_Per_Regions[Selected_region]++;
2874 int RO = this->GlobalCountOperation - this->Decompress_count;
2875 put(this->vertex_Removal_Order,
target(g, _pMesh), RO);
2884 for(
unsigned int k = 0; k < (valence - 1); k++)
2889 put(this->Vertex_Flag,
2892 if(CGAL::is_border_edge(g, _pMesh) ==
false)
2893 Halfedges.push(
opposite(g, _pMesh));
2896 put(this->vertex_Seed_Edge,
target(
next(g, _pMesh), _pMesh), -1);
2898 if((this->IsColored) && (!this->IsOneColor))
2903 Predicted_color = Get_Average_Vertex_Color_Lee(g, valence, _pMesh);
2906 Color_difference.
c0 =
2907 this->Decoder.
decode(this->Color_0_Model) + this->Smallest_C0;
2908 Color_difference.
c1 =
2909 this->Decoder.
decode(this->Color_1_Model) + this->Smallest_C1;
2910 Color_difference.
c2 =
2911 this->Decoder.
decode(this->Color_2_Model) + this->Smallest_C2;
2913 Color_Unit CV = Predicted_color + Color_difference;
2915 put(this->vertex_color_int,
2920 LAB[0] = this->C0_Min + CV.
c0 * Color_step;
2921 LAB[1] = this->C1_Min + CV.
c1 * Color_step;
2922 LAB[2] = this->C2_Min + CV.
c2 * Color_step;
2927 typedef typename boost::property_traits< VertexColorMap >::value_type
2931 Color(RGB[0], RGB[1], RGB[2]));
2933 #ifdef DBG_Un_Decimation_Conquest
2934 std::cout << __func__ <<
" marker #3"
2935 <<
" loop " << dbg_loop_counter << std::endl;
2936 std::cout << __func__ <<
" vertex="
2937 << vertex_to_string(
target(
next(g, _pMesh), _pMesh), _pm)
2939 std::cout << __func__ <<
" Color=" << RGB[0] <<
" " << RGB[1] <<
" "
2940 << RGB[2] << std::endl;
2945 if((this->IsColored) && (this->IsOneColor))
2947 g =
next(h, _pMesh);
2948 typedef typename boost::property_traits< VertexColorMap >::value_type
2953 this->OnlyColor[0], this->OnlyColor[1], this->OnlyColor[2]));
2955 #ifdef DBG_Un_Decimation_Conquest
2956 std::cout << __func__ <<
" marker #4"
2957 <<
" loop " << dbg_loop_counter << std::endl;
2958 std::cout << __func__
2959 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
2961 std::cout << __func__ <<
" Color=" << this->OnlyColor[0] <<
" "
2962 << this->OnlyColor[1] <<
" " << this->OnlyColor[2]
2969 else if((valence == 8) || (valence == 9))
2972 type = Find_Type(_pMesh, h, valence - 5);
2976 Vector normal = Normal_Patch(pass, valence - 5, _pMesh, _pm);
2978 Vector T1 = Calculate_T1_T2(h, normal, T2, _pMesh, _pm);
2980 if(normal ==
Vector(0.0, 0.0, 0.0))
2984 normal =
Vector(0, 0, 1);
2989 if(check_alpha ==
false)
2991 Frenet.
x = Decoder.
decode(alpha);
2992 Frenet.
y = Decoder.
decode(alpha);
2994 else if(check_alpha ==
true)
3000 if(check_gamma ==
false)
3001 Frenet.
z = Decoder.
decode(gamma);
3002 else if(check_gamma ==
true)
3005 Frenet.
x -= Alpha_offset;
3006 Frenet.
y -= Alpha_offset;
3007 Frenet.
z -= Gamma_offset;
3010 if(this->Is_Bijection_Enabled)
3011 Diff = Inverse_Frenet_Rotation(Frenet, T1, T2, normal);
3021 if((this->IsColored) && (!this->IsOneColor))
3023 Predicted_color.
c0 =
3024 Decoder.
decode(this->Color_0_Model) + this->Smallest_C0;
3025 Predicted_color.
c1 =
3026 Decoder.
decode(this->Color_1_Model) + this->Smallest_C1;
3027 Predicted_color.
c2 =
3028 Decoder.
decode(this->Color_2_Model) + this->Smallest_C2;
3035 Barycenter_Patch_After_Removal(pass, 3, _pMesh, _pm);
3036 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
3039 Point3d Center_vertex = this->Change_Int_Real(Center, Component_ID);
3043 if((this->IsColored) && (!this->IsOneColor))
3045 Average_color = Get_Average_Vertex_Color_After_Removal(g, 3, _pMesh);
3049 std::vector< halfedge_descriptor > Border_edges;
3050 int Number_jump = 0;
3052 if(CGAL::is_border_edge(
next(g, _pMesh), _pMesh))
3054 if(CGAL::is_border_edge(
prev(g, _pMesh), _pMesh))
3057 g =
next(g, _pMesh);
3060 Border_edges.push_back(
opposite(g, _pMesh));
3062 g =
prev(g, _pMesh);
3063 Border_edges.push_back(
opposite(g, _pMesh));
3072 Prev_edge,
opposite(Border_edges[1], _pMesh), _pMesh);
3073 init_vertex_attributes(
target(g, _pMesh));
3074 put(*_pm,
target(g, _pMesh), Center_vertex);
3075 #ifdef DBG_Un_Decimation_Conquest
3076 std::cout << __func__ <<
" marker PM#2"
3077 <<
" loop " << dbg_loop_counter << std::endl;
3078 std::cout << __func__
3079 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
3086 if((this->IsColored) && (!this->IsOneColor))
3088 CV = Average_color + Predicted_color;
3090 put(this->vertex_color_int,
3095 LAB[0] = this->C0_Min + CV.
c0 * this->Color_Quantization_Step;
3096 LAB[1] = this->C1_Min + CV.
c1 * this->Color_Quantization_Step;
3097 LAB[2] = this->C2_Min + CV.
c2 * this->Color_Quantization_Step;
3102 typedef typename boost::property_traits< VertexColorMap >::value_type
3104 put(*_v_cm,
target(g, _pMesh), Color(RGB[0], RGB[1], RGB[2]));
3106 #ifdef DBG_Un_Decimation_Conquest
3107 std::cout << __func__ <<
" marker #5"
3108 <<
" loop " << dbg_loop_counter << std::endl;
3109 std::cout << __func__
3110 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
3112 std::cout << __func__ <<
" Color=" << RGB[0] <<
" " << RGB[1] <<
" "
3113 << RGB[2] << std::endl;
3118 if((this->IsColored) && (this->IsOneColor))
3120 typedef typename boost::property_traits< VertexColorMap >::value_type
3125 this->OnlyColor[0], this->OnlyColor[1], this->OnlyColor[2]));
3127 #ifdef DBG_Un_Decimation_Conquest
3128 std::cout << __func__ <<
" marker #6"
3129 <<
" loop " << dbg_loop_counter << std::endl;
3130 std::cout << __func__
3131 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
3133 std::cout << __func__ <<
" Color=" << this->OnlyColor[0] <<
" "
3134 << this->OnlyColor[1] <<
" " << this->OnlyColor[2]
3140 Prev_edge =
next(Prev_edge, _pMesh);
3141 CGAL::Euler::add_face_to_border(
3142 Prev_edge,
opposite(Border_edges[0], _pMesh), _pMesh);
3146 if(Number_jump == 0)
3147 Tag_handle = Border_edges[1];
3148 if(Number_jump == 1)
3149 Tag_handle =
opposite(Border_edges[0], _pMesh);
3152 if((type == 1) || (type == 2) || (type == 4))
3162 for(
int i = 0; i < 2; i++)
3164 put(this->Facet_Flag,
3167 if(i != Number_jump)
3168 Halfedges.push(Border_edges[i]);
3172 else if(valence == 9)
3174 int Number_jump = -1;
3175 std::vector< halfedge_descriptor > Border_edges;
3177 if((type == 5) || (type == 8))
3180 if(CGAL::is_border_edge(
next(g, _pMesh), _pMesh))
3184 Border_edges.push_back(
opposite(g, _pMesh));
3196 else if(CGAL::is_border_edge(
3201 Border_edges.push_back(
opposite(
next(g, _pMesh), _pMesh));
3202 Border_edges.push_back(
opposite(g, _pMesh));
3217 Border_edges.push_back(
opposite(
next(g, _pMesh), _pMesh));
3218 Border_edges.push_back(
opposite(g, _pMesh));
3226 if(CGAL::is_border_edge(
prev(g, _pMesh), _pMesh))
3234 Border_edges.push_back(
opposite(g, _pMesh));
3240 else if(CGAL::is_border_edge(
3247 Border_edges.push_back(
opposite(g, _pMesh));
3248 Border_edges.push_back(
opposite(
prev(g, _pMesh), _pMesh));
3257 Border_edges.push_back(
opposite(g, _pMesh));
3258 Border_edges.push_back(
opposite(
prev(g, _pMesh), _pMesh));
3275 Point3d Barycenter((p0[0] + p1[0] + p2[0] + p3[0]) / 4.,
3276 (p0[1] + p1[1] + p2[1] + p3[1]) / 4.,
3277 (p0[2] + p1[2] + p2[2] + p3[2]) / 4.);
3279 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
3283 Point3d Center_vertex = this->Change_Int_Real(Center, Component_ID);
3289 Prev_edge,
opposite(Border_edges[2], _pMesh), _pMesh);
3290 init_vertex_attributes(
target(g, _pMesh));
3291 put(*_pm,
target(g, _pMesh), Center_vertex);
3292 #ifdef DBG_Un_Decimation_Conquest
3293 std::cout << __func__ <<
" marker PM#3"
3294 <<
" loop " << dbg_loop_counter << std::endl;
3295 std::cout << __func__
3296 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
3302 if((this->IsColored) && (!this->IsOneColor))
3307 Get_Vertex_Color(
opposite(Border_edges[0], _pMesh), _pMesh);
3308 Color_Unit Color_1 = Get_Vertex_Color(Border_edges[0], _pMesh);
3309 Color_Unit Color_2 = Get_Vertex_Color(Border_edges[1], _pMesh);
3310 Color_Unit Color_3 = Get_Vertex_Color(Border_edges[2], _pMesh);
3313 (int)(Color_0.
c0 + Color_1.
c0 + Color_2.
c0 + Color_3.
c0) / 4.0;
3315 (int)(Color_0.
c1 + Color_1.
c1 + Color_2.
c1 + Color_3.
c1) / 4.0;
3317 (int)(Color_0.
c2 + Color_1.
c2 + Color_2.
c2 + Color_3.
c2) / 4.0;
3319 CV = Average_color + Predicted_color;
3321 put(this->vertex_color_int,
3326 LAB[0] = this->C0_Min + CV.
c0 * this->Color_Quantization_Step;
3327 LAB[1] = this->C1_Min + CV.
c1 * this->Color_Quantization_Step;
3328 LAB[2] = this->C2_Min + CV.
c2 * this->Color_Quantization_Step;
3333 typedef typename boost::property_traits< VertexColorMap >::value_type
3335 put(*_v_cm,
target(g, _pMesh), Color(RGB[0], RGB[1], RGB[2]));
3337 #ifdef DBG_Un_Decimation_Conquest
3338 std::cout << __func__ <<
" marker #7"
3339 <<
" loop " << dbg_loop_counter << std::endl;
3340 std::cout << __func__
3341 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
3343 std::cout << __func__ <<
" Color=" << RGB[0] <<
" " << RGB[1] <<
" "
3344 << RGB[2] << std::endl;
3348 if((this->IsColored) && (this->IsOneColor))
3350 typedef typename boost::property_traits< VertexColorMap >::value_type
3355 this->OnlyColor[0], this->OnlyColor[1], this->OnlyColor[2]));
3357 #ifdef DBG_Un_Decimation_Conquest
3358 std::cout << __func__ <<
" marker #8"
3359 <<
" loop " << dbg_loop_counter << std::endl;
3360 std::cout << __func__
3361 <<
" vertex=" << vertex_to_string(
target(g, _pMesh), _pm)
3363 std::cout << __func__ <<
" Color=" << this->OnlyColor[0] <<
" "
3364 << this->OnlyColor[1] <<
" " << this->OnlyColor[2]
3368 Prev_edge =
next(Prev_edge, _pMesh);
3369 CGAL::Euler::add_face_to_border(
3370 Prev_edge,
opposite(Border_edges[1], _pMesh), _pMesh);
3371 CGAL::Euler::add_face_to_border(
3372 Prev_edge,
opposite(Border_edges[0], _pMesh), _pMesh);
3376 if(Number_jump == 0)
3378 if((type == 5) || (type == 8))
3380 if(
get(this->Vertex_Sign,
target(Border_edges[2], _pMesh)) ==
3382 put(this->Vertex_Sign,
target(Border_edges[2], _pMesh),
PLUS);
3383 if(
get(this->Vertex_Sign,
3385 put(this->Vertex_Sign,
3391 if(
get(this->Vertex_Sign,
target(Border_edges[2], _pMesh)) ==
3394 if(
get(this->Vertex_Sign,
3396 put(this->Vertex_Sign,
3402 else if(Number_jump == 1)
3404 if((type == 5) || (type == 8))
3406 if(
get(this->Vertex_Sign,
target(Border_edges[2], _pMesh)) ==
3409 if(
get(this->Vertex_Sign,
3411 put(this->Vertex_Sign,
3417 if(
get(this->Vertex_Sign,
target(Border_edges[2], _pMesh)) ==
3419 put(this->Vertex_Sign,
target(Border_edges[2], _pMesh),
PLUS);
3420 if(
get(this->Vertex_Sign,
3422 put(this->Vertex_Sign,
3429 if((type == 5) || (type == 8))
3431 if(
get(this->Vertex_Sign,
target(Border_edges[0], _pMesh)) ==
3433 put(this->Vertex_Sign,
target(Border_edges[0], _pMesh),
PLUS);
3434 if(
get(this->Vertex_Sign,
3436 put(this->Vertex_Sign,
3442 if(
get(this->Vertex_Sign,
target(Border_edges[0], _pMesh)) ==
3445 if(
get(this->Vertex_Sign,
3447 put(this->Vertex_Sign,
3453 for(
int i = 0; i < 3; i++)
3455 put(this->Facet_Flag,
3460 put(this->Vertex_Flag,
3464 if(i != Number_jump)
3465 Halfedges.push(Border_edges[i]);
3472 else if(valence == 7)
3491 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
3506 if(CGAL::is_border_edge(
next(h, _pMesh), _pMesh) ==
false)
3509 if(CGAL::is_border_edge(
prev(h, _pMesh), _pMesh) ==
false)
3517 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
3522 this->NumberDecimation[Component_ID] -=
3524 this->ComponentOperations[Component_ID] -= 1;
3525 this->ListOperation[Component_ID].pop_front();
3527 for(
int i = 0; i < (this->DumpSymbolDecimation + this->DumpSymbolRegulation);
3529 this->Connectivity[Component_ID].pop_front();
3531 for(
int i = 0; i < 2; i++)
3533 this->NumberSymbol[Component_ID].pop_front();
3534 this->NumberVertices[Component_ID].pop_front();
3540 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
3545 unsigned &Connectivity_size,
3546 unsigned &Color_size,
3548 const PointMap *_pm)
3551 unsigned int Max_Qbit = 0;
3552 for(
int i = 0; i < this->NumberComponents; i++)
3554 enc.
put_bits(this->ComponentOperations[i], 8);
3555 enc.
put_bits(this->Qbit[i] - 4, 4);
3556 enc.
put_bits(this->NumberChangeQuantization[i],
3558 enc.
put_bits(this->NumberColorQuantization[i], 3);
3560 if(this->Qbit[i] > Max_Qbit)
3561 Max_Qbit = this->Qbit[i];
3571 int Basemesh_vertex_number = 0;
3572 std::vector< int > Seed_edges(2 * this->NumberComponents, -1);
3577 pVertex !=
vertices(_pMesh).second;
3578 Basemesh_vertex_number++, pVertex++)
3580 put(this->Vertex_Number, *pVertex, Basemesh_vertex_number);
3585 Seed_edges[
get(this->vertex_Seed_Edge, *pVertex)] =
3586 Basemesh_vertex_number;
3591 get(*_pm, *pVertex),
get(this->vertex_Component_Number, *pVertex));
3598 if((this->IsColored) && (!this->IsOneColor))
3616 int Facet_index_bit = (int)ceil(
3619 int Count_facet_index = 0;
3621 pFacet !=
faces(_pMesh).second;
3624 Count_facet_index++;
3631 pHalfedge =
next(pHalfedge, _pMesh);
3634 }
while(pHalfedge !=
halfedge(*pFacet, _pMesh));
3638 for(
int i = 0; i < (int)Seed_edges.size(); i++)
3639 enc.
put_bits(Seed_edges[i], Facet_index_bit);
3641 Connectivity_size +=
3642 Facet_index_bit * (Count_facet_index + Seed_edges.size());
3646 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
3651 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
3654 std::list< int >::iterator Number_iterator =
3655 this->NumberVertices[Component_ID].begin();
3657 this->Geometry[Component_ID].begin();
3659 unsigned Number_phases = this->NumberVertices[Component_ID].size();
3662 for(
unsigned i = 0; i < Number_phases; i++)
3664 int Number_vertices_layer = *Number_iterator;
3667 int alpha_max = -10000;
3668 int alpha_min = 10000;
3669 int gamma_max = -10000;
3670 int gamma_min = 10000;
3671 int alpha = 0, beta = 0, gamma = 0;
3674 if(Number_vertices_layer != 0)
3676 for(
int j = 0; j < Number_vertices_layer; j++)
3679 if(alpha > alpha_max)
3681 if(alpha < alpha_min)
3685 if(beta > alpha_max)
3687 if(beta < alpha_min)
3691 if(gamma > gamma_max)
3693 if(gamma < gamma_min)
3699 this->AlphaRange[Component_ID].push_back(alpha_max - alpha_min + 1);
3700 this->AlphaOffset[Component_ID].push_back(-alpha_min);
3702 this->GammaRange[Component_ID].push_back(gamma_max - gamma_min + 1);
3703 this->GammaOffset[Component_ID].push_back(-gamma_min);
3707 this->AlphaRange[Component_ID].push_back(0);
3708 this->AlphaOffset[Component_ID].push_back(0);
3710 this->GammaRange[Component_ID].push_back(0);
3711 this->GammaOffset[Component_ID].push_back(0);
3719 std::list< int >::iterator it_gamma, it_alpha;
3720 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
3723 for(it_alpha = this->AlphaOffset[Component_ID].begin();
3724 it_alpha != this->AlphaOffset[Component_ID].end();
3727 if(*it_alpha < this->Smallest_Alpha)
3728 this->Smallest_Alpha = *it_alpha;
3730 for(it_gamma = this->GammaOffset[Component_ID].begin();
3731 it_gamma != this->GammaOffset[Component_ID].end();
3734 if(*it_gamma < this->Smallest_Gamma)
3735 this->Smallest_Gamma = *it_gamma;
3743 int C0_min = 50000, C1_min = 50000, C2_min = 50000;
3744 int C0_max = -50000, C1_max = -50000, C2_max = -50000;
3746 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
3750 std::list< Color_Unit >::iterator Vertex_color_iterator;
3751 for(Vertex_color_iterator = this->VertexColor[Component_ID].begin();
3752 Vertex_color_iterator != this->VertexColor[Component_ID].end();
3753 Vertex_color_iterator++)
3756 if(Vertex_color_iterator->c0 < C0_min)
3757 C0_min = Vertex_color_iterator->c0;
3758 if(Vertex_color_iterator->c0 > C0_max)
3759 C0_max = Vertex_color_iterator->c0;
3761 if(Vertex_color_iterator->c1 < C1_min)
3762 C1_min = Vertex_color_iterator->c1;
3763 if(Vertex_color_iterator->c1 > C1_max)
3764 C1_max = Vertex_color_iterator->c1;
3766 if(Vertex_color_iterator->c2 < C2_min)
3767 C2_min = Vertex_color_iterator->c2;
3768 if(Vertex_color_iterator->c2 > C2_max)
3769 C2_max = Vertex_color_iterator->c2;
3774 this->C0_Range = C0_max - C0_min + 1;
3775 this->C1_Range = C1_max - C1_min + 1;
3776 this->C2_Range = C2_max - C2_min + 1;
3778 if(this->C0_Range <= 1)
3780 if(this->C1_Range <= 1)
3782 if(this->C2_Range <= 1)
3785 this->Smallest_C0 = C0_min;
3786 this->Smallest_C1 = C1_min;
3787 this->Smallest_C2 = C2_min;
3794 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
3798 const PointMap *_pm,
3799 const int &NVertices,
3800 const bool Normal_flipping,
3801 const bool Use_metric,
3802 const float &Metric_thread,
3803 const bool Use_forget_metric,
3804 const int &Forget_value)
3810 unsigned Last_Number = 0;
3817 Last_Number = Current_Number;
3820 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
3825 if(this->ComponentOperations[Component_ID] == this->GlobalCountOperation)
3829 #ifdef DBG_Simplification
3830 std::cout <<
"in " << __func__
3831 <<
", before Decimation_Conquest, num_vertices(_pMesh) = "
3835 this->Decimation_Conquest(_pMesh,
3844 #ifdef DBG_Simplification
3845 std::cout <<
"in " << __func__
3846 <<
", after Decimation_Conquest, num_vertices(_pMesh) = "
3850 this->Regulation(_pMesh,
3859 int Diff_number_vertices =
3862 this->ComponentOperations[Component_ID] += 1;
3863 this->NumberDecimation[Component_ID] += 1;
3865 this->ListOperation[Component_ID].push_front(0);
3867 if(Diff_number_vertices == 0)
3868 this->Remove_Last_Phase_Elements(Component_ID);
3874 #ifdef DBG_Simplification
3880 unsigned int real_vertex_count = 0;
3882 real_vertex_count++;
3883 assert((Current_Number == real_vertex_count));
3888 if(Current_Number != Last_Number)
3889 this->GlobalCountOperation++;
3891 if(Current_Number < (
unsigned)NVertices)
3894 }
while((Current_Number != Last_Number));
3896 compute_normals(_pMesh, _pm);
3900 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
3904 const char *File_Name,
3906 unsigned &Connectivity_size,
3907 unsigned &Color_size,
3908 unsigned &Total_size,
3909 const PointMap *_pm)
3913 this->Calculate_Geometry_Color_Offset_Range();
3916 fopen(File_Name,
"wb");
3920 res = fwrite(&this->Smallest_Alpha,
3924 res = fwrite(&this->Smallest_Gamma,
3929 &this->Initial_file_size,
3933 res = fwrite(&this->NumberComponents,
sizeof(
int), 1, fp);
3935 for(
int i = 0; i < this->NumberComponents; i++)
3937 res = fwrite(&this->Quantization_Step[i],
3941 res = fwrite(&this->xmin[i],
sizeof(
float), 1, fp);
3942 res = fwrite(&this->ymin[i],
sizeof(
float), 1, fp);
3943 res = fwrite(&this->zmin[i],
sizeof(
float), 1, fp);
3954 if(this->IsOneColor)
3962 res = fwrite(&Colored,
sizeof(
char), 1, fp);
3964 res = fwrite(&OneColor,
sizeof(
char), 1, fp);
3967 int Num_color_base_mesh = 0;
3968 if((this->IsColored) && (!this->IsOneColor))
3971 res = fwrite(&this->Color_Quantization_Step,
sizeof(
float), 1, fp);
3974 res = fwrite(&this->C0_Min,
sizeof(
float), 1, fp);
3975 res = fwrite(&this->C1_Min,
sizeof(
float), 1, fp);
3976 res = fwrite(&this->C2_Min,
sizeof(
float), 1, fp);
3978 res = fwrite(&this->Smallest_C0,
sizeof(
int), 1, fp);
3979 res = fwrite(&this->Smallest_C1,
sizeof(
int), 1, fp);
3980 res = fwrite(&this->Smallest_C2,
sizeof(
int), 1, fp);
3982 Color_size +=
sizeof(int) * 8 * 9;
3985 if((this->IsColored) && (this->IsOneColor))
3989 &this->OnlyColor[0],
sizeof(
float), 1, fp);
3991 &this->OnlyColor[1],
sizeof(
float), 1, fp);
3993 &this->OnlyColor[2],
sizeof(
float), 1, fp);
4006 for(
int i = 0; i < this->NumberComponents; i++)
4008 if(this->IsClosed[i])
4015 if(this->Is_Bijection_Enabled)
4023 this->Write_Base_Mesh(
4024 _pMesh, enc, Connectivity_size, Color_size, Num_color_base_mesh, _pm);
4042 if((this->IsColored) && (!this->IsOneColor))
4062 this->DM_JCW_MOVE_ERROR.set_alphabet(3);
4065 for(
int i = 0; i < this->GlobalCountOperation; i++)
4068 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
4071 if(i < this->ComponentOperations[Component_ID])
4073 int Number_connectivity_symbols;
4075 if(this->IsClosed[Component_ID])
4076 Number_connectivity_symbols = 5;
4078 Number_connectivity_symbols = 7;
4080 int Type_operation = this->ListOperation[Component_ID].front();
4081 this->ListOperation[Component_ID].pop_front();
4084 if(Type_operation == 0)
4088 for(
int j = 0; j < 2; j++)
4095 Connectivity.
set_alphabet(Number_connectivity_symbols);
4101 Temp_connectivity.
set_alphabet(Number_connectivity_symbols);
4103 int Alpha_range = this->AlphaRange[Component_ID].front();
4104 this->AlphaRange[Component_ID].pop_front();
4105 int Alpha_offset = this->AlphaOffset[Component_ID].front();
4106 this->AlphaOffset[Component_ID].pop_front();
4108 int Gamma_range = this->GammaRange[Component_ID].front();
4109 this->GammaRange[Component_ID].pop_front();
4110 int Gamma_offset = this->GammaOffset[Component_ID].front();
4111 this->GammaOffset[Component_ID].pop_front();
4113 enc.
put_bits(Alpha_range, _Qbit + 1);
4114 if(this->Smallest_Alpha < 0)
4115 enc.
put_bits(Alpha_offset - this->Smallest_Alpha, _Qbit + 1);
4117 enc.
put_bits(Alpha_offset, _Qbit + 1);
4119 enc.
put_bits(Gamma_range, _Qbit + 1);
4120 if(this->Smallest_Gamma < 0)
4121 enc.
put_bits(Gamma_offset - this->Smallest_Gamma, _Qbit + 1);
4123 enc.
put_bits(Gamma_offset, _Qbit + 1);
4125 bool check_alpha =
false;
4126 bool check_gamma =
false;
4128 if((Alpha_range == 0) || (Alpha_range == 1))
4133 if((Gamma_range == 0) || (Gamma_range == 1))
4142 int Number_symbols = this->NumberSymbol[Component_ID].front();
4143 this->NumberSymbol[Component_ID].pop_front();
4145 for(
unsigned k = 0; k < (unsigned)Number_symbols; k++)
4147 unsigned symbol = this->Connectivity[Component_ID].front();
4148 this->Connectivity[Component_ID].pop_front();
4150 enc.
encode(symbol, Connectivity);
4153 Connectivity_encoder.
encode(symbol, Temp_connectivity);
4155 if(((j == 0) && (symbol != 1)) || ((j == 1) && (symbol != 4)))
4157 Point_Int Coeff = this->Geometry[Component_ID].front();
4158 this->Geometry[Component_ID].pop_front();
4160 int x = Coeff.
x + Alpha_offset;
4161 int y = Coeff.
y + Alpha_offset;
4162 int z = Coeff.
z + Gamma_offset;
4164 if(check_alpha ==
false)
4169 if(check_gamma ==
false)
4176 if((this->IsColored) && (!this->IsOneColor))
4178 Color_Unit VC = this->VertexColor[Component_ID].front();
4179 this->VertexColor[Component_ID].pop_front();
4181 enc.
encode(VC.
c0 - this->Smallest_C0, C0_model);
4182 enc.
encode(VC.
c1 - this->Smallest_C1, C1_model);
4183 enc.
encode(VC.
c2 - this->Smallest_C2, C2_model);
4186 Color_enc.
encode(VC.
c0 - this->Smallest_C0, PC_C0_model);
4187 Color_enc.
encode(VC.
c1 - this->Smallest_C1, PC_C1_model);
4188 Color_enc.
encode(VC.
c2 - this->Smallest_C2, PC_C2_model);
4197 if(!this->m_N_Errors.empty())
4199 int tt_count = this->m_N_Errors.front();
4200 this->m_N_Errors.pop_front();
4203 for(
int tt_i = 0; tt_i < tt_count; tt_i++)
4205 std::vector< int > Temp_error = this->m_JCW_Move_Error.front();
4206 this->m_JCW_Move_Error.pop_front();
4208 for(
int m = 0; m < 3; m++)
4210 int Te = Temp_error[m];
4215 enc.
encode(Te, this->DM_JCW_MOVE_ERROR);
4222 else if(Type_operation == 1)
4226 int Number_vertices =
4227 this->NumberQuantizationLayer[Component_ID].front();
4228 this->NumberQuantizationLayer[Component_ID].pop_front();
4232 for(
int i = 0; i < Number_vertices; i++)
4234 int Under_quantization_coeff =
4235 this->QuantizationCorrectVector[Component_ID].front();
4236 this->QuantizationCorrectVector[Component_ID].pop_front();
4238 enc.
encode(Under_quantization_coeff, Under_quantization_model);
4249 int Number_vertices =
4250 this->NumberProcessedVertices[Component_ID].front();
4251 this->NumberProcessedVertices[Component_ID].pop_front();
4256 Color_quantization_model[i].set_alphabet(8);
4262 Temp_quantization_model[i].set_alphabet(8);
4264 for(
int i = 0; i < Number_vertices; i++)
4266 int Color_index = this->ColorEncoderIndex[Component_ID].front();
4267 this->ColorEncoderIndex[Component_ID].pop_front();
4269 int Childcell_index =
4270 this->ColorChildcellIndex[Component_ID].front();
4271 this->ColorChildcellIndex[Component_ID].pop_front();
4273 enc.
encode(Childcell_index, Color_quantization_model[Color_index]);
4275 Color_enc.
encode(Childcell_index,
4276 Temp_quantization_model[Color_index]);
4280 delete[] Color_quantization_model;
4281 delete[] Temp_quantization_model;
4287 Connectivity_size += Connectivity_encoder.
stop_encoder() * 8;
4293 FILE *f_size = fopen(File_Name,
"rb");
4294 fseek(f_size, 0, SEEK_END);
4295 Total_size = ftell(f_size);
4302 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
4306 const int &_Component_ID,
4308 double &_Mean_color,
4309 int &Number_of_vertices)
4311 typedef boost::graph_traits< HalfedgeGraph >
GraphTraits;
4315 #ifdef DBG_Calculate_Edge_Color_Difference
4316 static unsigned int Calculate_Edge_Color_Difference_call_cnt = 0;
4317 Calculate_Edge_Color_Difference_call_cnt++;
4318 std::string dbg_header =
4319 std::string(
"in ") + std::string(__func__) + std::string(
", call_cnt=") +
4320 std::to_string(Calculate_Edge_Color_Difference_call_cnt);
4321 std::cout << dbg_header <<
", this->C0_Min = " << this->C0_Min << std::endl;
4322 std::cout << dbg_header <<
", this->C1_Min = " << this->C1_Min << std::endl;
4323 std::cout << dbg_header <<
", this->C2_Min = " << this->C2_Min << std::endl;
4328 std::cout << dbg_header
4329 <<
", vertex_Seed_Edge = " <<
get(this->vertex_Seed_Edge, *vi)
4332 color_int =
get(this->vertex_color_int, *vi);
4333 std::cout << dbg_header <<
", vertex_color_int = " << color_int.
c0 <<
","
4334 << color_int.
c1 <<
"," << color_int.
c2 << std::endl;
4336 PointMap pm =
get(boost::vertex_point, _pMesh);
4337 PointMap *_pm = ±
4340 float C0_min = this->C0_Min;
4341 float C1_min = this->C1_Min;
4342 float C2_min = this->C2_Min;
4344 float Color_small_step = 0.0;
4346 if(this->NumberColorQuantization[_Component_ID] == 0)
4348 Color_small_step = this->Color_Quantization_Step;
4354 this->Color_Quantization_Step *
4355 std::pow(2.0, this->NumberColorQuantization[_Component_ID]);
4357 #ifdef DBG_Calculate_Edge_Color_Difference
4358 std::cout << dbg_header <<
", Color_small_step = " << Color_small_step
4363 auto halfedge_iterator_pair = halfedges(_pMesh);
4367 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * _Component_ID) ||
4369 2 * _Component_ID + 1))
4373 #ifdef DBG_Calculate_Edge_Color_Difference
4375 "in Calculate_Edge_Color_Difference, *hi = ", *hi, _pMesh, _pm);
4379 auto vertex_iterator_pair =
vertices(_pMesh);
4384 put(this->Vertex_Flag, *pVert,
FREE);
4385 put(this->Vertex_Number, *pVert, -1);
4388 std::queue< vertex_descriptor >
vertices;
4396 int Count_vertices = 0;
4397 double Max_color = -5000.;
4398 double Mean_color = 0.;
4399 double L_min = 5000, A_min = 5000, B_min = 5000;
4400 double L_max = -5000, A_max = -5000, B_max = -5000;
4405 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4406 std::cout << dbg_header <<
", while_loop_cnt = " << ++while_loop_cnt
4408 std::cout << dbg_header <<
", vertices.size = " <<
vertices.size()
4413 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4414 print_vertex(
"in Calculate_Edge_Color_Difference, pop v = ", v, _pm);
4420 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4427 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4429 std::vector< std::string > dbg_diff_per_he;
4432 put(this->Vertex_Number, v, Count_vertices);
4434 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > hvc(v, _pMesh);
4435 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > phvc(hvc);
4440 CGAL_For_all(hvc, phvc)
4442 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4459 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4463 Color_0 =
get(this->vertex_color_int,
target(*hvc, _pMesh));
4465 Color_1 =
get(this->vertex_color_int,
4468 double LAB_0[3], LAB_1[3];
4470 LAB_0[0] = C0_min + Color_0.
c0 * Color_small_step;
4471 LAB_0[1] = C1_min + Color_0.
c1 * Color_small_step;
4472 LAB_0[2] = C2_min + Color_0.
c2 * Color_small_step;
4474 LAB_1[0] = C0_min + Color_1.
c0 * Color_small_step;
4475 LAB_1[1] = C1_min + Color_1.
c1 * Color_small_step;
4476 LAB_1[2] = C2_min + Color_1.
c2 * Color_small_step;
4478 if(LAB_0[0] > L_max)
4480 if(LAB_0[1] > A_max)
4482 if(LAB_0[2] > B_max)
4485 if(LAB_1[0] > L_max)
4487 if(LAB_1[1] > A_max)
4489 if(LAB_1[2] > B_max)
4492 if(LAB_0[0] < L_min)
4494 if(LAB_0[1] < A_min)
4496 if(LAB_0[2] < B_min)
4499 if(LAB_1[0] < L_min)
4501 if(LAB_1[1] < A_min)
4503 if(LAB_1[2] < B_min)
4506 for(
int i = 0; i < 3; i++)
4508 diff += (LAB_0[i] - LAB_1[i]) * (LAB_0[i] - LAB_1[i]);
4511 diff = std::sqrt(diff);
4512 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4517 char dbg_buffer[20];
4518 snprintf(dbg_buffer,
sizeof(dbg_buffer),
"%f", diff);
4519 dbg_diff_per_he.push_back(edge_to_string(*hvc, _pMesh, _pm) +
4520 " diff=" + dbg_buffer);
4526 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4539 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4542 for(
int i = 0; i < dbg_diff_per_he.size(); i++)
4543 std::cout << dbg_header <<
" " << dbg_diff_per_he[i]
4544 <<
" Count=" << Count << std::endl;
4552 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4553 std::cout << dbg_header <<
", v = " << vertex_to_string(v, _pm)
4554 <<
" Mean = " << Mean << std::endl;
4555 std::cout << dbg_header <<
", v = " << vertex_to_string(v, _pm)
4556 <<
" Mean_color = " << Mean_color << std::endl;
4559 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h(v, _pMesh);
4560 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2(h);
4563 #ifdef DBG_Calculate_Edge_Color_Difference_VERBOSE
4569 #ifdef DBG_Calculate_Edge_Color_Difference
4570 std::cout << dbg_header <<
", v = " << vertex_to_string(v, _pm)
4584 #ifdef DBG_Calculate_Edge_Color_Difference
4585 std::cout << dbg_header <<
", after while loop Mean_color = " << Mean_color
4589 Max_color = (L_max - L_min) * (L_max - L_min) +
4590 (A_max - A_min) * (A_max - A_min) +
4591 (B_max - B_min) * (B_max - B_min);
4593 Max_color = std::sqrt(Max_color);
4594 _Max_color = Max_color;
4595 _Mean_color = 3 * Mean_color / Count_vertices;
4596 Number_of_vertices = Count_vertices;
4598 #ifdef DBG_Calculate_Edge_Color_Difference
4601 std::cout << dbg_header <<
", Vertex_Flag = " <<
get(this->Vertex_Flag, *vi)
4603 std::cout << dbg_header
4604 <<
", Vertex_Number = " <<
get(this->Vertex_Number, *vi)
4609 std::cout << dbg_header <<
", _Mean_color = " << _Mean_color << std::endl;
4610 std::cout << dbg_header <<
", _Max_color = " << _Max_color << std::endl;
4611 std::cout << dbg_header <<
", Number_of_vertices = " << Number_of_vertices
4617 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
4621 const int _Component_ID,
4622 VertexColorMap *_v_cm)
4624 typedef typename boost::property_traits< VertexColorMap >::value_type Color;
4633 float Color_small_step = 0.0;
4635 if(this->NumberColorQuantization[_Component_ID] == 0)
4636 Color_small_step = this->Color_Quantization_Step;
4640 this->Color_Quantization_Step *
4641 std::pow(2.0, this->NumberColorQuantization[_Component_ID]);
4643 double Color_large_step = Color_small_step * 2;
4646 auto halfedge_iterator_pair = halfedges(_pMesh);
4650 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * _Component_ID) ||
4652 2 * _Component_ID + 1))
4660 put(this->Vertex_Flag, *pVert,
FREE);
4661 put(this->Vertex_Number, *pVert, -1);
4670 if(
get(vertex_Component_Number, *pVert) == _Component_ID)
4673 int LAB_init_C0 = color.
c0;
4674 int LAB_init_C1 = color.
c1;
4675 int LAB_init_C2 = color.
c2;
4678 int LAB_final_C0 = LAB_init_C0 / 2;
4679 int LAB_final_C1 = LAB_init_C1 / 2;
4680 int LAB_final_C2 = LAB_init_C2 / 2;
4682 int i = LAB_init_C0 % 2;
4683 int j = LAB_init_C1 % 2;
4684 int k = LAB_init_C2 % 2;
4686 int Q_index = Get_Correct_Vector(i, j, k);
4688 put(this->vertex_color_int,
4690 Color_Unit(LAB_final_C0, LAB_final_C1, LAB_final_C2));
4691 put(this->vertex_Q_Index, *pVert, Q_index);
4696 std::vector< float > LAB;
4698 LAB.push_back(this->C0_Min + LAB_final_C0 * Color_large_step);
4699 LAB.push_back(this->C1_Min + LAB_final_C1 * Color_large_step);
4700 LAB.push_back(this->C2_Min + LAB_final_C2 * Color_large_step);
4704 put(*_v_cm, *pVert, Color(RGB[0], RGB[1], RGB[2]));
4708 std::queue< vertex_descriptor >
vertices;
4710 std::list< int > Inter_color_quantization;
4711 std::list< int > Inter_index_per_color;
4718 int Vertex_index = 0;
4721 std::vector< std::vector< int > > Color_table;
4734 put(this->Vertex_Number, v, Vertex_index);
4736 int Q_index =
get(this->vertex_Q_Index, v);
4737 std::vector< int > LAB;
4739 LAB.push_back((
get(this->vertex_color_int, v)).c0);
4740 LAB.push_back((
get(this->vertex_color_int, v)).c1);
4741 LAB.push_back((
get(this->vertex_color_int, v)).c2);
4743 bool Is_existed_color =
false;
4746 for(
unsigned i = 0; i < Color_table.size(); i++)
4748 if((LAB[0] == Color_table[i][0]) && (LAB[1] == Color_table[i][1]) &&
4749 (LAB[2] == Color_table[i][2]))
4751 Is_existed_color =
true;
4752 Inter_color_quantization.push_front(Q_index);
4753 Inter_index_per_color.push_front(i);
4759 if(Is_existed_color ==
false)
4761 Inter_color_quantization.push_front(Q_index);
4762 Inter_index_per_color.push_front(Color_table.size());
4764 Color_table.push_back(LAB);
4766 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h;
4769 if(Vertex_index == 0)
4771 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
4775 }
while((*h) != (*hi));
4782 int Comp_number = -2;
4784 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
4786 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
4804 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
4816 int ssss = Inter_color_quantization.size();
4817 this->NumberProcessedVertices[_Component_ID].push_front(ssss);
4819 while(!Inter_color_quantization.empty())
4821 int index = Inter_color_quantization.front();
4822 Inter_color_quantization.pop_front();
4824 this->ColorChildcellIndex[_Component_ID].push_front(index);
4826 while(!Inter_index_per_color.empty())
4828 int Color = Inter_index_per_color.front();
4829 Inter_index_per_color.pop_front();
4831 this->ColorEncoderIndex[_Component_ID].push_front(Color);
4836 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
4840 const PointMap *_pm,
4841 const int &_Component_ID,
4844 typedef boost::graph_traits< HalfedgeGraph >
GraphTraits;
4849 auto face_iterator_pair =
faces(_pMesh);
4852 for(
face_iterator pFacet = pFacet_beg; pFacet != pFacet_end; ++pFacet)
4854 if(
get(this->facet_Component_Number, *pFacet) == _Component_ID)
4857 Area += Area_Facet_Triangle(
halfedge(*pFacet, _pMesh), _pMesh, _pm);
4861 ((
double)10.0 / (
double)this->HighestLengthBB[_Component_ID]), 2.0);
4862 this->ComponentArea[_Component_ID] = Area;
4866 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
4871 const int &Component_ID,
4880 double Small_step = 0.0;
4882 if(this->NumberChangeQuantization[Component_ID] == 0)
4883 Small_step = this->Quantization_Step[Component_ID];
4887 this->Quantization_Step[Component_ID] *
4888 std::pow(2.0, this->NumberChangeQuantization[Component_ID] - 1);
4895 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * Component_ID) ||
4897 2 * Component_ID + 1))
4905 put(this->Vertex_Flag, *pVert,
FREE);
4906 put(this->Vertex_Number, *pVert, -1);
4907 put(this->vertex_Component_Number, *pVert, -1);
4911 std::queue< vertex_descriptor > verticesq;
4912 std::list< int > Layer_symbols;
4916 verticesq.push(
target(*hi, _pMesh));
4919 int Vertex_index = 0;
4921 while(!verticesq.empty())
4932 put(this->Vertex_Number, v, Vertex_index);
4933 put(this->vertex_Component_Number, v, Component_ID);
4938 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > hvc(v, _pMesh);
4939 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > hvc2 = hvc;
4940 unsigned count_neighbor = 0;
4941 CGAL_For_all(hvc, hvc2)
4943 Neighbors[count_neighbor] =
4949 std::vector< int > D(6, 0);
4951 for(
unsigned i = 0; i < valence; i++)
4954 FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
4955 Neighbors[i], Center, gt);
4959 int I_dist = Vect[0] / Small_step / 2;
4960 D[0] += std::abs(I_dist);
4964 int I_dist = Vect[0] / Small_step / 2;
4965 D[1] += std::abs(I_dist);
4970 int I_dist = Vect[1] / Small_step / 2;
4971 D[2] += std::abs(I_dist);
4975 int I_dist = Vect[1] / Small_step / 2;
4976 D[3] += std::abs(I_dist);
4981 int I_dist = Vect[2] / Small_step / 2;
4982 D[4] += std::abs(I_dist);
4986 int I_dist = Vect[2] / Small_step / 2;
4987 D[5] += std::abs(I_dist);
4991 std::vector< double > U(3, 0);
4992 U[0] = std::abs((
double)D[0] / (
double)(D[0] + D[1]) - 0.5);
4993 U[1] = std::abs((
double)D[2] / (
double)(D[2] + D[3]) - 0.5);
4994 U[2] = std::abs((
double)D[4] / (
double)(D[4] + D[5]) - 0.5);
4996 std::multimap< double, int > U_order;
4997 U_order.insert(std::pair< double, int >(U[0], 0));
4998 U_order.insert(std::pair< double, int >(U[1], 1));
4999 U_order.insert(std::pair< double, int >(U[2], 2));
5001 std::multimap< double, int >::iterator it;
5003 std::vector< int > Weight_axe(3, 0);
5004 int Temp_weight = 1;
5005 for(it = U_order.begin(); it != U_order.end(); it++)
5007 Weight_axe[it->second] = Temp_weight;
5011 std::vector< int > Priority(8, 0);
5013 Weight_axe[0] * D[0] + Weight_axe[1] * D[2] + Weight_axe[2] * D[4];
5015 Weight_axe[0] * D[1] + Weight_axe[1] * D[2] + Weight_axe[2] * D[4];
5017 Weight_axe[0] * D[0] + Weight_axe[1] * D[3] + Weight_axe[2] * D[4];
5019 Weight_axe[0] * D[1] + Weight_axe[1] * D[3] + Weight_axe[2] * D[4];
5021 Weight_axe[0] * D[0] + Weight_axe[1] * D[2] + Weight_axe[2] * D[5];
5023 Weight_axe[0] * D[1] + Weight_axe[1] * D[2] + Weight_axe[2] * D[5];
5025 Weight_axe[0] * D[0] + Weight_axe[1] * D[3] + Weight_axe[2] * D[5];
5027 Weight_axe[0] * D[1] + Weight_axe[1] * D[3] + Weight_axe[2] * D[5];
5029 std::multimap< int, int > Priority_map;
5030 std::multimap< int, int >::iterator it_reorder;
5031 for(
int i = 0; i < 8; i++)
5032 Priority_map.insert(std::pair< int, int >(Priority[i], i));
5034 std::vector< int > Priority_reorder(8, 0);
5036 int Temp_priority = 0;
5038 bool Is_same_priority_value =
false;
5040 it_reorder = Priority_map.begin();
5041 for(
int i = 0; i < 7; i++)
5043 int P0 = it_reorder->first;
5045 int P1 = it_reorder->first;
5048 Is_same_priority_value =
true;
5051 if(!Is_same_priority_value)
5053 for(it_reorder = Priority_map.begin(); it_reorder != Priority_map.end();
5056 Priority_reorder[it_reorder->second] = 7 - Temp_priority;
5062 for(
int i = 0; i < 8; i++)
5064 Priority_reorder[i] = i;
5068 int Reordered_number = Decoder.
decode(Under_quantization_model);
5070 for(
int i = 0; i < 8; i++)
5072 if(Priority_reorder[i] == Reordered_number)
5074 put(this->vertex_Q_Index, v, i);
5079 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h;
5080 if(Vertex_index == 0)
5082 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
5086 }
while((*h) != (*hi));
5090 int Comp_number = -2;
5091 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
5092 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
5112 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
5129 if(
get(this->vertex_Component_Number, *pVertex) == Component_ID)
5131 int Coeff[3] = { 0 };
5132 Get_Coefficient_Up_Quantization(
get(this->vertex_Q_Index, *pVertex),
5135 Point3d New_position(pt[0] + Coeff[0] * Small_step / 2,
5136 pt[1] + Coeff[1] * Small_step / 2,
5137 pt[2] + Coeff[2] * Small_step / 2);
5138 put(*_pm, *pVertex, New_position);
5141 this->Qbit[Component_ID]++;
5142 this->NumberChangeQuantization[Component_ID]--;
5149 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
5153 const int &Component_ID,
5159 float _xmin = this->xmin[Component_ID];
5160 float _ymin = this->ymin[Component_ID];
5161 float _zmin = this->zmin[Component_ID];
5165 double Small_step = 0.0;
5167 if(this->NumberChangeQuantization[Component_ID] == 0)
5168 Small_step = this->Quantization_Step[Component_ID];
5171 Small_step = this->Quantization_Step[Component_ID] *
5172 std::pow(2.0, this->NumberChangeQuantization[Component_ID]);
5176 double Large_step = Small_step * 2;
5179 auto halfedge_iterator_pair = halfedges(_pMesh);
5183 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * Component_ID) ||
5185 2 * Component_ID + 1))
5193 put(this->Vertex_Flag, *pVert,
FREE);
5194 put(this->Vertex_Number, *pVert, -1);
5204 if(
get(this->vertex_Component_Number, *pVert) == Component_ID)
5212 int Qx = (int)(ceil((x - _xmin) / Small_step)) - 1;
5215 int Qy = (int)(ceil((y - _ymin) / Small_step)) - 1;
5218 int Qz = (int)(ceil((z - _zmin) / Small_step)) - 1;
5223 int Second_Qx = Qx / 2;
5224 int Second_Qy = Qy / 2;
5225 int Second_Qz = Qz / 2;
5231 int Q_index = Get_Correct_Vector(i, j, k);
5232 put(this->vertex_Q_Index, *pVert, Q_index);
5237 Point3d(_xmin + (Second_Qx + 0.5) * Large_step,
5238 _ymin + (Second_Qy + 0.5) * Large_step,
5239 _zmin + (Second_Qz + 0.5) * Large_step));
5246 std::queue< vertex_descriptor >
vertices;
5248 std::list< int > Layer_symbols;
5256 int Vertex_index = 0;
5270 put(this->Vertex_Number, v, Vertex_index);
5272 int Q_index =
get(this->vertex_Q_Index, v);
5273 unsigned Count_neighbor = 0;
5277 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > hvc =
5278 CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
5279 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > phvc = hvc;
5281 CGAL_For_all(hvc, phvc)
5283 Neighbors[Count_neighbor] =
5290 std::vector< int > D(6, 0);
5292 for(
unsigned i = 0; i < valence; i++)
5295 FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
5296 Neighbors[i], Center, gt);
5300 int I_dist = Vect[0] / Small_step / 2;
5301 D[0] += std::abs(I_dist);
5305 int I_dist = Vect[0] / Small_step / 2;
5306 D[1] += std::abs(I_dist);
5311 int I_dist = Vect[1] / Small_step / 2;
5312 D[2] += std::abs(I_dist);
5316 int I_dist = Vect[1] / Small_step / 2;
5317 D[3] += std::abs(I_dist);
5322 int I_dist = Vect[2] / Small_step / 2;
5323 D[4] += std::abs(I_dist);
5327 int I_dist = Vect[2] / Small_step / 2;
5328 D[5] += std::abs(I_dist);
5332 std::vector< double > U(3, 0);
5333 U[0] = std::abs((
double)D[0] / (
double)(D[0] + D[1]) - 0.5);
5334 U[1] = std::abs((
double)D[2] / (
double)(D[2] + D[3]) - 0.5);
5335 U[2] = std::abs((
double)D[4] / (
double)(D[4] + D[5]) - 0.5);
5337 std::multimap< double, int > U_order;
5338 U_order.insert(std::pair< double, int >(U[0], 0));
5339 U_order.insert(std::pair< double, int >(U[1], 1));
5340 U_order.insert(std::pair< double, int >(U[2], 2));
5342 std::multimap< double, int >::iterator it;
5344 std::vector< int > Weight_axe(3, 0);
5345 int Temp_weight = 1;
5346 for(it = U_order.begin(); it != U_order.end(); it++)
5348 Weight_axe[it->second] = Temp_weight;
5352 std::vector< int > Priority(8, 0);
5354 Weight_axe[0] * D[0] + Weight_axe[1] * D[2] + Weight_axe[2] * D[4];
5356 Weight_axe[0] * D[1] + Weight_axe[1] * D[2] + Weight_axe[2] * D[4];
5358 Weight_axe[0] * D[0] + Weight_axe[1] * D[3] + Weight_axe[2] * D[4];
5360 Weight_axe[0] * D[1] + Weight_axe[1] * D[3] + Weight_axe[2] * D[4];
5362 Weight_axe[0] * D[0] + Weight_axe[1] * D[2] + Weight_axe[2] * D[5];
5364 Weight_axe[0] * D[1] + Weight_axe[1] * D[2] + Weight_axe[2] * D[5];
5366 Weight_axe[0] * D[0] + Weight_axe[1] * D[3] + Weight_axe[2] * D[5];
5368 Weight_axe[0] * D[1] + Weight_axe[1] * D[3] + Weight_axe[2] * D[5];
5370 std::multimap< int, int > Priority_map;
5371 std::multimap< int, int >::iterator it_reorder;
5372 for(
int i = 0; i < 8; i++)
5373 Priority_map.insert(std::pair< int, int >(Priority[i], i));
5375 std::vector< int > Priority_reorder(8, 0);
5377 int Temp_priority = 0;
5378 bool Is_same_priority_value =
false;
5380 it_reorder = Priority_map.begin();
5381 for(
int i = 0; i < 7; i++)
5383 int P0 = it_reorder->first;
5385 int P1 = it_reorder->first;
5388 Is_same_priority_value =
true;
5391 if(!Is_same_priority_value)
5393 for(it_reorder = Priority_map.begin(); it_reorder != Priority_map.end();
5396 Priority_reorder[it_reorder->second] = 7 - Temp_priority;
5402 for(
int i = 0; i < 8; i++)
5404 Priority_reorder[i] = i;
5408 int Reordered_number = Priority_reorder[Q_index];
5410 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h;
5413 if(Vertex_index == 0)
5415 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
5419 }
while((*h) != (*hi));
5424 int Comp_number = -2;
5425 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
5426 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
5444 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
5453 Layer_symbols.push_front(Reordered_number);
5457 this->NumberQuantizationLayer[Component_ID].push_front(Layer_symbols.size());
5458 while(!Layer_symbols.empty())
5460 int index = Layer_symbols.front();
5461 Layer_symbols.pop_front();
5463 this->QuantizationCorrectVector[Component_ID].push_front(index);
5468 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
5473 VertexColorMap *_v_cm,
5475 const std::string &Input_File_Name)
5477 this->File_name = Input_File_Name;
5479 if(FILE *file2 = fopen(this->File_name.c_str(),
"r"))
5481 fseek(file2, 0, SEEK_END);
5482 this->Compressed_file_size = ftell(file2);
5487 throw std::runtime_error(
"Error: failed to open file '" + this->File_name +
5491 CGAL::clear(_pMesh);
5493 this->IsClosed.clear();
5498 this->Quantization_Step.clear();
5499 this->NumberColorQuantization.clear();
5500 this->NumberChangeQuantization.clear();
5501 this->ComponentOperations.clear();
5503 this->Decompress_count = 0;
5509 FILE *fp = fopen(this->File_name.c_str(),
"rb");
5511 this->DM_JCW_MOVE_ERROR.set_alphabet(3);
5515 res = fread(&this->Smallest_Alpha,
sizeof(
int), 1, fp);
5516 res = fread(&this->Smallest_Gamma,
sizeof(
int), 1, fp);
5517 res = fread(&this->Initial_file_size,
sizeof(
unsigned), 1, fp);
5518 res = fread(&this->NumberComponents,
sizeof(
int), 1, fp);
5521 float t_xmin, t_ymin, t_zmin;
5524 for(
int i = 0; i < this->NumberComponents; i++)
5526 res = fread(&Qpas,
sizeof(
float), 1, fp);
5527 res = fread(&t_xmin,
sizeof(
float), 1, fp);
5528 res = fread(&t_ymin,
sizeof(
float), 1, fp);
5529 res = fread(&t_zmin,
sizeof(
float), 1, fp);
5531 this->Quantization_Step.push_back(Qpas);
5532 this->xmin.push_back(t_xmin);
5533 this->ymin.push_back(t_ymin);
5534 this->zmin.push_back(t_zmin);
5537 char Colored, One_color;
5538 res = fread(&Colored,
sizeof(
char), 1, fp);
5540 this->IsOneColor =
false;
5543 this->IsColored =
true;
5544 res = fread(&One_color,
sizeof(
char), 1, fp);
5546 this->IsOneColor =
true;
5549 this->IsColored =
false;
5552 has_color = this->IsColored;
5555 if((this->IsColored) && (!this->IsOneColor))
5557 res = fread(&this->Color_Quantization_Step,
sizeof(
float), 1, fp);
5559 res = fread(&this->C0_Min,
5563 res = fread(&this->C1_Min,
5567 res = fread(&this->C2_Min,
5573 &this->Smallest_C0,
sizeof(
int), 1, fp);
5574 res = fread(&this->Smallest_C1,
sizeof(
int), 1, fp);
5575 res = fread(&this->Smallest_C2,
sizeof(
int), 1, fp);
5578 if((this->IsColored) && (this->IsOneColor))
5580 res = fread(&this->OnlyColor[0],
5585 &this->OnlyColor[1],
sizeof(
float), 1, fp);
5587 &this->OnlyColor[2],
sizeof(
float), 1, fp);
5590 this->Decoder.read_from_file(fp);
5595 for(
int i = 0; i < this->NumberComponents; i++)
5597 if(Decoder.get_bits(1) == 0)
5598 this->IsClosed.push_back(
true);
5600 this->IsClosed.push_back(
false);
5603 if(Decoder.get_bits(1) == 1)
5604 this->Is_Bijection_Enabled =
true;
5606 this->Is_Bijection_Enabled =
false;
5608 this->GlobalCountOperation = -1;
5610 unsigned Max_Qbit = 0;
5611 for(
int i = 0; i < this->NumberComponents; i++)
5613 int Number_operation = Decoder.get_bits(8);
5614 this->ComponentOperations.push_back(Number_operation);
5616 if(Number_operation > this->GlobalCountOperation)
5617 this->GlobalCountOperation = Number_operation;
5619 int Qbit = Decoder.get_bits(4);
5621 this->Qbit.push_back(Qbit);
5623 int NCQ = Decoder.get_bits(4);
5624 this->NumberChangeQuantization.push_back(NCQ);
5626 int Number_color_quantization_change =
5627 Decoder.get_bits(3);
5628 this->NumberColorQuantization.push_back(Number_color_quantization_change);
5630 if(this->Qbit[i] > Max_Qbit)
5631 Max_Qbit = this->Qbit[i];
5634 int Number_basemesh_vertex =
5635 Decoder.get_bits(15);
5636 int Number_basemesh_facet =
5637 Decoder.get_bits(16);
5640 std::vector< Point3d > vlist;
5641 std::vector< int > flist;
5642 std::vector< float > clist;
5643 std::vector< int > Color_index_list;
5645 for(
int i = 0; i < Number_basemesh_vertex; i++)
5648 Pt_int.
x = Decoder.get_bits(Max_Qbit + 1);
5649 Pt_int.
y = Decoder.get_bits(Max_Qbit + 1);
5650 Pt_int.
z = Decoder.get_bits(Max_Qbit + 1);
5654 Point3d Pt_real = Change_Int_Real(Pt_int, 0);
5655 vlist.push_back(Pt_real);
5657 if((this->IsColored) && (!this->IsOneColor))
5666 float L = this->C0_Min + TC.
c0 * this->Color_Quantization_Step;
5667 float a = this->C1_Min + TC.
c1 * this->Color_Quantization_Step;
5668 float b = this->C2_Min + TC.
c2 * this->Color_Quantization_Step;
5678 int Facet_index_bit =
5679 (int)ceil(log((
double)(Number_basemesh_vertex + 1)) / log((
double)2));
5681 for(
int i = 0; i < (Number_basemesh_facet * 3); i++)
5683 int v = Decoder.get_bits(Facet_index_bit);
5688 build_mesh(_pMesh, _pm, _v_cm, vlist, flist, clist, Color_index_list);
5690 compute_normals(_pMesh, _pm);
5693 std::map< int, int > Seed_Edges;
5695 for(
int i = 0; i < 2 * this->NumberComponents; i++)
5697 int Vertex_number = Decoder.get_bits(Facet_index_bit);
5698 Seed_Edges.insert(std::pair< int, int >(Vertex_number, i));
5701 int Basemesh_vertex_number = 0;
5705 std::map< int, int >::iterator Seed_edge_iterator = Seed_Edges.begin();
5707 int Count_detected_vertices = 0;
5709 Basemesh_vertex_number++, pVertex++)
5711 if(Count_detected_vertices < this->NumberComponents * 2)
5713 if(Basemesh_vertex_number == Seed_edge_iterator->first)
5715 put(this->vertex_Seed_Edge, *pVertex, Seed_edge_iterator->second);
5716 Seed_edge_iterator++;
5717 Count_detected_vertices++;
5723 put(this->vertex_Component_Number, *pVertex, -1);
5730 float Color_small_step = 0.0;
5732 if((this->IsColored) && (!this->IsOneColor))
5749 this->Color_0_Model.set_alphabet(this->C0_Range);
5751 this->Color_1_Model.set_alphabet(this->C1_Range);
5753 this->Color_2_Model.set_alphabet(this->C2_Range);
5755 if((this->IsColored) && (this->IsOneColor))
5761 typename boost::property_traits< VertexColorMap >::value_type Color;
5764 Color(this->OnlyColor[0], this->OnlyColor[1], this->OnlyColor[2]));
5773 pFacet !=
faces(_pMesh).second;
5776 put(this->facet_tag, *pFacet, -1);
5778 int Component_index = 0;
5780 for(
int Component_number = 0; Component_number < this->NumberComponents;
5786 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) !=
5787 2 * Component_number) ||
5789 2 * Component_number + 1))
5793 put(this->facet_tag, fh, Component_index);
5795 std::list< face_descriptor > facets;
5796 facets.push_front(fh);
5798 while(!facets.empty())
5803 put(this->facet_tag,
F, Component_index);
5805 CGAL::Halfedge_around_face_circulator< HalfedgeGraph > pHalfedge =
5806 CGAL::Halfedge_around_face_circulator< HalfedgeGraph >(
5808 CGAL::Halfedge_around_face_circulator< HalfedgeGraph > end = pHalfedge;
5810 CGAL_For_all(pHalfedge, end)
5813 if(
get(this->vertex_Component_Number,
target(*pHalfedge, _pMesh)) ==
5816 put(this->vertex_Component_Number,
5817 target(*pHalfedge, _pMesh),
5822 Point_Int Temp_pos = Change_Real_Int(Wrong_position, 0);
5823 Point3d Real_position = Change_Int_Real(Temp_pos, Component_number);
5825 put(*_pm,
target(*pHalfedge, _pMesh), Real_position);
5828 Wrong_LAB[0] =
get(*_v_cm,
target(*pHalfedge, _pMesh))[0];
5829 Wrong_LAB[1] =
get(*_v_cm,
target(*pHalfedge, _pMesh))[1];
5830 Wrong_LAB[2] =
get(*_v_cm,
target(*pHalfedge, _pMesh))[2];
5832 int Original_LAB[3];
5833 Original_LAB[0] = (int)floor((Wrong_LAB[0] - this->C0_Min) /
5834 this->Color_Quantization_Step +
5836 Original_LAB[1] = (int)floor((Wrong_LAB[1] - this->C1_Min) /
5837 this->Color_Quantization_Step +
5839 Original_LAB[2] = (int)floor((Wrong_LAB[2] - this->C2_Min) /
5840 this->Color_Quantization_Step +
5843 put(this->vertex_color_int,
5844 target(*pHalfedge, _pMesh),
5845 Color_Unit(Original_LAB[0], Original_LAB[1], Original_LAB[2]));
5847 if(this->NumberColorQuantization[Component_number] == 0)
5848 Color_small_step = this->Color_Quantization_Step;
5851 this->Color_Quantization_Step *
5853 this->NumberColorQuantization[Component_number]);
5857 LAB[0] = this->C0_Min + Original_LAB[0] * Color_small_step;
5858 LAB[1] = this->C1_Min + Original_LAB[1] * Color_small_step;
5859 LAB[2] = this->C2_Min + Original_LAB[2] * Color_small_step;
5863 typename boost::property_traits< VertexColorMap >::value_type
5866 target(*pHalfedge, _pMesh),
5867 Color(RGB[0], RGB[1], RGB[2]));
5871 if(pNFacet != boost::graph_traits< HalfedgeGraph >::null_face() &&
5872 get(this->facet_tag, pNFacet) == -1)
5874 facets.push_front(pNFacet);
5875 put(this->facet_tag, pNFacet, Component_index);
5884 this->IsDecompress =
true;
5885 this->Current_level = 0;
5887 this->Total_layer = this->GlobalCountOperation;
5890 float prog = (float)this->Calculate_Current_File_Size() /
5891 this->Compressed_file_size * 100;
5893 if(this->Initial_file_size != 0)
5894 ratio = 1 / ((float)this->Calculate_Current_File_Size() /
5895 this->Initial_file_size);
5897 std::ostringstream infos_tmp;
5898 infos_tmp <<
"Number of all levels : ";
5899 infos_tmp << int(this->Total_layer);
5901 infos_tmp << std::setw(3) << prog;
5903 infos_tmp << std::setw(3) << ratio;
5904 std::string infos(infos_tmp.str());
5907 this->Prog.push_back(prog);
5908 this->Ratio.clear();
5909 this->Ratio.push_back(ratio);
5911 std::cout << infos << std::endl;
5918 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
5923 VertexColorMap *_v_cm)
5925 if(this->Decompress_count < this->GlobalCountOperation)
5927 for(
int Component_ID = 0; Component_ID < this->NumberComponents;
5930 if(this->Decompress_count < this->ComponentOperations[Component_ID])
5932 int Operation = Decoder.get_bits(2);
5935 #ifdef DBG_Decompress_Each_Step
5936 std::cout <<
"DBG in " << __func__
5937 <<
" Decompress_count=" << this->Decompress_count
5938 <<
" Component_ID=" << Component_ID
5939 <<
" Operation=" << Operation << std::endl;
5940 DBG_print_mesh_geometry(_pMesh, _pm,
"before Un_Regulation");
5941 DBG_print_mesh_vertexcolor(_pMesh, _v_cm,
"before Un_Regulation");
5944 this->Un_Regulation(_pMesh, Decoder, Component_ID, _pm, _v_cm);
5946 #ifdef DBG_Decompress_Each_Step
5947 DBG_print_mesh_geometry(_pMesh, _pm,
"after Un_Regulation");
5948 DBG_print_mesh_vertexcolor(_pMesh, _v_cm,
"after Un_Regulation");
5951 this->Un_Decimation_Conquest(
5952 _pMesh, Decoder, Component_ID, _pm, _v_cm);
5954 #ifdef DBG_Decompress_Each_Step
5955 DBG_print_mesh_geometry(_pMesh, _pm,
"after Un_Decimation_Conquest");
5956 DBG_print_mesh_vertexcolor(
5957 _pMesh, _v_cm,
"after Un_Decimation_Conquest");
5960 else if(Operation == 1)
5962 this->Augment_Geometry_Quantization_Precision(
5963 _pMesh, Decoder, Component_ID, _pm);
5965 #ifdef DBG_Decompress_Each_Step
5966 std::cout <<
"DBG in " << __func__
5967 <<
" Decompress_count=" << this->Decompress_count
5968 <<
" Component_ID=" << Component_ID
5969 <<
" Operation=" << Operation << std::endl;
5970 DBG_print_mesh_geometry(
5971 _pMesh, _pm,
"after Augment_Geometry_Quantization_Precision");
5972 DBG_print_mesh_vertexcolor(
5973 _pMesh, _v_cm,
"after Augment_Geometry_Quantization_Precision");
5976 else if(Operation == 2)
5978 this->Augment_Color_Quantization_Precision(
5979 _pMesh, Decoder, Component_ID, _v_cm);
5981 #ifdef DBG_Decompress_Each_Step
5982 std::cout <<
"DBG in " << __func__
5983 <<
" Decompress_count=" << this->Decompress_count
5984 <<
" Component_ID=" << Component_ID
5985 <<
" Operation=" << Operation << std::endl;
5986 DBG_print_mesh_geometry(
5987 _pMesh, _pm,
"after Augment_Color_Quantization_Precision");
5988 DBG_print_mesh_vertexcolor(
5989 _pMesh, _v_cm,
"after Augment_Color_Quantization_Precision");
5996 this->Decompress_count++;
5997 compute_normals(_pMesh, _pm);
5999 return this->Decompress_count;
6018 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6023 const int &_Component_ID,
6024 VertexColorMap *_v_cm)
6029 Color_quantization_model[i].set_alphabet(8);
6035 float Color_small_step = 0.0;
6036 float Color_large_step = 0.0;
6039 if(this->NumberColorQuantization[_Component_ID] == 0)
6040 Color_large_step = this->Color_Quantization_Step;
6043 this->Color_Quantization_Step *
6044 std::pow(2.0, this->NumberColorQuantization[_Component_ID]);
6046 Color_small_step = Color_large_step / (float)2.0;
6052 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * _Component_ID) ||
6054 2 * _Component_ID + 1))
6062 put(this->Vertex_Flag, *pVert,
FREE);
6063 put(this->Vertex_Number, *pVert, -1);
6064 put(this->vertex_Component_Number, *pVert, -1);
6068 std::vector< std::vector< int > > Color_table;
6070 std::queue< vertex_descriptor > verticesq;
6073 verticesq.push(
target(*hi, _pMesh));
6076 int Vertex_index = 0;
6078 while(!verticesq.empty())
6089 put(this->Vertex_Number, v, Vertex_index);
6090 put(this->vertex_Component_Number, v, _Component_ID);
6092 std::vector< int > LAB;
6095 LAB.push_back(color.
c0);
6096 LAB.push_back(color.
c1);
6097 LAB.push_back(color.
c2);
6099 bool Is_existed_color =
false;
6101 int Color_index = -1;
6104 for(
int i = 0; i < (int)Color_table.size(); i++)
6106 if((LAB[0] == Color_table[i][0]) && (LAB[1] == Color_table[i][1]) &&
6107 (LAB[2] == Color_table[i][2]))
6109 Is_existed_color =
true;
6110 Color_index = Decoder.
decode(Color_quantization_model[i]);
6116 if(Is_existed_color ==
false)
6119 Decoder.
decode(Color_quantization_model[Color_table.size()]);
6120 Color_table.push_back(LAB);
6123 put(this->vertex_Q_Index, v, Color_index);
6128 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h;
6131 if(Vertex_index == 0)
6133 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
6137 }
while((*h) != (*hi));
6144 int Comp_number = -2;
6145 h = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(v, _pMesh);
6146 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
6164 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > h2 = h;
6180 if(
get(this->vertex_Component_Number, *pVert) == _Component_ID)
6182 int Coeff[3] = { 0 };
6183 Get_Coefficient_Up_Quantization(
get(this->vertex_Q_Index, *pVert), Coeff);
6186 int LAB_init_C0 = color.
c0;
6187 int LAB_init_C1 = color.
c1;
6188 int LAB_init_C2 = color.
c2;
6191 int LAB_final_C0 = LAB_init_C0 * 2;
6192 int LAB_final_C1 = LAB_init_C1 * 2;
6193 int LAB_final_C2 = LAB_init_C2 * 2;
6203 put(this->vertex_color_int,
6205 Color_Unit(LAB_final_C0, LAB_final_C1, LAB_final_C2));
6207 float Inter_color[3];
6210 Inter_color[0] = this->C0_Min + LAB_final_C0 * Color_small_step;
6211 Inter_color[1] = this->C1_Min + LAB_final_C1 * Color_small_step;
6212 Inter_color[2] = this->C2_Min + LAB_final_C2 * Color_small_step;
6214 LAB_To_RGB(Inter_color[0], Inter_color[1], Inter_color[2], RGB);
6217 typename boost::property_traits< VertexColorMap >::value_type Color;
6218 put(*_v_cm, *pVert, Color(RGB[0], RGB[1], RGB[2]));
6223 this->NumberColorQuantization[_Component_ID]--;
6225 delete[] Color_quantization_model;
6230 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6237 double Quantization_step = 0.0;
6241 if(this->NumberChangeQuantization[Component_ID] == 0)
6242 Quantization_step = this->Quantization_Step[Component_ID];
6245 this->Quantization_Step[Component_ID] *
6246 std::pow(2.0, (
int)this->NumberChangeQuantization[Component_ID]);
6248 float xmin = this->xmin[Component_ID];
6249 float ymin = this->ymin[Component_ID];
6250 float zmin = this->zmin[Component_ID];
6256 Point.x = (int)(ceil((x - xmin) / Quantization_step)) - 1;
6260 Point.y = (int)(ceil((y - ymin) / Quantization_step)) - 1;
6264 Point.z = (int)(ceil((z - zmin) / Quantization_step)) - 1;
6273 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6280 float Quantization_step = 0;
6284 if(this->NumberChangeQuantization[Component_ID] == 0)
6285 Quantization_step = this->Quantization_Step[Component_ID];
6288 this->Quantization_Step[Component_ID] *
6289 std::pow(2.0, (
int)this->NumberChangeQuantization[Component_ID]);
6291 float xmin = this->xmin[Component_ID];
6292 float ymin = this->ymin[Component_ID];
6293 float zmin = this->zmin[Component_ID];
6295 double x = xmin + (
Point.x + 0.5) * Quantization_step;
6296 double y = ymin + (
Point.y + 0.5) * Quantization_step;
6297 double z = zmin + (
Point.z + 0.5) * Quantization_step;
6309 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6313 const PointMap *_pm,
6315 const int &_Component_ID,
6316 const double &Mean_color,
6317 const double &Mean_area)
6321 int Type = Find_Type(_pMesh, g, Valence);
6323 float C0_min = this->C0_Min;
6324 float C1_min = this->C1_Min;
6325 float C2_min = this->C2_Min;
6327 float Color_step = 0.0;
6329 if(this->NumberColorQuantization[_Component_ID] == 0)
6330 Color_step = this->Color_Quantization_Step;
6333 this->Color_Quantization_Step *
6334 std::pow(2.0, (
double)this->NumberColorQuantization[_Component_ID]);
6336 std::vector< float > Center_color;
6337 Center_color.push_back(
6339 (
get(this->vertex_color_int,
target(
next(g, _pMesh), _pMesh))).c0 *
6341 Center_color.push_back(
6343 (
get(this->vertex_color_int,
target(
next(g, _pMesh), _pMesh))).c1 *
6345 Center_color.push_back(
6347 (
get(this->vertex_color_int,
target(
next(g, _pMesh), _pMesh))).c2 *
6350 std::vector< Color_Unit > Neighbors_color;
6352 std::vector< float > Projected_color;
6354 double Patch_area = 0.0;
6357 g =
next(g, _pMesh);
6358 for(
int i = 0; i < Valence; i++)
6363 c =
get(this->vertex_color_int,
target(g, _pMesh));
6364 Neighbors_color.push_back(c);
6366 Patch_area += Area_Facet_Triangle(g, _pMesh, _pm);
6368 g =
prev(g, _pMesh);
6375 for(
int i = 0; i < 3; i++)
6376 Average_color = Average_color + Neighbors_color[i];
6381 if((Type == 5) || (Type == 8))
6383 Average_color = Average_color + Neighbors_color[1];
6384 Average_color = Average_color + Neighbors_color[3];
6387 if((Type == 6) || (Type == 7))
6389 Average_color = Average_color + Neighbors_color[0];
6390 Average_color = Average_color + Neighbors_color[2];
6396 if((Type == 9) || (Type == 12))
6398 Average_color = Average_color + Neighbors_color[1];
6399 Average_color = Average_color + Neighbors_color[3];
6400 Average_color = Average_color + Neighbors_color[4];
6405 Average_color = Average_color + Neighbors_color[0];
6406 Average_color = Average_color + Neighbors_color[1];
6407 Average_color = Average_color + Neighbors_color[3];
6412 Average_color = Average_color + Neighbors_color[0];
6413 Average_color = Average_color + Neighbors_color[2];
6414 Average_color = Average_color + Neighbors_color[4];
6421 if((Type == 13) || (Type == 16))
6423 Average_color = Average_color + Neighbors_color[1];
6424 Average_color = Average_color + Neighbors_color[3];
6425 Average_color = Average_color + Neighbors_color[5];
6429 Average_color = Average_color + Neighbors_color[0];
6430 Average_color = Average_color + Neighbors_color[2];
6431 Average_color = Average_color + Neighbors_color[4];
6435 float Divised_c0, Divised_c1, Divised_c2;
6438 Divised_c0 = (float)Average_color.
c0 / 3.0;
6439 Divised_c1 = (
float)Average_color.
c1 / 3.0;
6440 Divised_c2 = (float)Average_color.
c2 / 3.0;
6444 Divised_c0 = (float)Average_color.
c0 / 2.0;
6445 Divised_c1 = (
float)Average_color.
c1 / 2.0;
6446 Divised_c2 = (float)Average_color.
c2 / 2.0;
6449 Projected_color.push_back(C0_min + Divised_c0 * Color_step);
6450 Projected_color.push_back(C1_min + Divised_c1 * Color_step);
6451 Projected_color.push_back(C2_min + Divised_c2 * Color_step);
6455 double Color_distance = (Projected_color[0] - Center_color[0]) *
6456 (Projected_color[0] - Center_color[0]) +
6457 (Projected_color[1] - Center_color[1]) *
6458 (Projected_color[1] - Center_color[1]) +
6459 (Projected_color[2] - Center_color[2]) *
6460 (Projected_color[2] - Center_color[2]);
6462 Color_distance = std::sqrt(Color_distance);
6466 double Relative_color_distance = Color_distance / Mean_color * 3.0;
6467 #ifdef DBG_Error_Projected_Surface
6468 std::cout <<
"Color_distance = " << Color_distance << std::endl;
6469 std::cout <<
"Mean_color = " << Mean_color << std::endl;
6470 std::cout <<
"Relative_color_distance = " << Relative_color_distance
6475 double Area_per_triangle = Patch_area / double(Valence);
6476 Area_per_triangle *= std::pow(
6477 ((
double)10.0 / (
double)this->HighestLengthBB[_Component_ID]), 2.0);
6479 double Relative_geo_distance = Area_per_triangle / Mean_area;
6480 #ifdef DBG_Error_Projected_Surface
6481 std::cout <<
"Area_per_triangle = " << Area_per_triangle << std::endl;
6482 std::cout <<
"Mean_area = " << Mean_area << std::endl;
6483 std::cout <<
"Relative_geo_distance = " << Relative_geo_distance << std::endl;
6486 double Global_distance = (Relative_color_distance) * (Relative_geo_distance);
6487 #ifdef DBG_Error_Projected_Surface
6488 std::cout <<
"Global_distance = " << Global_distance << std::endl;
6491 if(Global_distance > 0.5)
6498 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6502 const VertexColorMap *_v_cm)
6505 std::string outputFilePath = this->File_name;
6506 outputFilePath +=
".level" + std::to_string(this->Current_level) +
".off";
6518 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6522 const VertexColorMap *_v_cm,
6523 HalfedgeGraph &mesh_copy,
6524 VertexColorMap *v_cm_copy )
6527 boost::unordered_map< vertex_descriptor, vertex_descriptor > v2v;
6530 CGAL::clear(mesh_copy);
6531 CGAL::copy_face_graph(_pMesh, mesh_copy, std::inserter(v2v, v2v.end()));
6540 for(; it != end; ++it)
6542 auto color =
get(*_v_cm, it->first);
6543 put(*v_cm_copy, it->second, color);
6549 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6553 const HalfedgeGraph &_pMesh,
6554 const VertexColorMap *_v_cm,
6555 std::vector< HalfedgeGraph * > *intermediate_meshes,
6556 std::vector< VertexColorMap * > *intermediate_vertexColorMaps)
6558 if(!intermediate_meshes)
6562 HalfedgeGraph *m_copy =
new HalfedgeGraph;
6565 VertexColorMap *v_cm_copy =
nullptr;
6566 if(intermediate_vertexColorMaps)
6567 v_cm_copy =
new VertexColorMap;
6570 copy_mesh(_pMesh, _v_cm, *m_copy, v_cm_copy);
6573 intermediate_meshes->push_back(m_copy);
6574 if(intermediate_vertexColorMaps)
6575 intermediate_vertexColorMaps->push_back(v_cm_copy);
6581 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6585 HalfedgeGraph &_pMesh,
6587 VertexColorMap *_v_cm,
6589 std::vector< HalfedgeGraph * >
6590 *intermediate_meshes ,
6591 std::vector< VertexColorMap * >
6592 *intermediate_vertexColorMaps ,
6594 bool do_write_intermediate_meshes)
6597 auto time_start = std::chrono::steady_clock::now();
6601 if(this->Process_level == 0)
6606 truncate_colors(_pMesh, _v_cm);
6609 if(do_write_intermediate_meshes)
6610 write_intermediate_mesh(_pMesh, _v_cm);
6613 if(intermediate_meshes)
6614 keep_intermediate_mesh(
6615 _pMesh, _v_cm, intermediate_meshes, intermediate_vertexColorMaps);
6618 if(stop_level == -1 || stop_level > this->Total_layer)
6619 stop_level = this->Total_layer;
6622 while(this->Current_level != stop_level)
6624 #ifdef DBG_Decompression_All_From_File
6625 std::cout <<
"DBG in " << __func__
6626 <<
" Current_level=" << this->Current_level << std::endl;
6627 DBG_print_mesh_geometry(_pMesh, _pm,
"loop begin");
6628 DBG_print_mesh_vertexcolor(_pMesh, _v_cm,
"loop begin");
6631 this->Current_level = this->Decompress_Each_Step(_pMesh, _pm, _v_cm);
6632 this->Process_level++;
6640 truncate_colors(_pMesh, _v_cm);
6643 if(do_write_intermediate_meshes)
6644 write_intermediate_mesh(_pMesh, _v_cm);
6647 if(intermediate_meshes && this->Current_level < stop_level)
6648 keep_intermediate_mesh(
6649 _pMesh, _v_cm, intermediate_meshes, intermediate_vertexColorMaps);
6652 #ifdef DBG_Decompression_All_From_File
6653 DBG_print_mesh_geometry(_pMesh, _pm,
"loop end");
6654 DBG_print_mesh_vertexcolor(_pMesh, _v_cm,
"loop end");
6659 auto time_end = std::chrono::steady_clock::now();
6660 std::chrono::duration< double > time_diff = time_end - time_start;
6661 std::stringstream msgbuffer;
6662 msgbuffer <<
"Number of layers : " << this->Total_layer << std::endl;
6663 msgbuffer <<
"Calculation time for decompressing layers 1 to "
6664 << stop_level <<
" : " << (float)time_diff.count()
6665 <<
" seconds" << std::endl;
6666 msgbuffer <<
"Time for loading .p3d and decompressing layer 0 was not taken "
6669 std::cout << msgbuffer.str() << std::endl;
6671 return msgbuffer.str();
6675 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6680 if(this->Process_level == 0)
6682 this->Dec_File_Info = this->File_name;
6683 (this->Dec_File_Info).append(
".infos.txt");
6685 this->Dec_Info = fopen(this->Dec_File_Info.c_str(),
"w");
6688 this->Dec_Info = fopen(this->Dec_File_Info.c_str(),
"a");
6690 int CLevel = 0, Number_vertices = 0;
6694 CLevel = this->Visu_level;
6699 CLevel = this->Current_level;
6703 unsigned Current_file_size = this->Calculate_Current_File_Size();
6705 float prog = (float)Current_file_size / this->Compressed_file_size * 100;
6707 if(this->Process_level == this->Total_layer)
6710 float ratio = 1 / ((float)Current_file_size / this->Initial_file_size);
6712 fprintf(this->Dec_Info,
6713 "Level %2d #v : %8d %6u bytes Prog : %7.3f %% Ratio : "
6720 fclose(this->Dec_Info);
6728 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6735 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > hvc(
target(h, mesh),
6737 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > hvc_end(hvc);
6741 if(CGAL::is_border_edge(*hvc, mesh))
6746 }
while(++hvc != hvc_end);
6752 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6766 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6770 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6780 else if(valence == 4)
6785 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6789 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6799 else if(valence == 5)
6804 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6808 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6818 else if(valence == 6)
6823 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6827 else if((
get(this->Vertex_Sign,
target(h, _pMesh)) ==
PLUS) &&
6840 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
6850 int *Points_index =
new int[valence];
6860 Points_index[0] =
get(this->Vertex_Number,
target(g, _pMesh));
6861 g =
next(g, _pMesh);
6863 for(
int i = 1; i < valence; i++)
6874 if((type == 5) || (type == 8))
6877 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
6878 target(g, _pMesh), _pMesh);
6879 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
6881 CGAL_For_all(Hvc, Hvc_end)
6889 else if((type == 6) || (type == 7))
6892 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
6893 target(g, _pMesh), _pMesh);
6894 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
6896 CGAL_For_all(Hvc, Hvc_end)
6909 if((type == 9) || (type == 12))
6912 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
6913 target(g, _pMesh), _pMesh);
6914 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
6916 CGAL_For_all(Hvc, Hvc_end)
6924 Hvc = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(
6925 target(g, _pMesh), _pMesh);
6928 CGAL_For_all(Hvc, Hvc_end)
6939 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
6940 target(g, _pMesh), _pMesh);
6941 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
6943 CGAL_For_all(Hvc, Hvc_end)
6951 Hvc = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(
6952 target(g, _pMesh), _pMesh);
6955 CGAL_For_all(Hvc, Hvc_end)
6966 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
6967 target(g, _pMesh), _pMesh);
6968 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
6970 CGAL_For_all(Hvc, Hvc_end)
6978 Hvc = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(
6979 target(g, _pMesh), _pMesh);
6982 CGAL_For_all(Hvc, Hvc_end)
6995 if((type == 13) || (type == 16))
6998 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
6999 target(g, _pMesh), _pMesh);
7000 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
7002 CGAL_For_all(Hvc, Hvc_end)
7010 Hvc = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(
7011 target(g, _pMesh), _pMesh);
7014 CGAL_For_all(Hvc, Hvc_end)
7022 Hvc = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(
7023 target(g, _pMesh), _pMesh);
7026 CGAL_For_all(Hvc, Hvc_end)
7034 else if((type == 14) || (type == 15))
7037 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc(
7038 target(g, _pMesh), _pMesh);
7039 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > Hvc_end = Hvc;
7041 CGAL_For_all(Hvc, Hvc_end)
7049 Hvc = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(
7050 target(g, _pMesh), _pMesh);
7053 CGAL_For_all(Hvc, Hvc_end)
7061 Hvc = CGAL::Halfedge_around_target_circulator< HalfedgeGraph >(
7062 target(g, _pMesh), _pMesh);
7065 CGAL_For_all(Hvc, Hvc_end)
7075 delete[] Points_index;
7079 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7083 const PointMap *_pm,
7085 const unsigned &valence)
7091 int type = Find_Type(_pMesh, h, valence);
7096 g =
next(g, _pMesh);
7101 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
7104 V_normal = V_normal / length;
7110 for(
unsigned int i = 0; i < valence; i++)
7116 for(
unsigned int j = 0; j < (valence - 2); j++)
7118 Normal[j] =
Vector(0.0, 0.0, 0.0);
7128 else if((type == 5) || (type == 8))
7130 Normal[0] = Triangle_Normal(_pMesh, Points[0], Points[1], Points[3]);
7131 Normal[1] = Triangle_Normal(_pMesh, Points[1], Points[2], Points[3]);
7134 else if((type == 6) || (type == 7))
7136 Normal[0] = Triangle_Normal(_pMesh, Points[0], Points[1], Points[2]);
7137 Normal[1] = Triangle_Normal(_pMesh, Points[0], Points[2], Points[3]);
7141 else if((type == 9) || (type == 12))
7143 Normal[0] = Triangle_Normal(_pMesh, Points[0], Points[1], Points[4]);
7144 Normal[1] = Triangle_Normal(_pMesh, Points[1], Points[2], Points[3]);
7145 Normal[2] = Triangle_Normal(_pMesh, Points[1], Points[3], Points[4]);
7151 Normal[0] = Triangle_Normal(_pMesh, Points[0], Points[1], Points[3]);
7152 Normal[1] = Triangle_Normal(_pMesh, Points[1], Points[2], Points[3]);
7153 Normal[2] = Triangle_Normal(_pMesh, Points[0], Points[3], Points[4]);
7158 Normal[0] = Triangle_Normal(_pMesh, Points[0], Points[1], Points[2]);
7159 Normal[1] = Triangle_Normal(_pMesh, Points[0], Points[2], Points[4]);
7160 Normal[2] = Triangle_Normal(_pMesh, Points[2], Points[3], Points[4]);
7165 else if((type == 13) || (type == 16))
7167 Normal[0] = Triangle_Normal(_pMesh, Points[0], Points[1], Points[5]);
7168 Normal[1] = Triangle_Normal(_pMesh, Points[1], Points[2], Points[3]);
7169 Normal[2] = Triangle_Normal(_pMesh, Points[3], Points[4], Points[5]);
7170 Normal[3] = Triangle_Normal(_pMesh, Points[1], Points[3], Points[5]);
7173 else if((type == 14) || (type == 15))
7175 Normal[0] = Triangle_Normal(_pMesh, Points[0], Points[1], Points[2]);
7176 Normal[1] = Triangle_Normal(_pMesh, Points[2], Points[3], Points[4]);
7177 Normal[2] = Triangle_Normal(_pMesh, Points[4], Points[5], Points[0]);
7178 Normal[3] = Triangle_Normal(_pMesh, Points[0], Points[2], Points[4]);
7181 for(
unsigned int i = 0; i < (valence - 2); i++)
7185 if(length_normal != 0)
7186 Normal[i] = Normal[i] / length_normal;
7189 for(
unsigned int i = 0; i < (valence - 2); i++)
7195 if(cosine_rad >=
PI / 2)
7205 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7209 const PointMap *_pm,
7227 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
7230 normal = normal / length;
7236 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7240 const HalfedgeGraph &_pMesh,
7256 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
7259 normal = normal / length;
7265 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7269 const PointMap *_pm,
7272 const unsigned int &valence,
7273 const float &Threshold)
7279 double perimeter = 0;
7285 g =
next(g, _pMesh);
7289 Points[0] =
get(*_pm,
target(g, _pMesh));
7290 for(i = 1; i < (valence + 1); i++)
7298 Vectors[0] = Points[1] - Points[valence];
7300 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
7303 for(i = 1; i < valence; i++)
7305 Vectors[i] = Points[(i + 1)] - Points[i];
7308 perimeter = perimeter + per;
7314 volume = Volume(Points[0], Points[1], Points[3], Points[2], _pMesh);
7315 volume = std::abs(volume);
7317 area = Area_Facet_Triangle(Points[1], Points[2], Points[3], _pMesh);
7318 area = std::abs(area);
7321 else if(valence == 4)
7323 if((type == 5) || (type == 8))
7325 double vol = Volume(Points[0], Points[1], Points[4], Points[2], _pMesh);
7326 vol = std::abs(vol);
7327 volume = volume + vol;
7329 vol = Volume(Points[0], Points[2], Points[4], Points[3], _pMesh);
7330 vol = std::abs(vol);
7331 volume = volume + vol;
7333 double area_intermediate =
7334 Area_Facet_Triangle(Points[1], Points[2], Points[4], _pMesh);
7335 area_intermediate = std::abs(area_intermediate);
7336 area = area + area_intermediate;
7339 Area_Facet_Triangle(Points[2], Points[3], Points[4], _pMesh);
7340 area_intermediate = std::abs(area_intermediate);
7341 area = area + area_intermediate;
7344 else if((type == 6) || (type == 7))
7346 double vol = Volume(Points[0], Points[1], Points[3], Points[2], _pMesh);
7347 vol = std::abs(vol);
7348 volume = volume + vol;
7350 vol = Volume(Points[0], Points[1], Points[4], Points[3], _pMesh);
7351 vol = std::abs(vol);
7352 volume = volume + vol;
7354 double area_intermediate =
7355 Area_Facet_Triangle(Points[1], Points[2], Points[3], _pMesh);
7356 area_intermediate = std::abs(area_intermediate);
7357 area = area + area_intermediate;
7360 Area_Facet_Triangle(Points[1], Points[3], Points[4], _pMesh);
7361 area_intermediate = std::abs(area_intermediate);
7362 area = area + area_intermediate;
7366 else if(valence == 5)
7368 if((type == 9) || (type == 12))
7370 double vol = Volume(Points[0], Points[1], Points[5], Points[2], _pMesh);
7371 vol = std::abs(vol);
7372 volume = volume + vol;
7374 vol = Volume(Points[0], Points[2], Points[5], Points[4], _pMesh);
7375 vol = std::abs(vol);
7376 volume = volume + vol;
7378 vol = Volume(Points[0], Points[2], Points[4], Points[3], _pMesh);
7379 vol = std::abs(vol);
7380 volume = volume + vol;
7382 double area_intermediate =
7383 Area_Facet_Triangle(Points[1], Points[2], Points[5], _pMesh);
7384 area_intermediate = std::abs(area_intermediate);
7385 area = area + area_intermediate;
7388 Area_Facet_Triangle(Points[2], Points[4], Points[5], _pMesh);
7389 area_intermediate = std::abs(area_intermediate);
7390 area = area + area_intermediate;
7393 Area_Facet_Triangle(Points[2], Points[3], Points[4], _pMesh);
7394 area_intermediate = std::abs(area_intermediate);
7395 area = area + area_intermediate;
7400 double vol = Volume(Points[0], Points[1], Points[5], Points[4], _pMesh);
7401 vol = std::abs(vol);
7402 volume = volume + vol;
7404 vol = Volume(Points[0], Points[1], Points[4], Points[2], _pMesh);
7405 vol = std::abs(vol);
7406 volume = volume + vol;
7408 vol = Volume(Points[0], Points[2], Points[4], Points[3], _pMesh);
7409 vol = std::abs(vol);
7410 volume = volume + vol;
7412 double area_intermediate =
7413 Area_Facet_Triangle(Points[1], Points[4], Points[5], _pMesh);
7414 area_intermediate = std::abs(area_intermediate);
7415 area = area + area_intermediate;
7418 Area_Facet_Triangle(Points[1], Points[2], Points[4], _pMesh);
7419 area_intermediate = std::abs(area_intermediate);
7420 area = area + area_intermediate;
7423 Area_Facet_Triangle(Points[2], Points[3], Points[4], _pMesh);
7424 area_intermediate = std::abs(area_intermediate);
7425 area = area + area_intermediate;
7430 double vol = Volume(Points[0], Points[1], Points[3], Points[2], _pMesh);
7431 vol = std::abs(vol);
7432 volume = volume + vol;
7434 vol = Volume(Points[0], Points[1], Points[5], Points[3], _pMesh);
7435 vol = std::abs(vol);
7436 volume = volume + vol;
7438 vol = Volume(Points[0], Points[3], Points[5], Points[4], _pMesh);
7439 vol = std::abs(vol);
7440 volume = volume + vol;
7442 double area_intermediate =
7443 Area_Facet_Triangle(Points[1], Points[2], Points[3], _pMesh);
7444 area_intermediate = std::abs(area_intermediate);
7445 area = area + area_intermediate;
7448 Area_Facet_Triangle(Points[1], Points[3], Points[5], _pMesh);
7449 area_intermediate = std::abs(area_intermediate);
7450 area = area + area_intermediate;
7453 Area_Facet_Triangle(Points[3], Points[4], Points[5], _pMesh);
7454 area_intermediate = std::abs(area_intermediate);
7455 area = area + area_intermediate;
7459 else if(valence == 6)
7464 double vol = Volume(Points[0], Points[1], Points[6], Points[2], _pMesh);
7465 vol = std::abs(vol);
7466 volume = volume + vol;
7468 vol = Volume(Points[0], Points[2], Points[4], Points[3], _pMesh);
7469 vol = std::abs(vol);
7470 volume = volume + vol;
7472 vol = Volume(Points[0], Points[4], Points[6], Points[5], _pMesh);
7473 vol = std::abs(vol);
7474 volume = volume + vol;
7476 vol = Volume(Points[0], Points[2], Points[6], Points[4], _pMesh);
7477 vol = std::abs(vol);
7478 volume = volume + vol;
7480 double area_intermediate =
7481 Area_Facet_Triangle(Points[1], Points[2], Points[6], _pMesh);
7482 area_intermediate = std::abs(area_intermediate);
7483 area = area + area_intermediate;
7486 Area_Facet_Triangle(Points[2], Points[3], Points[4], _pMesh);
7487 area_intermediate = std::abs(area_intermediate);
7488 area = area + area_intermediate;
7491 Area_Facet_Triangle(Points[4], Points[5], Points[6], _pMesh);
7492 area_intermediate = std::abs(area_intermediate);
7493 area = area + area_intermediate;
7496 Area_Facet_Triangle(Points[2], Points[6], Points[4], _pMesh);
7497 area_intermediate = std::abs(area_intermediate);
7498 area = area + area_intermediate;
7501 else if((type == 14) ||
7504 double vol = Volume(Points[0], Points[1], Points[3], Points[2], _pMesh);
7505 vol = std::abs(vol);
7506 volume = volume + vol;
7508 vol = Volume(Points[0], Points[3], Points[5], Points[4], _pMesh);
7509 vol = std::abs(vol);
7510 volume = volume + vol;
7512 vol = Volume(Points[0], Points[1], Points[6], Points[5], _pMesh);
7513 vol = std::abs(vol);
7514 volume = volume + vol;
7516 vol = Volume(Points[0], Points[1], Points[5], Points[3], _pMesh);
7517 vol = std::abs(vol);
7518 volume = volume + vol;
7520 double area_intermediate =
7521 Area_Facet_Triangle(Points[1], Points[2], Points[3], _pMesh);
7522 area_intermediate = std::abs(area_intermediate);
7523 area = area + area_intermediate;
7526 Area_Facet_Triangle(Points[3], Points[4], Points[5], _pMesh);
7527 area_intermediate = std::abs(area_intermediate);
7528 area = area + area_intermediate;
7531 Area_Facet_Triangle(Points[1], Points[5], Points[6], _pMesh);
7532 area_intermediate = std::abs(area_intermediate);
7533 area = area + area_intermediate;
7536 Area_Facet_Triangle(Points[1], Points[3], Points[5], _pMesh);
7537 area_intermediate = std::abs(area_intermediate);
7538 area = area + area_intermediate;
7542 double volume_3_root = 0.0;
7544 double volume_measured = 0.0;
7547 volume_3_root = volume;
7549 volume_3_root = exp(1.0 / 3.0 * (
double)log(volume));
7553 volume_measured = volume_3_root / (perimeter / (double)valence);
7557 if(volume_measured > Threshold)
7568 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7572 const typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor
7574 const HalfedgeGraph &_pMesh,
7575 const PointMap *_pm)
7588 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7594 const HalfedgeGraph &_pMesh)
7598 Vector PQ = FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
7601 Vector QR = FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
7608 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
7615 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7622 const HalfedgeGraph &_pMesh)
7634 Vector AB = FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
7636 Vector AC = FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
7638 Vector AD = FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
7653 double vol = x1 * y2 * z3 + x2 * y3 * z1 + x3 * y1 * z2 - x1 * y3 * z2 -
7654 x3 * y2 * z1 - x2 * y1 * z3;
7660 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7665 return get(this->vertex_color_int,
target(h, _pMesh));
7669 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7674 const HalfedgeGraph &_pMesh)
7678 std::vector< Color_Unit >
7680 int Average_c0 = 0, Average_c1 = 0, Average_c2 = 0;
7682 g =
next(g, _pMesh);
7684 for(
int i = 0; i < valence; i++)
7689 for(
unsigned j = 0; j < Neighbor_color.size(); j++)
7691 if(Neighbor_color[j] == col)
7699 Neighbor_color.push_back(col);
7701 Average_c0 += col.
c0;
7702 Average_c1 += col.
c1;
7703 Average_c2 += col.
c2;
7710 Average_color.
c0 = (int)floor((
float)(Average_c0 / valence) + 0.5);
7711 Average_color.
c1 = (int)floor((
float)(Average_c1 / valence) + 0.5);
7712 Average_color.
c2 = (int)floor((
float)(Average_c2 / valence) + 0.5);
7714 double Critere_c0 = 50000.0, Critere_c1 = 50000.0, Critere_c2 = 50000.0;
7715 int Index_c0 = -1, Index_c1 = -1, Index_c2 = -1;
7719 for(
unsigned i = 0; i < Neighbor_color.size(); i++)
7721 int Color_component_0 = Neighbor_color[i].c0;
7722 int Color_component_1 = Neighbor_color[i].c1;
7723 int Color_component_2 = Neighbor_color[i].c2;
7725 if(std::abs(Color_component_0 - Average_color.
c0) < Critere_c0)
7727 Critere_c0 = std::abs(Color_component_0 - Average_color.
c0);
7730 if(std::abs(Color_component_1 - Average_color.
c1) < Critere_c1)
7732 Critere_c1 = std::abs(Color_component_1 - Average_color.
c1);
7735 if(std::abs(Color_component_2 - Average_color.
c2) < Critere_c2)
7737 Critere_c2 = std::abs(Color_component_2 - Average_color.
c2);
7743 Resulting_color.
c0 = Neighbor_color[Index_c0].c0;
7744 Resulting_color.
c1 = Neighbor_color[Index_c1].c1;
7745 Resulting_color.
c2 = Neighbor_color[Index_c2].c2;
7747 return Resulting_color;
7751 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7757 const HalfedgeGraph &_pMesh,
7758 const PointMap *_pm)
7763 double x = 0., y = 0., z = 0.;
7765 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > vh_it(
7767 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > vh_it_end = vh_it;
7769 CGAL_For_all(vh_it, vh_it_end)
7777 x = x / (double)valence;
7778 y = y / (double)valence;
7779 z = z / (double)valence;
7785 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7792 const HalfedgeGraph &_pMesh,
7793 const PointMap *_pm)
7796 double x = 0, y = 0, z = 0;
7797 for(
int i = 0; i < valence; i++)
7804 g =
next(g, _pMesh);
7817 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
7822 const unsigned &valence,
7824 const int &Component_ID,
7825 const PointMap *_pm)
7827 int type = Find_Type(pMesh, ch, valence);
7835 if((type == 1) || (type == 2) || (type == 4))
7840 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
7842 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
7852 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
7854 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
7861 else if((type == 5) || (type == 8))
7869 #ifdef DBG_Retriangulation
7870 std::cout <<
"split face" << std::endl;
7872 h = CGAL::Euler::split_face(h, g, pMesh);
7874 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
7875 put(this->facet_Component_Number,
7879 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
7880 put(this->facet_normal,
7882 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
7889 else if((type == 6) || (type == 7))
7897 #ifdef DBG_Retriangulation
7898 std::cout <<
"split face" << std::endl;
7900 h = CGAL::Euler::split_face(h, g, pMesh);
7902 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
7903 put(this->facet_Component_Number,
7907 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
7908 put(this->facet_normal,
7910 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
7917 else if((type == 9) || (type == 12))
7929 #ifdef DBG_Retriangulation
7930 std::cout <<
"split face" << std::endl;
7932 h = CGAL::Euler::split_face(h, g, pMesh);
7934 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
7935 put(this->facet_Component_Number,
7941 put(this->facet_normal,
7943 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
7946 #ifdef DBG_Retriangulation
7947 std::cout <<
"split face" << std::endl;
7949 h = CGAL::Euler::split_face(h, g, pMesh);
7951 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
7952 put(this->facet_Component_Number,
7956 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
7957 put(this->facet_normal,
7959 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
7980 #ifdef DBG_Retriangulation
7981 std::cout <<
"split face" << std::endl;
7983 h = CGAL::Euler::split_face(h, g, pMesh);
7985 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
7986 put(this->facet_Component_Number,
7992 put(this->facet_normal,
7994 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
7999 #ifdef DBG_Retriangulation
8000 std::cout <<
"split face" << std::endl;
8002 h = CGAL::Euler::split_face(h, g, pMesh);
8004 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8005 put(this->facet_Component_Number,
8009 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
8010 put(this->facet_normal,
8012 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8031 #ifdef DBG_Retriangulation
8032 std::cout <<
"split face" << std::endl;
8034 h = CGAL::Euler::split_face(h, g, pMesh);
8036 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8037 put(this->facet_Component_Number,
8044 put(this->facet_normal,
8046 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8049 #ifdef DBG_Retriangulation
8050 std::cout <<
"split face" << std::endl;
8052 h = CGAL::Euler::split_face(h, g, pMesh);
8054 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8055 put(this->facet_Component_Number,
8059 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
8060 put(this->facet_normal,
8062 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8071 else if((type == 13) || (type == 16))
8080 if(
get(this->Vertex_Sign,
8082 put(this->Vertex_Sign,
8087 #ifdef DBG_Retriangulation
8088 std::cout <<
"split face" << std::endl;
8090 h = CGAL::Euler::split_face(h, g, pMesh);
8092 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8093 put(this->facet_Component_Number,
8097 put(this->facet_normal,
8099 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8105 #ifdef DBG_Retriangulation
8106 std::cout <<
"split face" << std::endl;
8108 h = CGAL::Euler::split_face(h, g, pMesh);
8110 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8111 put(this->facet_Component_Number,
8118 put(this->facet_normal,
8120 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8123 #ifdef DBG_Retriangulation
8124 std::cout <<
"split face" << std::endl;
8126 h = CGAL::Euler::split_face(h, g, pMesh);
8128 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8129 put(this->facet_Component_Number,
8133 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
8134 put(this->facet_normal,
8136 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8145 else if((type == 14) || (type == 15))
8154 if(
get(this->Vertex_Sign,
8156 put(this->Vertex_Sign,
8162 #ifdef DBG_Retriangulation
8163 std::cout <<
"split face" << std::endl;
8165 h = CGAL::Euler::split_face(h, g, pMesh);
8167 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8168 put(this->facet_Component_Number,
8175 put(this->facet_normal,
8177 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8180 #ifdef DBG_Retriangulation
8181 std::cout <<
"split face" << std::endl;
8183 h = CGAL::Euler::split_face(h, g, pMesh);
8185 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8186 put(this->facet_Component_Number,
8193 put(this->facet_normal,
8195 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8198 #ifdef DBG_Retriangulation
8199 std::cout <<
"split face" << std::endl;
8201 h = CGAL::Euler::split_face(h, g, pMesh);
8203 put(this->facet_Component_Number,
face(h, pMesh), Component_ID);
8204 put(this->facet_Component_Number,
8208 put(this->facet_normal,
face(h, pMesh), Triangle_Normal(pMesh, _pm, h));
8209 put(this->facet_normal,
8211 Triangle_Normal(pMesh, _pm,
opposite(h, pMesh)));
8221 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
8227 const unsigned int &valence,
8228 const HalfedgeGraph &_pMesh,
8229 const PointMap *_pm)
8234 int type = Find_Type(_pMesh, h, valence);
8236 double area[5] = {0, 0, 0, 0, 0};
8240 for(
int i = 0; i < 5; i++)
8242 normals[i] =
Vector(0.0, 0.0, 0.0);
8246 if((type == 1) || (type == 2) || (type == 4))
8248 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8249 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8253 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8254 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8258 else if((type == 5) || (type == 8))
8260 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8261 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8263 normals[2] = Triangle_Normal(_pMesh, _pm, h);
8264 area[2] = Area_Facet_Triangle(h, _pMesh, _pm);
8267 else if((type == 6) || (type == 7))
8269 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8270 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8273 normals[2] = Triangle_Normal(_pMesh, _pm, h);
8274 area[2] = Area_Facet_Triangle(h, _pMesh, _pm);
8278 else if((type == 9) || (type == 12))
8280 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8281 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8284 normals[2] = Triangle_Normal(_pMesh, _pm, h);
8285 area[2] = Area_Facet_Triangle(h, _pMesh, _pm);
8288 normals[3] = Triangle_Normal(_pMesh, _pm, h);
8289 area[3] = Area_Facet_Triangle(h, _pMesh, _pm);
8295 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8296 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8299 normals[2] = Triangle_Normal(_pMesh, _pm, h);
8300 area[2] = Area_Facet_Triangle(h, _pMesh, _pm);
8303 normals[3] = Triangle_Normal(_pMesh, _pm, h);
8304 area[3] = Area_Facet_Triangle(h, _pMesh, _pm);
8310 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8311 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8314 normals[2] = Triangle_Normal(_pMesh, _pm, h);
8315 area[2] = Area_Facet_Triangle(h, _pMesh, _pm);
8318 normals[3] = Triangle_Normal(_pMesh, _pm, h);
8319 area[3] = Area_Facet_Triangle(h, _pMesh, _pm);
8323 else if((type == 13) || (type == 16))
8326 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8327 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8331 normals[2] = Triangle_Normal(_pMesh, _pm, h);
8332 area[2] = Area_Facet_Triangle(h, _pMesh, _pm);
8335 normals[3] = Triangle_Normal(_pMesh, _pm, h);
8336 area[3] = Area_Facet_Triangle(h, _pMesh, _pm);
8339 normals[4] = Triangle_Normal(_pMesh, _pm, h);
8340 area[4] = Area_Facet_Triangle(h, _pMesh, _pm);
8343 else if((type == 14) || (type == 15))
8346 normals[1] = Triangle_Normal(_pMesh, _pm, h);
8347 area[1] = Area_Facet_Triangle(h, _pMesh, _pm);
8351 normals[2] = Triangle_Normal(_pMesh, _pm, h);
8352 area[2] = Area_Facet_Triangle(h, _pMesh, _pm);
8355 normals[3] = Triangle_Normal(_pMesh, _pm, h);
8356 area[3] = Area_Facet_Triangle(h, _pMesh, _pm);
8359 normals[4] = Triangle_Normal(_pMesh, _pm, h);
8360 area[4] = Area_Facet_Triangle(h, _pMesh, _pm);
8363 for(
unsigned int i = 0; i < (valence - 2); i++)
8364 area[0] = area[0] + area[i + 1];
8366 for(
unsigned int i = 0; i < (valence - 2); i++)
8367 area[i + 1] = area[i + 1] / area[0];
8369 for(
unsigned int i = 0; i < (valence - 2); i++)
8372 normals[i + 1], area[i + 1], gt);
8375 normal =
Vector(0.0, 0.0, 0.0);
8378 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
8389 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
8397 const HalfedgeGraph &_pMesh,
8398 const PointMap *_pm)
8406 Vector u = FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
8410 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
8417 FEVV::Math::Vector::l2_distance< FEVV::Geometry_traits< HalfedgeGraph > >(
8424 FEVV::Math::Vector::dot_product< FEVV::Geometry_traits< HalfedgeGraph > >(
8428 cosine = dot / product;
8437 double beta_rad = 0;
8438 if(cosine_rad <=
PI / 2)
8439 beta_rad =
PI / 2 - cosine_rad;
8441 beta_rad = cosine_rad -
PI / 2;
8442 double beta = std::cos(beta_rad);
8448 normal, cosine, gt);
8452 tmp2, 1.0 / beta, gt);
8455 T1 =
Vector(0.0, 0.0, 0.0);
8467 return (x < 0.) ? -1 : 1;
8470 template<
typename T >
8478 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
8486 typedef Eigen::Matrix3d Matrix;
8489 R << T1[0], T2[0], normal[0], T1[1], T2[1], normal[1], T1[2], T2[2],
8492 R.transposeInPlace();
8496 D1 << 1, 0, 0, 0, 1, 0, 0, 0, 1;
8498 D2 << 0, 1, 0, 1, 0, 0, 0, 0, 1;
8500 D3 << -1, 0, 0, 0, -1, 0, 0, 0, 1;
8502 D4 << 1, 0, 0, 0, 0, 1, 0, 1, 0;
8504 D5 << 1, 0, 0, 0, -1, 0, 0, 0, -1;
8505 Matrix *S =
new Matrix[16];
8508 if(std::abs(M(0, 2)) > std::abs(M(1, 2)))
8527 phi =
Signe(-1 * M(0, 2)) *
8531 R1 << std::cos(phi), -std::sin(phi), 0, std::sin(phi), std::cos(phi), 0, 0, 0,
8534 S[2] << 1, -std::tan(phi / 2), 0, 0, 1, 0, 0, 0, 1;
8535 S[3] << 1, 0, 0, std::sin(phi), 1, 0, 0, 0, 1;
8539 R1inv << std::cos(phi), std::sin(phi), 0, -std::sin(phi), std::cos(phi), 0, 0,
8544 if(std::abs(M(1, 2)) > std::abs(M(2, 2)))
8563 psi =
Signe(-1 * M(1, 2)) *
8567 R2 << 1, 0, 0, 0, std::cos(psi), -std::sin(psi), 0, std::sin(psi),
8569 S[7] << 1, 0, 0, 0, 1, -std::tan(psi / 2), 0, 0, 1;
8570 S[8] << 1, 0, 0, 0, 1, 0, 0, std::sin(psi), 1;
8574 R2inv << 1, 0, 0, 0, std::cos(psi), std::sin(psi), 0, -std::sin(psi),
8578 if(std::abs(M(0, 1)) > std::abs(M(1, 1)))
8589 double theta = -100;
8595 theta =
Signe(-1 * M(0, 1)) *
8598 S[12] << 1, -std::tan(theta / 2), 0, 0, 1, 0, 0, 0, 1;
8599 S[13] << 1, 0, 0, std::sin(theta), 1, 0, 0, 0, 1;
8603 R3 << std::cos(theta), -std::sin(theta), 0, std::sin(theta), std::cos(theta),
8605 Matrix R3inv = R3.inverse();
8609 u << Dist.
x, Dist.
y, Dist.
z;
8613 for(
int i = 0; i < 15; i++)
8615 if((i == 0) || (i == 1) || (i == 5) || (i == 6) || (i == 10) || (i == 11))
8618 m_inter << S[i](0, 0), -S[i](0, 1), -S[i](0, 2), -S[i](1, 0), S[i](1, 1),
8619 -S[i](1, 2), -S[i](2, 0), -S[i](2, 1), S[i](2, 2);
8622 int x = 0, y = 0, z = 0;
8623 x = ceil(u(0) - 0.5);
8624 y = ceil(u(1) - 0.5);
8625 z = ceil(u(2) - 0.5);
8631 New_Coordinates.
x = (int)u(0);
8632 New_Coordinates.
y = (int)u(1);
8633 New_Coordinates.
z = (int)u(2);
8636 return New_Coordinates;
8641 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
8650 #ifdef DBG_Inverse_Frenet_Rotation
8651 static unsigned int dbg_Inverse_Frenet_Rotation_call_cnt = 0;
8652 std::cout << __func__ <<
" call #" << ++dbg_Inverse_Frenet_Rotation_call_cnt
8656 typedef Eigen::Matrix3d Matrix;
8659 R << T1[0], T2[0], normal[0], T1[1], T2[1], normal[1], T1[2], T2[2],
8664 D1 << 1, 0, 0, 0, 1, 0, 0, 0, 1;
8666 D2 << 0, 1, 0, 1, 0, 0, 0, 0, 1;
8668 D3 << -1, 0, 0, 0, -1, 0, 0, 0, 1;
8670 D4 << 1, 0, 0, 0, 0, 1, 0, 1, 0;
8672 D5 << 1, 0, 0, 0, -1, 0, 0, 0, -1;
8673 Matrix *S =
new Matrix[16];
8676 if(std::abs(M(0, 2)) > std::abs(M(1, 2)))
8695 phi =
Signe(-1 * M(0, 2)) *
8699 R1 << std::cos(phi), -std::sin(phi), 0, std::sin(phi), std::cos(phi), 0, 0, 0,
8702 S[2] << 1, -std::tan(phi / 2), 0, 0, 1, 0, 0, 0, 1;
8703 S[3] << 1, 0, 0, std::sin(phi), 1, 0, 0, 0, 1;
8708 R1inv << std::cos(phi), std::sin(phi), 0, -std::sin(phi), std::cos(phi), 0, 0,
8713 if(std::abs(M(1, 2)) > std::abs(M(2, 2)))
8732 psi =
Signe(-1 * M(1, 2)) *
8736 R2 << 1, 0, 0, 0, std::cos(psi), -std::sin(psi), 0, std::sin(psi),
8738 S[7] << 1, 0, 0, 0, 1, -std::tan(psi / 2), 0, 0, 1;
8739 S[8] << 1, 0, 0, 0, 1, 0, 0, std::sin(psi), 1;
8744 R2inv << 1, 0, 0, 0, std::cos(psi), std::sin(psi), 0, -std::sin(psi),
8748 if(std::abs(M(0, 1)) > std::abs(M(1, 1)))
8759 double theta = -100;
8765 theta =
Signe(-1 * M(0, 1)) *
8768 S[12] << 1, -std::tan(theta / 2), 0, 0, 1, 0, 0, 0, 1;
8769 S[13] << 1, 0, 0, std::sin(theta), 1, 0, 0, 0, 1;
8773 R3 << std::cos(theta), -std::sin(theta), 0, std::sin(theta), std::cos(theta),
8775 Matrix R3inv = R3.inverse();
8779 u << Frenet.
x, Frenet.
y, Frenet.
z;
8782 for(
int i = 14; i > -1; i--)
8786 #ifdef DBG_Inverse_Frenet_Rotation
8787 if(dbg_Inverse_Frenet_Rotation_call_cnt == 1596)
8789 std::cout << __func__ <<
" mark #1"
8790 <<
" i=" << i <<
" u=" << u(0) <<
" " << u(1) <<
" " << u(2)
8791 <<
" m_inter=" << m_inter(0, 0) <<
" " << m_inter(1, 0) <<
" "
8792 << m_inter(2, 0) <<
" " << m_inter(0, 1) <<
" " << m_inter(1, 1)
8793 <<
" " << m_inter(2, 1) <<
" " << m_inter(0, 2) <<
" "
8794 << m_inter(1, 2) <<
" " << m_inter(2, 2) << std::endl;
8808 u = -1 * m_inter * u;
8810 int x = 0, y = 0, z = 0;
8811 x = -std::ceil(u(0) - 0.5);
8812 y = -std::ceil(u(1) - 0.5);
8813 z = -std::ceil(u(2) - 0.5);
8815 #ifdef DBG_Inverse_Frenet_Rotation
8816 if(dbg_Inverse_Frenet_Rotation_call_cnt == 1596)
8818 std::cout << __func__ <<
" mark #2"
8819 <<
" i=" << i <<
" u=" << u(0) <<
" " << u(1) <<
" " << u(2)
8820 <<
" x=" << x <<
" y=" << y <<
" z=" << z << std::endl;
8825 #ifdef DBG_Inverse_Frenet_Rotation
8826 if(dbg_Inverse_Frenet_Rotation_call_cnt == 1596)
8828 std::cout << __func__ <<
" mark #3"
8829 <<
" i=" << i <<
" u=" << u(0) <<
" " << u(1) <<
" " << u(2)
8840 #ifdef DBG_Inverse_Frenet_Rotation
8841 if(dbg_Inverse_Frenet_Rotation_call_cnt == 1596)
8843 std::cout << __func__ <<
" mark #4"
8844 <<
" Dist=" << Dist.
x <<
" " << Dist.
y <<
" " << Dist.
z
8854 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
8859 const HalfedgeGraph &_pMesh)
8864 Average_color.
c0 = 0;
8865 Average_color.
c1 = 0;
8866 Average_color.
c2 = 0;
8868 for(
int i = 0; i < valence; i++)
8870 Color_Unit col = Get_Vertex_Color(g, _pMesh);
8871 Average_color.
c0 += col.
c0;
8872 Average_color.
c1 += col.
c1;
8873 Average_color.
c2 += col.
c2;
8875 g =
next(g, _pMesh);
8879 Resulting_color.
c0 = floor((
float)Average_color.
c0 / valence + 0.5);
8880 Resulting_color.
c1 = floor((
float)Average_color.
c1 / valence + 0.5);
8881 Resulting_color.
c2 = floor((
float)Average_color.
c2 / valence + 0.5);
8883 return Resulting_color;
8887 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
8892 const bool Use_metric,
8893 const float &Metric_thread,
8894 const bool Use_forget_metric,
8895 const int &Forget_value,
8896 const int &Component_ID,
8897 const PointMap *_pm)
8899 double Max_color, Mean_color;
8902 this->Calculate_Edge_Color_Difference(
8903 _pMesh, Component_ID, Max_color, Mean_color, Temp_NV);
8904 this->Recalculate_Component_Area(_pMesh, _pm, Component_ID, Number_facets);
8906 (double)this->ComponentArea[Component_ID] / (
double)Number_facets;
8913 int Number_vertices = 0;
8914 int Number_symbol = 0;
8916 auto halfedge_iterator_pair = halfedges(_pMesh);
8920 (
get(this->vertex_Seed_Edge,
target(*hi, _pMesh)) != 2 * Component_ID) ||
8922 2 * Component_ID + 1))
8928 put(this->Vertex_Flag,
8932 std::queue< halfedge_descriptor > Halfedges;
8933 Halfedges.push(First_halfedge);
8937 while(!Halfedges.empty())
8939 h = Halfedges.front();
8951 (Is_Border_Vertex(
next(h, _pMesh), _pMesh) ==
8963 bool Geometric_metric_condition =
false;
8964 if(Use_metric ==
true)
8966 if(Use_forget_metric ==
true)
8969 Geometric_metric_condition =
false;
8971 Geometric_metric_condition = Is_Geometric_Metric_Violated(
8972 _pMesh, _pm, h, type, valence, Metric_thread);
8976 Geometric_metric_condition = Is_Geometric_Metric_Violated(
8977 _pMesh, _pm, h, type, valence, Metric_thread);
8979 bool Is_Color_Too_Important =
false;
8981 #ifdef USE_COLOR_METRIC
8984 Is_Color_Too_Important = this->Error_Projected_Surface(
8985 _pMesh, _pm, h, Component_ID, Mean_color, Mean_area);
8991 bool Check_all_condition =
false;
8993 if((!Geometric_metric_condition) && (!Is_Color_Too_Important))
8994 Check_all_condition =
true;
8997 if(Check_all_condition)
9003 this->InterConnectivity.push_front(0);
9006 Point_Int Geo = Change_Real_Int(Geo_info, Component_ID);
9008 Point3d Barycenter = Barycenter_Patch_Before_Removal(g, _pMesh, _pm);
9009 Point_Int BC = Change_Real_Int(Barycenter, Component_ID);
9012 if((this->IsColored) && (!this->IsOneColor))
9016 Removed_vertex_color = Get_Vertex_Color(
next(h, _pMesh), _pMesh);
9019 Average_color = Get_Average_Vertex_Color_Lee(g, valence, _pMesh);
9021 Color_Unit Color_diff = Removed_vertex_color - Average_color;
9023 this->InterVertexColor.push_front(Color_diff);
9036 Vector normal = Triangle_Normal(_pMesh, P, Q, R);
9038 Vector T1 = Calculate_T1_T2(h, normal, T2, _pMesh, _pm);
9040 if(T1 ==
Vector(0.0, 0.0, 0.0))
9044 normal =
Vector(0, 0, 1);
9047 else if(normal ==
Vector(0.0, 0.0, 0.0))
9051 normal =
Vector(0, 0, 1);
9053 else if(T2 ==
Vector(0.0, 0.0, 0.0))
9057 normal =
Vector(0, 0, 1);
9063 if(this->Is_Bijection_Enabled)
9064 Frenet_Coordinates = Frenet_Rotation(Dist, T1, T2, normal);
9066 Frenet_Coordinates = Dist;
9068 this->InterGeometry.push_front(Frenet_Coordinates);
9070 g =
next(h, _pMesh);
9078 if(!CGAL::is_border_edge(
prev(g, _pMesh), _pMesh))
9083 if(!CGAL::is_border_edge(
next(h1, _pMesh), _pMesh))
9085 if(!CGAL::is_border_edge(
prev(h1, _pMesh), _pMesh))
9091 if(!CGAL::is_border_edge(
prev(g, _pMesh), _pMesh))
9096 if(!CGAL::is_border_edge(
next(h2, _pMesh), _pMesh))
9098 if(!CGAL::is_border_edge(
prev(h2, _pMesh), _pMesh))
9105 this->InterConnectivity.push_front(1);
9109 if(!CGAL::is_border_edge(
next(h, _pMesh), _pMesh))
9111 if(!CGAL::is_border_edge(
prev(h, _pMesh), _pMesh))
9117 this->InterConnectivity.push_front(1);
9121 if(!CGAL::is_border_edge(
next(h, _pMesh), _pMesh))
9123 if(!CGAL::is_border_edge(
prev(h, _pMesh), _pMesh))
9139 temp = CGAL::Euler::remove_center_vertex(temp, _pMesh);
9140 put(this->facet_Component_Number,
face(temp, _pMesh), Component_ID);
9144 if((this->IsColored) && (!this->IsOneColor))
9146 while(!this->InterVertexColor.empty())
9148 Color_Unit Col = this->InterVertexColor.front();
9149 this->InterVertexColor.pop_front();
9150 this->VertexColor[Component_ID].push_front(Col);
9153 while(!InterConnectivity.empty())
9155 int Symbol = this->InterConnectivity.front();
9156 this->InterConnectivity.pop_front();
9157 this->Connectivity[Component_ID].push_front(Symbol);
9160 while(!InterGeometry.empty())
9163 InterGeometry.pop_front();
9164 this->Geometry[Component_ID].push_front(Geo);
9167 this->NumberSymbol[Component_ID].push_front(Number_symbol);
9168 this->NumberVertices[Component_ID].push_front(Number_vertices);
9170 this->DumpSymbolRegulation = Number_symbol;
9173 return Number_vertices;
9179 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9184 compute_normals_per_facet(_pMesh, _pm);
9185 compute_normals_per_vertex(_pMesh);
9187 compute_normals_per_halfedge();
9195 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9203 compute_facet_normal(*fi, _pMesh, _pm);
9210 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9218 compute_vertex_normal(*vi, _pMesh);
9224 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9228 const HalfedgeGraph &_pMesh,
9229 const PointMap *_pm)
9235 CGAL::Halfedge_around_face_circulator< HalfedgeGraph > facet_begin(
9237 CGAL::Halfedge_around_face_circulator< HalfedgeGraph > h = facet_begin;
9246 FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
9249 FEVV::Math::Vector::sub< FEVV::Geometry_traits< HalfedgeGraph > >(
9261 normal, 1.0 / std::sqrt(sqnorm), gt);
9264 }
while(++h != facet_begin);
9267 FEVV::Math::Vector::dot_product< FEVV::Geometry_traits< HalfedgeGraph > >(
9271 put(this->facet_normal,
9275 sum, 1.0 / std::sqrt(sqnorm), gt));
9279 put(this->facet_normal, f,
Vector(0.0, 0.0, 0.0));
9287 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9291 const HalfedgeGraph &_pMesh)
9297 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > pHalfedge(v, _pMesh);
9298 CGAL::Halfedge_around_target_circulator< HalfedgeGraph > begin = pHalfedge;
9300 CGAL_For_all(pHalfedge, begin)
9302 if(!CGAL::is_border_edge(*pHalfedge, _pMesh))
9304 normal = normal +
get(this->facet_normal,
face(*pHalfedge, _pMesh));
9309 FEVV::Math::Vector::dot_product< FEVV::Geometry_traits< HalfedgeGraph > >(
9310 normal, normal, gt);
9317 normal, 1.0 / std::sqrt(sqnorm), gt));
9326 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9331 int number_vertices)
9333 double C = (double)volume / (
double)area / number_vertices;
9338 int Q = floor(a * log(C) + b + 0.5);
9344 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9349 int Correct_symbol = -1;
9351 if((i == 0) && (j == 0) && (k == 0))
9354 else if((i == 1) && (j == 0) && (k == 0))
9357 else if((i == 0) && (j == 1) && (k == 0))
9360 else if((i == 1) && (j == 1) && (k == 0))
9363 else if((i == 0) && (j == 0) && (k == 1))
9366 else if((i == 1) && (j == 0) && (k == 1))
9369 else if((i == 0) && (j == 1) && (k == 1))
9374 return Correct_symbol;
9380 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9385 VertexColorMap *_v_cm,
9386 const std::vector< Point3d > &vlist,
9387 const std::vector< int > &flist,
9388 const std::vector< float > &clist,
9389 const std::vector< int > &Color_index_list)
9391 assert(vlist.size() != 0);
9392 assert(flist.size() != 0);
9394 typedef typename boost::property_traits< VertexColorMap >::value_type Color;
9398 size_t Number_vertex = vlist.size();
9399 std::vector< vertex_descriptor > vertex_index_to_descriptor;
9400 vertex_index_to_descriptor.reserve(Number_vertex);
9401 for(
size_t i = 0; i < Number_vertex; i++)
9405 vertex_index_to_descriptor.push_back(v);
9414 Color tmp_color(clist[3 * i + 0], clist[3 * i + 1], clist[3 * i + 2]);
9415 put(*_v_cm, v, tmp_color);
9417 if(!Color_index_list.empty())
9424 throw std::runtime_error(
"Compression_Valence_Component::build_mesh(): "
9425 "Vertex Color Index not supported, fix it!");
9428 init_vertex_attributes(v);
9433 size_t Number_facet = flist.size() / 3;
9435 for(
size_t i = 0; i < Number_facet; i++)
9438 std::vector< vertex_descriptor > face_vertices;
9439 face_vertices.push_back(vertex_index_to_descriptor[flist[3 * i + 0]]);
9440 face_vertices.push_back(vertex_index_to_descriptor[flist[3 * i + 1]]);
9441 face_vertices.push_back(vertex_index_to_descriptor[flist[3 * i + 2]]);
9444 if(currentFace == GraphTraits::null_face())
9446 throw std::runtime_error(
"Compression_Valence_Component::build_mesh(): "
9447 "failed to create face!");
9453 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9465 if((type == 1) || (type == 2) || (type == 4))
9479 else if((type == 5) || (type == 8))
9487 g =
prev(g, _pMesh);
9488 CGAL::Euler::join_face(g, _pMesh);
9493 if(
get(this->Vertex_Sign,
9495 put(this->Vertex_Sign,
9501 else if((type == 6) || (type == 7))
9509 g =
next(g, _pMesh);
9510 CGAL::Euler::join_face(g, _pMesh);
9515 if(
get(this->Vertex_Sign,
9517 put(this->Vertex_Sign,
9524 else if((type == 9) || (type == 12))
9527 if(
get(this->Facet_Flag,
face(g, _pMesh)) !=
FREE)
9530 if(
get(this->Facet_Flag,
face(g, _pMesh)) !=
FREE)
9535 g =
prev(h, _pMesh);
9536 g = CGAL::Euler::join_face(g, _pMesh);
9537 g =
next(g, _pMesh);
9538 g = CGAL::Euler::join_face(g, _pMesh);
9543 if(
get(this->Vertex_Sign,
9545 put(this->Vertex_Sign,
9548 if(
get(this->Vertex_Sign,
9551 put(this->Vertex_Sign,
9560 if(
get(this->Facet_Flag,
face(g, _pMesh)) !=
FREE)
9564 if(
get(this->Facet_Flag,
face(g, _pMesh)) !=
FREE)
9570 g = CGAL::Euler::join_face(g, _pMesh);
9571 g = CGAL::Euler::join_face(g, _pMesh);
9577 if(
get(this->Vertex_Sign,
9579 put(this->Vertex_Sign,
9582 if(
get(this->Vertex_Sign,
9585 put(this->Vertex_Sign,
9602 g =
next(g, _pMesh);
9603 g = CGAL::Euler::join_face(g, _pMesh);
9604 g =
prev(g, _pMesh);
9605 g = CGAL::Euler::join_face(g, _pMesh);
9611 if(
get(this->Vertex_Sign,
9613 put(this->Vertex_Sign,
9616 if(
get(this->Vertex_Sign,
9619 put(this->Vertex_Sign,
9625 else if((type == 13) || (type == 16))
9628 if(
get(this->Facet_Flag,
face(g, _pMesh)) !=
FREE)
9640 g = CGAL::Euler::join_face(g, _pMesh);
9641 g = CGAL::Euler::join_face(g, _pMesh);
9642 g = CGAL::Euler::join_face(g, _pMesh);
9647 if(
get(this->Vertex_Sign,
9649 put(this->Vertex_Sign,
9652 if(
get(this->Vertex_Sign,
9655 put(this->Vertex_Sign,
9658 if(
get(this->Vertex_Sign,
9661 put(this->Vertex_Sign,
9668 else if((type == 14) || (type == 15))
9671 if(
get(this->Facet_Flag,
face(g, _pMesh)) !=
FREE)
9683 g = CGAL::Euler::join_face(g, _pMesh);
9684 g = CGAL::Euler::join_face(g, _pMesh);
9685 g = CGAL::Euler::join_face(g, _pMesh);
9690 if(
get(this->Vertex_Sign,
9692 put(this->Vertex_Sign,
9695 if(
get(this->Vertex_Sign,
9698 put(this->Vertex_Sign,
9701 if(
get(this->Vertex_Sign,
9704 put(this->Vertex_Sign,
9715 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9720 if(Correct_symbol == 0)
9726 else if(Correct_symbol == 1)
9732 else if(Correct_symbol == 2)
9738 else if(Correct_symbol == 3)
9744 else if(Correct_symbol == 4)
9750 else if(Correct_symbol == 5)
9756 else if(Correct_symbol == 6)
9762 else if(Correct_symbol == 7)
9771 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9788 put(this->vertex_Seed_Edge, v, -1);
9789 put(this->vertex_Region_Number, v, -1);
9790 put(this->vertex_Removal_Order, v, -1);
9794 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9799 typedef typename boost::property_traits< VertexColorMap >::value_type Color;
9806 Color c =
get(*_v_cm, *vi);
9808 if( c[0] <= 1 && c[1] <= 1 && c[2] <= 1 )
9812 double c0 = std::min(1.0,
static_cast<double>(c[0]));
9813 double c1 = std::min(1.0,
static_cast<double>(c[1]));
9814 double c2 = std::min(1.0,
static_cast<double>(c[2]));
9816 put(*_v_cm, *vi, Color(c0, c1, c2));
9822 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9826 const PointMap *_pm,
9827 const std::string &header)
9829 std::cout << header <<
" mesh-geometry:" << std::endl;
9832 auto vertex_iterator_pair =
vertices(_pMesh);
9835 for(; pVertex != pVertex_end; ++pVertex)
9838 auto p3d =
get(*_pm, *pVertex);
9839 std::cout <<
"V#" << count <<
" point: " << p3d[0] <<
" " << p3d[1] <<
" "
9840 << p3d[2] << std::endl;
9844 template<
typename HalfedgeGraph,
typename Po
intMap,
typename VertexColorMap >
9848 const VertexColorMap *_v_cm,
9849 const std::string &header)
9851 typedef typename boost::property_traits< VertexColorMap >::value_type Color;
9853 std::cout << header <<
" mesh-vertexcolor:" << std::endl;
9857 std::cout << header <<
"THE MESH HAS NO VERTEX COLOR MAP!" << std::endl;
9862 auto vertex_iterator_pair =
vertices(_pMesh);
9865 for(; pVertex != pVertex_end; ++pVertex)
9868 Color c =
get(*_v_cm, *pVertex);
9869 std::cout <<
"V#" << count <<
" color: " << c[0] <<
" " << c[1] <<
" "
9870 << c[2] << std::endl;
9875 #if defined _MSC_VER
9876 #pragma warning(pop)