OpenGLCtrlTransferFn Class Reference

#include <TAPsOpenGLCtrlTransferFn.hpp>

Inheritance diagram for OpenGLCtrlTransferFn:

Inheritance graph
[legend]
Collaboration diagram for OpenGLCtrlTransferFn:

Collaboration graph
[legend]

List of all members.

Public Member Functions

bool ChangeLUTValues (int x, int y)
bool CopyFrom1DTexture (GLuint from1DTex, bool isDataNormalized)
bool CopyTo1DTexture (GLuint to1DTex, bool isDataNormalized) const
virtual void Default ()
virtual void Draw ()
OpenGLCtrlButtonGetAlphaButton ()
OpenGLCtrlButtonGetBlueButton ()
OpenGLCtrlButtonGetGreenButton ()
void GetHistogramColor (float &r, float &g, float &b, float &a) const
OpenGLCtrlButtonGetRedButton ()
virtual bool IsInside (int x, int y)
virtual bool IsInsidePlusBorder (int x, int y)
template<typename T>
void LoadDataFrom (T data[256 *4], bool isDataNormalized)
template<typename T>
void LoadFreqsToHistogram (T freqs[256])
 OpenGLCtrlTransferFn ()
bool SetClickXY (int x, int y)
void SetHistogramColor (float r, float g, float b, float a)
void SetLUTToRampFn ()
void SetLUTToRandomFn ()
bool SetLUTValuesToRamp ()
bool SetLUTValuesToRandom ()
virtual void SetOpacity (float alpha)
virtual void SetStartPos (int x, int y)
virtual ~OpenGLCtrlTransferFn ()

Protected Member Functions

void DrawBackgroundScale ()
void DrawColors ()
void DrawHistogram ()
void DrawIntensities ()
void SetButtons ()
void SetDefaultLUT ()
void UpdateRGBA ()

Protected Attributes

OpenGLCtrlButton m_ButtonAlpha
OpenGLCtrlButton m_ButtonBlue
OpenGLCtrlButton m_ButtonGreen
OpenGLCtrlButton m_ButtonRed
int m_clickX
int m_clickY
IC_Histogram m_Histogram
int m_old_x
int m_old_y
GLubyte m_RGBA [256][4]
GLuint m_RGBA_1DTexture

Classes

class  IC_Histogram


Detailed Description

Transfer Function:

There are four channels; red, green, blue, and alpha of range [0,255], i.e. unnormalized 8-bit data.

See how to setup and use this OpenGL control by reading comments of the member functions listed in this header file.

Definition at line 32 of file TAPsOpenGLCtrlTransferFn.hpp.


Constructor & Destructor Documentation

BEGIN_NAMESPACE_TAPs__OpenGL OpenGLCtrlTransferFn::OpenGLCtrlTransferFn (  ) 

Definition at line 19 of file TAPsOpenGLCtrlTransferFn.cpp.

00020     : OpenGLCtrl(), m_RGBA_1DTexture( 0 )
00021 {
00022     Default();
00023 }

OpenGLCtrlTransferFn::~OpenGLCtrlTransferFn (  )  [virtual]

Definition at line 29 of file TAPsOpenGLCtrlTransferFn.cpp.

00030 {
00031     glDeleteTextures( 1, &m_RGBA_1DTexture );
00032 }


Member Function Documentation

bool OpenGLCtrlTransferFn::ChangeLUTValues ( int  x,
int  y 
)

Change Look Up Table Values. Call this function to change a value in the lookup table. The changed value and rocation is determined by the x and y (of mouse position) respectively.

Recommended Usage: with mouse motion

Definition at line 308 of file TAPsOpenGLCtrlTransferFn.cpp.

00309 {
00310     //
00311     if ( !IsInside( x, y ) )    return false;
00312     //
00313     x -= m_xyLowerLeftPt[0];
00314     y -= m_xyLowerLeftPt[1];
00315     //
00316     if      ( x <   0 ) x =   0;
00317     else if ( x > 255 ) x = 255;
00318     if      (   0 > y ) y =   0;
00319     else if ( 255 < y ) y = 255;
00320     //
00321     // Forward Changing
00322     if ( x >= m_old_x+1 ) {
00323         float yStep = (float)( y - m_old_y ) / (float)( x - m_old_x );
00324         float yVal = m_old_y;
00325         for ( int i = m_old_x; i <= x; ++i ) {
00326             if ( m_ButtonRed.GetStatus() ) {
00327                 m_RGBA[i][0] = (unsigned int)yVal;
00328             }
00329             if ( m_ButtonGreen.GetStatus() ) {
00330                 m_RGBA[i][1] = (unsigned int)yVal;
00331             }
00332             if ( m_ButtonBlue.GetStatus() ) {
00333                 m_RGBA[i][2] = (unsigned int)yVal;
00334             }
00335             if ( m_ButtonAlpha.GetStatus() ) {
00336                 m_RGBA[i][3] = (unsigned int)yVal;
00337             }
00338             yVal += yStep;
00339         }
00340     }
00341     //
00342     // Backward Changing
00343     else {
00344         float yStep = (float)( m_old_y - y ) / (float)( x - m_old_x );
00345         float yVal = m_old_y;
00346         for ( int i = m_old_x; i >= x; --i ) {
00347             if ( m_ButtonRed.GetStatus() ) {
00348                 m_RGBA[i][0] = (unsigned int)yVal;
00349             }
00350             if ( m_ButtonGreen.GetStatus() ) {
00351                 m_RGBA[i][1] = (unsigned int)yVal;
00352             }
00353             if ( m_ButtonBlue.GetStatus() ) {
00354                 m_RGBA[i][2] = (unsigned int)yVal;
00355             }
00356             if ( m_ButtonAlpha.GetStatus() ) {
00357                 m_RGBA[i][3] = (unsigned int)yVal;
00358             }
00359             yVal += yStep;
00360         }
00361     }
00362     //
00363     m_old_x = x;
00364     m_old_y = y;
00365     UpdateRGBA();
00366     //
00367     return true;
00368 }

