13 #ifndef MITKLINE_H_HEADER_INCLUDED_C19C01E2 14 #define MITKLINE_H_HEADER_INCLUDED_C19C01E2 17 #include <itkMatrix.h> 18 #include <itkTransform.h> 19 #include <vnl/vnl_cross.h> 20 #include <vnl/vnl_vector.h> 27 template <
class TCoordRep,
unsigned int NPo
intDimension = 3>
41 Line(
const itk::Point<TCoordRep, NPointDimension> &point,
const itk::Vector<TCoordRep, NPointDimension> &direction)
49 const itk::Point<TCoordRep, NPointDimension> &
GetPoint()
const {
return m_Point; }
60 void SetPoint(
const itk::Point<TCoordRep, NPointDimension> &point1)
62 itk::Point<TCoordRep, NPointDimension> point2;
65 m_Direction = point2.GetVectorFromOrigin() - point1.GetVectorFromOrigin();
81 void Set(
const itk::Point<TCoordRep, NPointDimension> &point,
82 const itk::Vector<TCoordRep, NPointDimension> &direction)
90 void SetPoints(
const itk::Point<TCoordRep, NPointDimension> &point1,
91 const itk::Point<TCoordRep, NPointDimension> &point2)
100 void SetPoint1(
const itk::Point<TCoordRep, NPointDimension> &point1)
102 itk::Vector<TCoordRep, NPointDimension> point2;
106 m_Direction = point2 - point1.GetVectorFromOrigin();
117 itk::Point<TCoordRep, NPointDimension>
GetPoint2()
const 119 itk::Point<TCoordRep, NPointDimension> point2;
126 void Transform(itk::Transform<TCoordRep, NPointDimension, NPointDimension> &transform)
136 void Transform(
const itk::Matrix<TCoordRep, NPointDimension, NPointDimension> &matrix)
143 double Distance(
const itk::Point<TCoordRep, NPointDimension> &point)
const 145 itk::Vector<TCoordRep, NPointDimension> diff;
147 return diff.GetNorm();
152 itk::Point<TCoordRep, NPointDimension>
Project(
const itk::Point<TCoordRep, NPointDimension> &point)
const 157 itk::Vector<TCoordRep, NPointDimension> diff;
160 itk::Vector<TCoordRep, NPointDimension> normalizedDirection =
m_Direction;
161 normalizedDirection.Normalize();
163 normalizedDirection *= dot_product(diff.GetVnlVector(), normalizedDirection.GetVnlVector());
165 return this->m_Point + normalizedDirection;
177 itk::Vector<TCoordRep, NPointDimension> diff;
183 if (diff.GetSquaredNorm() <=
m_Direction.GetSquaredNorm())
191 bool IsPartOfLine(
const itk::Point<TCoordRep, NPointDimension> &point)
const 203 vnl_vector<TCoordRep> normal;
207 if (normal.squared_magnitude() <
eps)
227 itk::Vector<TCoordRep, NPointDimension> diff;
229 if (diff.GetSquaredNorm() >
eps)
232 if (diff.GetSquaredNorm() >
eps)
264 itk::Point<TCoordRep, 2> p,
265 itk::Vector<TCoordRep, 2> d,
266 itk::Point<TCoordRep, 2> &s1,
267 itk::Point<TCoordRep, 2> &s2)
274 if (fabs(d[0]) >
eps)
276 t = (x1 - p[0]) / d[0];
277 itk::Point<TCoordRep, 2> l = p + d * t;
278 if ((l[1] >= y1) && (l[1] < y2))
288 if (fabs(d[0]) >
eps)
290 t = (x2 - p[0]) / d[0];
291 itk::Point<TCoordRep, 2> l = p + d * t;
293 if ((l[1] >= y1) && (l[1] < y2))
304 if (fabs(d[1]) >
eps)
306 t = (y1 - p[1]) / d[1];
307 itk::Point<TCoordRep, 2> l = p + d * t;
309 if ((l[0] >= x1) && (l[0] < x2))
319 if (fabs(d[1]) >
eps)
321 t = (y2 - p[1]) / d[1];
322 itk::Point<TCoordRep, 2> l = p + d * t;
323 if ((l[0] >= x1) && (l[0] < x2))
352 itk::Point<TCoordRep, 3> p,
353 itk::Vector<TCoordRep, 3> d,
354 itk::Point<TCoordRep, 3> &s1,
355 itk::Point<TCoordRep, 3> &s2)
367 itk::Point<TCoordRep, 3> point;
370 for (i = 0; i < 6; ++i)
373 if (fabs(d[j]) >
eps)
377 point = p + d * lambda;
382 if ((((point[k] >= box[k * 2]) && (point[
k] <= box[k * 2 + 1])) ||
383 ((point[
k] <= box[k * 2]) && (point[k] >= box[k * 2 + 1]))) &&
384 (((point[l] >= box[l * 2]) && (point[l] <= box[l * 2 + 1])) ||
385 ((point[l] <= box[l * 2]) && (point[l] >= box[l * 2 + 1])))
405 itk::Point<TCoordRep, NPointDimension>
m_Point;
void SetPoint2(const itk::Point< TCoordRep, NPointDimension > &point2)
Set/change end point of the line.
bool operator==(const Line< TCoordRep, NPointDimension > &line) const
Test if the two lines are identical.
bool IsParallel(const Line< TCoordRep, NPointDimension > &line) const
Test if a lines is parallel to this line.
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 operator!=(const Line< TCoordRep, NPointDimension > &line) const
Test if two lines are not identical.
bool IsPartOfStraightLine(const itk::Point< TCoordRep, NPointDimension > &point) const
Test if a point is part of the 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::Point< TCoordRep, NPointDimension > & GetPoint() const
Get start point of the line.
bool IsPartOfLine(const itk::Point< TCoordRep, NPointDimension > &point) const
Test if a point is part of the line (line having infinite length)
itk::Point< TCoordRep, NPointDimension > Project(const itk::Point< TCoordRep, NPointDimension > &point) const
Project a point on the line.
bool IsPartOfLine(const Line< TCoordRep, NPointDimension > &line) const
Test if a line is part of the line (line having infinite length)
double Distance(const itk::Point< TCoordRep, NPointDimension > &point) const
Distance of a point from the line.
const itk::Point< TCoordRep, NPointDimension > & GetPoint1() const
Get start point of the line.
const itk::Vector< TCoordRep, NPointDimension > & GetDirection() const
Get the direction vector 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.
itk::Vector< TCoordRep, NPointDimension > m_Direction
const itk::Point< TCoordRep, NPointDimension > GetPoint(TCoordRep t) const
Get point on the line with parameter t.
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
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.
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.