Skip to content

Commit

Permalink
Re #8569. Manually setting a shift in u coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Dec 12, 2013
1 parent 8857e24 commit b972f73
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 13 deletions.
Expand Up @@ -55,6 +55,9 @@ using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace MantidQt::API;

// Name of the QSettings group to store the InstrumentWindw settings
const char* InstrumentWindowSettingsGroup = "Mantid/InstrumentWindow";

/**
* Constructor.
*/
Expand Down Expand Up @@ -1344,3 +1347,20 @@ void InstrumentWindow::createTabs(QSettings& settings)
m_tabs << m_renderTab << pickTab << maskTab << treeTab;

}

/**
* Return a name for a group in QSettings to store InstrumentWindow configuration.
*/
QString InstrumentWindow::getSettingsGroupName() const
{
return QString::fromAscii( InstrumentWindowSettingsGroup );
}

/**
* Construct a name for a group in QSettings to store instrument-specific configuration.
*/
QString InstrumentWindow::getInstrumentSettingsGroupName() const
{
return QString::fromAscii( InstrumentWindowSettingsGroup ) + "/" +
QString::fromStdString( getInstrumentActor()->getInstrument()->getName() );
}
Expand Up @@ -91,14 +91,18 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs
void setViewType(const QString& type);
/// for saving the instrument window to mantid project
QString saveToString(const QString& geometry, bool saveAsTemplate= false);
InstrumentActor* getInstrumentActor(){return m_instrumentActor;}
InstrumentActor* getInstrumentActor() const {return m_instrumentActor;}
bool blocked()const{return m_blocked;}
void selectTab(int tab);
void selectTab(Tab tab){selectTab(int(tab));}
InstrumentWindowTab *getTab(const QString & title="") const;
InstrumentWindowTab *getTab(const Tab tab) const;
/// Get a filename for saving
QString getSaveFileName(const QString& title, const QString& filters, QString* selectedFilter = NULL);
/// Get a name for settings group
QString getSettingsGroupName() const;
/// Get a name for a instrument-specific settings group
QString getInstrumentSettingsGroupName() const;

signals:
void enableLighting(bool);
Expand Down
Expand Up @@ -2,6 +2,7 @@
#include "ProjectionSurface.h"
#include "UnwrappedSurface.h"
#include "Projection3D.h"
#include "RotationSurface.h"

#include <QMenu>
#include <QVBoxLayout>
Expand All @@ -18,6 +19,7 @@
#include <QSignalMapper>
#include <QMessageBox>
#include <QToolTip>
#include <QInputDialog>

#include <qwt_scale_widget.h>
#include <qwt_scale_engine.h>
Expand All @@ -27,6 +29,8 @@
#include "BinDialog.h"
#include "ColorMapWidget.h"

#include <limits>


InstrumentWindowRenderTab::InstrumentWindowRenderTab(InstrumentWindow* instrWindow):
InstrumentWindowTab(instrWindow)
Expand Down Expand Up @@ -128,6 +132,8 @@ InstrumentWindowTab(instrWindow)
m_wireframe->setCheckable(true);
m_wireframe->setChecked(false);
connect(m_wireframe, SIGNAL(toggled(bool)), m_instrWindow, SLOT(setWireframe(bool)));
m_UCorrection = new QAction("U Correction",this);
connect(m_UCorrection, SIGNAL(triggered()),this,SLOT(setUCorrection()));

// Create "Use OpenGL" action
m_GLView = new QAction("Use OpenGL",this);
Expand All @@ -147,6 +153,8 @@ InstrumentWindowTab(instrWindow)
displaySettingsMenu->addAction(m_wireframe);
displaySettingsMenu->addAction(m_lighting);
displaySettingsMenu->addAction(m_GLView);
displaySettingsMenu->addAction(m_UCorrection);

displaySettings->setMenu(displaySettingsMenu);
connect(displaySettingsMenu,SIGNAL(hovered(QAction*)),this,SLOT(showMenuToolTip(QAction*)));

Expand Down Expand Up @@ -251,20 +259,47 @@ void InstrumentWindowRenderTab::enable3DSurface(bool on)
}
}

