void VSA_Component::Init(int NbProxy) { ////Creation of the initial proxies by random seed triangle picking m_Table_Proxy.clear(); m_NbProxy=NbProxy; int NbFacet=m_Poly->size_of_facets(); int offset=NbFacet/NbProxy; int i=0; for(Facet_iterator pface = m_Poly->facets_begin(); pface != m_Poly->facets_end(); pface++) { if(i%offset==0)///this triangle is chosen { //a proxy is created Proxy NewProxy; NewProxy.Normal=pface->normal(); NewProxy.Seed=pface; ///the proxy is added m_Table_Proxy.push_back(NewProxy); } pface->LabelVSA=-1; i++; } m_Poly->NbFaceLabel=m_NbProxy; }
double VSA_Component::DistorsionError(Facet_iterator f,Proxy p) { Vector v=f->normal()-p.Normal; double nrm=v*v; double area=AreaFacetTriangleSeg(f); return nrm*area; }
void VSA_Component::ProxyFitting() { Vector * TabNormal=new Vector[m_NbProxy]; double * TabArea=new double[m_NbProxy]; double * DistanceMin=new double[m_NbProxy]; double * DistanceMax=new double[m_NbProxy]; for (int i=0;i<m_NbProxy;i++) { TabArea[i]=0; TabNormal[i]=CGAL::NULL_VECTOR; DistanceMin[i]=100000000; DistanceMax[i]=0; } for(Facet_iterator pface = m_Poly->facets_begin(); pface != m_Poly->facets_end(); pface++) { double area=AreaFacetTriangleSeg(pface); TabArea[pface->LabelVSA]+=area; TabNormal[pface->LabelVSA]=TabNormal[pface->LabelVSA]+pface->normal()*area; } for (int i=0;i<m_NbProxy;i++) { m_Table_Proxy[i].Normal=TabNormal[i]/TabArea[i]; m_Table_Proxy[i].Area=TabArea[i]; m_Table_Proxy[i].TotalDistorsion=0; } // a new seed is assigned to each proxy for(Facet_iterator pface = m_Poly->facets_begin(); pface != m_Poly->facets_end(); pface++) { double distance=DistorsionError(pface,m_Table_Proxy[pface->LabelVSA]); m_Table_Proxy[pface->LabelVSA].TotalDistorsion+=distance; if(distance<DistanceMin[pface->LabelVSA]) { DistanceMin[pface->LabelVSA]=distance; m_Table_Proxy[pface->LabelVSA].Seed=pface; } //we pick the facet corresponding to the max distorsion if(distance>DistanceMax[pface->LabelVSA]) { DistanceMax[pface->LabelVSA]=distance; m_Table_Proxy[pface->LabelVSA].MostDistordedFacet=pface; } } delete []DistanceMin; delete []TabNormal; delete []TabArea; delete []DistanceMax; }