Skip to content

Commit

Permalink
Here they are. This refs #5801
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Oct 8, 2012
1 parent ca16da7 commit 1d8dca9
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef REF_ARRAY_DATA_SOURCE_H
#define REF_ARRAY_DATA_SOURCE_H

#include <cstddef>
#include "MantidQtRefDetectorViewer/DataArray.h"
#include "MantidQtRefDetectorViewer/RefImageDataSource.h"

#include <QMainWindow>
#include <QtGui>

/**
@class RefArrayDataSource
This class provides a wrapper around a simple 2-D array of doubles
stored in row-major order in a 1-D array, so that the array can be
viewed using the ImageView data viewer.
@author Dennis Mikkelson
@date 2012-05-14
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 RefDetectorViewer
{

class EXPORT_OPT_MANTIDQT_IMAGEVIEWER RefArrayDataSource: public RefImageDataSource
{
public:

/// Construct a DataSource object based on the specified array of floats
RefArrayDataSource( double total_xmin, double total_xmax,
double total_ymin, double total_ymax,
size_t total_rows, size_t total_cols,
float* data );

RefArrayDataSource(QString wps_name);

~RefArrayDataSource();

/// 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:
float* data;
};

} // namespace MantidQt
} // namespace ImageView

#endif // REF_ARRAY_DATA_SOURCE_H
170 changes: 170 additions & 0 deletions Code/Mantid/MantidQt/RefDetectorViewer/src/RefArrayDataSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include <iostream>

#include <math.h>

#include "MantidQtRefDetectorViewer/RefArrayDataSource.h"
#include "MantidQtRefDetectorViewer/IVUtils.h"

namespace MantidQt
{
namespace RefDetectorViewer
{

/**
* Construct a DataSource object to to display data from the specified
* array. This class takes ownership of the data and will delete it
* when this class is deleted. The calling code should not change the
* values in the array or delete it!
*
* @param total_xmin The x-coordinate at the left edge of the first column
* of data.
* @param total_xmax The x-coordinate at the right edge of the last column
* of data.
* @param total_ymin The y-coordinate at the bottom edge of bottom row of
* the data region.
* @param total_ymax The y-coordinate at the top edge of the top row of
* the data region
* @param total_rows The number of rows the data values are divided into.
* @param total_cols The number of columns the test values are divided
* into.
* @param data The list of floats holding the data to be displayed,
* stored in row major order.
*/
RefArrayDataSource::RefArrayDataSource( double total_xmin, double total_xmax,
double total_ymin, double total_ymax,
size_t total_rows, size_t total_cols,
float* data )
:RefImageDataSource( total_xmin, total_xmax,
total_ymin, total_ymax,
total_rows, total_cols )
{
this->data = data;
}


RefArrayDataSource::RefArrayDataSource(QString wps_name):RefImageDataSource(10,10,20,20,10,20)
{
std::cout << "Inside RefArrayDataSource" << std::endl;




std::cout << "Leaving RefArrayDataSource" << std::endl;
}


RefArrayDataSource::~RefArrayDataSource()
{
delete[] data;
}


/**
* Get a data array covering the specified range of data, at the specified
* resolution. NOTE: The calling code is responsible for deleting the
* DataArray that is returned, when it is no longer needed.
*
* @param xmin Left edge of region to be covered.
* @param xmax Right edge of region to be covered.
* @param ymin Bottom edge of region to be covered.
* @param ymax Top edge of region to be covered.
* @param n_rows Number of rows to return. If the number of rows is less
* than the actual number of data rows in [ymin,ymax], the
* data will be subsampled, and only the specified number
* of rows will be returned.
* @param n_cols The event data will be rebinned using the specified
* number of colums.
* @param is_log_x Flag indicating whether or not the data should be
* binned logarithmically in the X-direction. This
* DataSource does not support rebinning to a log axis, so
* the DataArray is always returned with is_log_x = false.
*/
DataArray * RefArrayDataSource::GetDataArray( double xmin, double xmax,
double ymin, double ymax,
size_t n_rows, size_t n_cols,
bool is_log_x )
{
size_t first_col;
IVUtils::CalculateInterval( total_xmin, total_xmax, total_cols,
first_col, xmin, xmax, n_cols );

size_t first_row;
IVUtils::CalculateInterval( total_ymin, total_ymax, total_rows,
first_row, ymin, ymax, n_rows );

float* new_data = new float[n_rows * n_cols]; // This is deleted in the
// DataArray destructor

double x_step = (xmax - xmin) / (double)n_cols;
double y_step = (ymax - ymin) / (double)n_rows;
double mid_y,
mid_x;
double d_x_index,
d_y_index;
size_t source_row,
source_col;
size_t index = 0; // get data for middle of
for ( size_t row = 0; row < n_rows; row++ ) // each destination position
{
mid_y = ymin + ((double)row + 0.5) * y_step;
IVUtils::Interpolate( total_ymin, total_ymax, mid_y,
0.0, (double)total_rows, d_y_index );
source_row = (int)d_y_index;
for ( size_t col = 0; col < n_cols; col++ )
{
mid_x = xmin + ((double)col + 0.5) * x_step;
IVUtils::Interpolate( total_xmin, total_xmax, mid_x,
0.0, (double)total_cols, d_x_index );
source_col = (size_t)d_x_index;
new_data[index] = data[source_row * total_cols + source_col];
index++;
}
}
// The calling code is responsible
is_log_x = false; // for deleting the DataArray
DataArray* new_data_array = new DataArray( xmin, xmax, ymin, ymax,
is_log_x, n_rows, n_cols, new_data);
return new_data_array;
}


/**
* Get a data array covering the full range of data.
* NOTE: The calling code is responsible for deleting the DataArray that is
* returned, when it is no longer needed.
*
* @param is_log_x Flag indicating whether or not the data should be
* binned logarithmically. This DataSource does not
* support rebinning to a log axis, so the DataArray is
* always returned with is_log_x = false.
*/
DataArray * RefArrayDataSource::GetDataArray( bool is_log_x )
{
is_log_x = false;
return GetDataArray( total_xmin, total_xmax, total_ymin, total_ymax,
total_rows, total_cols, is_log_x );
}


/**
* Clear the vector of strings and then add pairs of strings giving information
* about the specified point, x, y. The first string in a pair should
* generally be a string describing the value being presented and the second
* string should contain the value.
*
* @param x The x-coordinate of the point of interest in the data.
* @param y The y-coordinate of the point of interest in the data.
* @param list Vector that will be filled out with the information strings.
*/
void RefArrayDataSource::GetInfoList( double x,
double y,
std::vector<std::string> &list )
{
list.clear();

IVUtils::PushNameValue( "X", 8, 3, x, list );
IVUtils::PushNameValue( "Y", 8, 3, y, list );
}

} // namespace MantidQt
} // namespace RefDetectorViewer

0 comments on commit 1d8dca9

Please sign in to comment.