Skip to content

Commit

Permalink
Now adapts to change in underlying DataSource
Browse files Browse the repository at this point in the history
If the underlying DataSource is changed, say by changing a TOF workspace to
'd', the ImageView just needs to be refreshed by moving a scroll bar or
pressing return in one of the min,max,step controls.  At that time, it will
adjust to the new data range.
refs #5058
  • Loading branch information
DennisMikkelson committed Apr 28, 2012
1 parent 041c5e8 commit 430f87c
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class EXPORT_OPT_MANTIDQT_IMAGEVIEWER EventWSDataSource: public ImageDataSource

~EventWSDataSource();

/// 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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ class EXPORT_OPT_MANTIDQT_IMAGEVIEWER ImageDataSource
virtual ~ImageDataSource();

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

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

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

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

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

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

/// Get a DataArray roughly spaning the specified rectangle. NOTE: The
/// actual size and number of steps returned in the DataArray will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class EXPORT_OPT_MANTIDQT_IMAGEVIEWER ImageDisplay
void SetPointedAtPoint( QPoint point );

private:
/// Check if the DataSource has been changed under us
bool DataSourceRangeChanged();

/// Get the rectangle currently covered by the image in pixel coordinates
void GetDisplayRectangle( QRect &rect );

Expand All @@ -105,6 +108,13 @@ class EXPORT_OPT_MANTIDQT_IMAGEVIEWER ImageDisplay
GraphDisplay* v_graph_display;

QTableWidget* image_table;
// save current total data range
// so we can reset the data source
// if we detect a change of range
double total_y_min;
double total_y_max;
double total_x_min;
double total_x_max;
};

} // namespace MantidQt
Expand Down
71 changes: 56 additions & 15 deletions Code/Mantid/MantidQt/ImageViewer/src/EventWSDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,19 @@ EventWSDataSource::EventWSDataSource( IEventWorkspace_sptr ev_ws )
:ImageDataSource( 0.0, 1.0, 0.0, 1.0, 0, 0 ) // some defaults
{
this->ev_ws = ev_ws;
total_xmin = ev_ws->getTofMin();
total_xmax = ev_ws->getTofMax();

total_xmin = ev_ws->getXMin();
total_xmax = ev_ws->getXMax();

total_ymin = 0; // y direction is spectrum index
total_ymax = (double)ev_ws->getNumberHistograms();

total_rows = ev_ws->getNumberHistograms();

total_cols = 1000000; // Allow up to a million virtual columns.
// The data will only be rebinned to a
// resolution corresponding to the screen.
// However, this number places a hard limit
// on the number of virtual columns, which
// affects the scroll bar size calculation
std::cout << "Xmin = " << ev_ws->getXMin() << std::endl;
std::cout << "Xmax = " << ev_ws->getXMax() << std::endl;

if ( total_xmax > 120000 )
{
total_xmax = 120000; // hack for now
std::cout << "WARNING: max tof too large, set to "
<< total_xmax << std::endl;
}
total_cols = 1000000; // Default data resolution
}


Expand All @@ -57,6 +51,51 @@ EventWSDataSource::~EventWSDataSource()
}


/**
* Get the smallest 'x' value covered by the data. Must override base class
* method, since the DataSource can be changed!
*/
double EventWSDataSource::GetXMin()
{
total_xmin = ev_ws->getXMin();
return total_xmin;

}


/**
* Get the largest 'x' value covered by the data. Must override base class
* method, since the DataSource can be changed!
*/
double EventWSDataSource::GetXMax()
{
total_xmax = ev_ws->getXMax();
return total_xmax;
}


/**
* Get the largest 'y' value covered by the data. Must override base class
* method, since the DataSource can be changed!
*/
double EventWSDataSource::GetYMax()
{
total_ymax = (double)ev_ws->getNumberHistograms();
return total_ymax;
}


/**
* Get the total number of rows the data is divided into. Must override base
* class method, since the DataSource can be changed!
*/
size_t EventWSDataSource::GetNRows()
{
total_ymax = (double)ev_ws->getNumberHistograms();
return total_rows;
}


