4
#include <vcg/complex/local_optimization/tri_edge_flip.h>
7
template <class BaseMesh>
8
class ParamEdgeFlip : public vcg::tri::PlanarEdgeFlip<BaseMesh, ParamEdgeFlip<BaseMesh> >
10
typedef typename BaseMesh::VertexType::EdgeType EdgeType;
11
typedef typename BaseMesh::VertexType BaseVertex;
12
typedef typename BaseMesh::VertexType VertexType;
13
typedef typename BaseMesh::FaceType BaseFace;
14
typedef typename BaseMesh::FaceType FaceType;
15
typedef typename BaseMesh::CoordType CoordType;
16
typedef typename BaseMesh::ScalarType ScalarType;
17
typedef vcg::tri::PlanarEdgeFlip<BaseMesh, ParamEdgeFlip<BaseMesh> > Super;
26
if(!vcg::face::CheckFlipEdge(*this->_pos.F(), this->_pos.E()))
28
///ScalarType diff=EdgeDiff();
30
return (this->_priority>0);
33
inline ParamEdgeFlip() {}
36
* Constructor with <I>pos</I> type
38
inline ParamEdgeFlip(const typename Super::PosType pos, int mark)
41
this->_localMark = mark;
42
this->_priority = this->ComputePriority();
46
///do the effective flip
47
void ExecuteFlip(FaceType &f, const int &edge)
49
std::vector<FaceType*> faces;
51
faces.push_back(f.FFp(edge));
52
std::vector<VertexType*> HresVert;
53
getHresVertex<FaceType>(faces,HresVert);
54
///parametrize H_res mesh respect to diamond
55
for (unsigned int i=0;i<HresVert.size();i++)
57
VertexType* v=HresVert[i];
59
FaceType* father=v->father;
60
CoordType bary=v->Bary;
61
assert((father==faces[0])||(father==faces[1]));
62
vcg::Point2<ScalarType> t0=father->V(0)->T().P();
63
vcg::Point2<ScalarType> t1=father->V(1)->T().P();
64
vcg::Point2<ScalarType> t2=father->V(2)->T().P();
66
//assert(testBaryCoords(bary));
67
if(!testBaryCoords(bary))
69
printf("BAry0 :%lf,%lf,%lf",bary.X(),bary.Y(),bary.Z());
73
GetUV<BaseMesh>(father,bary,v->T().U(),v->T().V());
75
///then do the effective flip
76
vcg::face::FlipEdge(f,edge);
78
///set son->father new link
79
for (unsigned int i=0;i<HresVert.size();i++)
81
VertexType* v=HresVert[i];
82
ScalarType U=v->T().U();
83
ScalarType V=v->T().V();
86
bool found=GetBaryFaceFromUV(faces,U,V,bary,index);
89
printf("\n U : %lf; V : %lf \n",U,V);
93
assert(testBaryCoords(bary));
94
v->father=faces[index];
100
///set father->son new link
101
for (unsigned int i=0;i<faces.size();i++)
102
faces[i]->vertices_bary.clear();
104
for (unsigned int i=0;i<HresVert.size();i++)
106
VertexType *son=HresVert[i];
107
FaceType *father=son->father;
108
CoordType bary=son->Bary;
109
father->vertices_bary.push_back(std::pair<BaseVertex*,vcg::Point3f>(son,bary));
114
ScalarType EdgeDiff()
126
VertexType *v0, *v1, *v2, *v3;
127
int edge0 = this->_pos.E();
128
v0 = this->_pos.F()->V0(edge0);
129
v1 = this->_pos.F()->V1(edge0);
130
v2 = this->_pos.F()->V2(edge0);
131
v3 = this->_pos.F()->FFp(edge0)->V2(this->_pos.F()->FFi(edge0));
132
int edge1=this->_pos.F()->FFi(edge0);
133
FaceType* f0=this->_pos.F();
134
FaceType* f1=this->_pos.F()->FFp(edge0);
136
///parametrize all possible diamonds
138
///make a copy of the mesh
139
std::vector<FaceType*> OrdFace;
140
OrdFace.push_back(f0);
141
OrdFace.push_back(f1);
146
///create a copy of the domain and of the H resolution
147
CopySubMeshLevels(OrdFace,Diam,DiamHres);
149
///parametrize domains
150
ParametrizeDiamondEquilateral(Diam,edge0,edge1);
152
///copy parametrization on original mesh
154
FaceType* on_edge[2];
155
on_edge[0]=&Diam.face[0];
156
on_edge[1]=&Diam.face[1];
157
assert(Diam.face[0].FFp(edge0)==&Diam.face[1]);///test
158
assert(Diam.face[1].FFp(edge1)==&Diam.face[0]);///test
160
///Evaluate lenght of shared edge
161
ScalarType L0=EstimateLenghtByParam<BaseMesh>(Diam.face[0].V(edge0),Diam.face[0].V((edge0+1)%3),on_edge);
163
///do the flip on the copied mesh do not affect the original mesh
164
ExecuteFlip(Diam.face[0],edge0);
166
UpdateTopologies(&Diam);
168
///get the non border edge of face0
170
if (!Diam.face[0].IsB(0))
173
if (!Diam.face[0].IsB(1))
176
if (!Diam.face[0].IsB(2))
180
ScalarType L1=EstimateLenghtByParam<BaseMesh>(Diam.face[0].V(NB_edge),Diam.face[0].V((NB_edge+1)%3),on_edge);
182
ScalarType value=L0-L1;
184
this->_priority = 1.0/value;
185
return (this->_priority);
189
void Execute(BaseMesh &m)
192
assert(this->_priority>0);
202
VertexType *v0, *v1, *v2, *v3;
203
int edge0 = this->_pos.E();
204
v0 = this->_pos.F()->V0(edge0);
205
v1 = this->_pos.F()->V1(edge0);
206
v2 = this->_pos.F()->V2(edge0);
207
v3 = this->_pos.F()->FFp(edge0)->V2(this->_pos.F()->FFi(edge0));
209
ScalarType h=(sqrt((ScalarType)3.0)/(ScalarType)2.0);
210
v0->T().P()=vcg::Point2<ScalarType>(0,(ScalarType)-0.5);
211
v1->T().P()=vcg::Point2<ScalarType>(0,(ScalarType)0.5);
212
v2->T().P()=vcg::Point2<ScalarType>(-h,0);
213
v3->T().P()=vcg::Point2<ScalarType>(h,0);
216
///save domain if need for demos
220
std::vector<FaceType*> faces;
221
FaceType* f=this->_pos.F();
222
int edge=this->_pos.E();
224
faces.push_back(f->FFp(edge));
225
std::vector<VertexType*> HresVert;
226
getHresVertex<FaceType>(faces,HresVert);
228
///parametrize H_res mesh respect to diamond
229
std::vector<VertexType*> OrderedVertices;
230
std::vector<FaceType*> OrderedFaces;
231
CopyMeshFromVertices(HresVert,OrderedVertices,OrderedFaces,hlev_mesh);
232
//for (int i=0;i<hlev_mesh.vert.size();i++)
233
//hlev_mesh.vert[i].C()=hlev_mesh.vert[i].OriginalCol;
235
vcg::tri::io::ExporterPLY<BaseMesh>::Save(hlev_mesh,"c:/export_submeshes/FLIPHlev3D.ply",vcg::tri::io::Mask::IOM_VERTCOLOR);
236
for (unsigned int i=0;i<hlev_mesh.vert.size();i++)
238
hlev_mesh.vert[i].P().X()=hlev_mesh.vert[i].T().U();
239
hlev_mesh.vert[i].P().Y()=hlev_mesh.vert[i].T().V();
240
hlev_mesh.vert[i].P().Z()=0;
242
vcg::tri::io::ExporterPLY<BaseMesh>::Save(hlev_mesh,"c:/export_submeshes/FLIPHlevUV.ply",vcg::tri::io::Mask::IOM_VERTCOLOR);
246
ExecuteFlip(*this->_pos.F(),this->_pos.E());
248
UpdateTopologies(&m);
250
///stars optimization
252
/*OptimizeStar<BaseMesh>(v0);
253
OptimizeStar<BaseMesh>(v1);
254
OptimizeStar<BaseMesh>(v2);
255
OptimizeStar<BaseMesh>(v3);*/
257
SmartOptimizeStar<BaseMesh>(v0);
258
SmartOptimizeStar<BaseMesh>(v1);
259
SmartOptimizeStar<BaseMesh>(v2);
260
SmartOptimizeStar<BaseMesh>(v3);
265
ScalarType ComputePriority()
267
this->_priority=EdgeDiff();
268
return this->_priority;
272
{return this->_pos.F();}
275
{return this->_pos.E();}