18 #include <vnl/vnl_least_squares_function.h>
19 #include <vtkPolyData.h>
20 #include <vtkPoints.h>
21 #include <vtkCellArray.h>
23 #include <vtkDelaunay2D.h>
31 const std::vector<a_point> & cloud) :
35 void f(
const vnl_vector<double>& x, vnl_vector<double>& fx);
43 a_point norm(x[0],x[1],x[2]);
48 for (
int i = 0; i< fx.size(); i++)
56 o <<
"**************" << std::endl;
57 o <<
"a_shape_plane:" << std::endl;
58 o <<
"**************" << std::endl;
59 o <<
"This is a 'plane' fitting class" << std::endl;
85 a_point norm = this->
normal();
86 return norm*this->
dist();
92 a_point norm = this->
normal();
94 a_point pt0 = norm*this->
dist();
95 return pt-norm*(norm*(
pt-pt0));
101 a_point norm = this->
normal();
103 a_point pt0 = norm*this->
dist();
104 return fabs(norm*(
pt-pt0));
112 if (dn.norm()==0)
return;
113 double d = (p1+p2+p3)*dn/3.;
131 }
while ((i1==i3)||(i2==i3));
132 a_point p1 = pts[i1];
133 a_point p2 = pts[i2];
134 a_point p3 = pts[i3];
135 this->
p3pts(p1,p2,p3);
140 std::vector<a_point> pts2;
141 int cs0 = pts.size();
153 a_point o = this->
origin();
156 if (
n[0]<
n[1]) r = 0;
else r = 1;
157 if (
n[r]>
n[2]) r = 2;
162 case 0 : a.x(1.);
break;
163 case 1 : a.y(1.);
break;
171 std::cout << std::endl;
180 std::vector<a_point> pts_proj;
181 pts_proj.push_back(x0);
182 for (
int i=1; i< pts.size(); i++)
185 pts_proj.push_back(x);
186 double d = (x-x0).norm();
195 vtkPoints * vpts = vtkPoints::New();
196 for (
int i=0; i< pts.size(); i++)
198 a_point x = pts_proj[i];
201 vpts->InsertNextPoint(u,
v,0);
203 vtkCellArray * vertices = vtkCellArray::New();
204 for (vtkIdType k = 0; k < pts.size(); k++)
205 vertices->InsertNextCell(1,&k);
206 vtkPolyData * data = vtkPolyData::New();
207 data->SetPoints(vpts);
209 data->SetVerts(vertices);
211 vtkDelaunay2D * del = vtkDelaunay2D::New();
212 del->SetInputData(data);
214 del->SetTolerance(0.001);
216 int n_pts = vpts->GetNumberOfPoints();
217 std::cout << n_pts << std::endl;
218 for (
int k = 0; k < n_pts; k++)
219 std::cout << pts_proj[k] << std::endl;
220 vtkCellArray * triangles;
221 triangles = del->GetOutput()->GetPolys();
222 int n_tri = del->GetOutput()->GetNumberOfPolys();
223 std::cout <<
n_tri << std::endl;
224 triangles->InitTraversal();
225 for (
int k = 0; k <
n_tri; k++)
228 const vtkIdType * ref_pt =
nullptr;
229 triangles->GetNextCell(npt,ref_pt);
230 std::cout << ref_pt[0] <<
'\t' << ref_pt[1] <<
'\t' << ref_pt[2] << std::endl;
void f(const vnl_vector< double > &x, vnl_vector< double > &fx)
const std::vector< a_point > & cloud_
a_shape_plane_function(a_shape_plane &shape, const std::vector< a_point > &cloud)
void export_triangles(const std::vector< a_point > &pts) const
void fit_cloud(std::vector< a_point > &pts, short int=1)
void normal(const a_point p)
void p3pts(const a_point p1, const a_point p2, const a_point p3)
a_point closest_point(const a_point p) const
static const std::string help()
void random_hint(const std::vector< a_point > &pts)
double dist_point(a_point p) const
vnl_vector< double > para_
void fit_cloud(const std::vector< a_point > &pts, vnl_least_squares_function &fn)
static const std::string help()
int best_fitting_cloud(const std::vector< a_point > &pts, std::vector< a_point > &pts2)
e_point cross(e_point &a, e_point &b)
double v(const uint32_t step, const uint32_t n)