Skip to content

Commit

Permalink
Added display option to toggle visibility of non-detectors.
Browse files Browse the repository at this point in the history
Re #6137.
  • Loading branch information
mantid-roman committed Feb 28, 2013
1 parent e6cb2b4 commit ec6420a
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 87 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ set ( MANTID_SRCS src/Mantid/AbstractMantidLog.cpp
src/Mantid/InstrumentWidget/SampleActor.cpp
src/Mantid/InstrumentWidget/GLActorCollection.cpp
src/Mantid/InstrumentWidget/GLActor.cpp
src/Mantid/InstrumentWidget/GLActorVisitor.cpp
src/Mantid/InstrumentWidget/GLColor.cpp
src/Mantid/InstrumentWidget/GLObject.cpp
src/Mantid/InstrumentWidget/GLTrackball.cpp
Expand Down Expand Up @@ -420,6 +421,7 @@ set ( MANTID_HDRS src/Mantid/AbstractMantidLog.h
src/Mantid/InstrumentWidget/SampleActor.h
src/Mantid/InstrumentWidget/GLActorCollection.h
src/Mantid/InstrumentWidget/GLActor.h
src/Mantid/InstrumentWidget/GLActorVisitor.h
src/Mantid/InstrumentWidget/GLColor.h
src/Mantid/InstrumentWidget/GLObject.h
src/Mantid/InstrumentWidget/GLTrackball.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ObjCompAssemblyActor.h"
#include "RectangularDetectorActor.h"
#include "OpenGLError.h"
#include "GLActorVisitor.h"

#include "MantidGeometry/Instrument.h"
#include "MantidKernel/V3D.h"
Expand Down Expand Up @@ -151,9 +152,9 @@ void CompAssemblyActor::draw(bool picking)const
OpenGLError::check("CompAssemblyActor::draw()");
}

bool CompAssemblyActor::accept(const GLActorVisitor& visitor)
bool CompAssemblyActor::accept(GLActorVisitor& visitor)
{
const SetVisibilityVisitor* svv = dynamic_cast<const SetVisibilityVisitor*>(&visitor);
SetVisibilityVisitor* svv = dynamic_cast<SetVisibilityVisitor*>(&visitor);
// accepting a set visibility visitor.
if (svv)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CompAssemblyActor : public ICompAssemblyActor
virtual std::string type()const {return "CompAssemblyActor";} ///< Type of the GL object
virtual void draw(bool picking = false)const; ///< Method that defines ObjComponent geometry. Calls ObjComponent draw method
void setVisibility(bool);
bool accept(const GLActorVisitor& visitor);
bool accept(GLActorVisitor& visitor);
virtual void setColors();

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "MantidGeometry/IDetector.h"
#include "MantidGeometry/IObjComponent.h"
#include "MantidGeometry/Instrument/ObjCompAssembly.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"

using namespace Mantid;
using namespace Geometry;
Expand Down Expand Up @@ -36,3 +37,16 @@ boost::shared_ptr<const Mantid::Geometry::ObjCompAssembly> ComponentActor::getOb
return boost::dynamic_pointer_cast<const Mantid::Geometry::ObjCompAssembly>(getComponent());
}

/**
* An component is a non-detector if it's an ObjComponent (has a shape) and not an ObjCompAssembly
* (a single object) and not a RectangularDetector (which is an assembly).
*/
bool ComponentActor::isNonDetector() const
{
auto obj = getObjComponent();
return obj &&
!getObjCompAssembly() &&
!getDetector() &&
!boost::dynamic_pointer_cast<const Mantid::Geometry::RectangularDetector>(obj);
}

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class ComponentActor : public GLActor
boost::shared_ptr<const Mantid::Geometry::IDetector> getDetector() const;
boost::shared_ptr<const Mantid::Geometry::ObjCompAssembly> getObjCompAssembly() const;
virtual void setColors(){}
/// Check if the component is a non-detector.
bool isNonDetector() const;
protected:
const InstrumentActor& m_instrActor;
Mantid::Geometry::ComponentID m_id; ///< Component ID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "GLActor.h"

#include "GLActorVisitor.h"

GLActor::~GLActor()
{
}

bool GLActor::accept(const GLActorVisitor& visitor)
bool GLActor::accept(GLActorVisitor& visitor)
{
return visitor.visit(this);
}
Expand Down Expand Up @@ -34,11 +34,10 @@ size_t GLActor::decodePickColor(unsigned char r,unsigned char g,unsigned char b)
index += g;
index *= 256;
index += b - 1;
//std::cerr << "decode " << int(r)<<' '<<int(g)<<' '<<int(b)<<' '<<index<<std::endl;
return index;
}