bool OpenGLCtrlTransferFn::CopyFrom1DTexture ( GLuint  from1DTex,
bool  isDataNormalized 
)

Definition at line 712 of file TAPsOpenGLCtrlTransferFn.cpp.

00714 {
00715     //---------------------------------------------------------------
00716     // DEBUG: Check texture compatability
00717 #ifdef TAPS_DEBUG_MODE
00718     //glGetTexLevelParameteriv( GL_TEXTURE_1D, ...
00719     // if ... return false
00720 #endif
00721     if ( from1DTex == NULL )    return false;
00722     //===============================================================
00723     // Read Transfer Function Look Up Table (Texture) from GPU
00724     //---------------------------------------------------------------
00725     // Normalized Data
00726     if ( isDataNormalized ) {
00727         GLfloat dataRGBA[256][4];
00728         //-------------------------------------------
00729         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00730         glBindTexture( GL_TEXTURE_1D, from1DTex );
00731         //---------------------------------------
00732         glGetTexImage( 
00733             GL_TEXTURE_1D,
00734             0,
00735             GL_RGBA,
00736             GL_FLOAT,
00737             dataRGBA
00738         );
00739         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00740         //---------------------------------------
00741         glBindTexture( GL_TEXTURE_1D, 0 );
00742         //---------------------------------------
00743         for ( int i = 0; i < 256; ++i ) {
00744             m_RGBA[i][0] = (GLubyte) ( dataRGBA[i][0] * 255 );
00745             m_RGBA[i][1] = (GLubyte) ( dataRGBA[i][1] * 255 );
00746             m_RGBA[i][2] = (GLubyte) ( dataRGBA[i][2] * 255 );
00747             m_RGBA[i][3] = (GLubyte) ( dataRGBA[i][3] * 255 );
00748         }
00749     }
00750     //---------------------------------------------------------------
00751     // Unnormalized Data
00752     else {
00753         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00754         glBindTexture( GL_TEXTURE_1D, from1DTex );
00755         //---------------------------------------
00756         glGetTexImage( 
00757             GL_TEXTURE_1D,
00758             0,
00759             GL_RGBA,
00760             GL_UNSIGNED_BYTE,
00761             m_RGBA
00762         );
00763         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00764         //---------------------------------------
00765         glBindTexture( GL_TEXTURE_1D, 0 );
00766     }
00767     //---------------------------------------------------------------
00768     //===============================================================
00769     UpdateRGBA();
00770     //---------------------------------------------------------------
00771     return true;
00772 }

bool OpenGLCtrlTransferFn::CopyTo1DTexture ( GLuint  to1DTex,
bool  isDataNormalized 
) const

Copy to/from 1D texture. Data in the texture to be copied to or read from can be normalized [0.0,1.0] (isDataNormalized == true) or unnormalized [0,255] (isDataNormalized == false).

Definition at line 644 of file TAPsOpenGLCtrlTransferFn.cpp.

