BRL-CAD
opennurbs_fit.h
Go to the documentation of this file.
1 /** @File opennurbs_fit.h
2  *
3  * Extensions to the openNURBS library, based off of Thomas Mörwald's
4  * surface fitting code in the Point Cloud Library (pcl). His code is
5  * BSD licensed:
6  *
7  * Copyright (c) 2011, Thomas Mörwald, Jonathan Balzer, Inc.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of Thomas Mörwald or Jonathan Balzer nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #ifndef LIBBREP_OPENNURBS_FIT_H
40 #define LIBBREP_OPENNURBS_FIT_H
41 
42 #include "opennurbs.h"
43 #include <vector>
44 #include <list>
45 #include <map>
46 #include <stdio.h>
47 
48 #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 6) && !defined(__clang__)
49 # pragma message "Disabling GCC shadow warnings via pragma due to Eigen headers..."
50 # pragma message "Disabling GCC float equality comparison warnings via pragma due to Eigen headers..."
51 # pragma message "Disabling GCC inline failure warnings via pragma due to Eigen headers..."
52 #endif
53 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
54 # pragma GCC diagnostic push
55 #endif
56 #if defined(__clang__)
57 # pragma clang diagnostic push
58 #endif
59 #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) && !defined(__clang__)
60 # pragma GCC diagnostic ignored "-Wshadow"
61 # pragma GCC diagnostic ignored "-Wfloat-equal"
62 # pragma GCC diagnostic ignored "-Winline"
63 #endif
64 #if defined(__clang__)
65 # pragma clang diagnostic ignored "-Wshadow"
66 # pragma clang diagnostic ignored "-Wfloat-equal"
67 # pragma clang diagnostic ignored "-Winline"
68 #endif
69 #undef Success
70 #include <Eigen/StdVector>
71 #undef Success
72 #include <Eigen/Dense>
73 #undef Success
74 #include <Eigen/Sparse>
75 #undef Success
76 #include <Eigen/SparseCholesky>
77 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
78 # pragma GCC diagnostic pop
79 #endif
80 #if defined(__clang__)
81 # pragma clang diagnostic pop
82 #endif
83 
84 namespace on_fit
85 {
86 
87 // **********************
88 // * from nurbs_data.h *
89 // **********************
90 
91 typedef std::vector<ON_2dVector > vector_vec2d;
92 typedef std::vector<ON_3dVector > vector_vec3d;
93 
94 /** \brief Data structure for NURBS surface fitting
95  * (FittingSurface, FittingSurfaceTDM, FittingCylinder, GlobalOptimization, GlobalOptimizationTDM) */
97 {
98  ON_Matrix *eigenvectors;
99  ON_3dVector mean;
100 
101  vector_vec3d interior; ///<< input
102  std::vector<double> interior_weight; ///<< input
103  std::vector<double> interior_error; ///>> output
104  vector_vec2d interior_param; ///>> output
105  vector_vec3d interior_line_start; ///>> output
106  vector_vec3d interior_line_end; ///>> output
107  vector_vec3d interior_normals; ///>> output
108 
109  vector_vec3d boundary; ///<< input
110  std::vector<double> boundary_weight; ///<< input
111  std::vector<double> boundary_error; ///>> output
112  vector_vec2d boundary_param; ///>> output
113  vector_vec3d boundary_line_start; ///>> output
114  vector_vec3d boundary_line_end; ///>> output
115  vector_vec3d boundary_normals; ///>> output
116 
117  vector_vec3d common_boundary_point;
118  std::vector<unsigned> common_boundary_idx;
119  vector_vec2d common_boundary_param;
120 
121  /** \brief Clear all interior data */
122  inline void
124  {
125  interior.clear ();
126  interior_weight.clear ();
127  interior_error.clear ();
128  interior_param.clear ();
129  interior_line_start.clear ();
130  interior_line_end.clear ();
131  interior_normals.clear ();
132  }
133 
134  /** \brief Clear all boundary data */
135  inline void
137  {
138  boundary.clear ();
139  boundary_weight.clear ();
140  boundary_error.clear ();
141  boundary_param.clear ();
142  boundary_line_start.clear ();
143  boundary_line_end.clear ();
144  boundary_normals.clear ();
145  }
146 
147  /** \brief Clear all common data */
148  inline void
150  {
151  common_boundary_point.clear ();
152  common_boundary_idx.clear ();
153  common_boundary_param.clear ();
154  }
155 
156 };
157 
158 
159 // **********************
160 // * from nurbs_tools.h *
161 // **********************
162 enum
163 {
164  NORTH = 1, NORTHEAST = 2, EAST = 3, SOUTHEAST = 4, SOUTH = 5, SOUTHWEST = 6, WEST = 7, NORTHWEST = 8
165 };
166 
167 
168 /** \brief Some useful tools for initialization, point search, ... */
170 {
171 public:
172 
173  /** \brief Get the closest point with respect to 'point'
174  * \param[in] point The point to which the closest point is searched for.
175  * \param[in] data Vector containing the set of points for searching. */
176  static unsigned
177  getClosestPoint (const ON_2dPoint &point, const vector_vec2d &data);
178 
179  /** \brief Get the closest point with respect to 'point'
180  * \param[in] point The point to which the closest point is searched for.
181  * \param[in] data Vector containing the set of points for searching. */
182  static unsigned
183  getClosestPoint (const ON_3dPoint &point, const vector_vec3d &data);
184 
185  /** \brief Get the closest point with respect to 'point' in Non-Euclidean metric
186  * \brief Related paper: TODO
187  * \param[in] point The point to which the closest point is searched for.
188  * \param[in] dir The direction defining 'inside' and 'outside'
189  * \param[in] data Vector containing the set of points for searching.
190  * \param[out] idxcp Closest point with respect to Euclidean metric. */
191  static unsigned
192  getClosestPoint (const ON_2dPoint &point, const ON_2dVector &dir, const vector_vec2d &data,
193  unsigned &idxcp);
194 
195  /** \brief Compute the mean of a set of points
196  * \param[in] data Set of points. */
197  static ON_3dVector
198  computeMean (const vector_vec3d &data);
199  /** \brief Compute the mean of a set of points
200  * \param[in] data Set of points. */
201  static ON_2dVector
202  computeMean (const vector_vec2d &data);
203 
204  /** \brief PCA - principal-component-analysis
205  * \param[in] data Set of points.
206  * \param[out] mean The mean of the set of points.
207  * \param[out] eigenvectors Matrix containing column-wise the eigenvectors of the set of points.
208  * \param[out] eigenvalues The eigenvalues of the set of points with respect to the eigenvectors. */
209  static void
210  pca (const vector_vec3d &data, ON_3dVector &mean, Eigen::Matrix3d &eigenvectors,
211  Eigen::Vector3d &eigenvalues);
212 
213  /** \brief Downsample data points to a certain size.
214  * \param[in] data1 The original set of points.
215  * \param[out] data2 The downsampled set of points of size 'size'.
216  * \param[in] size The desired size of the resulting set of points. */
217  static void
218  downsample_random (const vector_vec3d &data1, vector_vec3d &data2, unsigned size);
219  /** \brief Downsample data points to a certain size.
220  * \param[in/out] data1 The set of points for downsampling;
221  * will be replaced by the resulting set of points of size 'size'.
222  * \param[in] size The desired size of the resulting set of points. */
223  static void
224  downsample_random (vector_vec3d &data1, unsigned size);
225 
226 };
227 
228 
229 // **********************
230 // * from nurbs_solve.h *
231 // **********************
232 
233 /** \brief Solving the linear system of equations using Eigen or UmfPack.
234  * (can be defined in on_nurbs.cmake)*/
236 {
237 public:
238  /** \brief Empty constructor */
240  m_quiet (true)
241  {
242  }
243 
244  /** \brief Assign size and dimension (2D, 3D) of system of equations. */
245  void
246  assign (unsigned rows, unsigned cols, unsigned dims);
247 
248  /** \brief Set value for system matrix K (stiffness matrix, basis functions) */
249  void
250  K (unsigned i, unsigned j, double v);
251  /** \brief Set value for state vector x (control points) */
252  void
253  x (unsigned i, unsigned j, double v);
254  /** \brief Set value for target vector f (force vector) */
255  void
256  f (unsigned i, unsigned j, double v);
257 
258  /** \brief Get value for system matrix K (stiffness matrix, basis functions) */
259  double
260  K (unsigned i, unsigned j);
261  /** \brief Get value for state vector x (control points) */
262  double
263  x (unsigned i, unsigned j);
264  /** \brief Get value for target vector f (force vector) */
265  double
266  f (unsigned i, unsigned j);
267 
268  /** \brief Resize target vector f (force vector) */
269  void
270  resizeF (unsigned rows);
271 
272  /** \brief Print system matrix K (stiffness matrix, basis functions) */
273  void
274  printK ();
275  /** \brief Print state vector x (control points) */
276  void
277  printX ();
278  /** \brief Print target vector f (force vector) */
279  void
280  printF ();
281 
282  /** \brief Solves the system of equations with respect to x.
283  * - Using UmfPack incredibly speeds up this function. */
284  bool
285  solve ();
286 
287  /** \brief Compute the difference between solution K*x and target f */
288  ON_Matrix *diff ();
289 
290  /** \brief Enable/Disable debug outputs in console. */
291  inline void
292  setQuiet (bool val)
293  {
294  m_quiet = val;
295  }
296 
297 private:
298  bool m_quiet;
299  Eigen::SparseMatrix<double> m_Ksparse;
300  ON_Matrix *m_xeig;
301  ON_Matrix *m_feig;
302 
303 };
304 
305 
306 // ******************************
307 // * from fitting_surface_pdm.h *
308 // ******************************
309 
310 /** \brief Fitting a B-Spline surface to 3D point-clouds using point-distance-minimization
311  * Based on paper: TODO
312  * \author Thomas Moerwald
313  * \ingroup surface */
315 {
316 public:
317  ON_NurbsSurface m_nurbs;
319 
320  class myvec
321  {
322  public:
323  int side;
324  double hint;
325  myvec (int in_side, double in_hint)
326  {
327  this->side = in_side;
328  this->hint = in_hint;
329  }
330  };
331 
332  /** \brief Parameters for fitting */
333  struct Parameter
334  {
338 
342 
345 
346  Parameter (double intW = 1.0, double intS = 0.000001, double intR = 0.0, double bndW = 1.0,
347  double bndS = 0.000001, double bndR = 0.0, unsigned regU = 0, unsigned regV = 0) :
348  interior_weight (intW), interior_smoothness (intS), interior_regularisation (intR), boundary_weight (bndW),
349  boundary_smoothness (bndS), boundary_regularisation (bndR), regularisation_resU (regU),
350  regularisation_resV (regV)
351  {
352 
353  }
354 
355  };
356 
357  /** \brief Constructor initializing with the B-Spline surface given in argument 2.
358  * \param[in] data pointer to the 3D point-cloud data to be fit.
359  * \param[in] ns B-Spline surface used for fitting. */
360  FittingSurface (NurbsDataSurface *data, const ON_NurbsSurface &ns);
361 
362  /** \brief Constructor initializing B-Spline surface using initNurbsPCA(...).
363  * \param[in] order the polynomial order of the B-Spline surface.
364  * \param[in] data pointer to the 2D point-cloud data to be fit.
365  * \param[in] z vector defining front face of surface. */
366  FittingSurface (int order, NurbsDataSurface *data, ON_3dVector z = ON_3dVector(0.0, 0.0, 1.0));
367 
368  /** \brief Refines surface by inserting a knot in the middle of each element.
369  * \param[in] dim dimension of refinement (0, 1) */
370  void
371  refine (int dim);
372 
373  /** \brief Assemble the system of equations for fitting
374  * - for large point-clouds this is time consuming.
375  * - should be done once before refinement to initialize the starting points for point inversion. */
376  virtual void
377  assemble (Parameter param = Parameter ());
378 
379  /** \brief Solve system of equations using Eigen or UmfPack (can be defined in on_nurbs.cmake),
380  * and updates B-Spline surface if a solution can be obtained. */
381  virtual void
382  solve (double damp = 1.0);
383 
384  /** \brief Update surface according to the current system of equations.
385  * \param[in] damp damping factor from one iteration to the other. */
386  virtual void
387  updateSurf (double damp);
388 
389  /** \brief Set parameters for inverse mapping
390  * \param[in] in_max_steps maximum number of iterations.
391  * \param[in] in_accuracy stops iteration if specified accuracy is reached. */
392  void
393  setInvMapParams (unsigned in_max_steps, double in_accuracy);
394 
395  /** \brief Get the elements of a B-Spline surface.*/
396  static std::vector<double>
397  getElementVector (const ON_NurbsSurface &nurbs, int dim);
398 
399  /** \brief Inverse mapping / point inversion: Given a point pt, this function finds the closest
400  * point on the B-Spline surface using Newtons method and point-distance (L2-, Euclidean norm).
401  * \param[in] nurbs the B-Spline surface.
402  * \param[in] pt the point to which the closest point on the surface will be computed.
403  * \param[in] hint the starting point in parametric domain (warning: may lead to convergence at local minima).
404  * \param[in] error the distance between the point pt and p after convergence.
405  * \param[in] p closest point on surface.
406  * \param[in] tu the tangent vector at point p in u-direction.
407  * \param[in] tv the tangent vector at point p in v-direction.
408  * \param[in] maxSteps maximum number of iterations.
409  * \param[in] accuracy convergence criteria: if error is lower than accuracy the function returns
410  * \return closest point on surface in parametric domain.*/
411  static ON_2dPoint
412  inverseMapping (const ON_NurbsSurface &nurbs, const ON_3dPoint &pt, const ON_2dPoint &hint,
413  double &error, ON_3dPoint &p, ON_3dVector &tu, ON_3dVector &tv, int maxSteps = 100,
414  double accuracy = 1e-6, bool quiet = true);
415 
416  /** \brief Given a point pt, the function finds the closest midpoint of the elements of the surface.
417  * \param[in] nurbs the B-Spline surface.
418  * \param[in] pt the point to which the closest midpoint of the elements will be computed.
419  * return closest midpoint in parametric domain. */
420  static ON_2dPoint
421  findClosestElementMidPoint (const ON_NurbsSurface &nurbs, const ON_3dPoint &pt);
422 
423  /** \brief Inverse mapping / point inversion: Given a point pt, this function finds the closest
424  * point on the boundary of the B-Spline surface using Newtons method and point-distance (L2-, Euclidean norm).
425  * \param[in] nurbs the B-Spline surface.
426  * \param[in] pt the point to which the closest point on the surface will be computed.
427  * \param[in] error the distance between the point pt and p after convergence.
428  * \param[in] p closest boundary point on surface.
429  * \param[in] tu the tangent vector at point p in u-direction.
430  * \param[in] tv the tangent vector at point p in v-direction.
431  * \param[in] maxSteps maximum number of iterations.
432  * \param[in] accuracy convergence criteria: if error is lower than accuracy the function returns
433  * \return closest point on surface in parametric domain.*/
434  static ON_2dPoint
435  inverseMappingBoundary (const ON_NurbsSurface &nurbs, const ON_3dPoint &pt, double &error,
436  ON_3dPoint &p, ON_3dVector &tu, ON_3dVector &tv, int maxSteps = 100,
437  double accuracy = 1e-6, bool quiet = true);
438 
439  /** \brief Inverse mapping / point inversion: Given a point pt, this function finds the closest
440  * point on one side of the boundary of the B-Spline surface using Newtons method and
441  * point-distance (L2-, Euclidean norm).
442  * \param[in] nurbs the B-Spline surface.
443  * \param[in] pt the point to which the closest point on the surface will be computed.
444  * \param[in] side the side of the boundary (NORTH, SOUTH, EAST, WEST)
445  * \param[in] hint the starting point in parametric domain (warning: may lead to convergence at local minima).
446  * \param[in] error the distance between the point pt and p after convergence.
447  * \param[in] p closest boundary point on surface.
448  * \param[in] tu the tangent vector at point p in u-direction.
449  * \param[in] tv the tangent vector at point p in v-direction.
450  * \param[in] maxSteps maximum number of iterations.
451  * \param[in] accuracy convergence criteria: if error is lower than accuracy the function returns
452  * \return closest point on surface in parametric domain.*/
453  static ON_2dPoint
454  inverseMappingBoundary (const ON_NurbsSurface &nurbs, const ON_3dPoint &pt, int side, double hint,
455  double &error, ON_3dPoint &p, ON_3dVector &tu, ON_3dVector &tv,
456  int maxSteps = 100, double accuracy = 1e-6, bool quiet = true);
457 
458  /** \brief Initializing a B-Spline surface using 4 corners */
459  static ON_NurbsSurface
460  initNurbs4Corners (int order, ON_3dPoint ll, ON_3dPoint lr, ON_3dPoint ur, ON_3dPoint ul);
461 
462  /** \brief Initializing a B-Spline surface using principal-component-analysis and eigen values */
463  static ON_NurbsSurface
464  initNurbsPCA (int order, NurbsDataSurface *data, ON_3dVector z = ON_3dVector(0.0, 0.0, 1.0));
465 
466  /** \brief Initializing a B-Spline surface using principal-component-analysis and bounding box of points */
467  static ON_NurbsSurface
468  initNurbsPCABoundingBox (int order, NurbsDataSurface *data, ON_3dVector z = ON_3dVector(0.0, 0.0, 1.0));
469 
470  /** \brief Enable/Disable debug outputs in console. */
471  inline void
472  setQuiet (bool val)
473  {
474  m_quiet = val;
475  m_solver.setQuiet(val);
476  }
477 
478 protected:
479 
480  /** \brief Initialisation of member variables */
481  void
482  init ();
483 
484  /** \brief Assemble point-to-surface constraints for interior points. */
485  virtual void
486  assembleInterior (double wInt, unsigned &row);
487 
488  /** \brief Assemble point-to-surface constraints for boundary points. */
489  virtual void
490  assembleBoundary (double wBnd, unsigned &row);
491 
492  /** \brief Add minimization constraint: point-to-surface distance (point-distance-minimization). */
493  virtual void
494  addPointConstraint (const ON_2dVector &params, const ON_3dPoint &point, double weight, unsigned &row);
495  // void addBoundaryPointConstraint(double paramU, double paramV, double weight, unsigned &row);
496 
497  /** \brief Add minimization constraint: interior smoothness by control point regularisation. */
498  virtual void
499  addCageInteriorRegularisation (double weight, unsigned &row);
500 
501  /** \brief Add minimization constraint: boundary smoothness by control point regularisation. */
502  virtual void
503  addCageBoundaryRegularisation (double weight, int side, unsigned &row);
504 
505  /** \brief Add minimization constraint: corner smoothness by control point regularisation. */
506  virtual void
507  addCageCornerRegularisation (double weight, unsigned &row);
508 
509  /** \brief Add minimization constraint: interior smoothness by derivatives regularisation. */
510  virtual void
511  addInteriorRegularisation (int order, int resU, int resV, double weight, unsigned &row);
512 
513  /** \brief Add minimization constraint: boundary smoothness by derivatives regularisation. */
514  virtual void
515  addBoundaryRegularisation (int order, int resU, int resV, double weight, unsigned &row);
516 
518 
519  bool m_quiet;
520 
521  std::vector<double> m_elementsU;
522  std::vector<double> m_elementsV;
523 
524  double m_minU;
525  double m_minV;
526  double m_maxU;
527  double m_maxV;
528 
530  double in_accuracy;
531 
532  // index routines
533  int
534  grc2gl (int I, int J)
535  {
536  return m_nurbs.CVCount (1) * I + J;
537  } // global row/col index to global lexicographic index
538  int
539  lrc2gl (int E, int F, int i, int j)
540  {
541  return grc2gl (E + i, F + j);
542  } // local row/col index to global lexicographic index
543  int
544  gl2gr (int A)
545  {
546  return (int)(A / m_nurbs.CVCount (1));
547  } // global lexicographic in global row index
548  int
549  gl2gc (int A)
550  {
551  return (int)(A % m_nurbs.CVCount (1));
552  } // global lexicographic in global col index
553 };
554 
555 
556 }
557 #endif
558 
559 /*
560  * Local Variables:
561  * tab-width: 8
562  * mode: C++
563  * indent-tabs-mode: t
564  * c-file-style: "stroustrup"
565  * coding: utf-8
566  * End:
567  * ex: shiftwidth=4 tabstop=8
568  */
Definition: db_flip.c:35
virtual void addCageBoundaryRegularisation(double weight, int side, unsigned &row)
Add minimization constraint: boundary smoothness by control point regularisation. ...
void clear_common_boundary()
Clear all common data.
std::vector< double > boundary_error
vector_vec2d common_boundary_param
std::vector< double > boundary_weight
< input
void assign(unsigned rows, unsigned cols, unsigned dims)
Assign size and dimension (2D, 3D) of system of equations.
std::vector< double > interior_weight
< input
static ON_2dPoint findClosestElementMidPoint(const ON_NurbsSurface &nurbs, const ON_3dPoint &pt)
Given a point pt, the function finds the closest midpoint of the elements of the surface.
static ON_NurbsSurface initNurbsPCABoundingBox(int order, NurbsDataSurface *data, ON_3dVector z=ON_3dVector(0.0, 0.0, 1.0))
Initializing a B-Spline surface using principal-component-analysis and bounding box of points...
bool solve()
Solves the system of equations with respect to x.
void setQuiet(bool val)
Enable/Disable debug outputs in console.
Fitting a B-Spline surface to 3D point-clouds using point-distance-minimization Based on paper: TODO...
Parameter(double intW=1.0, double intS=0.000001, double intR=0.0, double bndW=1.0, double bndS=0.000001, double bndR=0.0, unsigned regU=0, unsigned regV=0)
std::vector< unsigned > common_boundary_idx
void init()
Initialisation of member variables.
virtual void assembleBoundary(double wBnd, unsigned &row)
Assemble point-to-surface constraints for boundary points.
void printK()
Print system matrix K (stiffness matrix, basis functions)
void K(unsigned i, unsigned j, double v)
Set value for system matrix K (stiffness matrix, basis functions)
static unsigned getClosestPoint(const ON_2dPoint &point, const vector_vec2d &data)
Get the closest point with respect to 'point'.
vector_vec3d boundary_line_start
output
std::vector< double > interior_error
void refine(int dim)
Refines surface by inserting a knot in the middle of each element.
void setQuiet(bool val)
Enable/Disable debug outputs in console.
virtual void assemble(Parameter param=Parameter())
Assemble the system of equations for fitting.
ON_NurbsSurface m_nurbs
static std::vector< double > getElementVector(const ON_NurbsSurface &nurbs, int dim)
Get the elements of a B-Spline surface.
virtual void addCageCornerRegularisation(double weight, unsigned &row)
Add minimization constraint: corner smoothness by control point regularisation.
COMPLEX data[64]
Definition: fftest.c:34
vector_vec3d interior
< input
std::vector< double > m_elementsU
Solving the linear system of equations using Eigen or UmfPack. (can be defined in on_nurbs...
Parameters for fitting.
myvec(int in_side, double in_hint)
vector_vec2d interior_param
output
Data structure for NURBS surface fitting (FittingSurface, FittingSurfaceTDM, FittingCylinder, GlobalOptimization, GlobalOptimizationTDM)
Definition: opennurbs_fit.h:96
NurbsSolve()
Empty constructor.
std::vector< ON_3dVector > vector_vec3d
Definition: opennurbs_fit.h:92
vector_vec3d interior_line_start
output
virtual void updateSurf(double damp)
Update surface according to the current system of equations.
static ON_2dPoint inverseMappingBoundary(const ON_NurbsSurface &nurbs, const ON_3dPoint &pt, double &error, ON_3dPoint &p, ON_3dVector &tu, ON_3dVector &tv, int maxSteps=100, double accuracy=1e-6, bool quiet=true)
Inverse mapping / point inversion: Given a point pt, this function finds the closest point on the bou...
Coord * point
Definition: chull3d.cpp:52
void f(unsigned i, unsigned j, double v)
Set value for target vector f (force vector)
virtual void addInteriorRegularisation(int order, int resU, int resV, double weight, unsigned &row)
Add minimization constraint: interior smoothness by derivatives regularisation.
Some useful tools for initialization, point search, ...
int lrc2gl(int E, int F, int i, int j)
std::vector< ON_2dVector > vector_vec2d
Definition: opennurbs_fit.h:91
FittingSurface(NurbsDataSurface *data, const ON_NurbsSurface &ns)
Constructor initializing with the B-Spline surface given in argument 2.
vector_vec3d boundary_normals
output
virtual void addBoundaryRegularisation(int order, int resU, int resV, double weight, unsigned &row)
Add minimization constraint: boundary smoothness by derivatives regularisation.
vector_vec3d boundary
output
virtual void addPointConstraint(const ON_2dVector &params, const ON_3dPoint &point, double weight, unsigned &row)
Add minimization constraint: point-to-surface distance (point-distance-minimization).
vector_vec3d boundary_line_end
output
virtual void assembleInterior(double wInt, unsigned &row)
Assemble point-to-surface constraints for interior points.
static ON_NurbsSurface initNurbs4Corners(int order, ON_3dPoint ll, ON_3dPoint lr, ON_3dPoint ur, ON_3dPoint ul)
Initializing a B-Spline surface using 4 corners.
void x(unsigned i, unsigned j, double v)
Set value for state vector x (control points)
static ON_2dPoint inverseMapping(const ON_NurbsSurface &nurbs, const ON_3dPoint &pt, const ON_2dPoint &hint, double &error, ON_3dPoint &p, ON_3dVector &tu, ON_3dVector &tv, int maxSteps=100, double accuracy=1e-6, bool quiet=true)
Inverse mapping / point inversion: Given a point pt, this function finds the closest point on the B-S...
void printF()
Print target vector f (force vector)
void setInvMapParams(unsigned in_max_steps, double in_accuracy)
Set parameters for inverse mapping.
std::vector< double > m_elementsV
static ON_3dVector computeMean(const vector_vec3d &data)
Compute the mean of a set of points.
#define A
Definition: msr.c:51
vector_vec3d interior_line_end
output
static ON_NurbsSurface initNurbsPCA(int order, NurbsDataSurface *data, ON_3dVector z=ON_3dVector(0.0, 0.0, 1.0))
Initializing a B-Spline surface using principal-component-analysis and eigen values.
vector_vec2d boundary_param
output
void clear_boundary()
Clear all boundary data.
NurbsDataSurface * m_data
void resizeF(unsigned rows)
Resize target vector f (force vector)
ON_Matrix * diff()
Compute the difference between solution K*x and target f.
void clear_interior()
Clear all interior data.
static void pca(const vector_vec3d &data, ON_3dVector &mean, Eigen::Matrix3d &eigenvectors, Eigen::Vector3d &eigenvalues)
PCA - principal-component-analysis.
int grc2gl(int I, int J)
vector_vec3d common_boundary_point
output
vector_vec3d interior_normals
output
static void downsample_random(const vector_vec3d &data1, vector_vec3d &data2, unsigned size)
Downsample data points to a certain size.
virtual void addCageInteriorRegularisation(double weight, unsigned &row)
Add minimization constraint: interior smoothness by control point regularisation. ...
virtual void solve(double damp=1.0)
Solve system of equations using Eigen or UmfPack (can be defined in on_nurbs.cmake), and updates B-Spline surface if a solution can be obtained.
void printX()
Print state vector x (control points)