CutRangeRep.cxx

Go to the documentation of this file.
00001 
00012 #include "CutRangeRep.h"
00013 
00014 #include "datasrcs/TupleCut.h"
00015 #include "graphics/ViewBase.h"
00016 #include "transforms/BinaryTransform.h"
00017 
00018 #include <stdexcept>
00019 
00020 using std::string;
00021 using std::vector;
00022 
00023 using namespace hippodraw;
00024 
00025 CutRangeRep::CutRangeRep ( )
00026   : PointRepBase ( "CutRangeRep", 0.0 )
00027 {
00028   const Color yellow ( Color::yellow );
00029   setColor ( yellow );
00030 }
00031 
00032 CutRangeRep::CutRangeRep ( const CutRangeRep & point_rep )
00033   : PointRepBase ( point_rep )
00034 {
00035 }
00036 
00037 CutRangeRep * CutRangeRep::clone()
00038 {
00039   return new CutRangeRep( *this );
00040 }
00041 
00042 void
00043 CutRangeRep::
00044 drawProjectedValues ( const DataSource *,
00045                       TransformBase *,
00046                       ViewBase * )
00047 {
00048 }
00049 
00050 void 
00051 CutRangeRep::
00052 drawProjectedValues ( const Range & x_range,
00053                       const Range & y_range,
00054                       const TransformBase & tb,
00055                       ViewBase & view )
00056 {
00057   int dim = m_cut_list.size();
00058   
00059   bool yes = m_cut_list[0].getInversion ();
00060   if ( dim == 2 ) yes |= m_cut_list[1].getInversion ();
00061   if ( yes ) {
00062     if ( dim == 1 ) {
00063       drawInvertedRange1D ( x_range, y_range, tb, view );
00064     }
00065     else {
00066       drawInvertedRange2D ( x_range, y_range, tb, view );
00067     }
00068   }
00069   else drawNormalRange ( x_range, y_range, tb, view );
00070 }
00071 
00072 void
00073 CutRangeRep::
00074 drawNormalRange ( const Range & x_range, const Range & y_range,
00075                   const TransformBase & tb,
00076                   ViewBase & view )
00077 {
00078   const BinaryTransform & t 
00079     = dynamic_cast < const BinaryTransform & > ( tb );
00080   
00081   double x1 = x_range.low ();
00082   double y1 = y_range.low ();
00083   double x2 = x_range.high ();
00084   double y2 = y_range.high ();
00085   
00086   if ( m_cut_list.size () >= 1 ) // i.e. this section applies to 1D and 2D cuts
00087     {
00088       const Range & range = m_cut_list[0].getRange ();
00089       double cut_low = range.low ();
00090       double cut_high = range.high ();
00091       if ( cut_low > x1 ) x1 = cut_low;
00092       if ( cut_high < x2 ) x2 = cut_high;
00093     }
00094   
00095   if ( m_cut_list.size () >= 2 ) // i.e., this section applies only to 2D cuts.
00096     {
00097       const Range & range = m_cut_list[1].getRange ();
00098       double cut_low = range.low ();
00099       double cut_high = range.high ();
00100       if ( cut_low > y1 ) y1 = cut_low;
00101       if ( cut_high < y2 ) y2 = cut_high;
00102     }
00103   
00104   t.transform ( x1, y1 );
00105   t.transform ( x2, y2 );
00106 
00107   int red;
00108   int green;
00109   int blue;
00110   
00111   if ( m_desel == false ) {
00112     red   = m_color.getRed ();
00113     green = m_color.getGreen ();
00114     blue  = m_color.getBlue ();
00115   }
00116   else {
00117     red = s_desel_color.getRed ();
00118     green = s_desel_color.getGreen ();
00119     blue = s_desel_color.getBlue ();
00120   }
00121   view.drawSquare ( x1, y1, x2, y2, red, green, blue );
00122 }
00123 
00124 void
00125 CutRangeRep::
00126 drawInvertedRange1D ( const Range & x_range, const Range & y_range,
00127                       const TransformBase & tb,
00128                       ViewBase & view )
00129 {
00130   double xl = x_range.low ();
00131   double xr = x_range.high ();
00132 
00133   const Range range = m_cut_list[0].getRange ();
00134   double cut_low = range.low();
00135   double cut_high = range.high ();
00136 
00137   double x1 = std::max ( cut_low, xl );
00138   double x2 = std::min ( cut_high, xr );
00139 
00140   double y1 = y_range.low ();
00141   double y2 = y_range.high ();
00142 
00143   double yl = y1;
00144   double yr = y2;
00145   const BinaryTransform & t 
00146     = dynamic_cast < const BinaryTransform & > ( tb );
00147   
00148   t.transform ( x1, y1 ); // careful, they get modified
00149   t.transform ( x2, y2 );
00150 
00151   t.transform ( xl, yl );
00152   t.transform ( xr, yr );
00153 
00154   int red;
00155   int green;
00156   int blue;
00157   
00158   if ( m_desel == false ) {
00159     red   = m_color.getRed ();
00160     green = m_color.getGreen ();
00161     blue  = m_color.getBlue ();
00162   }
00163   else {
00164     red = s_desel_color.getRed ();
00165     green = s_desel_color.getGreen ();
00166     blue = s_desel_color.getBlue ();
00167   }
00168   
00169   view.drawSquare ( xl, y1, x1, y2, red, green, blue );  
00170   view.drawSquare ( x2, y1, xr, yr, red, green, blue );  
00171 }
00172 
00173 void
00174 CutRangeRep::
00175 drawInvertedRange2D ( const Range & x_range, const Range & y_range,
00176                       const TransformBase & tb,
00177                       ViewBase & view )
00178 {
00179   const BinaryTransform & t 
00180     = dynamic_cast < const BinaryTransform & > ( tb );
00181   
00182   // loeer left hand corner of plot
00183   double xLow  = x_range.low ();
00184   double yLow  = y_range.low ();
00185 
00186   // upper right hand corner of plot
00187   double xHigh = x_range.high ();
00188   double yHigh = y_range.high ();
00189 
00190   // will be empty box in center
00191   double x1 = xLow;
00192   double x2 = xHigh;
00193   double y1 = yLow;
00194   double y2 = yHigh;
00195     
00196   if ( m_cut_list.size () >= 1 ) // i.e. this section applies to 1D and 2D cuts
00197     {
00198       const Range & range = m_cut_list[0].getRange ();
00199       double cut_low = range.low();
00200       double cut_high = range.high ();
00201       if ( cut_low > x1 ) x1 = cut_low;
00202       if ( cut_high < x2 ) x2 = cut_high;
00203     }
00204   
00205   if ( m_cut_list.size() >= 2 ) // i.e. applies only to 2D cuts
00206     {
00207       const Range & range = m_cut_list[1].getRange ();
00208       double cut_low = range.low();
00209       double cut_high = range.high();
00210       if ( cut_low > y1 ) y1 = cut_low;
00211       if ( cut_high < y2 ) y2 = cut_high;
00212     }
00213   
00214   t.transform ( x1, y1 );
00215   t.transform ( x2, y2 );
00216 
00217   t.transform ( xLow, yLow );
00218   t.transform ( xHigh, yHigh );
00219   
00220   int red;
00221   int green;
00222   int blue;
00223   
00224   if ( m_desel == false ) {
00225     red   = m_color.getRed ();
00226     green = m_color.getGreen ();
00227     blue  = m_color.getBlue ();
00228   }
00229   else {
00230     red = s_desel_color.getRed ();
00231     green = s_desel_color.getGreen ();
00232     blue = s_desel_color.getBlue ();
00233   }
00234   
00235   
00236   // left box
00237   view.drawSquare( xLow, yLow,    x1, yHigh, red, green, blue );
00238 
00239   // right box
00240   view.drawSquare(   x2, yLow, xHigh, yHigh, red, green, blue );
00241 
00242   // upper midle
00243   view.drawSquare(   x1,   y2,    x2, yHigh, red, green, blue );
00244 
00245   // lower midle
00246   view.drawSquare(   x1, yLow,    x2,    y1, red, green, blue );
00247 
00248 }
00249 
00250 const vector < TupleCut > &
00251 CutRangeRep::
00252 getCuts () const
00253 {
00254   return m_cut_list;
00255 }
00256 
00257 void
00258 CutRangeRep::
00259 addCut ( const TupleCut & cut )
00260 {
00261   m_cut_list.push_back ( cut );
00262 }
00263 
00264 void
00265 CutRangeRep::
00266 setCutRangeAt ( const Range & range, unsigned int i )
00267 {
00268   if ( i >= m_cut_list.size () ) throwRangeException ();
00269 
00270   m_cut_list[i].setRange ( range );
00271 }
00272 
00273 void
00274 CutRangeRep::
00275 toggleInverted ( unsigned int i )
00276 {
00277   if ( i >= m_cut_list.size () ) throwRangeException ();
00278 
00279   m_cut_list[i].toggleInverted ();
00280 }
00281 
00282 void
00283 CutRangeRep::
00284 setEnabled ( unsigned int i, bool yes )
00285 {
00286   if ( i >= m_cut_list.size () ) throwRangeException ();
00287 
00288   m_cut_list[i].setEnabled ( yes );
00289 }
00290 
00291 void
00292 CutRangeRep::
00293 throwRangeException ()
00294 {
00295   string what ( "CutRangeRep::setCutRange: index out of range." );
00296   throw std::out_of_range ( what );
00297 }

Generated for HippoDraw Class Library by doxygen