TAPs 0.7.7.3
TAPsOpenGLCtrlTransferFn.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsOpenGLCtrlTransferFn.hpp
00003 
00004 Transfer Fn Control via OpenGL
00005 
00006 SUKITTI PUNAK   (05/02/2007)
00007 UPDATE          (05/09/2007)
00008 ******************************************************************************/
00009 #ifndef TAPs_OPENGL_CONTROL_TRANSFER_FN_HPP
00010 #define TAPs_OPENGL_CONTROL_TRANSFER_FN_HPP
00011 
00022 // For DEBUGING
00023 #ifdef TAPs_DEBUG_MODE
00024 #endif
00025 
00026 #include "TAPsOpenGLCtrl.hpp"
00027 #include "TAPsOpenGLCtrlButton.hpp"
00028 
00029 BEGIN_NAMESPACE_TAPs__OpenGL
00030 //=============================================================================
00031 class OpenGLCtrlTransferFn : public /*virtual*/ OpenGLCtrl {
00032 //-----------------------------------------------------------------------------
00033 public:
00034     //-------------------------------------------------------------------------
00035     // Constructor and Destructor
00036     OpenGLCtrlTransferFn ();
00037     virtual ~OpenGLCtrlTransferFn ();
00038     //---------------------------------------------------------------
00039     // Get/Set Function(s)
00040     //-------------------------------------------
00041     virtual void Default ();
00042     virtual void SetStartPos ( int x, int y );
00043     //-------------------------------------------
00044     OpenGLCtrlButton & GetRedButton ()      { return m_ButtonRed; }
00045     OpenGLCtrlButton & GetGreenButton ()    { return m_ButtonGreen; }
00046     OpenGLCtrlButton & GetBlueButton ()     { return m_ButtonBlue; }
00047     OpenGLCtrlButton & GetAlphaButton ()    { return m_ButtonAlpha; }
00048     //-------------------------------------------
00049     // Inherited from class OpenGLCtrl.
00054     virtual void SetOpacity( float alpha );
00058     virtual bool IsInside ( int x, int y );
00062     virtual bool IsInsidePlusBorder ( int x, int y );
00067 //protected:
00068 //  virtual void SetSize ( int width, int height ) {}
00069 //public:
00070     //-------------------------------------------
00071     void SetLUTToRampFn ();
00072     void SetLUTToRandomFn ();
00073     //---------------------------------------------------------------
00077 //  virtual bool IsInside ( int x, int y )
00078 //  {
00079 //      return 
00080 //           m_xyLowerLeftPt[0] <= x && x <= m_xyLowerLeftPt[0]+m_DrawSizeXY[0]
00081 //        && m_xyLowerLeftPt[1]-m_BorderSize <= y && y <= m_xyLowerLeftPt[1]+m_DrawSizeXY[1]+m_BorderSize;
00082 //  }
00083     //---------------------------------------------------------------
00084     // Operation(s)
00088     bool SetClickXY ( int x, int y );
00097     bool ChangeLUTValues ( int x, int y );
00106     template <typename T>
00107     void LoadDataFrom ( T data[256*4], bool isDataNormalized );
00111     template <typename T>
00112     void LoadFreqsToHistogram ( T freqs[256] );
00116     bool SetLUTValuesToRamp ();
00120     bool SetLUTValuesToRandom ();
00124     void GetHistogramColor ( float & r, float & g, float & b, float & a ) const;
00125     void SetHistogramColor ( float r, float g, float b, float a );
00126     //---------------------------------------------------------------
00130     virtual void Draw ();       // start at xy-coordinates
00131     //---------------------------------------------------------------
00138     bool CopyTo1DTexture    ( GLuint to1DTex,   bool isDataNormalized ) const;
00139     bool CopyFrom1DTexture  ( GLuint from1DTex, bool isDataNormalized );
00140     //---------------------------------------------------------------
00141     // For DEBUGGING
00142 #ifdef TAPs_DEBUG_MODE
00143     void PrintTransferFnValues_0_1 () {
00144         std::cout << "Transfer Fn Values [0-1]:\n";
00145         std::cout << "-------------------------\n";
00146         for ( int i = 0; i < 256; ++i ) {
00147             std::cout << i << ": "
00148                     << (float)m_RGBA[i][0] / 255.0f << " "
00149                     << (float)m_RGBA[i][1] / 255.0f << " "
00150                     << (float)m_RGBA[i][2] / 255.0f << " "
00151                     << (float)m_RGBA[i][3] / 255.0f << "\n";
00152         }
00153         std::cout << "-------------------------\n";
00154     }
00155     void PrintTransferFnValues_0_255 () {
00156         std::cout << "Transfer Fn Values [0-255]:\n";
00157         std::cout << "---------------------------\n";
00158         for ( int i = 0; i < 256; ++i ) {
00159             std::cout << i << ": "
00160                     << (float)m_RGBA[i][0] << " "
00161                     << (float)m_RGBA[i][1] << " "
00162                     << (float)m_RGBA[i][2] << " "
00163                     << (float)m_RGBA[i][3] << "\n";
00164         }
00165         std::cout << "---------------------------\n";
00166     }
00167 #endif
00168     //---------------------------------------------------------------
00169 //-----------------------------------------------------------------------------
00170 protected:
00171     //---------------------------------------------------------------
00172     void DrawBackgroundScale ();
00173     void DrawIntensities ();
00174     void DrawColors ();
00175     void DrawHistogram ();
00176     //---------------------------------------------------------------
00177     void SetDefaultLUT ();
00178     void SetButtons ();
00179     //---------------------------------------------------------------
00187     void UpdateRGBA ();
00188     //-------------------------------------------------------------------------
00189     // Data Member(s)
00190     //---------------------------------------------------------------
00191     OpenGLCtrlButton    m_ButtonRed;
00192     OpenGLCtrlButton    m_ButtonGreen;
00193     OpenGLCtrlButton    m_ButtonBlue;
00194     OpenGLCtrlButton    m_ButtonAlpha;
00195     //
00196     GLubyte             m_RGBA[256][4];     // Local RGBA from [0-255]
00197     //
00198     class IC_Histogram {
00199     public:
00200         GLubyte             normalizedFreqs[256];   // Normalized histogram
00201         unsigned long int   totalFreqs;             // Total freqs in histogram
00202         unsigned long int   maxFreq;                // Max freq value in histogram
00203         GLfloat             histogramColor[4];      // histogram color
00204     };
00205     IC_Histogram            m_Histogram;
00206     //
00207     GLuint              m_RGBA_1DTexture;   // RGBA in GPU's texture
00208     //---------------------------------------------------------------
00209     // For helping changing values interactively
00210     int m_clickX, m_clickY;
00211     int m_old_x, m_old_y;
00212     //---------------------------------------------------------------
00213     //===============================================================
00214     //---------------------------------------------------------------
00215     // Static Data Member(s)
00216     //-------------------------------------------------------------------------
00217 };  // END CLASS OpenGLCtrlTransferFn
00218 
00219 //=============================================================================
00220 END_NAMESPACE_TAPs__OpenGL
00221 //-----------------------------------------------------------------------------
00222 // Include definition if TAPs_USE_EXPORT is not defined
00223 #if !defined( TAPs_USE_EXPORT )
00224     #include "TAPsOpenGLCtrlTransferFn.cpp"
00225 #endif
00226 //-----------------------------------------------------------------------------
00227 #endif
00228 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00229 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines