47 #ifndef _MIRA_RASTERTRANSFORMATION_H_ 48 #define _MIRA_RASTERTRANSFORMATION_H_ 287 return ((tgtArea.width() == 0) ||
288 (tgtArea.height() == 0) ||
294 if ((config.
srcArea.width() < 1) || (config.
srcArea.height() < 1) ||
298 lineStep = std::min(1., std::abs(config.
scale));
300 lineStep /= sqrt(2.);
311 rasterStep =
Point3d(cosRot * (dxEnd - dxStart) / config.
scale,
312 sinRot * (dxEnd - dxStart) / config.
scale,
315 double length = std::max(std::hypot(rasterStep.x(), rasterStep.y()),
316 std::abs(rasterStep.z()));
317 rasterStep /= length;
327 :
mConfig{
Rect2i(srcArea.x0(), srcArea.y0(), srcArea.width()-1, srcArea.height()-1),
328 Rect2i(tgtArea.x0(), tgtArea.y0(), tgtArea.width()-1, tgtArea.height()-1),
329 srcRef, tgtRef, scale, rotate, dense},
336 : mConfig(other.mConfig),
359 : mT(NULL), mLineValid(false)
372 mBresenham(other.mBresenham),
373 mCurrentLine(other.mCurrentLine),
375 mLineValid(other.mLineValid)
399 int left = area.x0();
400 int right = area.x1();
402 int bottom = area.y1();
404 double & x1 = p1.x();
405 double & y1 = p1.y();
406 double & z1 = p1.z();
407 double & x2 = p2.x();
408 double & y2 = p2.y();
409 double & z2 = p2.z();
411 int c1 = (x1 < left) + ((x1 > right) << 1) + ((y1 < top) << 2) + ((y1 > bottom) << 3);
412 int c2 = (x2 < left) + ((x2 > right) << 1) + ((y2 < top) << 2) + ((y2 > bottom) << 3);
414 if( ((c1 & c2) == 0) && ((c1 | c2) != 0 ))
421 a = c1 < 8 ? top : bottom;
422 x1 += (a - y1) * (x2 - x1) / (y2 - y1);
423 z1 += (a - y1) * (z2 - z1) / (y2 - y1);
425 c1 = (x1 < left) + (x1 > right) * 2;
430 a = c2 < 8 ? top : bottom;
431 x2 += (a - y2) * (x2 - x1) / (y2 - y1);
432 z2 += (a - y2) * (z2 - z1) / (y2 - y1);
434 c2 = (x2 < left) + (x2 > right) * 2;
436 if( ((c1 & c2) == 0) && ((c1 | c2) != 0) )
442 a = c1 == 1 ? left : right;
443 y1 += (a - x1) * (y2 - y1) / (x2 - x1);
444 z1 += (a - x1) * (z2 - z1) / (x2 - x1);
451 a = c2 == 1 ? left : right;
452 y2 += (a - x2) * (y2 - y1) / (x2 - x1);
453 z2 += (a - x2) * (z2 - z1) / (x2 - x1);
460 return (c1 | c2) == 0;
465 mTY = floor(mCurrentLine + 0.5 * mT->mImpl.lineStep);
467 if (mTY > mT->mConfig.tgtArea.y1())
468 return (mLineValid =
false);
470 double dy = mCurrentLine + 0.5f * mT->mImpl.lineStep - mT->mConfig.tgtRef.y();
472 Point3d start(mT->mConfig.srcRef.x()
473 + (mT->mImpl.cosRot * mT->mImpl.dxStart - mT->mImpl.sinRot * dy) / mT->mConfig.scale,
474 mT->mConfig.srcRef.y()
475 + (mT->mImpl.sinRot * mT->mImpl.dxStart + mT->mImpl.cosRot * dy) / mT->mConfig.scale,
476 mT->mConfig.tgtArea.x0());
478 Point3d end(mT->mConfig.srcRef.x()
479 + (mT->mImpl.cosRot * mT->mImpl.dxEnd - mT->mImpl.sinRot * dy) / mT->mConfig.scale,
480 mT->mConfig.srcRef.y()
481 + (mT->mImpl.sinRot * mT->mImpl.dxEnd + mT->mImpl.cosRot * dy) / mT->mConfig.scale,
482 mT->mConfig.tgtArea.x1());
487 mLineValid =
clipLine(mT->mConfig.srcArea, startClipped, end);
496 if (startClipped != start)
503 if (mT->mImpl.rasterStep.x() != 0)
504 steps = std::max(steps, std::ceil((startClipped.x() - start.x()) / mT->mImpl.rasterStep.x()));
506 if (mT->mImpl.rasterStep.y() != 0)
507 steps = std::max(steps, std::ceil((startClipped.y() - start.y()) / mT->mImpl.rasterStep.y()));
509 if (mT->mImpl.rasterStep.z() != 0)
510 steps = std::max(steps, std::ceil((startClipped.z() - start.z()) / mT->mImpl.rasterStep.z()));
512 startClipped = start + steps * mT->mImpl.rasterStep;
520 if (std::abs(startClipped.z() - std::round(startClipped.z())) < 0.25)
522 startClipped += mT->mImpl.rasterStep/2;
526 if (((startClipped.x() > start.x()) && (startClipped.x() > end.x())) ||
527 ((startClipped.x() < start.x()) && (startClipped.x() < end.x())) )
529 return (mLineValid =
false);
533 Point3d distance = end - startClipped;
534 double l = std::max(std::hypot(distance.x(), distance.y()), std::abs(distance.z()));
537 startBresenham[0] = startClipped.x();
538 startBresenham[1] = startClipped.y();
539 startBresenham[2] = startClipped.z();
540 startBresenham[3] = 0;
543 endBresenham[0] = end.x();
544 endBresenham[1] = end.y();
545 endBresenham[2] = end.z();
546 if (mT->mConfig.dense)
547 endBresenham[3] = sqrt(2.)*l;
551 mBresenham.init(startBresenham, endBresenham);
559 if (mBresenham.hasNext())
565 mCurrentLine += mT->mImpl.lineStep;
573 mCurrentLine = mT->mConfig.tgtArea.y0();
576 if (mCurrentLine >= mT->mConfig.tgtArea.y1())
579 mCurrentLine += mT->mImpl.lineStep;
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.