]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx
7907cdf98c0f505f8399713ebfc4b9c4f937250d
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ThresholdImageView.cxx
1
2 /**
3  *  \file 
4  *  \brief Class bbtk::ThresholdImageView . 
5  */
6
7 #include "ThresholdImageView.h"
8 #include <vtkImageReslice.h>
9 #include <vtkLookupTable.h>
10 #include <vtkImageData.h>
11
12
13   //=========================================================================
14   //=========================================================================
15   //=========================================================================
16   //=========================================================================
17         ThresholdImageView::ThresholdImageView( )
18   {
19           _minValue                                     =       0;
20           _maxValue                                     =       1000;
21           _baseColorR                           =       1;
22           _baseColorG                           =       0;
23           _baseColorB                           =       0;
24   }
25
26   //=========================================================================
27   ThresholdImageView::~ThresholdImageView()
28   {
29   }
30   //=========================================================================
31
32
33
34 //----------------------------------------------------------------------------
35 void ThresholdImageView::SetminMaxValue(int min, int max)
36 {
37         _minValue = min;
38         _maxValue = max;
39 }
40
41
42 //----------------------------------------------------------------------------
43 void ThresholdImageView::ConfigLookupTable()  // virtual
44 {
45         double range[2];
46         
47         GetImage()->GetScalarRange(range);
48         if (range[1]==0)
49         {
50                 range[1]=255;
51         }
52         
53         int minTot = floor (range[0]);
54         int maxTot = ceil (range[1]);
55         
56         int minVal = floor (_minValue);
57         int maxVal = floor (_maxValue);
58
59         vtkLookupTable* thresholdTable = GetThresholdTable();
60         thresholdTable->SetNumberOfTableValues(maxTot+1);
61         thresholdTable->SetTableRange(range); 
62         thresholdTable->SetAlphaRange(0, 1);
63         thresholdTable->SetValueRange(0, 1);
64         thresholdTable->SetSaturationRange(0, 0); 
65         thresholdTable->SetRampToLinear( );
66
67         //Assign a fake color for the upper image, and set the white as transparent
68         int i;
69         for(i = minTot; i <= maxTot; i++)
70         {
71                 if( i >= minVal && i <= maxVal )
72                 {
73                         thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
74                 }
75                 else if( i >= minTot && i < minVal )
76                 {
77                         thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
78                 }
79                 else if( i > maxVal && i < maxTot )
80                 {
81                         thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
82                 }
83                 else
84                 {
85                         thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
86                 }
87         } // for
88         thresholdTable->Build( );
89
90 }
91
92
93 //----------------------------------------------------------------------------
94 void ThresholdImageView::SetBaseColor(double r, double g, double b)
95 {
96         _baseColorR = r;
97         _baseColorG = g;
98         _baseColorB = b;
99 }
100
101
102 // EOF
103