GLColor GLActor::defaultDetectorColor()
{
return GLColor(255,100,0);
return GLColor(200,200,200);
}
41 changes: 12 additions & 29 deletions Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/GLActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
#include <ostream>

#include <QList>
//#include <QObject>

class UnwrappedCylinder;
class UnwrappedDetectorCyl;
class GLActorVisitor;

namespace Mantid
Expand Down Expand Up @@ -67,42 +64,28 @@ class GLActor
{
public:
GLActor():m_visible(true){}
virtual ~GLActor(); ///< Virtual destructor
///< Virtual destructor
virtual ~GLActor();
/// Toggle the visibility of the actor.
virtual void setVisibility(bool on){m_visible = on;}
/// Get the visibility status.
bool isVisible()const{return m_visible;}
/// Draw the actor in 3D.
virtual void draw(bool picking = false)const = 0;
/// Get the 3D bounding box of the actor
virtual void getBoundingBox(Mantid::Kernel::V3D& minBound,Mantid::Kernel::V3D& maxBound)const = 0;
virtual bool accept(const GLActorVisitor& visitor);
/// Accept a visitor
virtual bool accept(GLActorVisitor& visitor);
/// Convert a "pick ID" to a colour to put into the pick image.
static GLColor makePickColor(size_t pickID);
/// Decode a pick colour and return corresponding "pick ID"
static size_t decodePickColor(const GLColor& c);
/// Decode a pick colour and return corresponding "pick ID"
static size_t decodePickColor(unsigned char r,unsigned char g,unsigned char b);
/// Get colour of a component which doesn't have any counts associated with it.
static GLColor defaultDetectorColor();
protected:
bool m_visible; ///< Flag whether the actor is visible or not
};

class GLActorVisitor
{
public:
virtual ~GLActorVisitor(){}
virtual bool visit(GLActor*)const = 0;
};

/*
* The accept() method must return true if an actor is set visible and false otherwise
*/
class SetVisibilityVisitor: public GLActorVisitor
{
};

class SetAllVisibleVisitor: public SetVisibilityVisitor
{
public:
bool visit(GLActor* actor)const
{
actor->setVisibility(true);
return true;
}
};

#endif /*GLACTOR_H_*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "GLActorCollection.h"
#include "GLActorVisitor.h"
#include "OpenGLError.h"

#include "MantidKernel/Exception.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ void GLActorCollection::drawGL(bool picking )const
}
}

