]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
01c53b7d29a11309c7169099f666f5d598a2d184
[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=delta*3;
90
91
92         for(i = minTot; i <= maxTot; i++)
93         {
94                 ii=i-minTot;
95                 if ((ii>=delta0) && (ii<=delta1)) // iBlue
96                 {
97                         thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 1);    
98                         if (ii==0)
99                         {
100                                 thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 0);    
101                         } else {
102                                 thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 1);    
103                         }
104                         iBlue++;
105                 }
106                 if ((ii>=delta1) && (ii<=delta2)) // iYellow
107                 {
108                         thresholdTable->SetTableValue( i , iYellow/delta , iYellow/delta , (delta-iYellow)/delta , 1);  
109                         iYellow++;
110                 }
111                 if ((ii>=delta2) && (ii<=delta3)) // iRed
112                 {
113                         thresholdTable->SetTableValue( i , 1 , (delta-iRed)/delta , 0 , 1);     
114                         iRed++;
115                 }
116         } // for
117
118         thresholdTable->Build( );
119
120 }
121
122
123
124
125 // EOF
126