/**
* Surface-specific adjustments.
*/
void InstrumentWindowRenderTab::initSurface()
{
setAxis(QString::fromStdString(m_instrWindow->getInstrumentActor()->getInstrument()->getDefaultAxis()));
auto surface = getSurface();

// 3D axes switch needs to be shown for the 3D surface
auto p3d = boost::dynamic_pointer_cast<Projection3D>(surface);
if ( p3d )
{
p3d->set3DAxesState(areAxesOn());
}

bool detectorsOnly = !m_instrWindow->getInstrumentActor()->areGuidesShown();
m_displayDetectorsOnly->blockSignals(true);
m_displayDetectorsOnly->setChecked(detectorsOnly);
m_displayDetectorsOnly->blockSignals(false);
setPrecisionMenuItemChecked(surface->getPeakLabelPrecision());

// enable u-correction for surfaces of rotation. correction applied in the last
// session is loaded and re-applied in the new session
auto rotSurface = boost::dynamic_pointer_cast<RotationSurface>(surface);
if ( rotSurface )
{
m_UCorrection->setEnabled(true);
QString groupName = m_instrWindow->getInstrumentSettingsGroupName();
QSettings settings;
settings.beginGroup( groupName );
bool isManualUCorrection = settings.value("ManualUCorrection",false).asBool();
if ( isManualUCorrection )
{
double ucorr = settings.value("UCorrection",0.0).asDouble();
rotSurface->setUCorrection( ucorr );
}
}
else
{
m_UCorrection->setEnabled(false);
}
}

/**
Expand Down Expand Up @@ -491,7 +526,7 @@ void InstrumentWindowRenderTab::setColorMapAutoscaling(bool on)
QMenu* InstrumentWindowRenderTab::createPeaksMenu()
{
QSettings settings;
settings.beginGroup("Mantid/InstrumentWindow");
settings.beginGroup( m_instrWindow->getSettingsGroupName() );
QMenu* menu = new QMenu(this);

// show/hide peak hkl labels
Expand Down Expand Up @@ -631,3 +666,46 @@ void InstrumentWindowRenderTab::showMenuToolTip(QAction *action)
QToolTip::showText(QCursor::pos(),action->toolTip(),this);
}

/**
* Set the offset in u-coordinate of a 2d (unwrapped) surface
* @param ucorr :: New value for the correction.
*/
void InstrumentWindowRenderTab::setUCorrection()
{
auto surface = getSurface();
auto rotSurface = boost::dynamic_pointer_cast<RotationSurface>(surface);
if ( rotSurface )
{
bool ok;
double oldUCorr = rotSurface->getUCorrection();
// ask the user to enter a number for the u-correction
double ucorr = QInputDialog::getDouble(this, "MantiPplot - Input",
"U Correction", oldUCorr, -std::numeric_limits<double>::max(),std::numeric_limits<double>::max(), 4, &ok);
// update the surface only if the correction changes
if (ok && ucorr != oldUCorr)
{
rotSurface->setUCorrection( ucorr ); // manually set the correction
rotSurface->requestRedraw(); // redraw the view
QSettings settings;
settings.beginGroup( m_instrWindow->getInstrumentSettingsGroupName() );
settings.setValue("ManualUCorrection",true);
settings.setValue("UCorrection",ucorr);
}
}
}

/**
* Get current value for the u-correction for a RotationSurface.
* Return 0 if it's not a RotationSurface.
*/
double InstrumentWindowRenderTab::getUCorrection() const
{
auto surface = getSurface();
auto rotSurface = boost::dynamic_pointer_cast<RotationSurface>(surface);
if ( rotSurface )
{
return rotSurface->getUCorrection();
}
return 0.0;
}

Expand Up @@ -16,6 +16,7 @@ class QCheckBox;
class QAction;
class QActionGroup;
class QMenu;
class QLineEdit;