00646 {
00647     //---------------------------------------------------------------
00648     // DEBUG: Check texture compatability
00649 #ifdef TAPS_DEBUG_MODE
00650     //glGetTexLevelParameteriv( GL_TEXTURE_1D, ...
00651     // if ... return false
00652 #endif
00653     if ( to1DTex == NULL )  return false;
00654     //===============================================================
00655     // Write Transfer Function Look Up Table (Texture) to GPU
00656     //---------------------------------------------------------------
00657     // Normalized Data
00658     if ( isDataNormalized ) {
00659         GLfloat dataRGBA[256][4];
00660         for ( int i = 0; i < 256; ++i ) {
00661             dataRGBA[i][0] = (GLfloat) ( m_RGBA[i][0] / 255.0f );
00662             dataRGBA[i][1] = (GLfloat) ( m_RGBA[i][1] / 255.0f );
00663             dataRGBA[i][2] = (GLfloat) ( m_RGBA[i][2] / 255.0f );
00664             dataRGBA[i][3] = (GLfloat) ( m_RGBA[i][3] / 255.0f );
00665         }
00666         //-------------------------------------------
00667         glBindBuffer( GL_PIXEL_UNPACK_BUFFER, 0 );
00668         glBindTexture( GL_TEXTURE_1D, to1DTex );
00669         //-------------------------------------------
00670         glTexImage1D( GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, 
00671             GL_FLOAT, dataRGBA );
00672         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00673         //-------------------------------------------
00674         glBindTexture( GL_TEXTURE_1D, 0 );
00675     }
00676     //---------------------------------------------------------------
00677     // Unnormalized Data
00678     else {
00679         glBindBuffer( GL_PIXEL_UNPACK_BUFFER, 0 );
00680         glBindTexture( GL_TEXTURE_1D, to1DTex );
00681         //-------------------------------------------
00682         glTexImage1D( GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, 
00683             GL_UNSIGNED_BYTE, m_RGBA );
00684         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00685         //-------------------------------------------
00686         glBindTexture( GL_TEXTURE_1D, 0 );
00687     }
00688     //---------------------------------------------------------------
00689     //===============================================================
00690     /*
00691     // DEBUG
00692     for ( int i = 0; i < 6; ++i ) {
00693         std::cout << i << ": " 
00694             << (int)m_RGBA[i][0] << " " 
00695             << (int)m_RGBA[i][1] << " " 
00696             << (int)m_RGBA[i][2] << " " 
00697             << (int)m_RGBA[i][3] << "\n";
00698     }
00699     std::cout << "-----\n";
00700     for ( int i = 250; i < 256; ++i ) {
00701         std::cout << i << ": " 
00702             << (int)m_RGBA[i][0] << " " 
00703             << (int)m_RGBA[i][1] << " " 
00704             << (int)m_RGBA[i][2] << " " 
00705             << (int)m_RGBA[i][3] << "\n";
00706     }
00707     //*/
00708     //---------------------------------------------------------------
00709     return true;
00710 }

void OpenGLCtrlTransferFn::Default (  )  [virtual]

Reimplemented from OpenGLCtrl.

Definition at line 39 of file TAPsOpenGLCtrlTransferFn.cpp.

00040 {
00041     SetSize( 256, 256 );
00042     m_BorderSize = 8;
00043     m_BackgroundColor[0] = 0.7;
00044     m_BackgroundColor[1] = 0.7;
00045     m_BackgroundColor[2] = 0.7;
00046     m_BackgroundColor[3] = 0.3;
00047     //
00048     SetButtons();
00049     //
00050     SetDefaultLUT();
00051     //
00052     SetHistogramColor( 0.9f, 0.6f, 0.0f, 0.4f );
00053     //
00054     GLubyte zero[256];
00055     for ( int i = 0; i < 256; ++i ) {
00056         zero[i] = 0;
00057     }
00058     LoadFreqsToHistogram( zero );
00059     SetClickXY( 0, 0 ); // for setting the click dot
00060                         // but this one make red button's status true
00061     m_ButtonRed.SetStatus( false ); // so set red button to false 
00062 }

void OpenGLCtrlTransferFn::Draw (  )  [virtual]

Draw Function

Implements OpenGLCtrl.

Definition at line 376 of file TAPsOpenGLCtrlTransferFn.cpp.

00377 {
00378     DrawBackgroundScale();
00379     DrawHistogram ();
00380     DrawIntensities();
00381     DrawColors();
00382     m_ButtonRed.Draw();
00383     m_ButtonGreen.Draw();
00384     m_ButtonBlue.Draw();
00385     m_ButtonAlpha.Draw();
00386 }

void OpenGLCtrlTransferFn::DrawBackgroundScale (  )  [protected]

Definition at line 542 of file TAPsOpenGLCtrlTransferFn.cpp.