bool GLActorCollection::accept(const GLActorVisitor& visitor)
bool GLActorCollection::accept(GLActorVisitor& visitor)
{
const SetVisibilityVisitor* svv = dynamic_cast<const SetVisibilityVisitor*>(&visitor);
// accepting a set visibility visitor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GLActorCollection: public GLActor
void setVisibility(bool);
void draw(bool picking = false)const;
void getBoundingBox(Mantid::Kernel::V3D& minBound,Mantid::Kernel::V3D& maxBound)const;
bool accept(const GLActorVisitor& visitor);
bool accept(GLActorVisitor& visitor);

void addActor(GLActor*);
void removeActor(GLActor*);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "GLActorVisitor.h"

bool SetAllVisibleVisitor::visit(GLActor* actor)
{
actor->setVisibility(true);
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef GLACTORVISITOR_H
#define GLACTORVISITOR_H

#include "GLActor.h"

/**
* A base class for an actor visitor.
*/
class GLActorVisitor
{
public:
/// Virtual destructor.
virtual ~GLActorVisitor(){}
/// Abstract method that must be implemented in sub-classes
virtual bool visit(GLActor*) = 0;
};

/*
* The visit() method implemented by sub-classes must return true if an actor
* is set visible and false otherwise. This is requered by GLActorCollection::accept()
* method to determine whether the collection itself is visible or not.
*
* All visitors changing visibility should be sub-classed from this base class.
*/
class SetVisibilityVisitor: public GLActorVisitor
{
};

/**
* Set all actors visible.
*/
class SetAllVisibleVisitor: public SetVisibilityVisitor
{
public:
bool visit(GLActor*);
};

#endif // GLACTORVISITOR_H
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "CompAssemblyActor.h"
#include "ObjComponentActor.h"
#include "SampleActor.h"
#include "GLActorVisitor.h"

#include "MantidKernel/Exception.h"
#include "MantidKernel/V3D.h"
Expand Down Expand Up @@ -124,6 +125,11 @@ m_sampleActor(NULL)

m_sampleActor = new SampleActor(*this,shared_workspace->sample(),samplePosActor);
m_scene.addActor(m_sampleActor);
if ( !m_showGuides )
{
// hide guide and other components
showGuides( m_showGuides );
}
}

/**
Expand All @@ -141,10 +147,10 @@ InstrumentActor::~InstrumentActor()
* @param visitor
* @return
*/
bool InstrumentActor::accept(const GLActorVisitor& visitor)
bool InstrumentActor::accept(GLActorVisitor& visitor)
{
bool ok = m_scene.accept(visitor);
const SetVisibilityVisitor* vv = dynamic_cast<const SetVisibilityVisitor*>(&visitor);
SetVisibilityVisitor* vv = dynamic_cast<SetVisibilityVisitor*>(&visitor);
if (vv && m_sampleActor)
{
m_sampleActor->setVisibility(m_sampleActor->getSamplePosActor()->isVisible());
Expand Down Expand Up @@ -213,6 +219,8 @@ void InstrumentActor::applyMaskWorkspace()
alg->setPropertyValue( "Workspace", getWorkspace()->name() );
alg->setProperty( "MaskedWorkspace", m_maskWorkspace );
alg->execute();
// After the algorithm finishes the InstrumentWindow catches the after-replace notification
// and updates this instrument actor.
}

/**
Expand Down Expand Up @@ -292,6 +300,13 @@ size_t InstrumentActor::getWorkspaceIndex(Mantid::detid_t id) const
return (*m_detid2index_map)[id];
}

/**
* Set an interval in the data workspace x-vector's units in which the data are to be
* integrated to calculate the detector colours.
*
* @param xmin :: The lower bound.
* @param xmax :: The upper bound.
*/
void InstrumentActor::setIntegrationRange(const double& xmin,const double& xmax)
{
if (!getWorkspace()) return;
Expand Down Expand Up @@ -424,6 +439,15 @@ void InstrumentActor::update()
resetColors();
}

/**
* @param on :: True or false for on or off.
*/
void InstrumentActor::showGuides(bool on)
{
this->accept( SetVisibleNonDetectorVisitor( on ) );
m_showGuides = on;
}

GLColor InstrumentActor::getColor(Mantid::detid_t id)const
{
try {
Expand All @@ -440,6 +464,10 @@ void InstrumentActor::draw(bool picking)const
m_scene.draw(picking);
}

/**
* @param fname :: A color map file name.
* @param reset_colors :: An option to reset the detector colors.
*/
void InstrumentActor::loadColorMap(const QString& fname,bool reset_colors)
{
m_colorMap.loadMap(fname);
Expand Down Expand Up @@ -494,7 +522,9 @@ const Mantid::Kernel::V3D & InstrumentActor::getDetPos(size_t pickID)const
return m_detPos.at(pickID);
}


/**
* @param type :: 0 - linear, 1 - log10.
*/
void InstrumentActor::changeScaleType(int type)
{
m_colorMap.changeScaleType(static_cast<GraphOptions::ScaleType>(type));
Expand All @@ -513,8 +543,8 @@ void InstrumentActor::loadSettings()
{
loadColorMap(m_currentColorMap,false);
}

m_colorMap.changeScaleType(static_cast<GraphOptions::ScaleType>(scaleType));
m_showGuides = settings.value("ShowGuides", false).toBool();
settings.endGroup();
}

Expand All @@ -524,6 +554,7 @@ void InstrumentActor::saveSettings()
settings.beginGroup("Mantid/InstrumentWindow");
settings.setValue("ColormapFile", m_currentColorMap);
settings.setValue("ScaleType", (int)m_colorMap.getScaleType() );
settings.setValue("ShowGuides", m_showGuides);
settings.endGroup();
}

Expand Down Expand Up @@ -742,7 +773,7 @@ void InstrumentActor::BasisRotation(const Mantid::Kernel::V3D& Xfrom,
}
}

bool SetVisibleComponentVisitor::visit(GLActor* actor)const
bool SetVisibleComponentVisitor::visit(GLActor* actor)
{
ComponentActor* comp = dynamic_cast<ComponentActor*>(actor);
if (comp)
Expand All @@ -754,7 +785,23 @@ bool SetVisibleComponentVisitor::visit(GLActor* actor)const
return false;
}

bool FindComponentVisitor::visit(GLActor* actor)const
/**
* Visits an actor and if it is a "non-detector" sets its visibility.
*
* @param actor :: A visited actor.
* @return always false to traverse all the instrument tree.
*/
bool SetVisibleNonDetectorVisitor::visit(GLActor* actor)
{
ComponentActor* comp = dynamic_cast<ComponentActor*>(actor);
if ( comp && comp->isNonDetector() )
{
actor->setVisibility(m_on);
}
return false;
}

bool FindComponentVisitor::visit(GLActor* actor)
{
ComponentActor* comp = dynamic_cast<ComponentActor*>(actor);
if (comp)
Expand Down

0 comments on commit ec6420a

Please sign in to comment.