/**
* Implements the Render tab in InstrumentWindow.
Expand Down Expand Up @@ -66,13 +67,15 @@ private slots:
void scaleTypeChanged(int);
void glOptionChanged(bool);
void showMenuToolTip(QAction*);
void setUCorrection();

private:
void showEvent (QShowEvent *);
QMenu* createPeaksMenu();
QFrame * setupAxisFrame();
void setPrecisionMenuItemChecked(int n);
void enable3DSurface( bool on );
double getUCorrection() const;

QPushButton *m_surfaceTypeButton;
QPushButton *mSaveImage;
Expand Down Expand Up @@ -100,6 +103,7 @@ private slots:
QAction *m_wireframe;
QAction *m_lighting;
QAction *m_GLView; ///< toggle between OpenGL and simple view
QAction *m_UCorrection;
QActionGroup *m_precisionActionGroup;
QList<QAction*> m_precisionActions;

Expand Down
Expand Up @@ -10,7 +10,8 @@ RotationSurface::RotationSurface(const InstrumentActor* rootActor,const Mantid::
UnwrappedSurface(rootActor),
m_pos(origin),
m_zaxis(axis),
m_u_correction(0)
m_u_correction(0),
m_manual_u_correction(false)
{
}

Expand All @@ -22,7 +23,10 @@ void RotationSurface::init()
// the actor calls this->callback for each detector
m_unwrappedDetectors.clear();
m_assemblies.clear();
m_u_correction = 0.0;
if ( !m_manual_u_correction )
{
m_u_correction = 0.0;
}

size_t ndet = m_instrActor->ndetectors();
m_unwrappedDetectors.resize(ndet);
Expand Down Expand Up @@ -67,10 +71,13 @@ void RotationSurface::init()
m_yaxis = m_zaxis.cross_prod(m_xaxis);
}

// give some valid values to u bounds in case some code checks
// on u to be within them
m_u_min = -DBL_MAX;
m_u_max = DBL_MAX;
if ( !m_manual_u_correction )
{
// give some valid values to u bounds in case some code checks
// on u to be within them
m_u_min = -DBL_MAX;
m_u_max = DBL_MAX;
}

// For each detector in the order of actors
// cppcheck-suppress syntaxError
Expand Down Expand Up @@ -130,7 +137,10 @@ void RotationSurface::init()
if (udet.v > m_v_max) m_v_max = udet.v;
}

findAndCorrectUGap();
if ( !m_manual_u_correction )
{
findAndCorrectUGap();
}

double dU = fabs(m_u_max - m_u_min);
double dV = fabs(m_v_max - m_v_min);
Expand All @@ -156,7 +166,8 @@ void RotationSurface::init()
m_u_max += du;
m_v_min -= dv;
m_v_max += dv;
m_viewRect = RectF( QPointF(m_u_min,m_v_min), QPointF(m_u_max,m_v_max) );

m_viewRect = RectF( QPointF(m_u_min,m_v_min), QPointF(m_u_max,m_v_max) );

}

Expand Down Expand Up @@ -249,12 +260,24 @@ double RotationSurface::applyUCorrection(double u)const
u += m_u_correction;
if (u < m_u_min)
{
u += period;
double periods = floor( (m_u_max - u) / period ) * period;
u += periods;
}
if (u > m_u_max)
{
u -= period;
double periods = floor( (u - m_u_min) / period ) * period;
u -= periods;
}
return u;
}

/**
* Set new value for the u-correction.
* Correct all uv corrdinates of detectors.
*/
void RotationSurface::setUCorrection(double ucorr)
{
m_u_correction = ucorr;
m_manual_u_correction = true;
this->updateDetectors();
}
Expand Up @@ -12,6 +12,10 @@ class RotationSurface: public UnwrappedSurface
public:
RotationSurface(const InstrumentActor* rootActor,const Mantid::Kernel::V3D& origin,const Mantid::Kernel::V3D& axis);
void init();
// Get the value of the u-correction - a shift in the u-coord added to automatically determined uv coordinates
double getUCorrection() const {return m_u_correction;}
// Set new value for the u-correction
void setUCorrection(double ucorr);

protected:

Expand All @@ -32,7 +36,7 @@ class RotationSurface: public UnwrappedSurface
Mantid::Kernel::V3D m_xaxis; ///< The x axis
Mantid::Kernel::V3D m_yaxis; ///< The y axis
double m_u_correction; ///< Correction to u calculated by project() after findAndCorrectUGap()

bool m_manual_u_correction; ///< Flag set to prevent automatic FindAndCorrectUGap()
};

#endif // ROTATIONSURFACE_H

0 comments on commit b972f73

Please sign in to comment.