CutRangeRep.cxx
Go to the documentation of this file.
1 
12 #include "CutRangeRep.h"
13 
14 #include "datasrcs/TupleCut.h"
15 #include "graphics/ViewBase.h"
17 
18 #include <stdexcept>
19 
20 using std::string;
21 using std::vector;
22 
23 using namespace hippodraw;
24 
26  : PointRepBase ( "CutRangeRep", 0.0 )
27 {
28  const Color yellow ( Color::yellow );
29  setColor ( yellow );
30 }
31 
33  : PointRepBase ( point_rep )
34 {
35 }
36 
38 {
39  return new CutRangeRep( *this );
40 }
41 
42 void
45  TransformBase *,
46  ViewBase * )
47 {
48 }
49 
50 void
52 drawProjectedValues ( const Range & x_range,
53  const Range & y_range,
54  const TransformBase & tb,
55  ViewBase & view )
56 {
57  int dim = m_cut_list.size();
58 
59  bool yes = m_cut_list[0].getInversion ();
60  if ( dim == 2 ) yes |= m_cut_list[1].getInversion ();
61  if ( yes ) {
62  if ( dim == 1 ) {
63  drawInvertedRange1D ( x_range, y_range, tb, view );
64  }
65  else {
66  drawInvertedRange2D ( x_range, y_range, tb, view );
67  }
68  }
69  else drawNormalRange ( x_range, y_range, tb, view );
70 }
71 
72 void
74 drawNormalRange ( const Range & x_range, const Range & y_range,
75  const TransformBase & tb,
76  ViewBase & view )
77 {
78  const BinaryTransform & t
79  = dynamic_cast < const BinaryTransform & > ( tb );
80 
81  double x1 = x_range.low ();
82  double y1 = y_range.low ();
83  double x2 = x_range.high ();
84  double y2 = y_range.high ();
85 
86  if ( m_cut_list.size () >= 1 ) // i.e. this section applies to 1D and 2D cuts
87  {
88  const Range & range = m_cut_list[0].getRange ();
89  double cut_low = range.low ();
90  double cut_high = range.high ();
91  if ( cut_low > x1 ) x1 = cut_low;
92  if ( cut_high < x2 ) x2 = cut_high;
93  }
94 
95  if ( m_cut_list.size () >= 2 ) // i.e., this section applies only to 2D cuts.
96  {
97  const Range & range = m_cut_list[1].getRange ();
98  double cut_low = range.low ();
99  double cut_high = range.high ();
100  if ( cut_low > y1 ) y1 = cut_low;
101  if ( cut_high < y2 ) y2 = cut_high;
102  }
103 
104  t.transform ( x1, y1 );
105  t.transform ( x2, y2 );
106 
107  int red;
108  int green;
109  int blue;
110 
111  if ( m_desel == false ) {
112  red = m_color.getRed ();
113  green = m_color.getGreen ();
114  blue = m_color.getBlue ();
115  }
116  else {
117  red = s_desel_color.getRed ();
118  green = s_desel_color.getGreen ();
119  blue = s_desel_color.getBlue ();
120  }
121  view.drawSquare ( x1, y1, x2, y2, red, green, blue );
122 }
123 
124 void
126 drawInvertedRange1D ( const Range & x_range, const Range & y_range,
127  const TransformBase & tb,
128  ViewBase & view )
129 {
130  double xl = x_range.low ();
131  double xr = x_range.high ();
132 
133  const Range range = m_cut_list[0].getRange ();
134  double cut_low = range.low();
135  double cut_high = range.high ();
136 
137  double x1 = std::max ( cut_low, xl );
138  double x2 = std::min ( cut_high, xr );
139 
140  double y1 = y_range.low ();
141  double y2 = y_range.high ();
142 
143  double yl = y1;
144  double yr = y2;
145  const BinaryTransform & t
146  = dynamic_cast < const BinaryTransform & > ( tb );
147 
148  t.transform ( x1, y1 ); // careful, they get modified
149  t.transform ( x2, y2 );
150 
151  t.transform ( xl, yl );
152  t.transform ( xr, yr );
153 
154  int red;
155  int green;
156  int blue;
157 
158  if ( m_desel == false ) {
159  red = m_color.getRed ();
160  green = m_color.getGreen ();
161  blue = m_color.getBlue ();
162  }
163  else {
164  red = s_desel_color.getRed ();
165  green = s_desel_color.getGreen ();
166  blue = s_desel_color.getBlue ();
167  }
168 
169  view.drawSquare ( xl, y1, x1, y2, red, green, blue );
170  view.drawSquare ( x2, y1, xr, yr, red, green, blue );
171 }
172 
173 void
175 drawInvertedRange2D ( const Range & x_range, const Range & y_range,
176  const TransformBase & tb,
177  ViewBase & view )
178 {
179  const BinaryTransform & t
180  = dynamic_cast < const BinaryTransform & > ( tb );
181 
182  // loeer left hand corner of plot
183  double xLow = x_range.low ();
184  double yLow = y_range.low ();
185 
186  // upper right hand corner of plot
187  double xHigh = x_range.high ();
188  double yHigh = y_range.high ();
189 
190  // will be empty box in center
191  double x1 = xLow;
192  double x2 = xHigh;
193  double y1 = yLow;
194  double y2 = yHigh;
195 
196  if ( m_cut_list.size () >= 1 ) // i.e. this section applies to 1D and 2D cuts
197  {
198  const Range & range = m_cut_list[0].getRange ();
199  double cut_low = range.low();
200  double cut_high = range.high ();
201  if ( cut_low > x1 ) x1 = cut_low;
202  if ( cut_high < x2 ) x2 = cut_high;
203  }
204 
205  if ( m_cut_list.size() >= 2 ) // i.e. applies only to 2D cuts
206  {
207  const Range & range = m_cut_list[1].getRange ();
208  double cut_low = range.low();
209  double cut_high = range.high();
210  if ( cut_low > y1 ) y1 = cut_low;
211  if ( cut_high < y2 ) y2 = cut_high;
212  }
213 
214  t.transform ( x1, y1 );
215  t.transform ( x2, y2 );
216 
217  t.transform ( xLow, yLow );
218  t.transform ( xHigh, yHigh );
219 
220  int red;
221  int green;
222  int blue;
223 
224  if ( m_desel == false ) {
225  red = m_color.getRed ();
226  green = m_color.getGreen ();
227  blue = m_color.getBlue ();
228  }
229  else {
230  red = s_desel_color.getRed ();
231  green = s_desel_color.getGreen ();
232  blue = s_desel_color.getBlue ();
233  }
234 
235 
236  // left box
237  view.drawSquare( xLow, yLow, x1, yHigh, red, green, blue );
238 
239  // right box
240  view.drawSquare( x2, yLow, xHigh, yHigh, red, green, blue );
241 
242  // upper midle
243  view.drawSquare( x1, y2, x2, yHigh, red, green, blue );
244 
245  // lower midle
246  view.drawSquare( x1, yLow, x2, y1, red, green, blue );
247 
248 }
249 
250 const vector < TupleCut > &
252 getCuts () const
253 {
254  return m_cut_list;
255 }
256 
257 void
259 addCut ( const TupleCut & cut )
260 {
261  m_cut_list.push_back ( cut );
262 }
263 
264 void
266 setCutRangeAt ( const Range & range, unsigned int i )
267 {
268  if ( i >= m_cut_list.size () ) throwRangeException ();
269 
270  m_cut_list[i].setRange ( range );
271 }
272 
273 void
275 toggleInverted ( unsigned int i )
276 {
277  if ( i >= m_cut_list.size () ) throwRangeException ();
278 
279  m_cut_list[i].toggleInverted ();
280 }
281 
282 void
284 setEnabled ( unsigned int i, bool yes )
285 {
286  if ( i >= m_cut_list.size () ) throwRangeException ();
287 
288  m_cut_list[i].setEnabled ( yes );
289 }
290 
291 void
294 {
295  string what ( "CutRangeRep::setCutRange: index out of range." );
296  throw std::out_of_range ( what );
297 }

Generated for HippoDraw Class Library by doxygen