00543 {
00544     DrawBackgroundAndBorder();
00545     //-----------------------------------------------------
00546     // Draw Big Scale Ticks
00547     {
00548         float stepX = (m_DrawSizeXY[0]) / 36.0;
00549         float stepY = (m_DrawSizeXY[1]) / 36.0;
00550         float startX = m_xyLowerLeftPt[0];
00551         float startY = m_xyLowerLeftPt[1];
00552         // Long Tick Length
00553         float endX0   = m_xyLowerLeftPt[0] + m_DrawSizeXY[0];
00554         float endY0   = m_xyLowerLeftPt[1] + m_DrawSizeXY[1];
00555         // Middle Tick Length
00556         float midTickLenX = m_DrawSizeXY[0]/28.0;
00557         float midTickLenY = m_DrawSizeXY[0]/28.0;
00558         float endX1   = m_xyLowerLeftPt[0] + midTickLenX;
00559         float endY1   = m_xyLowerLeftPt[1] + midTickLenY;
00560         float strX1   = endX0 - midTickLenX;
00561         float strY1   = endY0 - midTickLenY;
00562         // Short Tick Length
00563         float shortTickLenX = m_DrawSizeXY[0]/52.0;
00564         float shortTickLenY = m_DrawSizeXY[0]/52.0;
00565         float endX2   = m_xyLowerLeftPt[0] + shortTickLenX;
00566         float endY2   = m_xyLowerLeftPt[1] + shortTickLenY;
00567         float strX2   = endX0 - shortTickLenX;
00568         float strY2   = endY0 - shortTickLenY;
00569         glBegin( GL_LINES );
00570         //
00571         glColor4f( 0, 0, 0, m_BackgroundColor[3] );
00572         for ( int i = 0; i < 9; ++i ) {
00573             //
00574             // Vertical Long Tick
00575             glVertex2f( startX, m_xyLowerLeftPt[1] );
00576             glVertex2f( startX, endY0 );
00577             startX += stepX;
00578             // Vertical Short Tick
00579             glVertex2f( startX, m_xyLowerLeftPt[1] );
00580             glVertex2f( startX, endY2 );
00581             // Vertical Short Tick
00582             glVertex2f( startX, strY2 );
00583             glVertex2f( startX, endY0 );
00584             startX += stepX;
00585             // Vertical Middle Tick
00586             glVertex2f( startX, m_xyLowerLeftPt[1] );
00587             glVertex2f( startX, endY1 );
00588             // Vertical Middle Tick
00589             glVertex2f( startX, strY1 );
00590             glVertex2f( startX, endY0 );
00591             startX += stepX;
00592             // Vertical Short Tick
00593             glVertex2f( startX, m_xyLowerLeftPt[1] );
00594             glVertex2f( startX, endY2 );
00595             // Vertical Short Tick
00596             glVertex2f( startX, strY2 );
00597             glVertex2f( startX, endY0 );
00598             startX += stepX;
00599             //
00600             // Horizontal Long Tick
00601             glVertex2f( m_xyLowerLeftPt[0], startY );
00602             glVertex2f( endX0, startY );
00603             startY += stepY;
00604             // Horizontal Short Tick
00605             glVertex2f( m_xyLowerLeftPt[0], startY );
00606             glVertex2f( endX2, startY );
00607             // Horizontal Short Tick
00608             glVertex2f( strX2, startY );
00609             glVertex2f( endX0, startY );
00610             startY += stepY;
00611             // Horizontal Middle Tick
00612             glVertex2f( m_xyLowerLeftPt[0], startY );
00613             glVertex2f( endX1, startY );
00614             // Horizontal Middle Tick
00615             glVertex2f( strX1, startY );
00616             glVertex2f( endX0, startY );
00617             startY += stepY;
00618             // Horizontal Short Tick
00619             glVertex2f( m_xyLowerLeftPt[0], startY );
00620             glVertex2f( endX2, startY );
00621             // Horizontal Short Tick
00622             glVertex2f( strX2, startY );
00623             glVertex2f( endX0, startY );
00624             startY += stepY;
00625             //
00626         }
00627         // Vertical Long Tick
00628         glVertex2f( startX, m_xyLowerLeftPt[1] );
00629         glVertex2f( startX, endY0 );
00630         // Horizontal Long Tick
00631         glVertex2f( m_xyLowerLeftPt[0], startY );
00632         glVertex2f( endX0, startY );
00633         //
00634         glEnd();
00635     }
00636 }

void OpenGLCtrlTransferFn::DrawColors (  )  [protected]

Definition at line 406 of file TAPsOpenGLCtrlTransferFn.cpp.

00407 {
00408     glEnable( GL_TEXTURE_1D );
00409     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
00410     //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
00411     glBindTexture( GL_TEXTURE_1D, m_RGBA_1DTexture );
00412     glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00413     glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00414     glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
00415     //-------------------------------------------
00416     int startX = m_xyLowerLeftPt[0];
00417     int endX   = startX + m_DrawSizeXY[0];
00418     int startY = m_xyLowerLeftPt[1] + m_DrawSizeXY[1] + m_BorderSize;
00419     int w, h;
00420     m_ButtonRed.GetSize( w, h );
00421     int endY   = startY + h;
00422     glDisable( GL_TEXTURE_1D );
00423     glBegin( GL_QUADS );
00424         int midY = ( endY + startY ) / 2;
00425         glColor4f( 0, 0, 0, 1 );
00426         glVertex2i( startX, midY );
00427         glVertex2i( startX, startY );
00428         glVertex2i( endX, startY );
00429         glVertex2i( endX, midY );
00430         //
00431         glColor4f( 1, 1, 1, 1 );
00432         glVertex2i( startX, endY );
00433         glVertex2i( startX, midY );
00434         glVertex2i( endX, midY );
00435         glVertex2i( endX, endY );
00436     glEnd();
00437     //
00438     glEnable( GL_TEXTURE_1D );
00439     glBegin( GL_QUADS );
00440         glTexCoord1i( 0 );
00441         glVertex2i( startX, endY );
00442         glVertex2i( startX, startY );
00443         glTexCoord1i( 1 );
00444         glVertex2i( endX, startY );
00445         glVertex2i( endX, endY );
00446     glEnd();
00447     //-------------------------------------------
00448     glBindTexture( GL_TEXTURE_1D, 0 );
00449     glDisable( GL_TEXTURE_1D );
00450 }

