-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #4165: Parameter to resize RectangularDetectors.
Note to testers: Use the ResizeRectangularDetector algorithm to change the X/Y size of a bank. Try ray-tracing to it (e.g. peak finding or RayTracerTester). It should look scaled in the instrument view.
- Loading branch information
Janik Zikovsky
committed
Nov 22, 2011
1 parent
888f7ba
commit d6f4e19
Showing
18 changed files
with
577 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ResizeRectangularDetector.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef MANTID_ALGORITHMS_RESIZERECTANGULARDETECTOR_H_ | ||
#define MANTID_ALGORITHMS_RESIZERECTANGULARDETECTOR_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
/** ResizeRectangularDetector : TODO: DESCRIPTION | ||
@date 2011-11-22 | ||
Copyright © 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport ResizeRectangularDetector : public API::Algorithm | ||
{ | ||
public: | ||
ResizeRectangularDetector(); | ||
virtual ~ResizeRectangularDetector(); | ||
|
||
virtual const std::string name() const; | ||
virtual int version() const; | ||
virtual const std::string category() const; | ||
|
||
private: | ||
virtual void initDocs(); | ||
void init(); | ||
void exec(); | ||
|
||
|
||
}; | ||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_ALGORITHMS_RESIZERECTANGULARDETECTOR_H_ */ |
124 changes: 124 additions & 0 deletions
124
Code/Mantid/Framework/Algorithms/src/ResizeRectangularDetector.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/*WIKI* | ||
This algorithm will resize a [[RectangularDetector]] by applying X and Y scaling factors. | ||
Each pixel's position will be modifed relative to the 0,0 point of the detector by these factors. | ||
Typically, a RectangularDetector is constructed around its center, so this would scale the detector around its center. | ||
This only works on [[RectangularDetector]]s. Banks formed by e.g. tubes cannot be scaled in this way. | ||
Internally, this sets the "scalex" and "scaley" parameters on the [[RectangularDetector]]. | ||
Note that the scaling is relative to the original size, and is not cumulative: that is, | ||
if you Resize * 2 and again * 3, your final detector is 3 times larger than the original, not 6 times. | ||
Note: As of this writing, the algorithm does NOT modify the shape of individual pixels. This means | ||
that algorithms based on solid angle calculations might be off. | ||
Ray-tracing (e.g. peak finding) are unaffected. | ||
See also [[MoveInstrumentComponent]] and [[RotateInstrumentComponent]] for other ways to move components. | ||
*WIKI*/ | ||
|
||
#include "MantidAlgorithms/ResizeRectangularDetector.h" | ||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/WorkspaceProperty.h" | ||
#include "MantidAPI/MatrixWorkspace.h" | ||
#include "MantidGeometry/Instrument.h" | ||
#include "MantidGeometry/IComponent.h" | ||
#include "MantidGeometry/Instrument/RectangularDetector.h" | ||
|
||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Geometry; | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(ResizeRectangularDetector) | ||
|
||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
ResizeRectangularDetector::ResizeRectangularDetector() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
ResizeRectangularDetector::~ResizeRectangularDetector() | ||
{ | ||
} | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Algorithm's name for identification. @see Algorithm::name | ||
const std::string ResizeRectangularDetector::name() const { return "ResizeRectangularDetector";}; | ||
|
||
/// Algorithm's version for identification. @see Algorithm::version | ||
int ResizeRectangularDetector::version() const { return 1;}; | ||
|
||
/// Algorithm's category for identification. @see Algorithm::category | ||
const std::string ResizeRectangularDetector::category() const { return "DataHandling\\Instrument";} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Sets documentation strings for this algorithm | ||
void ResizeRectangularDetector::initDocs() | ||
{ | ||
this->setWikiSummary("Resize a RectangularDetector in X and/or Y."); | ||
this->setOptionalMessage("Resize a RectangularDetector in X and/or Y."); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void ResizeRectangularDetector::init() | ||
{ | ||
// When used as a sub-algorithm the workspace name is not used - hence the "Anonymous" to satisfy the validator | ||
declareProperty(new WorkspaceProperty<MatrixWorkspace>("Workspace","Anonymous",Direction::InOut)); | ||
declareProperty("ComponentName","", | ||
"The name of the RectangularDetector to resize."); | ||
declareProperty("ScaleX", 1.0, | ||
"The scaling factor in the X direction. Default 1.0"); | ||
declareProperty("ScaleY", 1.0, | ||
"The scaling factor in the Y direction. Default 1.0"); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void ResizeRectangularDetector::exec() | ||
{ | ||
MatrixWorkspace_sptr WS = getProperty("Workspace"); | ||
std::string ComponentName = getPropertyValue("ComponentName"); | ||
double ScaleX = getProperty("ScaleX"); | ||
double ScaleY = getProperty("ScaleY"); | ||
|
||
if (ComponentName.empty()) | ||
throw std::runtime_error("You must specify a ComponentName."); | ||
|
||
Instrument_const_sptr inst = WS->getInstrument(); | ||
IComponent_const_sptr comp; | ||
|
||
comp = inst->getComponentByName(ComponentName); | ||
if (!comp) | ||
throw std::runtime_error("Component with name " + ComponentName + " was not found."); | ||
|
||
RectangularDetector_const_sptr det = boost::dynamic_pointer_cast<const RectangularDetector>(comp); | ||
if (!det) | ||
throw std::runtime_error("Component with name " + ComponentName + " is not a RectangularDetector."); | ||
|
||
Geometry::ParameterMap& pmap = WS->instrumentParameters(); | ||
// Add a parameter for the new scale factors | ||
pmap.addDouble(det.get(), "scalex", ScaleX); | ||
pmap.addDouble(det.get(), "scaley", ScaleY); | ||
} | ||
|
||
|
||
|
||
} // namespace Mantid | ||
} // namespace Algorithms |
72 changes: 72 additions & 0 deletions
72
Code/Mantid/Framework/Algorithms/test/ResizeRectangularDetectorTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef MANTID_ALGORITHMS_RESIZERECTANGULARDETECTORTEST_H_ | ||
#define MANTID_ALGORITHMS_RESIZERECTANGULARDETECTORTEST_H_ | ||
|
||
#include "MantidAlgorithms/ResizeRectangularDetector.h" | ||
#include "MantidAPI/MatrixWorkspace.h" | ||
#include "MantidDataObjects/EventWorkspace.h" | ||
#include "MantidGeometry/Instrument.h" | ||
#include "MantidGeometry/Instrument/RectangularDetector.h" | ||
#include "MantidKernel/System.h" | ||
#include "MantidKernel/Timer.h" | ||
#include "MantidKernel/V3D.h" | ||
#include "MantidTestHelpers/WorkspaceCreationHelper.h" | ||
#include <cxxtest/TestSuite.h> | ||
#include <iomanip> | ||
#include <iostream> | ||
|
||
using namespace Mantid; | ||
using namespace Mantid::Kernel; | ||
using namespace Mantid::Geometry; | ||
using namespace Mantid::Algorithms; | ||
using namespace Mantid::API; | ||
|
||
class ResizeRectangularDetectorTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
void test_Init() | ||
{ | ||
ResizeRectangularDetector alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
} | ||
|
||
void test_exec() | ||
{ | ||
Mantid::DataObjects::EventWorkspace_sptr ews = WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(2, 10); | ||
|
||
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(ews); | ||
|
||
ResizeRectangularDetector alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("Workspace", ws) ); | ||
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("ComponentName", "bank1") ); | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("ScaleX", 2.0) ); | ||
TS_ASSERT_THROWS_NOTHING( alg.setProperty("ScaleY", 0.5) ); | ||
TS_ASSERT_THROWS_NOTHING( alg.execute(); ); | ||
TS_ASSERT( alg.isExecuted() ); | ||
|
||
Instrument_const_sptr inst = ws->getInstrument(); | ||
boost::shared_ptr<const RectangularDetector> det = boost::dynamic_pointer_cast<const RectangularDetector>(inst->getComponentByName("bank1")); | ||
|
||
// Bank 1 got scaled | ||
V3D pos; | ||
pos = det->getAtXY(1,1)->getPos(); | ||
TS_ASSERT( ws->instrumentParameters().contains(det.get(), "scalex") ); | ||
TS_ASSERT( ws->instrumentParameters().contains(det.get(), "scaley") ); | ||
TS_ASSERT_EQUALS( pos,V3D(0.008*2, 0.008*0.5, 5.0) ); | ||
TS_ASSERT_DELTA( det->xstep(), 0.008 * 2, 1e-6); | ||
|
||
// Bank 2 did not get scaled | ||
det = boost::dynamic_pointer_cast<const RectangularDetector>(inst->getComponentByName("bank2")); | ||
pos = det->getAtXY(1,1)->getPos(); | ||
TS_ASSERT_EQUALS( pos,V3D(0.008*1.0, 0.008*1.0, 10.0) ); | ||
TS_ASSERT_DELTA( det->xstep(), 0.008 * 1, 1e-6); | ||
|
||
} | ||
|
||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_ALGORITHMS_RESIZERECTANGULARDETECTORTEST_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.