Skip to content

Commit

Permalink
Move result ConvexPolygon outside of the loop
Browse files Browse the repository at this point in the history
Refs #12584
  • Loading branch information
martyngigg committed Jun 25, 2015
1 parent cb5c273 commit aa38947
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Code/Mantid/Framework/Algorithms/src/Rebin2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ void Rebin2D::rebinToOutput(const Geometry::Quadrilateral &inputQ,
en_start, en_end))
return;

// It seems to be more efficient to construct this once and clear it before each calculation
// in the loop
ConvexPolygon intersectOverlap;
for (size_t qi = qstart; qi < qend; ++qi) {
const double vlo = verticalAxis[qi];
const double vhi = verticalAxis[qi + 1];
Expand All @@ -193,13 +196,13 @@ void Rebin2D::rebinToOutput(const Geometry::Quadrilateral &inputQ,
if (boost::math::isnan(yValue)) {
continue;
}
ConvexPolygon overlap;
if(intersection(outputQ, inputQ, overlap)) {
const double weight = overlap.area() / inputQ.area();
intersectOverlap.clear();
if(intersection(outputQ, inputQ, intersectOverlap)) {
const double weight = intersectOverlap.area() / inputQ.area();
yValue *= weight;
double eValue = inputWS->readE(i)[j] * weight;
if (inputWS->isDistribution()) {
const double overlapWidth = overlap.maxX() - overlap.minX();
const double overlapWidth = intersectOverlap.maxX() - intersectOverlap.minX();
yValue *= overlapWidth;
eValue *= overlapWidth;
}
Expand Down Expand Up @@ -238,6 +241,9 @@ void Rebin2D::rebinToFractionalOutput(const Geometry::Quadrilateral &inputQ,
// Don't do the overlap removal if already RebinnedOutput.
// This wreaks havoc on the data.
const bool removeOverlap(inputWS->isDistribution() && inputWS->id() != "RebinnedOutput");
// It seems to be more efficient to construct this once and clear it before each calculation
// in the loop
ConvexPolygon intersectOverlap;
for (size_t qi = qstart; qi < qend; ++qi) {
const double vlo = verticalAxis[qi];
const double vhi = verticalAxis[qi + 1];
Expand All @@ -252,13 +258,13 @@ void Rebin2D::rebinToFractionalOutput(const Geometry::Quadrilateral &inputQ,
if (boost::math::isnan(yValue)) {
continue;
}
ConvexPolygon overlap;
if(intersection(outputQ, inputQ, overlap)) {
const double weight = overlap.area() / inputQ.area();
intersectOverlap.clear();
if(intersection(outputQ, inputQ, intersectOverlap)) {
const double weight = intersectOverlap.area() / inputQ.area();
yValue *= weight;
double eValue = inputWS->readE(i)[j] * weight;
if (removeOverlap) {
const double overlapWidth = overlap.maxX() - overlap.minX();
const double overlapWidth = intersectOverlap.maxX() - intersectOverlap.minX();
yValue *= overlapWidth;
eValue *= overlapWidth;
}
Expand Down

0 comments on commit aa38947

Please sign in to comment.