void OpenGLCtrlTransferFn::DrawHistogram (  )  [protected]

Definition at line 388 of file TAPsOpenGLCtrlTransferFn.cpp.

00389 {
00390     GLfloat xStep = (m_DrawSizeXY[0]-1) / 255.0;
00391     GLfloat yStep = (m_DrawSizeXY[1]-1) / 255.0;
00392     //
00393     // Histogram
00394     GLfloat X = m_xyLowerLeftPt[0];
00395     glColor4fv( m_Histogram.histogramColor );
00396     glLineWidth( 1 );
00397     glBegin( GL_LINES );
00398     for ( int i = 0; i < 256; ++i ) {
00399         glVertex2i( X, m_xyLowerLeftPt[1] );
00400         glVertex2i( X, m_xyLowerLeftPt[1] + m_Histogram.normalizedFreqs[i]*yStep );
00401         X += xStep;
00402     }
00403     glEnd();
00404 }

void OpenGLCtrlTransferFn::DrawIntensities (  )  [protected]

Definition at line 452 of file TAPsOpenGLCtrlTransferFn.cpp.

00453 {
00457     //glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00458     //glBindTexture( GL_TEXTURE_1D, m_RGBA_1DTexture );
00460     //glGetTexImage( 
00461     //  GL_TEXTURE_1D,
00462     //  0,
00463     //  GL_RGBA,
00464     //  GL_UNSIGNED_BYTE,
00465     //  m_RGBA
00466     //);
00467     //TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00469     //glBindTexture( GL_TEXTURE_1D, 0 );
00472 
00473     //===============================================================
00474     // Draw Mark Point
00475     //---------------------------------------------------------------
00476     glPointSize( 5 );
00477     glColor4f( 0.5, 0.5, 0.0, 0.7 );
00478     glBegin( GL_POINTS );
00479         glVertex2i( m_clickX + m_xyLowerLeftPt[0], m_clickY + m_xyLowerLeftPt[1] );
00480     glEnd();
00481     //---------------------------------------------------------------
00482     //===============================================================
00483 
00484     //===============================================================
00485     // Draw RGBA Lines
00486     //---------------------------------------------------------------
00487     GLfloat xStep = (m_DrawSizeXY[0]-1) / 255.0;
00488     GLfloat yStep = (m_DrawSizeXY[1]-1) / 255.0;
00489     //
00490     //
00491     // Red
00492     GLfloat X = m_xyLowerLeftPt[0];
00493     glColor4f( 1, 0, 0, 0.8 );
00494     if ( m_ButtonRed.GetStatus() )  glLineWidth( 3 );
00495     else                            glLineWidth( 1 );
00496     glBegin( GL_LINE_STRIP );
00497     for ( int i = 0; i < 256; ++i ) {
00498         glVertex2i( X, m_xyLowerLeftPt[1] + m_RGBA[i][0]*yStep + 2 );
00499         X += xStep;
00500     }
00501     glEnd();
00502     //
00503     // Green
00504     X = m_xyLowerLeftPt[0];
00505     glColor4f( 0, 1, 0, 0.7 );
00506     if ( m_ButtonGreen.GetStatus() )    glLineWidth( 3 );
00507     else                                glLineWidth( 1 );
00508     glBegin( GL_LINE_STRIP );
00509     for ( int i = 0; i < 256; ++i ) {
00510         glVertex2f( X, m_xyLowerLeftPt[1] + m_RGBA[i][1]*yStep + 1 );
00511         X += xStep;
00512     }
00513     glEnd();
00514     //
00515     // Blue
00516     X = m_xyLowerLeftPt[0];
00517     glColor4f( 0, 0, 1, 0.9 );
00518     if ( m_ButtonBlue.GetStatus() ) glLineWidth( 3 );
00519     else                            glLineWidth( 1 );
00520     glBegin( GL_LINE_STRIP );
00521     for ( int i = 0; i < 256; ++i ) {
00522         glVertex2f( X, m_xyLowerLeftPt[1] + m_RGBA[i][2]*yStep );
00523         X += xStep;
00524     }
00525     glEnd();
00526     //
00527     // Alpha
00528     X = m_xyLowerLeftPt[0];
00529     glColor4f( 0.25, 0.25, 0.25, 0.9 );
00530     if ( m_ButtonAlpha.GetStatus() )    glLineWidth( 3 );
00531     else                                glLineWidth( 1 );
00532     glBegin( GL_LINE_STRIP );
00533     for ( int i = 0; i < 256; ++i ) {
00534         glVertex2f( X, m_xyLowerLeftPt[1] + m_RGBA[i][3]*yStep - 1 );
00535         X += xStep;
00536     }
00537     glEnd();
00538     //---------------------------------------------------------------
00539     //===============================================================
00540 }

OpenGLCtrlButton& OpenGLCtrlTransferFn::GetAlphaButton (  )  [inline]

Definition at line 48 of file TAPsOpenGLCtrlTransferFn.hpp.

00048 { return m_ButtonAlpha; }

OpenGLCtrlButton& OpenGLCtrlTransferFn::GetBlueButton (  )  [inline]

