From 62b93e356f5ec7d8291a2bc4860f1def979d3ff2 Mon Sep 17 00:00:00 2001 From: Roman Tolchenov Date: Fri, 3 Jan 2014 08:56:44 +0000 Subject: [PATCH] Re #8580. Added Out of plane angle units to instr view miniplot --- .../InstrumentWindowPickTab.cpp | 58 +++++++++++++------ .../InstrumentWindowPickTab.h | 6 +- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp index 064017a6a57d..4d12d1715e28 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp @@ -124,10 +124,16 @@ m_freezePlot(false) m_unitsMapper->setMapping(m_phiUnits,PHI); connect(m_phiUnits,SIGNAL(triggered()),m_unitsMapper,SLOT(map())); + m_outOfPlaneAngleUnits = new QAction("Out of plane angle",this); + m_outOfPlaneAngleUnits->setCheckable(true); + m_unitsMapper->setMapping(m_outOfPlaneAngleUnits,OUT_OF_PLANE_ANGLE); + connect(m_outOfPlaneAngleUnits,SIGNAL(triggered()),m_unitsMapper,SLOT(map())); + m_unitsGroup = new QActionGroup(this); m_unitsGroup->addAction(m_detidUnits); m_unitsGroup->addAction(m_lengthUnits); m_unitsGroup->addAction(m_phiUnits); // re #4169 disabled until fixed or removed + m_unitsGroup->addAction(m_outOfPlaneAngleUnits); connect(m_unitsMapper,SIGNAL(mapped(int)),this,SLOT(setTubeXUnits(int))); // Instrument display context menu actions @@ -351,6 +357,7 @@ void InstrumentWindowPickTab::updateSelectionInfo(int detid) case DETECTOR_ID: xUnits = "Detector ID"; break; case LENGTH: xUnits = "Length"; break; case PHI: xUnits = "Phi"; break; + case OUT_OF_PLANE_ANGLE: xUnits = "Out of plane angle"; break; default: xUnits = "Detector ID"; } } @@ -397,6 +404,7 @@ void InstrumentWindowPickTab::plotContextMenu() else { m_sumDetectors->setChecked(m_plotSum); + m_integrateTimeBins->setChecked(!m_plotSum); m_integrateTimeBins->setEnabled(true); } context.addSeparator(); @@ -445,6 +453,7 @@ void InstrumentWindowPickTab::plotContextMenu() case DETECTOR_ID: m_detidUnits->setChecked(true); break; case LENGTH: m_lengthUnits->setChecked(true); break; case PHI: m_phiUnits->setChecked(true); break; + case OUT_OF_PLANE_ANGLE: m_outOfPlaneAngleUnits->setChecked(true); break; default: m_detidUnits->setChecked(true); } } @@ -957,6 +966,7 @@ void InstrumentWindowPickTab::prepareDataForSumsPlot( * DETECTOR_ID * LENGTH * PHI + * OUT_OF_PLANE_ANGLE * The units can be set with setTubeXUnits(...) method. * @param detid :: A detector id. The miniplot will display data for a component containing the detector * with this id. @@ -990,6 +1000,8 @@ void InstrumentWindowPickTab::prepareDataForIntegralsPlot( size_t imin,imax; instrActor->getBinMinMaxIndex(wi,imin,imax); + Mantid::Kernel::V3D samplePos = instrActor->getInstrument()->getSample()->getPos(); + const int n = ass->nelements(); if (n == 0) { @@ -1000,6 +1012,8 @@ void InstrumentWindowPickTab::prepareDataForIntegralsPlot( std::map xymap,errmap; // get the first detector in the tube for lenth calculation Mantid::Geometry::IDetector_sptr idet0 = boost::dynamic_pointer_cast((*ass)[0]); + Mantid::Kernel::V3D normal = (*ass)[1]->getPos() - idet0->getPos(); + normal.normalize(); for(int i = 0; i < n; ++i) { Mantid::Geometry::IDetector_sptr idet = boost::dynamic_pointer_cast((*ass)[i]); @@ -1007,14 +1021,22 @@ void InstrumentWindowPickTab::prepareDataForIntegralsPlot( { try { const int id = idet->getID(); + // get the x-value for detector idet double xvalue = 0; switch(m_tubeXUnits) { case LENGTH: xvalue = idet->getDistance(*idet0); break; case PHI: xvalue = bOffsetPsi ? idet->getPhiOffset(M_PI) : idet->getPhi(); break; + case OUT_OF_PLANE_ANGLE: + { + Mantid::Kernel::V3D pos = idet->getPos(); + xvalue = getOutOfPlaneAngle(pos, samplePos, normal); + break; + } default: xvalue = static_cast(id); } size_t index = instrActor->getWorkspaceIndex(id); + // get the y-value for detector idet const Mantid::MantidVec& Y = ws->readY(index); double sum = std::accumulate(Y.begin() + imin,Y.begin() + imax,0); xymap[xvalue] = sum; @@ -1066,24 +1088,6 @@ void InstrumentWindowPickTab::prepareDataForIntegralsPlot( } } -/** - * Return value of TubeXUnits for its symbolic name. - * @param name :: Symbolic name of the units, caseless: Detector_ID, Length, Phi - */ -InstrumentWindowPickTab::TubeXUnits InstrumentWindowPickTab::getTubeXUnits(const QString& name) const -{ - QString caseless_name = name.toUpper(); - if (caseless_name == "LENGTH") - { - return LENGTH; - } - if (caseless_name == "PHI") - { - return PHI; - } - return DETECTOR_ID; -} - /** * Return symbolic name of a TubeXUnit. * @param unit :: One of TubeXUnits. @@ -1095,6 +1099,7 @@ QString InstrumentWindowPickTab::getTubeXUnitsName(InstrumentWindowPickTab::Tube { case LENGTH: return "Length"; case PHI: return "Phi"; + case OUT_OF_PLANE_ANGLE: return "Out of plane angle"; default: return "Detector_ID"; } return "Detector_ID"; @@ -1300,6 +1305,7 @@ void InstrumentWindowPickTab::initSurface() void InstrumentWindowPickTab::saveSettings(QSettings &settings) const { settings.setValue("TubeXUnits",getTubeXUnits()); + settings.setValue("PlotSum", m_plotSum); } /** @@ -1309,6 +1315,8 @@ void InstrumentWindowPickTab::loadSettings(const QSettings &settings) { int unitsNum = settings.value("TubeXUnits",0).toInt(); m_tubeXUnits = TubeXUnits( unitsNum ); + m_plotSum = settings.value("PlotSum",true).toBool(); + setPlotCaption(); } /** @@ -1420,3 +1428,17 @@ void InstrumentWindowPickTab::updatePlotMultipleDetectors() m_plot->replot(); } +/** + * Calculate the angle between a vector ( == pos - origin ) and a plane ( orthogonal to normal ). + * The angle is positive if the vector and the normal make an acute angle. + * @param pos :: Vector's end. + * @param origin :: Vector's origin. + * @param normal :: Normal to the plane. + * @return :: Angle between the vector and the plane in radians in [-pi/2, pi/2]. + */ +double InstrumentWindowPickTab::getOutOfPlaneAngle(const Mantid::Kernel::V3D& pos, const Mantid::Kernel::V3D& origin, const Mantid::Kernel::V3D& normal) +{ + Mantid::Kernel::V3D vec = pos - origin; + vec.normalize(); + return asin(vec.scalar_prod(normal)); +} diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h index 14f78c7b215c..82676001f9de 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h @@ -44,7 +44,7 @@ class InstrumentWindowPickTab: public InstrumentWindowTab /// markers. Selected peaks can be deleted by pressing the Delete key. enum SelectionType {Single=0,AddPeak,ErasePeak,SingleDetectorSelection,Tube, Draw}; enum ToolType {Zoom,PixelSelect,TubeSelect,PeakSelect,PeakErase, DrawEllipse, DrawRectangle, EditShape}; - enum TubeXUnits {DETECTOR_ID = 0,LENGTH,PHI,NUMBER_OF_UNITS}; + enum TubeXUnits {DETECTOR_ID = 0,LENGTH,PHI,OUT_OF_PLANE_ANGLE,NUMBER_OF_UNITS}; InstrumentWindowPickTab(InstrumentWindow* instrWindow); void updatePick(int detid); @@ -98,10 +98,10 @@ private slots: std::vector&x, std::vector&y, std::vector* err = NULL); - TubeXUnits getTubeXUnits(const QString& name) const; QString getTubeXUnitsName(TubeXUnits unit) const; QString getNonDetectorInfo(); QColor getShapeBorderColor() const; + static double getOutOfPlaneAngle(const Mantid::Kernel::V3D& pos, const Mantid::Kernel::V3D& origin, const Mantid::Kernel::V3D& normal); /* Pick tab controls */ OneCurvePlot* m_plot; ///< Miniplot to display data in the detectors @@ -126,7 +126,7 @@ private slots: QAction *m_linearY; QActionGroup *m_yScale; QActionGroup* m_unitsGroup; - QAction *m_detidUnits,*m_lengthUnits,*m_phiUnits; + QAction *m_detidUnits,*m_lengthUnits,*m_phiUnits,*m_outOfPlaneAngleUnits; QSignalMapper *m_unitsMapper; // Instrument display context menu actions