Skip to content

Commit

Permalink
Re #6159. Added a helper mask workspace to InstrumentActor
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Nov 21, 2012
1 parent 4ef82fa commit 82800bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "MantidGeometry/ICompAssembly.h"
#include "MantidGeometry/IObjComponent.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/IMaskWorkspace.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FrameworkManager.h"

#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/algorithm/string.hpp>
Expand Down Expand Up @@ -296,6 +298,10 @@ double InstrumentActor::getIntegratedCounts(Mantid::detid_t id)const
}
}

/**
* Recalculate the detector colors based on the integrated values in m_specIntegrs and
* the masking information in ....
*/
void InstrumentActor::resetColors()
{
QwtDoubleInterval qwtInterval(m_DataMinScaleValue,m_DataMaxScaleValue);
Expand Down Expand Up @@ -505,6 +511,31 @@ void InstrumentActor::setAutoscaling(bool on)
}
}

/**
* Initialize the helper mask workspace with the mask from the data workspace.
*/
void InstrumentActor::initMaskHelper()
{
if ( m_maskWorkspace ) return;
// extract the mask (if any) from the data to the mask workspace
const std::string maskName = "__InstrumentActor_MaskWorkspace";
Mantid::API::IAlgorithm * alg = Mantid::API::FrameworkManager::Instance().createAlgorithm("ExtractMask",-1);
alg->setPropertyValue( "InputWorkspace", getWorkspace()->name() );
alg->setPropertyValue( "OutputWorkspace", maskName );
alg->execute();

try
{
m_maskWorkspace = boost::dynamic_pointer_cast<Mantid::API::IMaskWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve(maskName));
Mantid::API::AnalysisDataService::Instance().remove( maskName );
}
catch( ... )
{
// don't know what to do here yet ...
QMessageBox::warning(NULL,"MantidPlot - Warning","An error accured when extracting the mask.","OK");
}
}

/**
* Find a rotation from one orthonormal basis set (Xfrom,Yfrom,Zfrom) to
* another orthonormal basis set (Xto,Yto,Zto). Both sets must be right-handed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Mantid
namespace API
{
class MatrixWorkspace;
class IMaskWorkspace;
}
namespace Geometry
{
Expand Down Expand Up @@ -71,8 +72,10 @@ class InstrumentActor: public QObject, public GLActor
InstrumentActor(const QString &wsName, bool autoscaling = true, double scaleMin = 0.0, double scaleMax = 0.0);
~InstrumentActor(); ///< Destructor
virtual std::string type()const {return "InstrumentActor";} ///< Type of the GL object
/// Draw the instrument in 3D
void draw(bool picking = false)const;
void getBoundingBox(Mantid::Kernel::V3D& minBound,Mantid::Kernel::V3D& maxBound)const{m_scene.getBoundingBox(minBound,maxBound);}
/// Run visitors callback on each component
bool accept(const GLActorVisitor& visitor);

boost::shared_ptr<const Mantid::Geometry::Instrument> getInstrument() const;
Expand Down Expand Up @@ -117,6 +120,10 @@ class InstrumentActor: public QObject, public GLActor
Mantid::Kernel::Quat& R,
bool out = false
);

/* Masking */

void initMaskHelper();
signals:
void colorMapChanged();
protected:
Expand All @@ -127,7 +134,11 @@ class InstrumentActor: public QObject, public GLActor

size_t push_back_detid(Mantid::detid_t)const;

/// The workspace whose data are shown
const boost::weak_ptr<const Mantid::API::MatrixWorkspace> m_workspace;
/// The helper masking workspace keeping the mask build in the mask tab but not applied to the data workspace.
boost::shared_ptr<Mantid::API::IMaskWorkspace> m_maskWorkspace;
/// The colormap
MantidColorMap m_colorMap;
/// integrated spectra
std::vector<double> m_specIntegrs;
Expand All @@ -136,10 +147,10 @@ class InstrumentActor: public QObject, public GLActor
double m_WkspBinMin, m_WkspBinMax; ///< min and max over whole workspace
/// The user requested data and bin ranges
double m_DataMinValue, m_DataMaxValue; ///< min and max for current bin (x integration) range
double m_DataMinScaleValue, m_DataMaxScaleValue; ///< min and max of the color map scale
double m_DataMinScaleValue, m_DataMaxScaleValue; /// min and max of the color map scale
double m_BinMinValue, m_BinMaxValue;
/// Flag to rescale the colormap axis automatically when the data or integration range change
bool m_autoscaling;
//boost::shared_ptr<const std::vector<boost::shared_ptr<const Mantid::Geometry::IObjComponent> > > m_plottables;

/// Vector where INDEX = (detector id + m_id2wi_offset); VALUE = workspace index.
std::vector<size_t> m_id2wi_vector;
Expand All @@ -156,8 +167,10 @@ class InstrumentActor: public QObject, public GLActor
/// Colors in order of workspace indexes
mutable std::vector<GLColor> m_colors;
QString m_currentColorMap;
GLColor m_maskedColor; ///< Colour of a masked detector
GLColor m_failedColor; ///< Colour of a "failed" detector
/// Colour of a masked detector
GLColor m_maskedColor;
/// Colour of a "failed" detector
GLColor m_failedColor;

GLActorCollection m_scene;
SampleActor* m_sampleActor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void InstrumentWindowMaskTab::init()
connect(m_instrumentDisplay->getSurface(),SIGNAL(shapeSelected()),this,SLOT(shapeSelected()));
connect(m_instrumentDisplay->getSurface(),SIGNAL(shapesDeselected()),this,SLOT(shapesDeselected()));
connect(m_instrumentDisplay->getSurface(),SIGNAL(shapeChanged()),this,SLOT(shapeChanged()));
m_instrumentWindow->getInstrumentActor()->initMaskHelper();
}

void InstrumentWindowMaskTab::setActivity()
Expand Down

0 comments on commit 82800bd

Please sign in to comment.