Definition at line 47 of file TAPsOpenGLCtrlTransferFn.hpp.

00047 { return m_ButtonBlue; }

OpenGLCtrlButton& OpenGLCtrlTransferFn::GetGreenButton (  )  [inline]

Definition at line 46 of file TAPsOpenGLCtrlTransferFn.hpp.

00046 { return m_ButtonGreen; }

void OpenGLCtrlTransferFn::GetHistogramColor ( float &  r,
float &  g,
float &  b,
float &  a 
) const

Get/Set histogram color.

Definition at line 248 of file TAPsOpenGLCtrlTransferFn.cpp.

00250 {
00251     r = m_Histogram.histogramColor[0];
00252     g = m_Histogram.histogramColor[1];
00253     b = m_Histogram.histogramColor[2];
00254     a = m_Histogram.histogramColor[3];
00255 }

OpenGLCtrlButton& OpenGLCtrlTransferFn::GetRedButton (  )  [inline]

Definition at line 45 of file TAPsOpenGLCtrlTransferFn.hpp.

00045 { return m_ButtonRed; }

bool OpenGLCtrlTransferFn::IsInside ( int  x,
int  y 
) [virtual]

Inquire whether the position is inside the object.

Reimplemented from OpenGLCtrl.

Definition at line 159 of file TAPsOpenGLCtrlTransferFn.cpp.

00160 {
00161     return 
00162          m_xyLowerLeftPt[0]-m_BorderSize <= x && x <= m_xyLowerLeftPt[0]+m_DrawSizeXY[0]+m_BorderSize
00163       && m_xyLowerLeftPt[1]-m_BorderSize <= y && y <= m_xyLowerLeftPt[1]+m_DrawSizeXY[1]+m_BorderSize;
00164 }

bool OpenGLCtrlTransferFn::IsInsidePlusBorder ( int  x,
int  y 
) [virtual]

Inquire whether the position is inside the object including its border.

Reimplemented from OpenGLCtrl.

Definition at line 166 of file TAPsOpenGLCtrlTransferFn.cpp.

00167 {
00168     return 
00169          m_xyLowerLeftPt[0]-m_BorderSize <= x && x <= m_xyLowerLeftPt[0]+m_DrawSizeXY[0]+m_BorderSize
00170       && m_xyLowerLeftPt[1]-m_BorderSize-30 <= y && y <= m_xyLowerLeftPt[1]+m_DrawSizeXY[1]+m_BorderSize;
00171 }

template<typename T>
void OpenGLCtrlTransferFn::LoadDataFrom ( data[256 *4],
bool  isDataNormalized 
) [inline]

Load (replace) data to the RGBA lookup table. This one will automatically call UpdateRGBA to update the RGBA after the loading. The load data can be normalized [0.0,1.0] (isDataNormalized == true) or unnormalized [0,255] (isDataNormalized == false).

Definition at line 191 of file TAPsOpenGLCtrlTransferFn.cpp.

00192 {
00193     //-- Data is normalized [0.0,1.0]
00194     if ( isDataNormalized ) {
00195         int idx = 0;
00196         for( i = 0; i < 256; ++i ) {
00197             m_RGBA[idx] = (GLubyte) ( data[idx++] * 255 );
00198             m_RGBA[idx] = (GLubyte) ( data[idx++] * 255 );
00199             m_RGBA[idx] = (GLubyte) ( data[idx++] * 255 );
00200             m_RGBA[idx] = (GLubyte) ( data[idx++] * 255 );
00201         }
00202     }
00203     //-- Data is unnormalized [0,255]
00204     else {
00205         int idx = 0;
00206         for( i = 0; i < 256; ++i ) {
00207             m_RGBA[idx] = data[idx++];
00208             m_RGBA[idx] = data[idx++];
00209             m_RGBA[idx] = data[idx++];
00210             m_RGBA[idx] = data[idx++];
00211         }
00212     }
00213 }

template<typename T>
void OpenGLCtrlTransferFn::LoadFreqsToHistogram ( freqs[256]  )  [inline]

Load and convert frequencies data into histogram.

Definition at line 216 of file TAPsOpenGLCtrlTransferFn.cpp.

00217 {
00218     // Find max frequency and total frequencies
00219     int i = 0;
00220     m_Histogram.totalFreqs  =
00221     m_Histogram.maxFreq     = freqs[i];
00222     for ( i = 1; i < 256; ++i ) {
00223         m_Histogram.totalFreqs += freqs[i];
00224         if ( static_cast<unsigned long int>( freqs[i] ) > m_Histogram.maxFreq ) {
00225             m_Histogram.maxFreq = freqs[i];
00226         }
00227     }
00228     // Record normalized frequencies
00229     double normalizationFactor = (double) m_Histogram.maxFreq / 255.0;
00230     if ( normalizationFactor > 0 ) {
00231         for( i = 0; i < 256; ++i ) {
00232             m_Histogram.normalizedFreqs[i] = 
00233                 static_cast<GLubyte>( (double) freqs[i] / normalizationFactor );
00234             //std::cout << i << ":\t" << (int)m_Histogram.normalizedFreqs[i] << "\t--> " << freqs[i] << "\n";
00235         }
00236         //std::cout << "normalizationFactor: " << normalizationFactor << "\n";
00237     }
00238     else {
00239         for( i = 0; i < 256; ++i ) {
00240             m_Histogram.normalizedFreqs[i] = 0.0;
00241             //std::cout << "i:\t" << (int)m_Histogram.normalizedFreqs[i] << "\t--> " << freqs[i] << "\n";
00242         }
00243     }
00244     //std::cout << "Max Freq: " << m_Histogram.maxFreq << "\n";
00245     //std::cout << "Tot Freq: " << m_Histogram.totalFreqs << "\n";
00246 }

