47 #ifndef _MIRA_RASTERTRANSFORMATION_H_ 48 #define _MIRA_RASTERTRANSFORMATION_H_ 287 return (!srcArea.isValid() ||
288 !tgtArea.isValid() ||
289 (tgtArea.width() == 0) ||
290 (tgtArea.height() == 0) ||
299 lineStep = std::min(1., std::abs(config.
scale));
301 lineStep /= sqrt(2.);
312 rasterStep =
Point3d(cosRot * (dxEnd - dxStart) / config.
scale,
313 sinRot * (dxEnd - dxStart) / config.
scale,
316 double length = std::max(std::hypot(rasterStep.x(), rasterStep.y()),
317 std::abs(rasterStep.z()));
318 rasterStep /= length;
328 :
mConfig{
Rect2i(srcArea.x0(), srcArea.y0(), srcArea.width()-1, srcArea.height()-1),
329 Rect2i(tgtArea.x0(), tgtArea.y0(), tgtArea.width()-1, tgtArea.height()-1),
330 srcRef, tgtRef, scale, rotate, dense},
337 : mConfig(other.mConfig),
388 int left = area.x0();
389 int right = area.x1();
391 int bottom = area.y1();
393 double & x1 = p1.x();
394 double & y1 = p1.y();
395 double & z1 = p1.z();
396 double & x2 = p2.x();
397 double & y2 = p2.y();
398 double & z2 = p2.z();
400 int c1 = (x1 < left) + ((x1 > right) << 1) + ((y1 < top) << 2) + ((y1 > bottom) << 3);
401 int c2 = (x2 < left) + ((x2 > right) << 1) + ((y2 < top) << 2) + ((y2 > bottom) << 3);
403 if( ((c1 & c2) == 0) && ((c1 | c2) != 0 ))
410 a = c1 < 8 ? top : bottom;
411 x1 += (a - y1) * (x2 - x1) / (y2 - y1);
412 z1 += (a - y1) * (z2 - z1) / (y2 - y1);
414 c1 = (x1 < left) + (x1 > right) * 2;
419 a = c2 < 8 ? top : bottom;
420 x2 += (a - y2) * (x2 - x1) / (y2 - y1);
421 z2 += (a - y2) * (z2 - z1) / (y2 - y1);
423 c2 = (x2 < left) + (x2 > right) * 2;
425 if( ((c1 & c2) == 0) && ((c1 | c2) != 0) )
431 a = c1 == 1 ? left : right;
432 y1 += (a - x1) * (y2 - y1) / (x2 - x1);
433 z1 += (a - x1) * (z2 - z1) / (x2 - x1);
440 a = c2 == 1 ? left : right;
441 y2 += (a - x2) * (y2 - y1) / (x2 - x1);
442 z2 += (a - x2) * (z2 - z1) / (x2 - x1);
449 return (c1 | c2) == 0;
454 mTY = floor(mCurrentLine + 0.5 * mT->mImpl.lineStep);
456 if (mTY > mT->mConfig.tgtArea.y1())
457 return (mLineValid =
false);
459 double dy = mCurrentLine + 0.5f * mT->mImpl.lineStep - mT->mConfig.tgtRef.y();
461 Point3d start(mT->mConfig.srcRef.x()
462 + (mT->mImpl.cosRot * mT->mImpl.dxStart - mT->mImpl.sinRot * dy) / mT->mConfig.scale,
463 mT->mConfig.srcRef.y()
464 + (mT->mImpl.sinRot * mT->mImpl.dxStart + mT->mImpl.cosRot * dy) / mT->mConfig.scale,
465 mT->mConfig.tgtArea.x0());
467 Point3d end(mT->mConfig.srcRef.x()
468 + (mT->mImpl.cosRot * mT->mImpl.dxEnd - mT->mImpl.sinRot * dy) / mT->mConfig.scale,
469 mT->mConfig.srcRef.y()
470 + (mT->mImpl.sinRot * mT->mImpl.dxEnd + mT->mImpl.cosRot * dy) / mT->mConfig.scale,
471 mT->mConfig.tgtArea.x1());
476 mLineValid =
clipLine(mT->mConfig.srcArea, startClipped, end);
485 if (startClipped != start)
492 if (mT->mImpl.rasterStep.x() != 0)
493 steps = std::max(steps, std::ceil((startClipped.x() - start.x()) / mT->mImpl.rasterStep.x()));
495 if (mT->mImpl.rasterStep.y() != 0)
496 steps = std::max(steps, std::ceil((startClipped.y() - start.y()) / mT->mImpl.rasterStep.y()));
498 if (mT->mImpl.rasterStep.z() != 0)
499 steps = std::max(steps, std::ceil((startClipped.z() - start.z()) / mT->mImpl.rasterStep.z()));
501 startClipped = start + steps * mT->mImpl.rasterStep;
509 if (std::abs(startClipped.z() - std::round(startClipped.z())) < 0.25)
511 startClipped += mT->mImpl.rasterStep/2;
515 if (((startClipped.x() > start.x()) && (startClipped.x() > end.x())) ||
516 ((startClipped.x() < start.x()) && (startClipped.x() < end.x())) )
518 return (mLineValid =
false);
522 Point3d distance = end - startClipped;
523 double l = std::max(std::hypot(distance.x(), distance.y()), std::abs(distance.z()));
526 startBresenham[0] = startClipped.x();
527 startBresenham[1] = startClipped.y();
528 startBresenham[2] = startClipped.z();
529 startBresenham[3] = 0;
532 endBresenham[0] = end.x();
533 endBresenham[1] = end.y();
534 endBresenham[2] = end.z();
535 if (mT->mConfig.dense)
536 endBresenham[3] = sqrt(2.)*l;
540 mBresenham.init(startBresenham, endBresenham);
548 if (mBresenham.hasNext())
554 mCurrentLine += mT->mImpl.lineStep;
562 mCurrentLine = mT->mConfig.tgtArea.y0();
565 if (mCurrentLine >= mT->mConfig.tgtArea.y1())
568 mCurrentLine += mT->mImpl.lineStep;
Rect< int, 2 > Rect2i
A 2D rect with integer precision.
Definition: Rect.h:742
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:231
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:318
Truncates a floating point value to a given number of decimals.