vrcore  0.45
visuReal Messkern
 All Classes Files Functions Variables
algorithms.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <opencv2/opencv.hpp>
9 
10 namespace vr {
11 
12 class Plane;
13 
22 class Line
23 {
24 public:
25  friend class Plane;
26  Line() : point_(0.0, 0.0, 0.0), direction_(1.0, 0.0, 0.0) {};
27  Line(const cv::Vec3d& point, const cv::Vec3d& direction);
31  const cv::Vec3d& getDirection() const;
35  const cv::Vec3d& getPoint() const;
40  cv::Vec3d getPoint(const double t) const;
45  cv::Vec3d operator ()(const double t) const;
46  void getIntersection(double& t, const Plane& plane) const;
47  cv::Vec3d getIntersection(const Plane& plane) const;
49  void getNearestPoint(double& t, const Line& line) const;
50  cv::Vec3d getNearestPoint(const Line& line) const;
54  double normalize();
55 private:
56  cv::Vec3d point_;
57  cv::Vec3d direction_;
58 };
59 
60 
68 class Plane
69 {
70 public:
71  friend class Line;
72  Plane(const cv::Vec3d& normal, const double lambda);
73  Plane(const cv::Vec3d& direction1,
74  const cv::Vec3d& direction2,
75  const cv::Vec3d& point);
76  cv::Vec3d getIntersection(const Line& line) const;
77  Line getIntersection(const Plane& plane) const;
78  const cv::Vec3d& getNormal() const;
79  double getLambda() const;
80 private:
81  cv::Vec3d normal_;
82  double lambda_;
83 };
84 
94 {
95 public:
96  AxisParallelEllipse(cv::Point2d& center, cv::Point2d& radius);
98  bool contains(cv::Point2d& point)
99  {
100  double dx2 = point.x - center_.x;
101  double dy2 = point.y - center_.y;
102 
103  double rx2 = radius_.x * radius_.x;
104  double ry2 = radius_.y * radius_.y;
105 
106  return dx2 / rx2 + dy2 / ry2 <= 1.0;
107  };
108 private:
109  cv::Point2d center_;
110  cv::Point2d radius_;
111 };
112 
113 
115 template <typename T> int sgn(T val) {
116  return (T(0) < val) - (val < T(0));
117 }
118 
119 
124 int adaptedNewtonsMethod(cv::Vec3d& depth, double* residuum,
125  double p_L, double p_R, double p_M,
126  double q_LR, double q_LM, double q_RM,
127  double d_LR, double d_LM, double d_RM,
128  double epsilon);
129 
130 // Gibt den Lösungsvektor
131 cv::Vec3d adaptedNewtonsMethodForBC(const cv::Vec3d& F_O, const cv::Vec3d& F_A, const cv::Vec3d& F_U,
132  double rq, const cv::Vec3d& start, double epsilon);
133 
142 template <int n>
143 cv::Vec<double, n> SP(const cv::Vec<double, n>& p, const cv::Vec<double, n>& v, const cv::Vec<double, n>& w)
144 {
145  double t = (p - v).dot(w) / w.dot(w);
146  return v + (w * t);
147 }
148 
160 int calcLineCircleIntersections (double& result1, double& result2,
161  const cv::Vec2d& linePoint, const cv::Vec2d& lineDirection, const cv::Vec2d& center, const double radius);
162 
172 int calcLineCircleIntersections (cv::Vec2d& result1, cv::Vec2d& result2,
173  const cv::Vec2d& linePoint, const cv::Vec2d& lineDirection, const cv::Vec2d& center, const double radius);
174 
185 int calcLineSphereIntersections (cv::Vec3d& result1, cv::Vec3d& result2,
186  const cv::Vec3d& linePoint, const cv::Vec3d& lineDirection, const cv::Vec3d& center, const double radius);
187 
188 
199 bool getPlaneNormalForm(cv::Vec3d& normal,
200  double& lambda,
201  const cv::Vec3d& direction1,
202  const cv::Vec3d& direction2,
203  const cv::Vec3d& planePoint);
204 
213 void calcLinePlaneIntersection(double& result,
214  const cv::Vec3d& linePoint, const cv::Vec3d& lineDirection,
215  const cv::Vec3d& planeNormal, const double lambda);
216 
225 cv::Vec3d calcLinePlaneIntersection(const cv::Vec3d& linePoint, const cv::Vec3d& lineDirection,
226  const cv::Vec3d& planeNormal, const double lambda);
227 
238 cv::Vec3d calcLineIntersection(
239  const cv::Vec2d& line1Point1, const cv::Vec2d& line1Point2,
240  const cv::Vec2d& line2Point1, const cv::Vec2d& line2Point2);
241 
242 void calcLineIntersection(cv::Vec2d& result,
243  const cv::Vec2d& line1Point1, const cv::Vec2d& line1Point2,
244  const cv::Vec2d& line2Point1, const cv::Vec2d& line2Point2);
245 
251 inline double deg2rad(double deg) {
252  return (deg * CV_PI / 180.0);
253 }
254 
255 
261 inline double rad2deg(double rad) {
262  return (rad * 180.0 / CV_PI);
263 }
264 
273 inline bool IsPointInEllipse(const cv::Point2d p,
274  const cv::Point2d& center, const cv::Point2d& radius)
275 {
276  double dx2 = p.x - center.x;
277  double dy2 = p.y - center.y;
278 
279  dx2 *= dx2;
280  dy2 *= dy2;
281 
282  double rx2 = radius.x * radius.x;
283  double ry2 = radius.y * radius.y;
284 
285  return dx2 / rx2 + dy2 / ry2 <= 1.0;
286 }
287 
288 } // namespace vr
double normalize()
normalisiert den Richtungsvektor und gibt den alten Betrag zurück.
Definition: algorithms.cpp:247
Achsenparallele Ellipse.
Definition: algorithms.h:93
const cv::Vec3d & getPoint() const
gibt den Ankerpunkt zurück
Definition: algorithms.cpp:261
cv::Vec3d operator()(const double t) const
wie getPoint(), nur konziser
Definition: algorithms.cpp:271
const cv::Vec3d & getDirection() const
gibt den Richtungsvektor zurück.
Definition: algorithms.cpp:256
void getNearestPoint(double &t, const Line &line) const
*this und line sind windschiefe Geraden.
Definition: algorithms.cpp:276
Ebene.
Definition: algorithms.h:68
Gerade im Raum.
Definition: algorithms.h:22