Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <Pipeline/cmtkImageToImageRGB.h>
00034
00035 namespace
00036 cmtk
00037 {
00038
00041
00042 ImageToImageRGB::ImageToImageRGB() :
00043 CheckerboxPadding( true )
00044 {
00045 this->m_Image = NULL;
00046 this->m_Colormap = NULL;
00047 AlphaMode = AlphaModeNone;
00048
00049 this->RegisterInput( &this->m_Image );
00050 this->RegisterInput( &this->m_Colormap );
00051 }
00052
00053 ImageToImageRGB::~ImageToImageRGB()
00054 {
00055 if ( this->m_Image )
00056 this->m_Image->Unregister();
00057 if ( this->m_Colormap )
00058 this->m_Colormap->Unregister();
00059 }
00060
00061 void ImageToImageRGB::SetInput( Image *const image )
00062 {
00063 this->ReplaceObject( this->m_Image, image );
00064 }
00065
00066 void ImageToImageRGB::SetColormap( Colormap *const colormap )
00067 {
00068 this->ReplaceObject( this->m_Colormap, colormap );
00069 }
00070
00071 void ImageToImageRGB::Execute()
00072 {
00073 if ( (this->m_Image == NULL) || (this->m_Colormap == NULL) ) return;
00074 const TypedArray *inPtr = this->m_Image->GetData();
00075 if ( !inPtr ) return;
00076
00077 ImageRGB *output = this->GetOutput();
00078 output->CopyStructure( this->m_Image );
00079
00080 if ( AlphaMode == AlphaModeNone )
00081 output->SetAlphaChannel( IMAGE_RGB );
00082 else
00083 output->SetAlphaChannel( IMAGE_RGBA );
00084
00085 void *outPtr = output->GetDataPtr( true );
00086
00087 switch ( AlphaMode )
00088 {
00089 case AlphaModeNone:
00090 this->m_Colormap->Apply( outPtr, inPtr );
00091 if ( inPtr->GetPaddingFlag() )
00092 this->MarkPaddingData( output->GetDims( AXIS_X ), output->GetDims( AXIS_Y ), static_cast<RGB*>( outPtr ), inPtr );
00093 break;
00094 case AlphaModeConst:
00095 this->m_Colormap->Apply( outPtr, inPtr, true );
00096 if ( inPtr->GetPaddingFlag() )
00097 this->MarkPaddingData( output->GetDims( AXIS_X ), output->GetDims( AXIS_Y ), static_cast<RGBA*>( outPtr ), inPtr );
00098 break;
00099 }
00100
00101 this->UpdateExecuteTime();
00102 }
00103
00104 template<class T>
00105 void
00106 ImageToImageRGB::MarkPaddingData
00107 ( const unsigned int dimsx, const unsigned int dimsy, T *const rgba, const TypedArray* data ) const
00108 {
00109 T* p = rgba;
00110 unsigned int idx = 0;
00111
00112 byte bright = 170;
00113 byte dark = 80;
00114 if ( !this->CheckerboxPadding )
00115 bright = dark = 0;
00116
00117 for ( unsigned int y = 0; y < dimsy; ++y )
00118 {
00119 for ( unsigned int x = 0; x < dimsx; ++x, ++idx, ++p )
00120 {
00121 if ( data->PaddingDataAt( idx ) )
00122 {
00123 if ( ((x >> 4)&1) ^ ((y >> 4)&1) )
00124 {
00125 p->R = p->G = p->B = bright;
00126 }
00127 else
00128 {
00129 p->R = p->G = p->B = dark;
00130 }
00131 }
00132 }
00133 }
00134 }
00135
00136 }