]> Creatis software - creaMaracasVisu.git/blob - lib/Kernel/ITKVTK/itkvtkcolortransferfunction.txx
e3e044e6fa45bfeff8f77968d661f425ae73e7e3
[creaMaracasVisu.git] / lib / Kernel / ITKVTK / itkvtkcolortransferfunction.txx
1 #ifndef ITKVTKCOLORTRANSFERFUNCTION_TXX
2 #define ITKVTKCOLORTRANSFERFUNCTION_TXX
3
4 namespace itk{
5
6
7 template< class TypeImage>
8 VTKColorTransferFunction<TypeImage>::VTKColorTransferFunction()
9 {
10
11 }
12
13 template< class TypeImage>
14 VTKColorTransferFunction<TypeImage>::~VTKColorTransferFunction()
15 {
16     m_Output->Delete();
17 }
18
19 template< class TypeImage>
20 void VTKColorTransferFunction<TypeImage>::Update(){
21     GenerateOutputInformation();
22     GenerateData();
23 }
24
25 template< class TypeImage>
26 void VTKColorTransferFunction<TypeImage>::GenerateOutputInformation(){
27      m_Output = vtkColorTransferFunction::New();
28 }
29
30
31
32 template< class TypeImage>
33 void VTKColorTransferFunction<TypeImage>::GenerateData(){
34
35
36
37     InputImagePointerType imagergb = this->GetInput();
38
39     if(!imagergb){
40         itkExceptionMacro(<<"Set the image first!");
41     }
42
43
44     typedef itk::ImageRegionConstIterator< InputImageType > rgbiteratorType;
45     rgbiteratorType rgbit(imagergb, imagergb->GetLargestPossibleRegion());
46
47
48     rgbit.GoToBegin();
49
50
51     m_Output->RemoveAllPoints ();
52
53
54     while(!rgbit.IsAtEnd()){
55
56
57         typename InputImageType::PixelType::ComponentType lum = 0.299*rgbit.Get()[0] + 0.587*rgbit.Get()[1] + 0.114*rgbit.Get()[2];
58
59         m_Output->AddRGBPoint(lum, rgbit.Get()[0]/255.0, rgbit.Get()[1]/255.0, rgbit.Get()[2]/255.0);
60
61         ++rgbit;        
62
63     }
64
65
66
67
68 }
69
70 }
71 #endif