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 #include "mitkLabeledImageLookupTable.h"
00020 #include <vtkLookupTable.h>
00021 #include <cstdlib>
00022
00023
00027 mitk::LabeledImageLookupTable::LabeledImageLookupTable()
00028 : m_LevelWindow(128,256)
00029 {
00030 if ( m_LookupTable == NULL )
00031 {
00032 itkWarningMacro("LookupTable is NULL, it should have been initialized by the default constructor of mitk::LookupTable");
00033 m_LookupTable = vtkLookupTable::New();
00034 }
00035 m_LookupTable->SetNumberOfTableValues(256);
00036
00037
00038 m_LookupTable->SetTableValue( 0, 0.0, 0.0, 0.0, 0.0 );
00039
00040
00041
00042 vtkFloatingPointType r, g, b;
00043
00044
00045
00046
00047 std::srand( 2 );
00048 for ( vtkIdType index = 1 ; index < 256 ; ++index )
00049 {
00050 GenerateRandomColor(r, g, b);
00051 m_LookupTable->SetTableValue(index, r, g, b);
00052 }
00053
00054
00055
00056 m_LevelWindow.SetRangeMinMax(0,255);
00057 m_LevelWindow.SetWindowBounds(0,255);
00058 m_LevelWindow.SetFixed(true);
00059
00060 }
00061
00065 mitk::LabeledImageLookupTable::~LabeledImageLookupTable()
00066 {
00067
00068 }
00069
00070
00079 void mitk::LabeledImageLookupTable::SetColorForLabel ( const mitk::LabeledImageLookupTable::LabelType& label, const vtkFloatingPointType& r, const vtkFloatingPointType& g, const vtkFloatingPointType& b, const vtkFloatingPointType a )
00080 {
00081 if ( m_LookupTable == NULL )
00082 {
00083 itkWarningMacro("LookupTable is NULL, but it should have been initialized by the constructor");
00084 return;
00085 }
00086 m_LookupTable->SetTableValue(label, r, g, b, a);
00087 }
00088
00089
00090
00097 vtkFloatingPointType* mitk::LabeledImageLookupTable::GetColorForLabel ( const mitk::LabeledImageLookupTable::LabelType& label )
00098 {
00099 if ( m_LookupTable == NULL )
00100 {
00101 itkWarningMacro("LookupTable is NULL, but it should have been initialized by the constructor");
00102 return NULL;
00103 }
00104 return m_LookupTable->GetTableValue( label );
00105 }
00106
00107
00112 void mitk::LabeledImageLookupTable::GenerateRandomColor ( vtkFloatingPointType& r, vtkFloatingPointType& g, vtkFloatingPointType& b )
00113 {
00114 r = GenerateRandomNumber();
00115 g = GenerateRandomNumber();
00116 b = GenerateRandomNumber();
00117 }
00118
00119
00124 vtkFloatingPointType mitk::LabeledImageLookupTable::GenerateRandomNumber()
00125 {
00126 return ( ( ( vtkFloatingPointType ) ( std::rand( ) ) ) / ( ( vtkFloatingPointType ) ( RAND_MAX ) ) );
00127 }