]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
- new version
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ColorLayerImageView.cxx
1
2 /**
3  *  \file 
4  *  \brief Class bbtk::ThresholdImageView . 
5  */
6
7 #include "ColorLayerImageView.h"
8
9 #include <vtkImageReslice.h>
10 #include <vtkLookupTable.h>
11 #include <vtkImageData.h>
12
13
14   //=========================================================================
15   //=========================================================================
16   //=========================================================================
17   //=========================================================================
18         ColorLayerImageView::ColorLayerImageView( )
19   {
20           _z2                   =       0;
21           _fix_dinamic  =       true;
22   }
23
24   //=========================================================================
25   ColorLayerImageView::~ColorLayerImageView()
26   {
27   }
28   //=========================================================================
29
30
31 //----------------------------------------------------------------------------
32 void ColorLayerImageView::SetSliceFixDinamic(bool fix_dinamic)
33 {
34         _fix_dinamic = fix_dinamic;
35 }
36
37 //----------------------------------------------------------------------------
38 void ColorLayerImageView::SetZ2(int z2)  
39 {
40         _z2 = z2;
41 }
42
43 //----------------------------------------------------------------------------
44 int ColorLayerImageView::GetZ() // virtual 
45 {
46         int result=0;
47         if (_fix_dinamic==false)
48         {
49                 result = _z2;
50         } else  {
51                 result = LayerImageBase::GetZ();
52         }  
53
54         return result;
55 }
56
57
58 //----------------------------------------------------------------------------
59 void ColorLayerImageView::ConfigLookupTable()  // virtual
60 {
61         double range[2];
62         
63         GetImage()->GetScalarRange(range);
64         if (range[1]==0)
65         {
66                 range[1]=255;
67         }
68         
69         int minTot = floor (range[0]);
70         int maxTot = ceil (range[1]);
71         
72
73         vtkLookupTable* thresholdTable = GetThresholdTable();
74         thresholdTable->SetNumberOfTableValues(maxTot+1);
75         thresholdTable->SetTableRange(range); 
76         thresholdTable->SetAlphaRange(0, 1);
77         thresholdTable->SetValueRange(0, 1);
78         thresholdTable->SetSaturationRange(0, 0); 
79         thresholdTable->SetRampToLinear( );
80
81         //Assign a fake color for the upper image, and set the white as transparent
82         int i,ii;
83         double iBlue=0 , iYellow=0 , iRed=0;
84         double delta=(maxTot-minTot)/3.0;
85
86         double delta0=delta*0;
87         double delta1=delta*1;
88         double delta2=delta*2;
89         double delta3=maxTot;  
90
91         for(i = minTot; i <= maxTot; i++)
92         {
93                 ii=i-minTot;
94                 if ((ii>=delta0) && (ii<=delta1)) // iBlue
95                 {
96                         thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 1);    
97                         if (ii==0)
98                         {
99                                 thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 0);    
100                         } else {
101                                 thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 1);    
102                         }
103                         iBlue++;
104                 }
105                 if ((ii>=delta1) && (ii<=delta2)) // iYellow
106                 {
107                         thresholdTable->SetTableValue( i , iYellow/delta , iYellow/delta , (delta-iYellow)/delta , 1);  
108                         iYellow++;
109                 }
110                 if ((ii>=delta2) && (ii<=delta3)) // iRed
111                 {
112                         thresholdTable->SetTableValue( i ,  1, (delta-iRed)/delta , 0 , 1);     
113                         iRed++;
114                 }
115         } // for
116
117         thresholdTable->Build( );
118
119 }
120
121
122
123
124 // EOF
125