MorphoGraphX  2.0-1-227
Bezier.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 
12 #ifndef __BEZIER_HPP__
13 #define __BEZIER_HPP__
14 
15 #include <Parms.hpp>
16 #include <Geometry.hpp>
17 
18 namespace mgx
19 {
20  class mgx_EXPORT Bezier
21  {
22  private:
23  Point2u _bezPoints; // number of bezier control points in each direction
24  Point2d _bezSize; // size of Bezier in each direction
25  Point2u _bezLines; // number of lines for drawing Bezier, in each direction
26  std::vector<Point3d> _bezierV; // position of control points
27  std::vector<uint> _binomV; // binomial coefficients to evaluate Bezier
28 
29  public:
30  Bezier() : _bezPoints(5 ,5), _bezSize(20 ,20), _bezierV(0), _binomV(0) {}
31  ~Bezier() {}
32 
33  Point2u bezPoints() const {
34  return _bezPoints;
35  }
37  {
38  if(n != _bezPoints) {
39  _bezPoints = n;
40  // re-populate the vectors for binomial and control points
41  initBez();
42 // hasChanged();
43  }
44  }
45 
46  Point2d bezSize() const {
47  return _bezSize;
48  }
50  _bezSize = n;
51  }
52 
53  Point2u bezLines() const {
54  return _bezLines;
55  }
57  if(n.x() < 2)
58  n.x() = 2;
59  if(n.y() < 2)
60  n.y() = 2;
61  _bezLines = n;
62  }
63 
64  void setBezierV(const std::vector<Point3d>& points)
65  {
66  if(points.size() == _bezierV.size()) {
67  _bezierV = points;
68 // hasChanged();
69  }
70  }
71  const std::vector<Point3d>& bezierV() const {
72  return _bezierV;
73  }
74  std::vector<Point3d>& bezierV() {
75  return _bezierV;
76  }
77 
79  return _bezierV[idx(u, v)];
80  }
81  const Point3d& bezierV(uint u, uint v) const {
82  return _bezierV[idx(u, v)];
83  }
84 
85  void resetBezier() {
86  _bezPoints = Point2u(5,5);
87  _bezSize = Point2d(20.0,20.0);
88  _bezLines = Point2u(10,10);
89  _bezierV.clear();
90  _binomV.clear();
91  }
92 
93  void readParms(Parms& parms, QString section);
94 
95  void loadBezier(QString filename);
96  void saveBezier(QString filename);
97 
98  // Copy and/or scale
99  void scale(float ScaleX, float ScaleY);
100 
101  // Create new interpolated (and scaled) surface
102  void interpolate(Bezier &src1, Bezier &src2,
103  double scale1, double scale2, double s);
104  // Initialize bezier
105  void initBez();
106 
107  // Return x,y,z point from u,v parameters
108  Point3d evalCoord(float u, float v) const; // ALR: const needed in CuttingSurface
109  Point3d evalCoordTrim(double& u, double& v);
110 
111  Point3d evalCoordSpline(double u, double v);
112 
113  // Converts u,v into an array value (assuming u is the first coordinate)
114  uint idx(uint u, uint v) const {
115  return (v * _bezPoints.x() + u);
116  }
117 
118  // returns a vector of points which represents a discretized line of the bezier grid along a fix v-coordinate
119  void discretizeLine(int discPoints, double vPos, Matrix4d rotMat,
120  std::vector<Point3d>& discretizedBez, std::vector<Point3d>& differentialBez);
121 
122  // returns a vector of points which represents a discretized line of the bezier grid along a fix v-coordinate
123  // the points of this line have approx equal spacial distribution
124  void discretizeLineEqualWeight(int discPoints, double vPos, Matrix4d rotMat,
125  std::vector<Point3d>& discretizedBez, std::vector<Point3d>& differentialBez, double& totalLength);
126 
127  // returns an 2D array of points which represents a discretized grid of the bezier
128  void discretizeGrid(int discPoints, Matrix4d rotMat,
129  std::vector<std::vector<Point3d> >& discretizedBez);
130  };
131 }
132 
133 #endif
mgx::Bezier::Bezier
Bezier()
Definition: Bezier.hpp:30
mgx::uint
unsigned int uint
Definition: Geometry.hpp:41
mgx::Bezier
Definition: Bezier.hpp:20
mgx::Bezier::setBezLines
void setBezLines(Point2u n)
Definition: Bezier.hpp:56
mgx::Point2u
Vector< 2, uint > Point2u
Definition: Geometry.hpp:74
mgx::Bezier::setBezierV
void setBezierV(const std::vector< Point3d > &points)
Definition: Bezier.hpp:64
n
#define n
Definition: Eigenvalues.hpp:36
mgx::Bezier::resetBezier
void resetBezier()
Definition: Bezier.hpp:85
mgx::Bezier::bezierV
const std::vector< Point3d > & bezierV() const
Definition: Bezier.hpp:71
Geometry.hpp
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::Bezier::bezierV
Point3d & bezierV(uint u, uint v)
Definition: Bezier.hpp:78
mgx::Bezier::bezLines
Point2u bezLines() const
Definition: Bezier.hpp:53
mgx::interpolate
T CU_HOST_DEVICE interpolate(const T &a, const T &b, const T &s)
Interpolate between values.
Definition: Geometry.hpp:177
Parms.hpp
mgx::Bezier::bezierV
const Point3d & bezierV(uint u, uint v) const
Definition: Bezier.hpp:81
mgx::Bezier::bezierV
std::vector< Point3d > & bezierV()
Definition: Bezier.hpp:74
mgx::Bezier::setBezSize
void setBezSize(Point2d n)
Definition: Bezier.hpp:49
mgx::Bezier::bezSize
Point2d bezSize() const
Definition: Bezier.hpp:46
mgx::Point2d
Vector< 2, double > Point2d
Definition: Geometry.hpp:55
mgx::Vector< 2, uint >
mgx::Bezier::~Bezier
~Bezier()
Definition: Bezier.hpp:31
mgx::Vector::x
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:721
mgx::Matrix< 4, 4, double >
mgx::Parms
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:116
mgx::Bezier::idx
uint idx(uint u, uint v) const
Definition: Bezier.hpp:114
mgx::Bezier::bezPoints
Point2u bezPoints() const
Definition: Bezier.hpp:33
mgx::Bezier::setBezPoints
void setBezPoints(Point2u n)
Definition: Bezier.hpp:36