47 #ifndef _MIRA_RASTERTRANSFORMATION_H_ 48 #define _MIRA_RASTERTRANSFORMATION_H_ 265 : mSrcArea(srcArea.x0(), srcArea.y0(), srcArea.width()-1, srcArea.height()-1),
266 mTgtArea(tgtArea.x0(), tgtArea.y0(), tgtArea.width()-1, tgtArea.height()-1),
273 if ((srcArea.width() < 1) || (srcArea.height() < 1) || (tgtArea.width() < 1) || (tgtArea.height() < 1))
320 return !(*
this == other);
326 mT(NULL), mLineValid(false) {}
331 mBresenham(other.mBresenham),
332 mCurrentLine(other.mCurrentLine),
334 mLineValid(other.mLineValid)
358 int left = area.x0(), right = area.x1(),
359 top = area.y0(), bottom = area.y1();
363 double & x1 = p1.x();
364 double & y1 = p1.y();
365 double & z1 = p1.z();
366 double & x2 = p2.x();
367 double & y2 = p2.y();
368 double & z2 = p2.z();
370 c1 = (x1 < left) + ((x1 > right) << 1) + ((y1 < top) << 2) + ((y1 > bottom) << 3);
371 c2 = (x2 < left) + ((x2 > right) << 1) + ((y2 < top) << 2) + ((y2 > bottom) << 3);
373 if( ((c1 & c2) == 0) && ((c1 | c2) != 0 ))
380 a = c1 < 8 ? top : bottom;
381 x1 += (a - y1) * (x2 - x1) / (y2 - y1);
382 z1 += (a - y1) * (z2 - z1) / (y2 - y1);
384 c1 = (x1 < left) + (x1 > right) * 2;
389 a = c2 < 8 ? top : bottom;
390 x2 += (a - y2) * (x2 - x1) / (y2 - y1);
391 z2 += (a - y2) * (z2 - z1) / (y2 - y1);
393 c2 = (x2 < left) + (x2 > right) * 2;
395 if( ((c1 & c2) == 0) && ((c1 | c2) != 0) )
401 a = c1 == 1 ? left : right;
402 y1 += (a - x1) * (y2 - y1) / (x2 - x1);
403 z1 += (a - x1) * (z2 - z1) / (x2 - x1);
410 a = c2 == 1 ? left : right;
411 y2 += (a - x2) * (y2 - y1) / (x2 - x1);
412 z2 += (a - x2) * (z2 - z1) / (x2 - x1);
419 return (c1 | c2) == 0;
424 mTY = floor(mCurrentLine + 0.5 * mT->mLineStep);
426 if (mTY > mT->mTgtArea.y1())
427 return (mLineValid =
false);
429 double dy = mCurrentLine + 0.5f * mT->mLineStep - mT->mTgtRef.y();
432 + (mT->mCosRot * mT->mDxStart - mT->mSinRot * dy) / mT->mScale,
434 + (mT->mSinRot * mT->mDxStart + mT->mCosRot * dy) / mT->mScale,
438 + (mT->mCosRot * mT->mDxEnd - mT->mSinRot * dy) / mT->mScale,
440 + (mT->mSinRot * mT->mDxEnd + mT->mCosRot * dy) / mT->mScale,
446 mLineValid = clipLine(mT->mSrcArea, startClipped, end);
455 if (startClipped != start)
462 if (mT->mRasterStep.x() != 0)
463 steps = std::max(steps, std::ceil((startClipped.x() - start.x()) / mT->mRasterStep.x()));
465 if (mT->mRasterStep.y() != 0)
466 steps = std::max(steps, std::ceil((startClipped.y() - start.y()) / mT->mRasterStep.y()));
468 if (mT->mRasterStep.z() != 0)
469 steps = std::max(steps, std::ceil((startClipped.z() - start.z()) / mT->mRasterStep.z()));
471 startClipped = start + steps * mT->mRasterStep;
479 if (std::abs(startClipped.z() - std::round(startClipped.z())) < 0.25)
481 startClipped += mT->mRasterStep/2;
485 if (((startClipped.x() > start.x()) && (startClipped.x() > end.x())) ||
486 ((startClipped.x() < start.x()) && (startClipped.x() < end.x())) )
488 return (mLineValid =
false);
492 Point3d distance = end - startClipped;
493 double l = std::max(std::hypot(distance.x(), distance.y()), std::abs(distance.z()));
496 startBresenham[0] = startClipped.x();
497 startBresenham[1] = startClipped.y();
498 startBresenham[2] = startClipped.z();
499 startBresenham[3] = 0;
502 endBresenham[0] = end.x();
503 endBresenham[1] = end.y();
504 endBresenham[2] = end.z();
506 endBresenham[3] = sqrt(2.)*l;
510 mBresenham.init(startBresenham, endBresenham);
518 if (mBresenham.hasNext())
524 mCurrentLine += mT->mLineStep;
532 mCurrentLine = mT->mTgtArea.y0();
535 if (mCurrentLine >= mT->mTgtArea.y1())
538 mCurrentLine += mT->mLineStep;
Rect< int, 2 > Rect2i
A 2D rect with integer precision.
Definition: Rect.h:740
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
const Axis & axis(uint32 d) const
Returns axis structure for a specified dimension.
Definition: Bresenham.h:424
Point< double, 2 > Point2d
a 2D 64 bit floating precision point
Definition: Point.h:229
T truncate(T value, uint32 decimals)
Truncates a floating point value to a given number of decimals.
Definition: Truncate.h:69
Provides multidimensional rectangle templates.
This header provides a set of functions to iterate over lines with the Bresenham or Bresenham Run-Sli...
Typedefs for different Pose datatypes that are internally RigidTransforms.
Point< double, 3 > Point3d
a 3D 64 bit floating precision point
Definition: Point.h:305
Truncates a floating point value to a given number of decimals.