CFEL - ASG Software Suite  2.5.0
CASS
one_d_viewer_data.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013 Lutz Foucar
2 
3 /**
4  * @file one_d_viewer_data.cpp contains the wrapper of the data for the 1d viewer
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <QtCore/QDebug>
10 
11 #include "one_d_viewer_data.h"
12 
13 #include "result.hpp"
14 
15 using namespace jocassview;
16 using namespace cass;
17 
19  : _logMinPos(QPointF(1,1)),
20  _xLog(false),
21  _yLog(false)
22 {
23  d_boundingRect = QRectF(1.0, 1.0, -2.0, -2.0); //invalid
24 }
25 
27 {
28 
29 }
30 
31 size_t OneDViewerData::size() const
32 {
33  return result() ? result()->shape().first : 0;
34 }
35 
37 {
38  if (!result())
39  return QPointF(0,0);
40 
41  const qreal xMin(d_boundingRect.left());
42  const qreal xWidth(d_boundingRect.width());
43  const qreal x(xMin + i*xWidth/(size()-1));
44  const qreal y((*result())[i]);
45  //const qreal y(res[i]);
46  return QPointF(x,y);
47 }
48 
50 {
51  QRectF rect(d_boundingRect);
52  if (_xLog)
53  rect.setLeft(_logMinPos.x());
54  if (_yLog)
55  rect.setTop(_logMinPos.y());
56  return rect;
57 }
58 
60 {
61  if(!result)
62  return;
63  _result = result;
64 
65  /** set the initial bounding rect in x */
66  const result_t::axe_t &xaxis(_result->axis(result_t::xAxis));
67  d_boundingRect.setLeft(xaxis.low);
68  d_boundingRect.setRight(xaxis.up);
69 
70  /** go through all data points of the curve and find min/max values for lin
71  * and log scale purposes
72  */
73  d_boundingRect.setTop(1e30);
74  d_boundingRect.setBottom(-1e30);
75  _logMinPos.setX(1e30);
76  _logMinPos.setY(1e30);
77  for (size_t i(0); i < size(); ++i)
78  {
79  const qreal x(sample(i).x());
80  const qreal y(sample(i).y());
81 
82  /** skip the check if the either coordinate of the point is not a number */
83  if (!std::isfinite(x) || !std::isfinite(y))
84  continue;
85 
86  /** find the max y value */
87  if (d_boundingRect.bottom() < y)
88  d_boundingRect.setBottom(y);
89 
90  /** find the min y value */
91  if (y < d_boundingRect.top())
92  d_boundingRect.setTop(y);
93 
94  /** find the min y value that is positive */
95  if (y < _logMinPos.y() && 0 < y)
96  _logMinPos.setY(y);
97 
98  /** find the min x value that is positive */
99  if (x < _logMinPos.x() && 0 < x)
100  _logMinPos.setX(x);
101  }
102 }
103 
105 {
106  return _result;
107 }
108 
110 {
111  return _result;
112 }
113 
115 {
116  _xLog = log;
117 }
118 
120 {
121  _yLog = log;
122 }
bool _xLog
flag to tell whether x scale will be drawn in log
virtual QRectF boundingRect() const
return the bounding rectangle
virtual QPointF sample(size_t i) const
return the x value for data point
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
QPointF _logMinPos
the minimum positions in x and y for log scales
an axis of a more than 0 dimensional container
Definition: result.hpp:29
virtual ~OneDViewerData()
destructor
result classes
OneDViewerData()
default constructor
setLeft(qreal x)
void setResult(result_t::shared_pointer result)
set the cass data to be wrapped by this
virtual size_t size() const
return the size of the data
result_t::shared_pointer _result
pointer to the cass data
void setYRangeForLog(bool log)
set up the bounding rect for when y should be log scale
setTop(qreal y)
setX(qreal x)
setY(qreal y)
Data::result_t::shared_pointer result()
retrieve pointer to the cass data
void setXRangeForLog(bool log)
set up the bounding rect for when x should be log scale
bool _yLog
flag to tell whether y scale will be drawn in log
contains the wrapper of the data for the 1d viewer