void OpenGLCtrlTransferFn::SetButtons (  )  [protected]

Definition at line 80 of file TAPsOpenGLCtrlTransferFn.cpp.

00081 {
00082     //
00083     m_ButtonRed.SetText( "Red" );
00084     m_ButtonGreen.SetText( "Green" );
00085     m_ButtonBlue.SetText( "Blue" );
00086     m_ButtonAlpha.SetText( "Alpha" );
00087     //
00088     m_ButtonRed.SetBackgroundActColor( 1, 0, 0, 0.8 );
00089     m_ButtonGreen.SetBackgroundActColor( 0, 1, 0, 0.7 );
00090     m_ButtonBlue.SetBackgroundActColor( 0.1, 0.1, 1, 0.9 );
00091     m_ButtonAlpha.SetBackgroundActColor( 1, 1, 1, 0.7 );
00092     //
00093     m_ButtonRed.SetForegroundActColor( 0.1, 0, 0, 0.7 );
00094     m_ButtonGreen.SetForegroundActColor( 0, 0.1, 0, 0.7 );
00095     m_ButtonBlue.SetForegroundActColor( 0.8, 0.8, 1, 0.7 );
00096     m_ButtonAlpha.SetForegroundActColor( 0, 0, 0, 0.7 );
00097     //
00098     m_ButtonRed.SetBackgroundColor( 0.15, 0, 0, 0.7 );
00099     m_ButtonGreen.SetBackgroundColor( 0, 0.1, 0, 0.7 );
00100     m_ButtonBlue.SetBackgroundColor( 0, 0, 0.3, 0.7 );
00101     m_ButtonAlpha.SetBackgroundColor( 0, 0, 0, 0.7 );
00102     //
00103     m_ButtonRed.SetForegroundColor( 1, 0, 0, 0.7 );
00104     m_ButtonGreen.SetForegroundColor( 0, 0.7, 0, 0.7 );
00105     m_ButtonBlue.SetForegroundColor( 0, 0, 1, 0.7 );
00106     m_ButtonAlpha.SetForegroundColor( 0.6, 0.6, 0.6, 0.7 );
00107 }

bool OpenGLCtrlTransferFn::SetClickXY ( int  x,
int  y 
)

Inquire whether the position is inside the object. Handle mouse click inside the transform control

Definition at line 271 of file TAPsOpenGLCtrlTransferFn.cpp.

00272 {
00273     //
00274     if ( !IsInsidePlusBorder( x, y ) )  return false;
00275     //
00276     // Check Button Click
00277     if ( GetRedButton().IsInside( x, y ) ) {
00278         GetRedButton().ToggleStatus();
00279         return true;
00280     }
00281     if ( GetGreenButton().IsInside( x, y ) ) {
00282         GetGreenButton().ToggleStatus();
00283         return true;
00284     }
00285     if ( GetBlueButton().IsInside( x, y ) ) {
00286         GetBlueButton().ToggleStatus();
00287         return true;
00288     }
00289     if ( GetAlphaButton().IsInside( x, y ) ) {
00290         GetAlphaButton().ToggleStatus();
00291         return true;
00292     }
00293     //
00294     x -= m_xyLowerLeftPt[0];
00295     y -= m_xyLowerLeftPt[1];
00296     //
00297     if      ( x <   0 ) x =   0;
00298     else if ( x > 255 ) x = 255;
00299     if      ( y <   0 ) y =   0;
00300     else if ( y > 255 ) y = 255;
00301     //
00302     m_clickX = m_old_x = x;
00303     m_clickY = m_old_y = y;
00304     //
00305     return true;
00306 }

void OpenGLCtrlTransferFn::SetDefaultLUT (  )  [protected]

Definition at line 109 of file TAPsOpenGLCtrlTransferFn.cpp.

00110 {
00111     for ( int i = 0; i < 256; ++i ) {
00112         m_RGBA[i][0] = m_RGBA[i][1] = m_RGBA[i][2] = m_RGBA[i][3] = i;
00113     }
00114     if ( m_RGBA_1DTexture != 0 ) {
00115         glDeleteTextures( 1, &m_RGBA_1DTexture );
00116     }
00117     {
00118         //glEnable( GL_TEXTURE_1D );
00119         glGenTextures( 1, &m_RGBA_1DTexture );
00120         glBindTexture( GL_TEXTURE_1D, m_RGBA_1DTexture );
00121         glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00122         glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
00123         glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
00124         glTexImage1D( GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, 
00125             GL_UNSIGNED_BYTE, m_RGBA );
00126         glBindTexture( GL_TEXTURE_1D, 0 );
00127     }
00128 }