/**
* Get a data array covering the specified range of data, at the specified
* resolution. NOTE: The calling code is responsible for deleting the
Expand Down Expand Up @@ -164,7 +203,9 @@ void EventWSDataSource::GetInfoList( double x,
IVUtils::Format(8,3,x,x_str);
list.push_back(x_str);

list.push_back("Test Y:");
std::string y_label = ev_ws->YUnit();
list.push_back(y_label);
// list.push_back("Test Y:");
std::string y_str;
IVUtils::Format(8,3,y,y_str);
list.push_back(y_str);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/ImageViewer/src/IVUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ bool IVUtils::Interpolate( double min,
* max value, if max is in the interior of a bin.
* @param steps On input this should be the number of bins desired
* between the min and max values. This will be adjusted
* to be more than the number os steps available.
* to be more than the number of steps available.
*/
bool IVUtils::CalculateInterval( double global_min,
double global_max,
Expand Down
12 changes: 6 additions & 6 deletions Code/Mantid/MantidQt/ImageViewer/src/ImageDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ImageDataSource::~ImageDataSource()
/**
* Get the smallest 'x' value covered by the data.
*/
double ImageDataSource::GetXMin() const
double ImageDataSource::GetXMin()
{
return total_xmin;
}
Expand All @@ -50,7 +50,7 @@ double ImageDataSource::GetXMin() const
/**
* Get the largest 'x' value covered by the data.
*/
double ImageDataSource::GetXMax() const
double ImageDataSource::GetXMax()
{
return total_xmax;
}
Expand All @@ -59,7 +59,7 @@ double ImageDataSource::GetXMax() const
/**
* Get the smallest 'y' value covered by the data.
*/
double ImageDataSource::GetYMin() const
double ImageDataSource::GetYMin()
{
return total_ymin;
}
Expand All @@ -68,7 +68,7 @@ double ImageDataSource::GetYMin() const
/**
* Get the largest 'y' value covered by the data.
*/
double ImageDataSource::GetYMax() const
double ImageDataSource::GetYMax()
{
return total_ymax;
}
Expand All @@ -77,7 +77,7 @@ double ImageDataSource::GetYMax() const
/**
* Get the total number of rows the data is divided into
*/
size_t ImageDataSource::GetNRows() const
size_t ImageDataSource::GetNRows()
{
return total_rows;
}
Expand All @@ -86,7 +86,7 @@ size_t ImageDataSource::GetNRows() const
/**
* Get the total number of columns the data is divided into
*/
size_t ImageDataSource::GetNCols() const
size_t ImageDataSource::GetNCols()
{
return total_cols;
}
Expand Down
61 changes: 38 additions & 23 deletions Code/Mantid/MantidQt/ImageViewer/src/ImageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ void ImageDisplay::SetDataSource( ImageDataSource* data_source )
h_graph_display->SetDataSource( data_source );
v_graph_display->SetDataSource( data_source );

double scale_y_min = data_source->GetYMin();
double scale_y_max = data_source->GetYMax();
total_y_min = data_source->GetYMin();
total_y_max = data_source->GetYMax();

double scale_x_min = data_source->GetXMin();
double scale_x_max = data_source->GetXMax();
total_x_min = data_source->GetXMin();
total_x_max = data_source->GetXMax();

int n_rows = 500; // get reasonable size initial image data
int n_cols = 500;
// data_array is deleted in the ImagePlotItem
data_array = data_source->GetDataArray( scale_x_min, scale_x_max,
scale_y_min, scale_y_max,
data_array = data_source->GetDataArray( total_x_min, total_x_max,
total_y_min, total_y_max,
n_rows, n_cols,
false );

Expand All @@ -103,6 +103,8 @@ void ImageDisplay::SetDataSource( ImageDataSource* data_source )

image_plot_item->SetData( data_array, &color_table );

range_handler->ConfigureRangeControls( data_source );

QRect draw_area;
GetDisplayRectangle( draw_area );
slider_handler->ConfigureSliders( draw_area, data_source );
Expand All @@ -120,13 +122,19 @@ void ImageDisplay::UpdateRange()
{
return; // no image data to update
}

if ( DataSourceRangeChanged() )
{
SetDataSource( data_source ); // re-initialize with the altered source
}

double min = 0;
double max = 0;
double step = 0;
range_handler->GetRange( min, max, step );

int n_bins = (int)(( max - min ) / step);

int n_bins = (int)(( max - min ) / step); // range controls now determine
// the number of bins
QRect display_rect;
GetDisplayRectangle( display_rect );

Expand All @@ -148,22 +156,23 @@ void ImageDisplay::UpdateImage()
return; // no image data to update
}

if ( DataSourceRangeChanged() )
{
SetDataSource( data_source ); // re-initialize with the altered source
}

QRect display_rect;
GetDisplayRectangle( display_rect );

double scale_y_min = data_source->GetYMin();
double scale_y_max = data_source->GetYMax();
/*
double scale_x_min = data_source->GetXMin();
double scale_x_max = data_source->GetXMax();
*/

double scale_x_min = 0;
double scale_x_max = 0;
double step = 0;
range_handler->GetRange( scale_x_min, scale_x_max, step );

int n_rows = (int)data_source->GetNRows();
// int n_cols = (int)data_source->GetNCols();
int n_cols = (int)( ( scale_x_max - scale_x_min ) / step );

if ( slider_handler->VSliderOn() )
Expand Down Expand Up @@ -424,16 +433,22 @@ void ImageDisplay::GetDisplayRectangle( QRect &rect )
rect.setBottom( 440 );
rect.setTop ( 6 );
}
/*
std::cout << "GetDisplayRect: pix_x_min = " << pix_x_min << std::endl;
std::cout << "GetDisplayRect: pix_x_max = " << pix_x_max << std::endl;
std::cout << "GetDisplayRect: pix_y_min = " << pix_y_min << std::endl;
std::cout << "GetDisplayRect: pix_y_max = " << pix_y_max << std::endl;
std::cout << "GetDisplayRect: rect x = " << rect.x() << std::endl;
std::cout << "GetDisplayRect: rect y = " << rect.y() << std::endl;
std::cout << "GetDisplayRect: rect width = " << rect.width() << std::endl;
std::cout << "GetDisplayRect: rect height = " << rect.height() << std::endl;
*/
}


