CFEL - ASG Software Suite  2.5.0
CASS
two_d_viewer_data.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013 Lutz Foucar
2 
3 /**
4  * @file two_d_viewer_data.cpp contains the wrappe of the data for the 2d viewer
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <algorithm>
10 
11 #include <QtCore/QDebug>
12 
13 #include "two_d_viewer_data.h"
14 
15 #include "result.hpp"
16 
17 using namespace jocassview;
18 using namespace cass;
19 
21 {
22 
23 }
24 
26 {
27 
28 }
29 
31 {
32  if (!result)
33  return;
34 
35  _result = result;
36  const result_t::axe_t &xaxis(_result->axis(result_t::xAxis));
37  setInterval(Qt::XAxis,QwtInterval(xaxis.low,xaxis.up));
38  const result_t::axe_t &yaxis(_result->axis(result_t::yAxis));
39  setInterval(Qt::YAxis,QwtInterval(yaxis.low,yaxis.up));
40  setInterval(Qt::ZAxis,origZInterval(false));
41  _wasUpdated = true;
42 }
43 
45 {
46  _wasUpdated = false;
47  return _result;
48 }
49 
50 QwtInterval TwoDViewerData::origZInterval(bool log)const
51 {
52  if (!_result)
53  return (QwtInterval(0,0));
54 
55  QwtInterval zRange(1e30,-1e30);
56  result_t::const_iterator it(_result->begin());
57  result_t::const_iterator End(_result->end());
58  for (;it != End;++it)
59  {
60  if (!std::isfinite(*it))
61  continue;
62  if (log && !std::isfinite(log10(*it)))
63  continue;
64  if (*it < zRange.minValue())
65  zRange.setMinValue(*it);
66  if (zRange.maxValue() < *it)
67  zRange.setMaxValue(*it);
68  }
69  return zRange;
70 }
71 
72 double TwoDViewerData::value(double x, double y) const
73 {
74  if(!_result)
75  return 0;
76 
77  const int xSize(_result->shape().first);
78  const int xMin(interval(Qt::XAxis).minValue());
79  const int xWidth(interval(Qt::XAxis).width());
80  const int binx(xSize * (x - xMin) / xWidth);
81  if (binx < 0 || xSize <= binx)
82  return 0;
83 
84  const int ySize(_result->shape().second);
85  const int yMin(interval(Qt::YAxis).minValue());
86  const int yWidth(interval(Qt::YAxis).width());
87  const int biny(ySize * (y - yMin) / yWidth);
88  if (biny < 0 || ySize <= biny)
89  return 0;
90 
91  const int globalbin(biny*xSize + binx);
92  return (*_result)[globalbin];
93 }
QwtInterval origZInterval(bool log) const
return the min max values of the values in the data
storage_t::const_iterator const_iterator
a const iterator on the storage
Definition: result.hpp:338
virtual ~TwoDViewerData()
destructor
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
contains the wrappe of the data for the 2d viewer
an axis of a more than 0 dimensional container
Definition: result.hpp:29
result classes
void setResult(result_t::shared_pointer result)
set the cass data to be wrapped by this
virtual double value(double x, double y) const
return the value of the data at point x,y
result_t::shared_pointer result()
retrieve the pointer to the data
TwoDViewerData()
default constructor