]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuTransferFunctionView.cxx
d829ab0132116d39157955adbe22a68fee364fa6
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuTransferFunctionView.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "bbmaracasvisuTransferFunctionView.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 namespace bbcreaMaracasVisu
29 {
30
31 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransferFunctionView)
32 BBTK_BLACK_BOX_IMPLEMENTATION(TransferFunctionView,bbtk::WxBlackBox);
33
34 //-----------------------------------------------------
35 void TransferFunctionView::Process()
36 {
37
38         
39
40         
41
42         if(bbGetInputIn()!=NULL){
43
44                 if(_currentimg != bbGetInputIn()){
45                         _currentimg =  bbGetInputIn();
46                         //mwxwidget->initializeHistogram(_currentimg);                  
47                         mwxwidget->setImageData(_currentimg);   
48                         //mwxwidget->Refresh(); 
49                 }               
50
51                 onColorChange();
52                 
53                 /*bbSetOutputGreyLevel(greylevel);
54                 bbSetOutputValue(value);
55                 bbSetOutputGreyLevelColors(greylevelcolors);
56                 bbSetOutputRed(red);
57                 bbSetOutputGreen(green);
58                 bbSetOutputBlue(blue);*/
59
60
61
62
63         }
64         
65     
66 }
67
68 void TransferFunctionView::onColorChange(){
69
70         std::vector<double> greylevel;
71         std::vector<double> value;
72
73         std::vector<double> greylevelcolors;
74         std::vector<double> red;
75         std::vector<double> green;
76         std::vector<double> blue;
77
78         mwxwidget->GetValuesPointsFunction(greylevel, value);
79         mwxwidget->GetValuesColorPointsFunction(greylevelcolors,red, green,blue);
80
81
82         _tfun->RemoveAllPoints();
83         for(int i = 0; i < greylevel.size();i++){
84                 _tfun->AddPoint(greylevel[i], value[i]);
85                 std::cout<<"TransferFunctionView::Process()transfer function "<<greylevel[i]<<" "<< value[i]<<std::endl;
86         }
87         _ctfun->RemoveAllPoints();
88         _ctfun->SetScaleToLinear ();
89         _ctfun->ClampingOff();
90         _ctfun->AllowDuplicateScalarsOn();
91         double w=mwxwidget->GetWindowLevel();
92         double c=mwxwidget->GetColorLevel();
93
94         if (greylevelcolors.size()>1)
95         {
96             double min = greylevelcolors[0];
97                 double max = greylevelcolors[greylevelcolors.size()-1];
98                 double dif = max-min;
99                 if (dif==0) dif=0.0001;
100                 double nc;
101                 int i;
102                 i=0;
103                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
104                 for(i = 0; i < greylevelcolors.size();i++)
105                 {
106                         nc = ((greylevelcolors[i]-min)/dif)*w + c-w/2;
107 //                      _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
108                         _ctfun->AddRGBPoint( nc , red[i],green[i], blue[i]);
109                 std::cout<<"EED TransferFunctionView::Process()transfer color function <<"<<nc<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
110                 }
111                 i=greylevelcolors.size()-1;
112                 _ctfun->AddRGBPoint( greylevelcolors[i] , red[i],green[i], blue[i]);
113         }               
114
115         bbSignalOutputModification();
116         
117         _tfun->Update();
118         bbSetOutputOpacityFunction(_tfun);
119         bbSetOutputColorFunction(_ctfun);
120 }
121
122 void TransferFunctionView::onSliderChange()
123         {
124         
125                 //EED
126                 onColorChange();
127
128                 bbSignalOutputModification();
129
130
131 //      bbSetOutputWindowLevel(mwxwidget->GetWindowLevel());
132 //      bbSetOutputColorLevel(mwxwidget->GetColorLevel());
133
134 }
135
136 //-----------------------------------------------------
137 void TransferFunctionView::CreateWidget(wxWindow* parent)
138 {
139         bbtkDebugMessageInc("Core",9,"TransferFunctionView::CreateWxWindow()"<<std::endl);
140         
141         mwxwidget = new HistogramDialogComboBox(parent);                                
142
143
144         HandlerTransferFunctionView* handler = new HandlerTransferFunctionView(this);
145
146         parent->Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction) (&HandlerTransferFunctionView::onColorChange),NULL,handler);
147         parent->Connect(mwxwidget->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) (&HandlerTransferFunctionView::onSliderChange),NULL,handler);
148
149     bbtkDebugDecTab("Core",9);
150         bbSetOutputWidget( mwxwidget );                         
151 }
152
153 //-----------------------------------------------------
154
155 void TransferFunctionView::bbUserSetDefaultValues()
156 {
157         mwxwidget = NULL;
158         _currentimg = NULL;
159
160         _tfun = NULL;
161         _ctfun = NULL;   
162
163         bbSetOutputOpacityFunction(0);
164         bbSetOutputColorFunction(0);
165
166 }
167
168         
169         //-----------------------------------------------------------------     
170         void TransferFunctionView::bbUserInitializeProcessing()
171         {
172                 _tfun = vtkPiecewiseFunction::New();
173                 _ctfun = vtkColorTransferFunction::New();  
174                 _ctfun->SetClamping(-1);
175                 bbSetInputIn(NULL);
176         }
177         
178         //-----------------------------------------------------------------     
179         void TransferFunctionView::bbUserFinalizeProcessing()
180         {
181         }
182
183                 
184         //-----------------------------------------------------------------     
185         
186
187         HandlerTransferFunctionView::HandlerTransferFunctionView(TransferFunctionView* box)
188         {
189                 _box = box;             
190         }
191         
192         HandlerTransferFunctionView::~HandlerTransferFunctionView()
193         {
194         }       
195         
196         void HandlerTransferFunctionView::onColorChange(wxCommandEvent& event)
197         {
198                 _box->onColorChange();
199         }
200         
201         void HandlerTransferFunctionView::onSliderChange(wxCommandEvent& event)
202         {
203                 _box->onSliderChange();
204         }
205
206 }
207
208
209 // EO namespace bbcreaMaracasVisu
210
211