Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ColorBoxPointRep.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 #include "ColorBoxPointRep.h"
00017 
00018 #include "BinToColor.h"
00019 #include "BinToColorFactory.h"
00020 
00021 #include "datasrcs/DataPointTuple.h"
00022 #include "datasrcs/DataSource.h"
00023 #include "graphics/ViewBase.h"
00024 #include "transforms/BinaryTransform.h"
00025 
00026 #include <cassert>
00027 
00028 using namespace hippodraw;
00029 
00030 using std::vector;
00031 
00032 ColorBoxPointRep::
00033 ColorBoxPointRep ( )
00034   : PointRepBase ( "ColorBox", 0.0 )
00035 {
00036   BinToColorFactory * factory = BinToColorFactory::instance ();
00037   m_bin_to_color = factory -> create ( "Rainbow" );
00038 }
00039 
00040 ColorBoxPointRep::ColorBoxPointRep ( const ColorBoxPointRep & point_rep )
00041   : PointRepBase ( point_rep )
00042 {
00043   BinToColor * btc = point_rep.m_bin_to_color;
00044 
00045   m_bin_to_color = btc -> clone ();
00046 }
00047 
00048 ColorBoxPointRep::~ColorBoxPointRep()
00049 {
00050   delete m_bin_to_color;
00051 }
00052 
00053 RepBase * ColorBoxPointRep::clone()
00054 {
00055   return new ColorBoxPointRep( *this );
00056 }
00057 
00058 const BinToColor *
00059 ColorBoxPointRep::
00060 getValueTransform ( ) const
00061 {
00062   return m_bin_to_color;
00063 }
00064 
00065 void
00066 ColorBoxPointRep::
00067 setValueTransform ( BinToColor * btc )
00068 {
00069   delete m_bin_to_color;
00070   m_bin_to_color = btc;
00071 }
00072 
00073 namespace dp = hippodraw::DataPoint3DTuple;
00074 
00075 void
00076 ColorBoxPointRep::
00077 drawProjectedValues ( const DataSource * ntuple,
00078                       TransformBase * transform,
00079                       ViewBase * view )
00080 {
00081   const Range & range = view -> getRange ( Axes::Z );
00082 
00083   double high = range.high();
00084   double low = range.low();
00085 
00086   const BinaryTransform * bt
00087     = dynamic_cast < const BinaryTransform * > ( transform );
00088   assert ( bt != 0 );
00089 
00090   bt -> transformZ ( high );
00091   bt -> transformZ ( low );
00092 
00093   Range newrange ( low, high );
00094   m_bin_to_color->setRange ( newrange );
00095   const HippoRectangle & user_rect = view -> getUserRect ();
00096 
00097   bool isLinear = bt -> isLinearInXY ();
00098   bool surpress_zero = low == 0.0;
00099 
00100   unsigned int size = ntuple -> rows ();
00101 
00102   for ( unsigned int i = 0; i < size; i++ ) {
00103     const vector < double > & row = ntuple -> getRow ( i );
00104 
00105     double value = row [ dp::Z ];
00106     if ( surpress_zero && value == 0.0 ) continue;
00107 
00108     double half_xwidth = row [ dp::XERR ];
00109     double half_ywidth = row [ dp::YERR ];
00110 
00111     double x1 = row [ dp::X ] - half_xwidth;
00112     double y1 = row [ dp::Y ] - half_ywidth;
00113     double x2 = row [ dp::X ] + half_xwidth;
00114     double y2 = row [ dp::Y ] + half_ywidth;
00115 
00116     assert ( x1 < x2 && y1 < y2 );
00117 
00118     if ( isLinear == false ) {
00119       bt -> transform ( x1, y1 );
00120       bt -> transform ( x2, y2 );
00121     }
00122 
00123     user_rect.makeInBounds ( x1, y1 );
00124     user_rect.makeInBounds ( x2, y2 );
00125 
00126     if ( m_desel ) {
00127       const int gray = 226;
00128       view -> drawSquare ( x1, y1, x2, y2, gray, gray, gray );
00129       return;
00130     }
00131 
00132     bt -> transformZ ( value );
00133     if ( value > user_rect.getZ() ) {
00134        if ( !user_rect.isInDepth ( value ) ) {
00135           double x(0), y(0);
00136           user_rect.makeInBounds(x, y, value);
00137        }
00138        Color color;
00139        m_bin_to_color -> doubleToColor ( value, color );
00140        view -> drawSquare ( x1, y1, x2, y2,
00141                             color.getRed (), 
00142                             color.getGreen(), 
00143                             color.getBlue() );
00144     }
00145   }
00146 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3