Skip to content

Commit

Permalink
Added 2 renamed files. This refs #5801
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Oct 1, 2012
1 parent ad2e48e commit 7d8e003
Show file tree
Hide file tree
Showing 2 changed files with 295 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#ifndef REF_IMAGE_DATA_SOURCE_H
#define REF_IMAGE_DATA_SOURCE_H

#include <cstddef>
#include <vector>
#include <string>
#include "MantidQtRefDetectorViewer/DataArray.h"
#include "MantidQtRefDetectorViewer/DllOptionIV.h"

/**
@class ImageDataSource
This class is an abstract base class for classes that can provide
data to be displayed in an ImageView data viewer.
@author Dennis Mikkelson
@date 2012-04-03
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 RefImageDataSource
{
public:

/// construct data source with specified total range and data size
RefImageDataSource( double total_xmin, double total_xmax,
double total_ymin, double total_ymax,
size_t total_rows, size_t total_cols );

virtual ~RefImageDataSource();

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

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

/// Get the smallest 'y' value covered by the data
virtual double GetYMin();

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

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

/// Get the total number of columns of data
virtual size_t GetNCols();

/// Clamp x to the interval of x-values covered by this DataSource
virtual void RestrictX( double & x );

/// Clamp y to the interval of y-values covered by this DataSource
virtual void RestrictY( double & y );

/// Clamp row to a valid row number for this DataSource
virtual void RestrictRow( int & row );

/// Clamp col to a valid column number for this dataSource
virtual void RestrictCol( int & col );

/// Get a DataArray roughly spaning the specified rectangle. NOTE: The
/// actual size and number of steps returned in the DataArray will be
/// adjusted to match the underlying data.
virtual DataArray* GetDataArray( double xmin,
double xmax,
double ymin,
double ymax,
size_t n_rows,
size_t n_cols,
bool is_log_x ) = 0;

/// Convenience method to get data covering the full range at max resolution
virtual DataArray* GetDataArray( bool is_log_x );

/// Get list of pairs of strings with info about the data at location x, y
virtual void GetInfoList( double x,
double y,
std::vector<std::string> &list ) = 0;
protected:
double total_xmin;
double total_xmax;
double total_ymin;
double total_ymax;
size_t total_rows;
size_t total_cols;
};

} // namespace MantidQt
} // namespace RefDetectorViewer


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

#include <math.h>

#include "MantidQtRefDetectorViewer/RefImageDataSource.h"

namespace MantidQt
{
namespace RefDetectorViewer
{


/**
* Construct data source with specified total range and data size.
*
* @param total_xmin The smallest 'x' value covered by the data
* @param total_xmax The largest 'x' value covered by the data
* @param total_ymin The smallest 'y' value covered by the data
* @param total_ymax The largest 'y' value covered by the data
* @param total_rows The total number of rows the data is divided into
* @param total_cols The total number of columns the data is divided into
*/
RefImageDataSource::RefImageDataSource( double total_xmin, double total_xmax,
double total_ymin, double total_ymax,
size_t total_rows, size_t total_cols )
{
this->total_xmin = total_xmin;
this->total_xmax = total_xmax;
this->total_ymin = total_ymin;
this->total_ymax = total_ymax;
this->total_rows = total_rows;
this->total_cols = total_cols;
}


RefImageDataSource::~RefImageDataSource()
{
}


/**
* Get the smallest 'x' value covered by the data.
*/
double RefImageDataSource::GetXMin()
{
return total_xmin;
}


/**
* Get the largest 'x' value covered by the data.
*/
double RefImageDataSource::GetXMax()
{
return total_xmax;
}


/**
* Get the smallest 'y' value covered by the data.
*/
double RefImageDataSource::GetYMin()
{
return total_ymin;
}


/**
* Get the largest 'y' value covered by the data.
*/
double RefImageDataSource::GetYMax()
{
return total_ymax;
}


/**
* Get the total number of rows the data is divided into
*/
size_t RefImageDataSource::GetNRows()
{
return total_rows;
}


/**
* Get the total number of columns the data is divided into
*/
size_t RefImageDataSource::GetNCols()
{
return total_cols;
}


/**
* Clamp x to the interval of x-values covered by this DataSource
* @param x If x is more than xmax it will be set to xmax. If x is less
* than xmin, it will be set to xmin.
*/
void RefImageDataSource::RestrictX( double & x )
{
if ( x > total_xmax )
{
x = total_xmax;
}
else if ( x < total_xmin )
{
x = total_xmin;
}
}


/**
* Clamp y to the interval of y-values covered by this DataSource.
* @param y If y is more than ymax it will be set to ymax. If y is less
* than ymin, it will be set to ymin.
*/
void RefImageDataSource::RestrictY( double & y )
{
if ( y > total_ymax )
{
y = total_ymax;
}
else if ( y < total_ymin )
{
y = total_ymin;
}
}


/**
* Clamp row to a valid row number for this DataSource.
* @param row If row is more than n_rows-1, it is set to n_rows-1. If
* row < 0 it is set to zero.
*/
void RefImageDataSource::RestrictRow( int & row )
{
if ( row >= (int)total_rows )
{
row = (int)total_rows - 1;
}
else if ( row < 0 )
{
row = 0;
}
}


/**
* Clamp col to a valid column number for this DataSource.
* @param col If col is more than n_cols-1, it is set to n_cols-1. If
* col < 0 it is set to zero.
*/
void RefImageDataSource::RestrictCol( int & col )
{
if ( col >= (int)total_cols )
{
col = (int)total_cols - 1;
}
else if ( col < 0 )
{
col = 0;
}
}


/**
* Convenience method to get all the data at the maximum resolution.
*/
DataArray* RefImageDataSource::GetDataArray( bool is_log_x )
{
return GetDataArray( total_xmin, total_xmax, total_ymin, total_ymax,
total_rows, total_cols, is_log_x );
}

} // namespace MantidQt
} // namespace ImageView

0 comments on commit 7d8e003

Please sign in to comment.