void OpenGLCtrlTransferFn::SetHistogramColor ( float  r,
float  g,
float  b,
float  a 
)

Definition at line 257 of file TAPsOpenGLCtrlTransferFn.cpp.

00259 {
00260     m_Histogram.histogramColor[0] = r;
00261     m_Histogram.histogramColor[1] = g;
00262     m_Histogram.histogramColor[2] = b;
00263     m_Histogram.histogramColor[3] = a;
00264 }

void OpenGLCtrlTransferFn::SetLUTToRampFn (  ) 

Currently the transfer function control supports only 256x256 size. So the SetSize function is overrided with "protected" modifier.

Definition at line 130 of file TAPsOpenGLCtrlTransferFn.cpp.

00131 {
00132     for ( int i = 0; i < 256; ++i ) {
00133         m_RGBA[i][0] = m_RGBA[i][1] = m_RGBA[i][2] = m_RGBA[i][3] = i;
00134     }
00135     UpdateRGBA();
00136 }

void OpenGLCtrlTransferFn::SetLUTToRandomFn (  ) 

Definition at line 138 of file TAPsOpenGLCtrlTransferFn.cpp.

00139 {
00140     srand ( time(NULL) );
00141     for ( int i = 0; i < 256; ++i ) {
00142         m_RGBA[i][0] = rand() % 256;
00143         m_RGBA[i][1] = rand() % 256;
00144         m_RGBA[i][2] = rand() % 256;
00145         m_RGBA[i][3] = rand() % 256;
00146     }
00147     UpdateRGBA();
00148 }

bool OpenGLCtrlTransferFn::SetLUTValuesToRamp (  ) 

Set the transfer function lookup table to ramp function.

bool OpenGLCtrlTransferFn::SetLUTValuesToRandom (  ) 

Set the transfer function lookup table to random function.

void OpenGLCtrlTransferFn::SetOpacity ( float  alpha  )  [virtual]

Set all alpha channels of this object, except the border alpha channel.

Reimplemented from OpenGLCtrl.

Definition at line 150 of file TAPsOpenGLCtrlTransferFn.cpp.

00151 {
00152     OpenGLCtrl::SetOpacity( alpha );
00153     m_ButtonRed.SetOpacity( alpha );
00154     m_ButtonGreen.SetOpacity( alpha );
00155     m_ButtonBlue.SetOpacity( alpha );
00156     m_ButtonAlpha.SetOpacity( alpha );
00157 }

void OpenGLCtrlTransferFn::SetStartPos ( int  x,
int  y 
) [virtual]

Reimplemented from OpenGLCtrl.

Definition at line 64 of file TAPsOpenGLCtrlTransferFn.cpp.

00065 {
00066     //x = x;
00067     //m_xyLowerLeftPt[0] = x;
00068     //m_xyLowerLeftPt[1] = y;
00069     //
00070     //int X = m_xyLowerLeftPt[0];
00071     m_ButtonRed.SetStartPos( x+10, y );
00072     m_ButtonGreen.SetStartPos( x+70, y );
00073     m_ButtonBlue.SetStartPos( x+130, y );
00074     m_ButtonAlpha.SetStartPos( x+190, y );
00075     //
00076     y += 30;
00077     OpenGLCtrl::SetStartPos( x, y );
00078 }

void OpenGLCtrlTransferFn::UpdateRGBA (  )  [protected]

Update the RGBA lookup table. This one is automatically called by ChangeLUTValues function and other methods that

Recommended Usage: with mouse click

Definition at line 173 of file TAPsOpenGLCtrlTransferFn.cpp.

00174 {
00175     //===============================================================
00176     // Write Transfer Function Look Up Table (Texture) to GPU
00177     //---------------------------------------------------------------
00178     glBindBuffer( GL_PIXEL_UNPACK_BUFFER, 0 );
00179     glBindTexture( GL_TEXTURE_1D, m_RGBA_1DTexture );
00180     //-------------------------------------------
00181     glTexImage1D( GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, 
00182         GL_UNSIGNED_BYTE, m_RGBA );
00183     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00184     //-------------------------------------------
00185     glBindTexture( GL_TEXTURE_1D, 0 );
00186     //---------------------------------------------------------------
00187     //===============================================================
00188 }


Member Data Documentation

Definition at line 195 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 194 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 193 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 192 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 211 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 211 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 206 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 212 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 212 of file TAPsOpenGLCtrlTransferFn.hpp.

GLubyte OpenGLCtrlTransferFn::m_RGBA[256][4] [protected]

Definition at line 197 of file TAPsOpenGLCtrlTransferFn.hpp.

Definition at line 208 of file TAPsOpenGLCtrlTransferFn.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Oct 13 11:45:43 2008 for TAPs by  doxygen 1.5.6