17 #include <itkMatrix.h>
18 #include <itkTransform.h>
19 #include <vnl/vnl_cross.h>
20 #include <vnl/vnl_vector.h>
35 template <
class TCoordRep,
unsigned int NPo
intDimension = 3>
52 Line(
const itk::Point<TCoordRep, NPointDimension> &point,
const itk::Vector<TCoordRep, NPointDimension> &direction)
59 const itk::Point<TCoordRep, NPointDimension> &
GetPoint()
const {
return m_Point; }
78 void SetPoint(
const itk::Point<TCoordRep, NPointDimension> &point1)
80 itk::Point<TCoordRep, NPointDimension> point2;
83 m_Direction = point2.GetVectorFromOrigin() - point1.GetVectorFromOrigin();
105 void Set(
const itk::Point<TCoordRep, NPointDimension> &point,
106 const itk::Vector<TCoordRep, NPointDimension> &direction)
117 void SetPoints(
const itk::Point<TCoordRep, NPointDimension> &point1,
118 const itk::Point<TCoordRep, NPointDimension> &point2)
132 void SetPoint1(
const itk::Point<TCoordRep, NPointDimension> &point1)
134 itk::Vector<TCoordRep, NPointDimension> point2;
138 m_Direction = point2 - point1.GetVectorFromOrigin();
156 itk::Point<TCoordRep, NPointDimension>
GetPoint2()
const
158 itk::Point<TCoordRep, NPointDimension> point2;
169 void Transform(itk::Transform<TCoordRep, NPointDimension, NPointDimension> &transform)
181 void Transform(
const itk::Matrix<TCoordRep, NPointDimension, NPointDimension> &matrix)
191 double Distance(
const itk::Point<TCoordRep, NPointDimension> &point)
const
193 itk::Vector<TCoordRep, NPointDimension> diff;
195 return diff.GetNorm();
205 itk::Point<TCoordRep, NPointDimension>
Project(
const itk::Point<TCoordRep, NPointDimension> &point)
const
210 itk::Vector<TCoordRep, NPointDimension> diff;
213 itk::Vector<TCoordRep, NPointDimension> normalizedDirection =
m_Direction;
214 normalizedDirection.Normalize();
216 normalizedDirection *= dot_product(diff.GetVnlVector(), normalizedDirection.GetVnlVector());
218 return this->m_Point + normalizedDirection;
234 itk::Vector<TCoordRep, NPointDimension> diff;
240 if (diff.GetSquaredNorm() <=
m_Direction.GetSquaredNorm())
251 bool IsPartOfLine(
const itk::Point<TCoordRep, NPointDimension> &point)
const
268 vnl_vector<TCoordRep> normal;
272 if (normal.squared_magnitude() <
eps)
300 itk::Vector<TCoordRep, NPointDimension> diff;
302 if (diff.GetSquaredNorm() >
eps)
305 if (diff.GetSquaredNorm() >
eps)
345 itk::Point<TCoordRep, 2> p,
346 itk::Vector<TCoordRep, 2> d,
347 itk::Point<TCoordRep, 2> &s1,
348 itk::Point<TCoordRep, 2> &s2)
355 if (fabs(d[0]) >
eps)
357 t = (x1 - p[0]) / d[0];
358 itk::Point<TCoordRep, 2> l = p + d * t;
359 if ((l[1] >= y1) && (l[1] < y2))
369 if (fabs(d[0]) >
eps)
371 t = (x2 - p[0]) / d[0];
372 itk::Point<TCoordRep, 2> l = p + d * t;
374 if ((l[1] >= y1) && (l[1] < y2))
385 if (fabs(d[1]) >
eps)
387 t = (y1 - p[1]) / d[1];
388 itk::Point<TCoordRep, 2> l = p + d * t;
390 if ((l[0] >= x1) && (l[0] < x2))
400 if (fabs(d[1]) >
eps)
402 t = (y2 - p[1]) / d[1];
403 itk::Point<TCoordRep, 2> l = p + d * t;
404 if ((l[0] >= x1) && (l[0] < x2))
433 itk::Point<TCoordRep, 3> p,
434 itk::Vector<TCoordRep, 3> d,
435 itk::Point<TCoordRep, 3> &s1,
436 itk::Point<TCoordRep, 3> &s2)
448 itk::Point<TCoordRep, 3> point;
451 for (i = 0; i < 6; ++i)
454 if (fabs(d[j]) >
eps)
458 point = p + d * lambda;
463 if ((((point[k] >= box[k * 2]) && (point[k] <= box[k * 2 + 1])) ||
464 ((point[k] <= box[k * 2]) && (point[k] >= box[k * 2 + 1]))) &&
465 (((point[l] >= box[l * 2]) && (point[l] <= box[l * 2 + 1])) ||
466 ((point[l] <= box[l * 2]) && (point[l] >= box[l * 2 + 1])))
486 itk::Point<TCoordRep, NPointDimension>
m_Point;
Describes a line in N-dimensional space.
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.
itk::Point< TCoordRep, NPointDimension > m_Point
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.
bool IsPartOfLine(const Line< TCoordRep, NPointDimension > &line) const
Test if another line is part of this line (line having infinite length).
const itk::Point< TCoordRep, NPointDimension > & GetPoint() const
Get start point of the line (const).
itk::Point< TCoordRep, NPointDimension > Project(const itk::Point< TCoordRep, NPointDimension > &point) const
Project a point onto the line.
double Distance(const itk::Point< TCoordRep, NPointDimension > &point) const
Compute the distance of a point from 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.
bool IsPartOfLine(const itk::Point< TCoordRep, NPointDimension > &point) const
Test if a point is part of the line (line having infinite length).
Line(const itk::Point< TCoordRep, NPointDimension > &point, const itk::Vector< TCoordRep, NPointDimension > &direction)
Define line by point and direction.
const Line< TCoordRep, NPointDimension > & operator=(const Line< TCoordRep, NPointDimension > &line)
Set the line by another line (copy assignment).
itk::Vector< TCoordRep, NPointDimension > & GetDirection()
Get the direction vector of the line (non-const).
void SetPoints(const itk::Point< TCoordRep, NPointDimension > &point1, const itk::Point< TCoordRep, NPointDimension > &point2)
Define line by two points.
void SetDirection(const itk::Vector< TCoordRep, NPointDimension > &direction)
Set the direction vector of the line.
bool operator==(const Line< TCoordRep, NPointDimension > &line) const
Test if the two lines are identical.
void Transform(itk::Transform< TCoordRep, NPointDimension, NPointDimension > &transform)
Transform the line with an ITK Transform.
void Set(const itk::Point< TCoordRep, NPointDimension > &point, const itk::Vector< TCoordRep, NPointDimension > &direction)
Define line by point and direction.
const itk::Vector< TCoordRep, NPointDimension > & GetDirection() const
Get the direction vector of the line (const).
bool operator!=(const Line< TCoordRep, NPointDimension > &line) const
Test if two lines are not identical.
bool IsParallel(const Line< TCoordRep, NPointDimension > &line) const
Test if a line is parallel to this line.
bool IsPartOfStraightLine(const itk::Point< TCoordRep, NPointDimension > &point) const
Test if a point is part of the line segment.
const itk::Point< TCoordRep, NPointDimension > GetPoint(TCoordRep t) const
Get point on the line at parameter t.
void SetPoint1(const itk::Point< TCoordRep, NPointDimension > &point1)
Set/change start point of the line.
itk::Vector< TCoordRep, NPointDimension > m_Direction
void SetPoint(const itk::Point< TCoordRep, NPointDimension > &point1)
Set/change start point of the line.
void Transform(const itk::Matrix< TCoordRep, NPointDimension, NPointDimension > &matrix)
Transform the line with a matrix.
itk::Point< TCoordRep, NPointDimension > & GetPoint()
Get start point of the line (non-const).
itk::Point< TCoordRep, NPointDimension > GetPoint2() const
Get end point of the line.
Convenience header that includes all MITK numeric types.
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
Line< ScalarType, 3 > Line3D
double ScalarType
Scalar type used throughout MITK for geometric computations.