8 #ifndef META_OCEAN_CV_ADVANCED_PIXEL_LINE_H
9 #define META_OCEAN_CV_ADVANCED_PIXEL_LINE_H
27 template <
typename T>
class PixelLineT;
87 inline PixelLineT(
const T& x0,
const T& y0,
const T& x1,
const T& y1);
159 explicit inline operator bool()
const;
176 template <
typename T>
182 template <
typename T>
186 lineMinY(min(p0.y(), p1.y())),
187 lineMaxY(max(p0.y(), p1.y()))
192 template <
typename T>
196 lineMinY(min(y0, y1)),
197 lineMaxY(max(y0, y1))
202 template <
typename T>
208 template <
typename T>
214 template <
typename T>
217 ocean_assert(isValid());
218 return lineP0.y() == lineP1.y();
221 template <
typename T>
224 ocean_assert(isValid());
225 return lineP0.x() == lineP1.x();
228 template <
typename T>
231 ocean_assert(isValid());
232 return lineP0 == lineP1;
235 template <
typename T>
238 ocean_assert(isValid());
239 ocean_assert(lineMinY <= lineMaxY);
246 if (y < lineMinY || y > lineMaxY)
251 if (lineP0.y() == lineP1.y())
253 x = min(lineP0.x(), lineP1.x());
259 const float t = float(
int(y) - SignedType(lineP0.y())) / float(SignedType(lineP1.y()) - SignedType(lineP0.y()));
260 x = lineP0.x() + T(
float((SignedType(lineP1.x()) - SignedType(lineP0.x()))) * t + 0.5f);
266 template <
typename T>
269 return lineP0.isValid() && lineP1.isValid();
272 template <
typename T>
275 ocean_assert(isValid() && line.
isValid());
279 const SignedType vx0 = SignedType(lineP1.x()) - SignedType(lineP0.x());
280 const SignedType vy0 = SignedType(lineP1.y()) - SignedType(lineP0.y());
282 const SignedType vx1 = SignedType(line.
lineP1.x()) - SignedType(line.
lineP0.x());
283 const SignedType vy1 = SignedType(line.
lineP1.y()) - SignedType(line.
lineP0.y());
285 return vx0 * vy1 - vx1 * vy0;
288 template <
typename T>
294 template <
typename T>
297 return !(*
this == line);
300 template <
typename T>
This class implements a 2D line with pixel precision.
Definition: PixelLine.h:65
bool isHorizontal() const
Returns whether this line is horizontal.
Definition: PixelLine.h:215
bool isVertical() const
Returns whether this line is vertical.
Definition: PixelLine.h:222
T lineMinY
Lower vertical position.
Definition: PixelLine.h:170
PixelPositionT< T > lineP0
First line end point.
Definition: PixelLine.h:164
PixelLineT()
Creates an invalid line object.
Definition: PixelLine.h:177
PixelPositionT< T > lineP1
Second line end point.
Definition: PixelLine.h:167
bool operator!=(const PixelLineT< T > &line) const
Returns whether two line objects are not equal.
Definition: PixelLine.h:295
T lineMaxY
Upper vertical position.
Definition: PixelLine.h:173
SignedTyper< T >::Type operator*(const PixelLineT< T > &line) const
Multiplies two line objects and returns the scalar product.
Definition: PixelLine.h:273
bool isValid() const
Returns whether this line holds two valid end points.
Definition: PixelLine.h:267
const PixelPositionT< T > & p0() const
Returns the first end point of this line.
Definition: PixelLine.h:203
bool isPoint() const
Returns whether this line is a point.
Definition: PixelLine.h:229
const PixelPositionT< T > & p1() const
Returns the second end point of this line.
Definition: PixelLine.h:209
bool operator==(const PixelLineT< T > &line) const
Returns whether two line objects are equal.
Definition: PixelLine.h:289
bool horizontalIntersection(const T y, T &x) const
Calculates the intersection between this line and a horizontal scan line.
Definition: PixelLine.h:236
This class implements a 2D pixel position with pixel precision.
Definition: PixelPosition.h:65
T Type
Definition of the signed data type, if existing.
Definition: DataType.h:294
std::vector< PixelLine > PixelLines
Definition of a vector holding pixel lines (with positive coordinate values).
Definition: PixelLine.h:48
PixelLineT< int > PixelLineI
Definition of a PixelLine object with a data type allowing positive and negative coordinate values.
Definition: PixelLine.h:41
PixelLineT< unsigned int > PixelLine
Definition of the default PixelLine object with a data type allowing only positive coordinate values.
Definition: PixelLine.h:27
std::vector< PixelLineI > PixelLinesI
Definition of a vector holding pixel lines (with positive and negative coordinate values).
Definition: PixelLine.h:55
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15