]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuTransferFunctionView.cxx
c02ccc6f7820ea06211bb84a7b8cb2a80cceebab
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuTransferFunctionView.cxx
1 #include "bbmaracasvisuTransferFunctionView.h"
2 #include "bbcreaMaracasVisuPackage.h"
3 namespace bbcreaMaracasVisu
4 {
5
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransferFunctionView)
7 BBTK_BLACK_BOX_IMPLEMENTATION(TransferFunctionView,bbtk::WxBlackBox);
8
9 //-----------------------------------------------------
10 void TransferFunctionView::Process()
11 {
12
13         
14
15         
16
17         if(bbGetInputIn()!=NULL){
18
19                 if(_currentimg != bbGetInputIn()){
20                         _currentimg =  bbGetInputIn();
21                         //mwxwidget->initializeHistogram(_currentimg);                  
22                         mwxwidget->setImageData(_currentimg);   
23                         //mwxwidget->Refresh(); 
24                 }               
25
26                 onColorChange();
27                 
28                 /*bbSetOutputGreyLevel(greylevel);
29                 bbSetOutputValue(value);
30                 bbSetOutputGreyLevelColors(greylevelcolors);
31                 bbSetOutputRed(red);
32                 bbSetOutputGreen(green);
33                 bbSetOutputBlue(blue);*/
34
35
36
37
38         }
39         
40     
41 }
42
43 void TransferFunctionView::onColorChange(){
44
45         std::vector<double> greylevel;
46         std::vector<double> value;
47
48         std::vector<double> greylevelcolors;
49         std::vector<double> red;
50         std::vector<double> green;
51         std::vector<double> blue;
52
53         mwxwidget->GetValuesPointsFunction(greylevel, value);
54         mwxwidget->GetValuesColorPointsFunction(greylevelcolors,red, green,blue);
55
56
57         _tfun->RemoveAllPoints();
58         for(int i = 0; i < greylevel.size();i++){
59                 _tfun->AddPoint(greylevel[i], value[i]);
60                 std::cout<<"TransferFunctionView::Process()transfer function "<<greylevel[i]<<" "<< value[i]<<std::endl;
61         }
62         _ctfun->RemoveAllPoints();
63         _ctfun->SetScaleToLinear ();
64         _ctfun->ClampingOff();
65         _ctfun->AllowDuplicateScalarsOn();
66         double w=mwxwidget->GetWindowLevel();
67         double c=mwxwidget->GetColorLevel();
68
69         if (greylevelcolors.size()>1)
70         {
71             double min = greylevelcolors[0];
72                 double max = greylevelcolors[greylevelcolors.size()-1];
73                 double dif = max-min;
74                 if (dif==0) dif=0.0001;
75                 double nc;
76                 int i;
77                 i=0;
78                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
79                 for(i = 0; i < greylevelcolors.size();i++)
80                 {
81                         nc = ((greylevelcolors[i]-min)/dif)*w + c-w/2;
82 //                      _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
83                         _ctfun->AddRGBPoint( nc , red[i],green[i], blue[i]);
84                 std::cout<<"EED TransferFunctionView::Process()transfer color function <<"<<nc<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
85                 }
86                 i=greylevelcolors.size()-1;
87                 _ctfun->AddRGBPoint( greylevelcolors[i] , red[i],green[i], blue[i]);
88         }               
89
90         bbSignalOutputModification();
91         
92         _tfun->Update();
93         bbSetOutputOpacityFunction(_tfun);
94         bbSetOutputColorFunction(_ctfun);
95 }
96
97 void TransferFunctionView::onSliderChange()
98         {
99         
100                 //EED
101                 onColorChange();
102
103                 bbSignalOutputModification();
104
105
106 //      bbSetOutputWindowLevel(mwxwidget->GetWindowLevel());
107 //      bbSetOutputColorLevel(mwxwidget->GetColorLevel());
108
109 }
110
111 //-----------------------------------------------------
112 void TransferFunctionView::CreateWidget(wxWindow* parent)
113 {
114         bbtkDebugMessageInc("Core",9,"TransferFunctionView::CreateWxWindow()"<<std::endl);
115         
116         mwxwidget = new HistogramDialogComboBox(parent);                                
117
118
119         HandlerTransferFunctionView* handler = new HandlerTransferFunctionView(this);
120
121         parent->Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction) (&HandlerTransferFunctionView::onColorChange),NULL,handler);
122         parent->Connect(mwxwidget->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) (&HandlerTransferFunctionView::onSliderChange),NULL,handler);
123
124     bbtkDebugDecTab("Core",9);
125         bbSetOutputWidget( mwxwidget );                         
126 }
127
128 //-----------------------------------------------------
129
130 void TransferFunctionView::bbUserSetDefaultValues()
131 {
132         mwxwidget = NULL;
133         _currentimg = NULL;
134
135         _tfun = NULL;
136         _ctfun = NULL;   
137
138         bbSetOutputOpacityFunction(0);
139         bbSetOutputColorFunction(0);
140
141 }
142
143         
144         //-----------------------------------------------------------------     
145         void TransferFunctionView::bbUserInitializeProcessing()
146         {
147                 _tfun = vtkPiecewiseFunction::New();
148                 _ctfun = vtkColorTransferFunction::New();  
149                 _ctfun->SetClamping(-1);
150                 bbSetInputIn(NULL);
151         }
152         
153         //-----------------------------------------------------------------     
154         void TransferFunctionView::bbUserFinalizeProcessing()
155         {
156         }
157
158                 
159         //-----------------------------------------------------------------     
160         
161
162         HandlerTransferFunctionView::HandlerTransferFunctionView(TransferFunctionView* box)
163         {
164                 _box = box;             
165         }
166         
167         HandlerTransferFunctionView::~HandlerTransferFunctionView()
168         {
169         }       
170         
171         void HandlerTransferFunctionView::onColorChange(wxCommandEvent& event)
172         {
173                 _box->onColorChange();
174         }
175         
176         void HandlerTransferFunctionView::onSliderChange(wxCommandEvent& event)
177         {
178                 _box->onSliderChange();
179         }
180
181 }
182
183
184 // EO namespace bbcreaMaracasVisu
185
186