17 #ifndef MITKLINE_H_HEADER_INCLUDED_C19C01E2
18 #define MITKLINE_H_HEADER_INCLUDED_C19C01E2
21 #include <itkMatrix.h>
22 #include <itkTransform.h>
23 #include <vnl/vnl_cross.h>
24 #include <vnl/vnl_vector.h>
31 template <
class TCoordRep,
unsigned int NPo
intDimension = 3>
45 Line(
const itk::Point<TCoordRep, NPointDimension> &point,
const itk::Vector<TCoordRep, NPointDimension> &direction)
53 const itk::Point<TCoordRep, NPointDimension> &
GetPoint()
const {
return m_Point; }
64 void SetPoint(
const itk::Point<TCoordRep, NPointDimension> &point1)
66 itk::Point<TCoordRep, NPointDimension> point2;
69 m_Direction = point2.GetVectorFromOrigin() - point1.GetVectorFromOrigin();
85 void Set(
const itk::Point<TCoordRep, NPointDimension> &point,
86 const itk::Vector<TCoordRep, NPointDimension> &direction)
94 void SetPoints(
const itk::Point<TCoordRep, NPointDimension> &point1,
95 const itk::Point<TCoordRep, NPointDimension> &point2)
104 void SetPoint1(
const itk::Point<TCoordRep, NPointDimension> &point1)
106 itk::Vector<TCoordRep, NPointDimension> point2;
110 m_Direction = point2 - point1.GetVectorFromOrigin();
121 itk::Point<TCoordRep, NPointDimension>
GetPoint2()
const
123 itk::Point<TCoordRep, NPointDimension> point2;
130 void Transform(itk::Transform<TCoordRep, NPointDimension, NPointDimension> &transform)
140 void Transform(
const itk::Matrix<TCoordRep, NPointDimension, NPointDimension> &matrix)
147 double Distance(
const itk::Point<TCoordRep, NPointDimension> &point)
const
149 itk::Vector<TCoordRep, NPointDimension> diff;
151 return diff.GetNorm();
156 itk::Point<TCoordRep, NPointDimension>
Project(
const itk::Point<TCoordRep, NPointDimension> &point)
const
161 itk::Vector<TCoordRep, NPointDimension> diff;
164 itk::Vector<TCoordRep, NPointDimension> normalizedDirection =
m_Direction;
165 normalizedDirection.Normalize();
167 normalizedDirection *= dot_product(diff.GetVnlVector(), normalizedDirection.GetVnlVector());
169 return this->m_Point + normalizedDirection;
181 itk::Vector<TCoordRep, NPointDimension> diff;
187 if (diff.GetSquaredNorm() <=
m_Direction.GetSquaredNorm())
195 bool IsPartOfLine(
const itk::Point<TCoordRep, NPointDimension> &point)
const
207 vnl_vector<TCoordRep> normal;
211 if (normal.squared_magnitude() <
eps)
231 itk::Vector<TCoordRep, NPointDimension> diff;
233 if (diff.GetSquaredNorm() >
eps)
236 if (diff.GetSquaredNorm() >
eps)
268 itk::Point<TCoordRep, 2> p,
269 itk::Vector<TCoordRep, 2> d,
270 itk::Point<TCoordRep, 2> &s1,
271 itk::Point<TCoordRep, 2> &s2)
278 if (fabs(d[0]) >
eps)
280 t = (x1 - p[0]) / d[0];
281 itk::Point<TCoordRep, 2> l = p + d * t;
282 if ((l[1] >= y1) && (l[1] < y2))
292 if (fabs(d[0]) >
eps)
294 t = (x2 - p[0]) / d[0];
295 itk::Point<TCoordRep, 2> l = p + d * t;
297 if ((l[1] >= y1) && (l[1] < y2))
308 if (fabs(d[1]) >
eps)
310 t = (y1 - p[1]) / d[1];
311 itk::Point<TCoordRep, 2> l = p + d * t;
313 if ((l[0] >= x1) && (l[0] < x2))
323 if (fabs(d[1]) >
eps)
325 t = (y2 - p[1]) / d[1];
326 itk::Point<TCoordRep, 2> l = p + d * t;
327 if ((l[0] >= x1) && (l[0] < x2))
356 itk::Point<TCoordRep, 3> p,
357 itk::Vector<TCoordRep, 3> d,
358 itk::Point<TCoordRep, 3> &s1,
359 itk::Point<TCoordRep, 3> &s2)
371 itk::Point<TCoordRep, 3> point;
374 for (i = 0; i < 6; ++i)
377 if (fabs(d[j]) >
eps)
381 point = p + d * lambda;
386 if ((((point[k] >= box[k * 2]) && (point[k] <= box[k * 2 + 1])) ||
387 ((point[k] <= box[k * 2]) && (point[k] >= box[k * 2 + 1]))) &&
388 (((point[l] >= box[l * 2]) && (point[l] <= box[l * 2 + 1])) ||
389 ((point[l] <= box[l * 2]) && (point[l] >= box[l * 2 + 1])))
409 itk::Point<TCoordRep, NPointDimension>
m_Point;
void SetPoint2(const itk::Point< TCoordRep, NPointDimension > &point2)
Set/change end point of the line.
const itk::Point< TCoordRep, NPointDimension > & GetPoint1() const
Get start point of the line.
double Distance(const itk::Point< TCoordRep, NPointDimension > &point) const
Distance of a point from the line.
bool operator!=(const Line< TCoordRep, NPointDimension > &line) const
Test if two lines are not identical.
itk::Point< TCoordRep, NPointDimension > & GetPoint()
Get start point of the line.
void SetDirection(const itk::Vector< TCoordRep, NPointDimension > &direction)
Set the direction vector of the line.
void SetPoint(const itk::Point< TCoordRep, NPointDimension > &point1)
Set/change start point of the line.
Line< ScalarType, 3 > Line3D
DataCollection - Class to facilitate loading/accessing structured data.
itk::Point< TCoordRep, NPointDimension > m_Point
bool IsParallel(const Line< TCoordRep, NPointDimension > &line) const
Test if a lines is parallel to this line.
static int BoxLineIntersection(TCoordRep x1, TCoordRep y1, TCoordRep z1, TCoordRep x2, TCoordRep y2, TCoordRep z2, itk::Point< TCoordRep, 3 > p, itk::Vector< TCoordRep, 3 > d, itk::Point< TCoordRep, 3 > &s1, itk::Point< TCoordRep, 3 > &s2)
Calculates the intersection points of a straight line in 3D with a box.
const itk::Vector< TCoordRep, NPointDimension > & GetDirection() const
Get the direction vector of the line.
const itk::Point< TCoordRep, NPointDimension > GetPoint(TCoordRep t) const
Get point on the line with parameter t.
const itk::Point< TCoordRep, NPointDimension > & GetPoint() const
Get start point of the line.
void Transform(itk::Transform< TCoordRep, NPointDimension, NPointDimension > &transform)
Transform the line with a Transform.
void SetPoints(const itk::Point< TCoordRep, NPointDimension > &point1, const itk::Point< TCoordRep, NPointDimension > &point2)
Define line by two points.
bool IsPartOfLine(const itk::Point< TCoordRep, NPointDimension > &point) const
Test if a point is part of the line (line having infinite length)
bool IsPartOfStraightLine(const itk::Point< TCoordRep, NPointDimension > &point) const
Test if a point is part of the line.
itk::Vector< TCoordRep, NPointDimension > m_Direction
itk::Point< TCoordRep, NPointDimension > Project(const itk::Point< TCoordRep, NPointDimension > &point) const
Project a point on the line.
itk::Point< TCoordRep, NPointDimension > GetPoint2() const
Get end point of the line.
static int RectangleLineIntersection(TCoordRep x1, TCoordRep y1, TCoordRep x2, TCoordRep y2, itk::Point< TCoordRep, 2 > p, itk::Vector< TCoordRep, 2 > d, itk::Point< TCoordRep, 2 > &s1, itk::Point< TCoordRep, 2 > &s2)
Calculates the intersection points of a straight line in 2D with a rectangle.
MITKCORE_EXPORT const ScalarType eps
bool IsPartOfLine(const Line< TCoordRep, NPointDimension > &line) const
Test if a line is part of the line (line having infinite length)
itk::Vector< TCoordRep, NPointDimension > & GetDirection()
Get the direction vector of the line.
void Transform(const itk::Matrix< TCoordRep, NPointDimension, NPointDimension > &matrix)
Transform the line with a matrix.
void SetPoint1(const itk::Point< TCoordRep, NPointDimension > &point1)
Set/change start point of the line.
void Set(const itk::Point< TCoordRep, NPointDimension > &point, const itk::Vector< TCoordRep, NPointDimension > &direction)
Define line by point and direction.
bool operator==(const Line< TCoordRep, NPointDimension > &line) const
Test if the two lines are identical.
const Line< TCoordRep, NPointDimension > & operator=(const Line< TCoordRep, NPointDimension > &line)
Set the line by another line.
Line(const itk::Point< TCoordRep, NPointDimension > &point, const itk::Vector< TCoordRep, NPointDimension > &direction)
Define line by point and direction.