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