Skip to content

Commit

Permalink
Adding classes so ImageViewer works for MatrixWorkspaces
Browse files Browse the repository at this point in the history
Added MatrixWSDataSource and MatrixWSImageView classes,
so ImageViewer can be applied to MatrixWorkspaces.
A common base class for Matrix and Event workspace data
sources should be created, or generateHistogram() should
be added to IEventWorkspace.
refs #5058
  • Loading branch information
DennisMikkelson committed May 8, 2012
1 parent 7a7db90 commit 4e295d4
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,12 @@ void MantidDockWidget::addMatrixWorkspaceMenuItems(QMenu *menu, Mantid::API::Mat
// Don't plot a spectrum if only one X value
m_plotSpec->setEnabled ( matrixWS->blocksize() > 1 );
m_plotSpecErr->setEnabled ( matrixWS->blocksize() > 1 );
/*
if( boost::dynamic_pointer_cast<const IEventWorkspace>(matrixWS) )
{
*/
menu->addAction(m_showImageViewer); // The 2D image viewer
}
// }
menu->addAction(m_colorFill);
// Show the color fill plot if you have more than one histogram
m_colorFill->setEnabled( ( matrixWS->axes() > 1 && matrixWS->getNumberHistograms() > 1) );
Expand Down
16 changes: 14 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "MantidAPI/MemoryManager.h"

#include "MantidQtImageViewer/EventWSImageView.h"
#include "MantidQtImageViewer/MatrixWSImageView.h"

using namespace std;

Expand Down Expand Up @@ -677,8 +678,19 @@ void MantidUI::showImageViewer()
}
else
{
m_appWindow->writeToLogWindow("Only event workspaces are currently supported.");
m_appWindow->writeToLogWindow("Please convert to event workspace before using the ImageView.");
MatrixWorkspace_sptr matwsp = boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve( wsName.toStdString()) );
if ( matwsp )
{
MantidQt::ImageView::MatrixWSImageView image_view( matwsp );
}
else
{
m_appWindow->writeToLogWindow(
"Only event or matrix workspaces are currently supported.");
m_appWindow->writeToLogWindow(
"Please convert to one of these before using the ImageView.");
}
}
}
catch (std::runtime_error &e)
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/MantidQt/ImageViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set ( SRC_FILES
src/TestDataSource.cpp
src/EventWSDataSource.cpp
src/EventWSImageView.cpp
src/MatrixWSDataSource.cpp
src/MatrixWSImageView.cpp
)

# Include files aren't required, but this makes them appear in Visual Studio
Expand All @@ -36,6 +38,8 @@ set ( INC_FILES
inc/MantidQtImageViewer/TestDataSource.h
inc/MantidQtImageViewer/EventWSDataSource.h
inc/MantidQtImageViewer/EventWSImageView.h
inc/MantidQtImageViewer/MatrixWSDataSource.h
inc/MantidQtImageViewer/MatrixWSImageView.h
)

set ( MOC_FILES
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#ifndef MATRIX_WS_DATA_SOURCE_H
#define MATRIX_WS_DATA_SOURCE_H

#include <cstddef>

#include "MantidQtImageViewer/DataArray.h"
#include "MantidQtImageViewer/ImageDataSource.h"
#include "MantidQtImageViewer/DllOptionIV.h"

#include "MantidAPI/MatrixWorkspace.h"

/**
@class MatrixWSDataSource
This class provides a concrete implementation of an ImageDataSource
that gets it's data from a matrix workspace.
@author Dennis Mikkelson
@date 2012-05-08
Copyright © 2012 ORNL, STFC Rutherford Appleton Laboratories
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Code Documentation is available at
<http://doxygen.mantidproject.org>
*/

namespace MantidQt
{
namespace ImageView
{

class EXPORT_OPT_MANTIDQT_IMAGEVIEWER MatrixWSDataSource: public ImageDataSource
{
public:

/// Construct a DataSource object around the specifed MatrixWorkspace
MatrixWSDataSource( Mantid::API::MatrixWorkspace_sptr mat_ws );

~MatrixWSDataSource();

/// OVERRIDES: Get the smallest 'x' value covered by the data
virtual double GetXMin();

/// OVERRIDES: Get the largest 'x' value covered by the data
virtual double GetXMax();

/// OVERRIDES: Get the largest 'y' value covered by the data
virtual double GetYMax();

/// OVERRIDES: Get the total number of rows of data
virtual size_t GetNRows();

/// Get DataArray covering full range of data in x, and y directions
DataArray * GetDataArray( bool is_log_x );

/// Get DataArray covering restricted range of data
DataArray * GetDataArray( double xmin,
double xmax,
double ymin,
double ymax,
size_t n_rows,
size_t n_cols,
bool is_log_x );

/// Get a list containing pairs of strings with information about x,y
void GetInfoList( double x,
double y,
std::vector<std::string> &list );
private:
Mantid::API::MatrixWorkspace_sptr mat_ws;

};

} // namespace MantidQt
} // namespace ImageView

#endif // MATRIX_WS_DATA_SOURCE_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef MATRIX_WS_IMAGE_VIEW_H
#define MATRIX_WS_IMAGE_VIEW_H

#include "MantidQtImageViewer/DllOptionIV.h"

#include "MantidAPI/IEventWorkspace.h"

/**
@class MatrixWSDataSource
This is the top level class for showing a matrix workspace
using an ImageViewer.
@author Dennis Mikkelson
@date 2012-05-08
Copyright © 2012 ORNL, STFC Rutherford Appleton Laboratories
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Code Documentation is available at
<http://doxygen.mantidproject.org>
*/
#include "MantidQtImageViewer/ImageView.h"

namespace MantidQt
{
namespace ImageView
{

class EXPORT_OPT_MANTIDQT_IMAGEVIEWER MatrixWSImageView
{
public:

/// Construct an image viewer for the specifed MatrixWorkspace
MatrixWSImageView( Mantid::API::MatrixWorkspace_sptr mat_ws );

~MatrixWSImageView();

private:
ImageView *image_view;
};

} // namespace MantidQt
} // namespace ImageView

#endif // MATRIX_WS_IMAGE_VIEW_H
1 change: 1 addition & 0 deletions Code/Mantid/MantidQt/ImageViewer/src/EventWSImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ EventWSImageView::EventWSImageView( IEventWorkspace_sptr ev_ws )

EventWSImageView::~EventWSImageView()
{
// nothing to do here, since image_view is deleted when the window close
}

0 comments on commit 4e295d4

Please sign in to comment.