00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef NURBS_FITTING_PATCH_H
00039 #define NURBS_FITTING_PATCH_H
00040
00041 #include <pcl/pcl_exports.h>
00042 #include <pcl/surface/on_nurbs/nurbs_tools.h>
00043 #include <pcl/surface/on_nurbs/nurbs_data.h>
00044 #include <pcl/surface/on_nurbs/nurbs_solve.h>
00045
00046 namespace pcl
00047 {
00048 namespace on_nurbs
00049 {
00055 class PCL_EXPORTS FittingSurface
00056 {
00057 public:
00058 ON_NurbsSurface m_nurbs;
00059 NurbsDataSurface *m_data;
00060
00061 class myvec
00062 {
00063 public:
00064 int side;
00065 double hint;
00066
00067 myvec (int side, double hint)
00068 {
00069 this->side = side;
00070 this->hint = hint;
00071 }
00072 };
00073
00075 struct Parameter
00076 {
00077 double interior_weight;
00078 double interior_smoothness;
00079 double interior_regularisation;
00080
00081 double boundary_weight;
00082 double boundary_smoothness;
00083 double boundary_regularisation;
00084
00085 unsigned regularisation_resU;
00086 unsigned regularisation_resV;
00087
00088 Parameter (double intW = 1.0, double intS = 0.000001, double intR = 0.0, double bndW = 1.0,
00089 double bndS = 0.000001, double bndR = 0.0, unsigned regU = 0, unsigned regV = 0) :
00090 interior_weight (intW), interior_smoothness (intS), interior_regularisation (intR), boundary_weight (bndW),
00091 boundary_smoothness (bndS), boundary_regularisation (bndR), regularisation_resU (regU),
00092 regularisation_resV (regV)
00093 {
00094 }
00095 };
00096
00101 FittingSurface (NurbsDataSurface *data, const ON_NurbsSurface &ns);
00102
00108 FittingSurface (int order, NurbsDataSurface *data, Eigen::Vector3d z = Eigen::Vector3d (0.0, 0.0, 1.0));
00109
00113 void
00114 refine (int dim);
00115
00116 static void
00117 refine (ON_NurbsSurface &nurbs, int dim);
00118
00123 virtual void
00124 assemble (Parameter param = Parameter ());
00125
00129 virtual void
00130 solve (double damp = 1.0);
00131
00135 virtual void
00136 updateSurf (double damp);
00137
00142 void
00143 setInvMapParams (unsigned in_max_steps, double in_accuracy);
00144
00146 static std::vector<double>
00147 getElementVector (const ON_NurbsSurface &nurbs, int dim);
00148
00162 static Eigen::Vector2d
00163 inverseMapping (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, const Eigen::Vector2d &hint,
00164 double &error, Eigen::Vector3d &p, Eigen::Vector3d &tu, Eigen::Vector3d &tv, int maxSteps = 100,
00165 double accuracy = 1e-6, bool quiet = true);
00166
00167 static Eigen::Vector2d
00168 inverseMapping (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, const Eigen::Vector2d &hint,
00169 Eigen::Vector3d &p, int maxSteps, double accuracy, bool quiet);
00170
00176 static Eigen::Vector2d
00177 findClosestElementMidPoint (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt);
00178
00191 static Eigen::Vector2d
00192 inverseMappingBoundary (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, double &error,
00193 Eigen::Vector3d &p, Eigen::Vector3d &tu, Eigen::Vector3d &tv, int maxSteps = 100,
00194 double accuracy = 1e-6, bool quiet = true);
00195
00211 static Eigen::Vector2d
00212 inverseMappingBoundary (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, int side, double hint,
00213 double &error, Eigen::Vector3d &p, Eigen::Vector3d &tu, Eigen::Vector3d &tv,
00214 int maxSteps = 100, double accuracy = 1e-6, bool quiet = true);
00215
00217 static ON_NurbsSurface
00218 initNurbs4Corners (int order, ON_3dPoint ll, ON_3dPoint lr, ON_3dPoint ur, ON_3dPoint ul);
00219
00221 static ON_NurbsSurface
00222 initNurbsPCA (int order, NurbsDataSurface *data, Eigen::Vector3d z = Eigen::Vector3d (0.0, 0.0, 1.0));
00223
00225 static ON_NurbsSurface
00226 initNurbsPCABoundingBox (int order, NurbsDataSurface *data, Eigen::Vector3d z = Eigen::Vector3d (0.0, 0.0, 1.0));
00227
00229 inline void
00230 setQuiet (bool val)
00231 {
00232 m_quiet = val;
00233 m_solver.setQuiet (val);
00234 }
00235
00236 protected:
00237
00239 void
00240 init ();
00241
00243 virtual void
00244 assembleInterior (double wInt, unsigned &row);
00245
00247 virtual void
00248 assembleBoundary (double wBnd, unsigned &row);
00249
00251 virtual void
00252 addPointConstraint (const Eigen::Vector2d ¶ms, const Eigen::Vector3d &point, double weight, unsigned &row);
00253
00254
00256 virtual void
00257 addCageInteriorRegularisation (double weight, unsigned &row);
00258
00260 virtual void
00261 addCageBoundaryRegularisation (double weight, int side, unsigned &row);
00262
00264 virtual void
00265 addCageCornerRegularisation (double weight, unsigned &row);
00266
00268 virtual void
00269 addInteriorRegularisation (int order, int resU, int resV, double weight, unsigned &row);
00270
00272 virtual void
00273 addBoundaryRegularisation (int order, int resU, int resV, double weight, unsigned &row);
00274
00275 NurbsSolve m_solver;
00276
00277 bool m_quiet;
00278
00279 std::vector<double> m_elementsU;
00280 std::vector<double> m_elementsV;
00281
00282 double m_minU;
00283 double m_minV;
00284 double m_maxU;
00285 double m_maxV;
00286
00287 int in_max_steps;
00288 double in_accuracy;
00289
00290
00291 int
00292 grc2gl (int I, int J)
00293 {
00294 return m_nurbs.CVCount (1) * I + J;
00295 }
00296 int
00297 lrc2gl (int E, int F, int i, int j)
00298 {
00299 return grc2gl (E + i, F + j);
00300 }
00301 int
00302 gl2gr (int A)
00303 {
00304 return (static_cast<int> (A / m_nurbs.CVCount (1)));
00305 }
00306 int
00307 gl2gc (int A)
00308 {
00309 return (static_cast<int> (A % m_nurbs.CVCount (1)));
00310 }
00311 };
00312
00313 }
00314 }
00315
00316 #endif // PATCHFITTING_H_