bool ImageDisplay::DataSourceRangeChanged()
{
if ( total_y_min != data_source->GetYMin() ||
total_y_max != data_source->GetYMax() ||
total_x_min != data_source->GetXMin() ||
total_x_max != data_source->GetXMax() )
{
return true;
}
else
{
return false;
}
}


Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/MantidQt/ImageViewer/src/ImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ImageView::ImageView( ImageDataSource* data_source )
saved_slider_handler = slider_handler;

RangeHandler* range_handler = new RangeHandler( ui );
range_handler->ConfigureRangeControls( data_source );
saved_range_handler = range_handler;

h_graph = new GraphDisplay( ui->h_graphPlot, ui->h_graph_table, false );
Expand Down
12 changes: 8 additions & 4 deletions Code/Mantid/MantidQt/ImageViewer/src/RangeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ void RangeHandler::GetRange( double &min, double &max, double &step )

IVUtils::FindValidInterval( min, max );

double max_steps = static_cast<double>(total_n_steps) * (max - min)/(total_max_x - total_min_x);
if ( (max-min) / step > max_steps )
if ( step < 0 ) // just require step to be > 0, no other
{ // bounds
step = -step;
}

if ( step == 0 ) // take a default step size
{
step = (total_max_x - total_min_x)/static_cast<double>(total_n_steps);
}
step = (total_max_x - total_min_x) / 2000;
}

SetRange( min, max, step );
}
Expand Down
4 changes: 1 addition & 3 deletions Code/Mantid/MantidQt/ImageViewer/src/SliderHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ void SliderHandler::ConfigureSliders( QRect draw_area,
int n_rows = (int)data_source->GetNRows();
ConfigureSlider( v_scroll, n_rows, draw_area.height(), n_rows );

QScrollBar* h_scroll = iv_ui->imageHorizontalScrollBar;
int n_cols = (int)data_source->GetNCols();
ConfigureSlider( h_scroll, n_cols, draw_area.width(), 0 );
ConfigureHSlider( 2000, draw_area.width() ); // initial default, 2000 bins
}


Expand Down

0 comments on commit 430f87c

Please sign in to comment.