Public Member Functions

ScalarGradientCompute< T > Class Template Reference

List of all members.

Public Member Functions

 ScalarGradientCompute (T *_dataPtr, unsigned char *_tmpPtr, unsigned char *_tmpPtr2, int _sizeX, int _sizeY, int _sizeZ, int _fullX, int _fullY, int _fullZ, float _offset, float _scale)
float sample (int x, int y, int z)
void fill (int x, int y, int z)
int clamp (int x)
void write (int x, int y, int z, float grayValue, float gx, float gy, float gz)
void compute (int x, int y, int z)
void computeClamp (int x, int y, int z)
void compute1D (int y, int z)
void fill1D (int y, int z)
void computeClamp1D (int y, int z)
void computeClamp2D (int z)
void compute2D (int z)
void fill2D (int z)
void fillSlices (int currentChunkStart, int currentChunkEnd)

Detailed Description

template<class T>
class ScalarGradientCompute< T >

Definition at line 722 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.


Constructor & Destructor Documentation

template<class T>
ScalarGradientCompute< T >::ScalarGradientCompute ( T *  _dataPtr,
unsigned char *  _tmpPtr,
unsigned char *  _tmpPtr2,
int  _sizeX,
int  _sizeY,
int  _sizeZ,
int  _fullX,
int  _fullY,
int  _fullZ,
float  _offset,
float  _scale 
) [inline]

Definition at line 748 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

  {
    dataPtr=_dataPtr;
    tmpPtr=_tmpPtr;
    tmpPtr2=_tmpPtr2;
    sizeX=_sizeX;
    sizeY=_sizeY;
    sizeZ=_sizeZ;
    fullX=_fullX;
    fullY=_fullY;
    fullZ=_fullZ;
    offset=_offset;
    scale=_scale;

    sizeXY=sizeX*sizeY;
    sizeXm1=sizeX-1;
    sizeYm1=sizeY-1;
    sizeZm1=sizeZ-1;
    
    fullXY=fullX*fullY;
  }

Member Function Documentation

template<class T>
int ScalarGradientCompute< T >::clamp ( int  x ) [inline]

Definition at line 790 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

Referenced by ScalarGradientCompute< T >::write().

  {
    if(x<0) x=0; else if(x>255) x=255;
    return x;
  }
template<class T>
void ScalarGradientCompute< T >::compute ( int  x,
int  y,
int  z 
) [inline]

Definition at line 857 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::sample(), and ScalarGradientCompute< T >::write().

Referenced by ScalarGradientCompute< T >::compute1D().

  {
    float grayValue = sample(x,y,z);
    float gx,gy,gz;

    gx = sample(x+1,y,z) - sample(x-1,y,z);
    gy = sample(x,y+1,z) - sample(x,y-1,z);
    gz = sample(x,y,z+1) - sample(x,y,z-1);
    
    write( x, y, z, grayValue, gx, gy, gz );
 
  }
template<class T>
void ScalarGradientCompute< T >::compute1D ( int  y,
int  z 
) [inline]

Definition at line 890 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::compute(), ScalarGradientCompute< T >::computeClamp(), and ScalarGradientCompute< T >::fill().

Referenced by ScalarGradientCompute< T >::compute2D().

  {
    int x;
    
    x=0;
    computeClamp(x,y,z);
    x++;
    
    while(x<sizeX-1)
    {
      compute(x,y,z);     
      x++;
    }
    
    if(x<sizeX)
    {
      computeClamp(x,y,z);
      x++;
    }

    while(x<fullX)
    {
      fill(x,y,z);
      x++;
    }
  }      
template<class T>
void ScalarGradientCompute< T >::compute2D ( int  z ) [inline]

Definition at line 968 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::compute1D(), ScalarGradientCompute< T >::computeClamp1D(), and ScalarGradientCompute< T >::fill1D().

Referenced by ScalarGradientCompute< T >::fillSlices().

  {
    int y;

    y=0;
    computeClamp1D(y,z);     
    y++;
    
    while(y<sizeY-1)
    {
      compute1D(y,z);     
      y++;
    }
    
    if(y<sizeY)
    {
      computeClamp1D(y,z);
      y++;
    }

    while(y<fullY)
    {
      fill1D(y,z);
      y++;
    }      
  }
template<class T>
void ScalarGradientCompute< T >::computeClamp ( int  x,
int  y,
int  z 
) [inline]

Definition at line 870 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::sample(), and ScalarGradientCompute< T >::write().

Referenced by ScalarGradientCompute< T >::compute1D(), and ScalarGradientCompute< T >::computeClamp1D().

  {
    float grayValue = sample(x,y,z);
    float gx,gy,gz;

    if(x==0)            gx = 2.0f * ( sample(x+1,y,z) - grayValue       );
    else if(x==sizeXm1) gx = 2.0f * ( grayValue       - sample(x-1,y,z) );
    else                gx =          sample(x+1,y,z) - sample(x-1,y,z);
    
    if(y==0)            gy = 2.0f * ( sample(x,y+1,z) - grayValue       );
    else if(y==sizeYm1) gy = 2.0f * ( grayValue       - sample(x,y-1,z) );
    else                gy =          sample(x,y+1,z) - sample(x,y-1,z);
    
    if(z==0)            gz = 2.0f * ( sample(x,y,z+1) - grayValue       );
    else if(z==sizeZm1) gz = 2.0f * ( grayValue       - sample(x,y,z-1) );
    else                gz =          sample(x,y,z+1) - sample(x,y,z-1);
    
    write( x, y, z, grayValue, gx, gy, gz );
  }
