]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuTransferFunctionView.cxx
#2844 creaMaracasVisu Feature New Normal - ManualPaint_model box, Refresh TransferF...
[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         if(bbGetInputIn()!=NULL)
38         {
39
40                 if(_currentimg != bbGetInputIn()){
41                         _currentimg =  bbGetInputIn();
42                         //mwxwidget->initializeHistogram(_currentimg);                  
43                         mwxwidget->setImageData(_currentimg);   
44                         //mwxwidget->Refresh(); 
45                 }               
46
47 //              onColorChange();
48                 /*
49                 bbSetOutputGreyLevel(greylevel);
50                 bbSetOutputValue(value);
51                 bbSetOutputGreyLevelColors(greylevelcolors);
52                 bbSetOutputRed(red);
53                 bbSetOutputGreen(green);
54                 bbSetOutputBlue(blue);
55                 */
56         } // if In
57 }
58
59 void TransferFunctionView::onColorChange()
60 {
61
62         std::vector<double> greylevel;
63         std::vector<double> value;
64
65         std::vector<double> greylevelcolors;
66         std::vector<double> red;
67         std::vector<double> green;
68         std::vector<double> blue;
69
70         mwxwidget->GetValuesPointsFunction(greylevel, value);
71         mwxwidget->GetValuesColorPointsFunction(greylevelcolors,red, green,blue);
72
73
74         _tfun->RemoveAllPoints();
75         unsigned int i;
76         for(i = 0; i < greylevel.size();i++){
77                 _tfun->AddPoint(greylevel[i], value[i]);
78                 std::cout<<"TransferFunctionView::Process()transfer function "<<greylevel[i]<<" "<< value[i]<<std::endl;
79         }
80         _ctfun->RemoveAllPoints();
81         _ctfun->SetScaleToLinear ();
82         _ctfun->ClampingOff();
83         _ctfun->AllowDuplicateScalarsOn();
84         double w=mwxwidget->GetWindowLevel();
85         double c=mwxwidget->GetColorLevel();
86
87         if (greylevelcolors.size()>1)
88         {
89             double min = greylevelcolors[0];
90                 double max = greylevelcolors[greylevelcolors.size()-1];
91                 double dif = max-min;
92                 if (dif==0) dif=0.0001;
93                 double nc;
94                 unsigned int i;
95                 i=0;
96                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
97                 for(i = 0; i < greylevelcolors.size();i++)
98                 {
99                         nc = ((greylevelcolors[i]-min)/dif)*w + c-w/2;
100 //                      _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
101                         _ctfun->AddRGBPoint( nc , red[i],green[i], blue[i]);
102                 std::cout<<"EED TransferFunctionView::Process()transfer color function <<"<<nc<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
103                 }
104                 i=greylevelcolors.size()-1;
105                 _ctfun->AddRGBPoint( greylevelcolors[i] , red[i],green[i], blue[i]);
106         }               
107
108         
109         _tfun->Update();
110         bbSetOutputOpacityFunction(_tfun);
111         bbSetOutputColorFunction(_ctfun );
112         bbSetOutputActive( mwxwidget->GetActive() );
113
114         bbSignalOutputModification();
115
116 }
117
118 void TransferFunctionView::onSliderChange()
119         {
120         
121                 //EED
122                 onColorChange();
123
124                 bbSignalOutputModification();
125
126 printf("EED TransferFunctionView::onSliderChange  ---------------------  \n");
127
128 //      bbSetOutputWindowLevel(mwxwidget->GetWindowLevel());
129 //      bbSetOutputColorLevel(mwxwidget->GetColorLevel());
130
131 }
132
133 /*
134 //-----------------------------------------------------
135 void TransferFunctionView::onActive()
136 {
137         bbSignalOutputModification();
138
139    printf("EED TransferFunctionView::onActive popopopopopopopop \n");
140 }
141 */
142
143 //-----------------------------------------------------
144 void TransferFunctionView::CreateWidget(wxWindow* parent)
145 {
146         bbtkDebugMessageInc("Core",9,"TransferFunctionView::CreateWxWindow()"<<std::endl);      
147         mwxwidget = new HistogramDialogComboBox(parent);                                
148         HandlerTransferFunctionView* handler = new HandlerTransferFunctionView(this);
149 //      parent->Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction) (&HandlerTransferFunctionView::onActive),NULL,handler);
150         parent->Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction) (&HandlerTransferFunctionView::onColorChange),NULL,handler);
151         parent->Connect(mwxwidget->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) (&HandlerTransferFunctionView::onSliderChange),NULL,handler);
152         bbSetOutputWidget( mwxwidget );                         
153     bbtkDebugDecTab("Core",9);
154 }
155
156 //-----------------------------------------------------
157
158 void TransferFunctionView::bbUserSetDefaultValues()
159 {
160         mwxwidget       = NULL;
161         _currentimg = NULL;
162         _tfun           = NULL;
163         _ctfun          = NULL;   
164         bbSetOutputOpacityFunction(0);
165         bbSetOutputColorFunction(0);
166 }
167         
168         //-----------------------------------------------------------------     
169         void TransferFunctionView::bbUserInitializeProcessing()
170         {
171                 _tfun = vtkPiecewiseFunction::New();
172                 _ctfun = vtkColorTransferFunction::New();  
173                 _ctfun->SetClamping(-1);
174                 bbSetInputIn(NULL);
175         }
176         
177         //-----------------------------------------------------------------     
178         void TransferFunctionView::bbUserFinalizeProcessing()
179         {
180         }
181
182         //-----------------------------------------------------------------     
183         HandlerTransferFunctionView::HandlerTransferFunctionView(TransferFunctionView* box)
184         {
185                 _box = box;             
186         }
187         
188         HandlerTransferFunctionView::~HandlerTransferFunctionView()
189         {
190         }       
191         
192         void HandlerTransferFunctionView::onColorChange(wxCommandEvent& event)
193         {
194                 _box->onColorChange();
195         }
196         
197         void HandlerTransferFunctionView::onSliderChange(wxCommandEvent& event)
198         {
199                 _box->onSliderChange();
200         }
201
202 /*
203         void HandlerTransferFunctionView::onActive(wxCommandEvent& event)
204         {
205                 _box->onActive();
206         }
207 */
208
209 }
210
211 // EO namespace bbcreaMaracasVisu
212
213