Skip to content

Commit

Permalink
Re #4079. Added some protection against infinites and NaNs
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Nov 10, 2011
1 parent bd95540 commit 2be0df9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void GLObject::construct()const
this->define();
glEndList();
//if (dynamic_cast<ObjCompAssemblyActor*>(this))
std::cerr<<"construct " << getName() << ' ' << mDisplayListId << '\n';
if(glGetError()==GL_OUT_OF_MEMORY) //Throw an exception
throw Mantid::Kernel::Exception::OpenGLError("OpenGL: Out of video memory");
mChanged=false; //Object Marked as changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/AnalysisDataService.h"

#include <boost/math/special_functions/fpclassify.hpp>

#include <QSettings>
#include <QMessageBox>

Expand Down Expand Up @@ -191,6 +193,11 @@ void InstrumentActor::setIntegrationRange(const double& xmin,const double& xmax)
for (size_t i=0; i < m_specIntegrs.size(); i++)
{
double sum = m_specIntegrs[i];
if( boost::math::isinf(sum) || boost::math::isnan(sum) )
{
throw std::runtime_error("The workspace contains values that cannot be displayed (infinite or NaN).\n"
"Please run ReplaceSpecialValues algorithm for correction.");
}
//integrated_values[i] = sum;
if( sum < m_DataMinValue )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ using namespace MantidQt::API;
InstrumentWindow::InstrumentWindow(const QString& wsName, const QString& label, ApplicationWindow *app , const QString& name , Qt::WFlags f ):
MdiSubWindow(label, app, name, f), WorkspaceObserver(),
m_workspaceName(wsName),
m_instrumentActor(NULL),
mViewChanged(false), m_blocked(false)
{
m_surfaceType = FULL3D;
Expand Down Expand Up @@ -161,16 +162,6 @@ InstrumentWindow::InstrumentWindow(const QString& wsName, const QString& label,
connect(this,SIGNAL(needSetIntegrationRange(double,double)),this,SLOT(setIntegrationRange(double,double)));
setAcceptDrops(true);

// Previously in (now removed) setWorkspaceName method
m_InstrumentDisplay->makeCurrent();
m_instrumentActor = new InstrumentActor(m_workspaceName);
m_xIntegration->setTotalRange(m_instrumentActor->minBinValue(),m_instrumentActor->maxBinValue());
m_xIntegration->setUnits(QString::fromStdString(m_instrumentActor->getWorkspace()->getAxis(0)->unit()->caption()));
setSurfaceType(m_surfaceType); // This call must come after the InstrumentActor is created
setupColorMap();
mInstrumentTree->setInstrumentActor(m_instrumentActor);
setInfoText(m_InstrumentDisplay->getSurface()->getInfoText());

setWindowTitle(QString("Instrument - ") + m_workspaceName);
}

Expand All @@ -179,9 +170,29 @@ InstrumentWindow::InstrumentWindow(const QString& wsName, const QString& label,
*/
InstrumentWindow::~InstrumentWindow()
{
saveSettings();
if (m_instrumentActor)
{
saveSettings();
delete m_instrumentActor;
}
delete m_InstrumentDisplay;
delete m_instrumentActor;
}

/**
* Init the geometry and colour map outside constructor to prevent creating a broken MdiSubwindow.
* Must be called straight after constructor.
*/
void InstrumentWindow::init()
{
// Previously in (now removed) setWorkspaceName method
m_InstrumentDisplay->makeCurrent();
m_instrumentActor = new InstrumentActor(m_workspaceName);
m_xIntegration->setTotalRange(m_instrumentActor->minBinValue(),m_instrumentActor->maxBinValue());
m_xIntegration->setUnits(QString::fromStdString(m_instrumentActor->getWorkspace()->getAxis(0)->unit()->caption()));
setSurfaceType(m_surfaceType); // This call must come after the InstrumentActor is created
setupColorMap();
mInstrumentTree->setInstrumentActor(m_instrumentActor);
setInfoText(m_InstrumentDisplay->getSurface()->getInfoText());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs

explicit InstrumentWindow(const QString& wsName, const QString& label = QString(), ApplicationWindow *app = 0, const QString& name = QString(), Qt::WFlags f = 0);
~InstrumentWindow();
void init();
QString getWorkspaceName() const { return m_workspaceName; }
void updateWindow();

Expand Down
26 changes: 21 additions & 5 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,19 +1682,37 @@ void MantidUI::manageMantidWorkspaces()
*/
InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)
{

QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
if( !Mantid::API::AnalysisDataService::Instance().doesExist(wsName.toStdString()) ) return NULL;
Mantid::API::MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(getWorkspace(wsName));
if (!ws) return NULL;
Mantid::Geometry::Instrument_const_sptr instr = ws->getInstrument();
if (!instr || instr->getName().empty())
{
QApplication::restoreOverrideCursor();
QMessageBox::critical(appWindow(),"MantidPlot - Error","Instrument view cannot be opened");
return NULL;
}

//Need a new window
const QString windowName(QString("InstrumentWindow:") + wsName);
InstrumentWindow *insWin = new InstrumentWindow(wsName,QString("Instrument"),appWindow(),windowName);
try
{
insWin->init();
}
catch(const std::exception& e)
{
QApplication::restoreOverrideCursor();
QMessageBox::critical(appWindow(),"MantidPlot - Error",e.what());
if (insWin)
{
appWindow()->closeWindow(insWin);
insWin->close();
}
return NULL;
}

insWin->selectTab(tab);

appWindow()->d_workspace->addSubWindow(insWin);
Expand All @@ -1709,22 +1727,20 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)
SLOT(createDetectorTable(const QString&,const std::vector<int>&,bool)));
connect(insWin, SIGNAL(execMantidAlgorithm(const QString&,const QString&,Mantid::API::AlgorithmObserver*)), this,
SLOT(executeAlgorithm(const QString&, const QString&,Mantid::API::AlgorithmObserver*)));

QApplication::restoreOverrideCursor();
return insWin;
}


void MantidUI::showMantidInstrument(const QString& wsName)
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
InstrumentWindow *insWin = getInstrumentView(wsName);
if (!insWin)
{
QApplication::restoreOverrideCursor();
QMessageBox::critical(appWindow(),"MantidPlot - Error","Instrument view cannot be opened");
return;
}
insWin->show();
QApplication::restoreOverrideCursor();
}

void MantidUI::showMantidInstrument()
Expand Down

0 comments on commit 2be0df9

Please sign in to comment.