template<class T>
void ScalarGradientCompute< T >::computeClamp1D ( int  y,
int  z 
) [inline]

Definition at line 930 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::computeClamp(), and ScalarGradientCompute< T >::fill().

Referenced by ScalarGradientCompute< T >::compute2D(), and ScalarGradientCompute< T >::computeClamp2D().

  {
    int x;
    
    x=0;
    
    while(x<sizeX)
    {
      computeClamp(x,y,z);     
      x++;
    }

    while(x<fullX)
    {
      fill(x,y,z);
      x++;
    }
  }      
template<class T>
void ScalarGradientCompute< T >::computeClamp2D ( int  z ) [inline]

Definition at line 949 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::computeClamp1D(), and ScalarGradientCompute< T >::fill1D().

Referenced by ScalarGradientCompute< T >::fillSlices().

  {
    int y;

    y=0;

    while(y<sizeY)
    {
      computeClamp1D(y,z);     
      y++;
    }
    
    while(y<fullY)
    {
      fill1D(y,z);
      y++;
    }      
  }
template<class T>
void ScalarGradientCompute< T >::fill ( int  x,
int  y,
int  z 
) [inline]

Definition at line 775 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

Referenced by ScalarGradientCompute< T >::compute1D(), ScalarGradientCompute< T >::computeClamp1D(), and ScalarGradientCompute< T >::fill1D().

  {
    int doff = x + y * fullX + (z-offZ) * fullXY;
    
    tmpPtr[doff*4+0]= 0;
    tmpPtr[doff*4+1]= 0;
    tmpPtr[doff*4+2]= 0;
    tmpPtr[doff*4+3]= 0;
          /*
    tmpPtr2[doff*3+0]= 0;
    tmpPtr2[doff*3+1]= 0;
    tmpPtr2[doff*3+2]= 0;       
    */
  }
template<class T>
void ScalarGradientCompute< T >::fill1D ( int  y,
int  z 
) [inline]
template<class T>
void ScalarGradientCompute< T >::fill2D ( int  z ) [inline]

Definition at line 995 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::fill1D().

Referenced by ScalarGradientCompute< T >::fillSlices().

  {
    int y;

    y=0;
    while(y<fullY)
    {
      fill1D(y,z);
      y++;
    }      
  }
template<class T>
void ScalarGradientCompute< T >::fillSlices ( int  currentChunkStart,
int  currentChunkEnd 
) [inline]

Definition at line 1007 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::compute2D(), ScalarGradientCompute< T >::computeClamp2D(), and ScalarGradientCompute< T >::fill2D().

Referenced by vtkVolumeTextureMapper3DComputeScalars().

  {
    offZ=currentChunkStart;

/*
    int num = omp_get_num_procs();
    MITK_INFO << "omp uses " << num << " processors";
*/

    #pragma omp parallel for
    for(int z=currentChunkStart;z<=currentChunkEnd;z++)
    {
      if(z==0 || z==sizeZ-1)
        computeClamp2D(z);
      else if(z>=sizeZ)
        fill2D(z);
      else
        compute2D(z);
    }
  }    
template<class T>
float ScalarGradientCompute< T >::sample ( int  x,
int  y,
int  z 
) [inline]

Definition at line 770 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

Referenced by ScalarGradientCompute< T >::compute(), and ScalarGradientCompute< T >::computeClamp().

  {
    return float(dataPtr[ x + y * sizeX + z * sizeXY ]);
  }
template<class T>
void ScalarGradientCompute< T >::write ( int  x,
int  y,
int  z,
float  grayValue,
float  gx,
float  gy,
float  gz 
) [inline]

Definition at line 796 of file vtkMitkOpenGLVolumeTextureMapper3D.cpp.

References ScalarGradientCompute< T >::clamp(), and QuadProgPP::t().

Referenced by ScalarGradientCompute< T >::compute(), and ScalarGradientCompute< T >::computeClamp().

  {
  
 /*       
    gx /= aspect[0];
    gy /= aspect[1];
    gz /= aspect[2];
 */
    // Compute the gradient magnitude

    int iGrayValue = static_cast<int>( (grayValue + offset) * scale + 0.5f );

    gx *= scale;
    gy *= scale;
    gz *= scale;

    float t = sqrtf( gx*gx + gy*gy + gz*gz );

    if ( t > 0.01f )
    {
      if( t < 2.0f )
      {
        float fac = 2.0f/t;
        gx *= fac;
        gy *= fac;
        gz *= fac;
      } 
      else if( t > 255.0f)
      {
        float fac = 255.0f/t;
        gx *= fac;
        gy *= fac;
        gz *= fac;
      } 
    }
    else
    {
      gx=gy=gz=0.0f;
    }

    int nx = static_cast<int>(0.5f*gx+127.5f);
    int ny = static_cast<int>(0.5f*gy+127.5f);
    int nz = static_cast<int>(0.5f*gz+127.5f);
    
    int doff = x + y * fullX + (z-offZ) * fullXY;
    
    //tmpPtr[doff*2+0]= 0;
       
    tmpPtr[doff*4+0]= clamp(nx);
    tmpPtr[doff*4+1]= clamp(ny);
    tmpPtr[doff*4+2]= clamp(nz);       
    tmpPtr[doff*4+3]= clamp(iGrayValue);

/*
    if( z == fullZ/2 )
    if( y == fullY/2 )
      MITK_INFO << x << " " << y << " " << z << " : " << iGrayValue << " : " << iGradient;
  */  
  }

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines