1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "bbmaracasvisuTransferFunctionView.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 namespace bbcreaMaracasVisu
31 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransferFunctionView)
32 BBTK_BLACK_BOX_IMPLEMENTATION(TransferFunctionView,bbtk::WxBlackBox);
34 //-----------------------------------------------------
35 void TransferFunctionView::Process()
42 if(bbGetInputIn()!=NULL){
44 if(_currentimg != bbGetInputIn()){
45 _currentimg = bbGetInputIn();
46 //mwxwidget->initializeHistogram(_currentimg);
47 mwxwidget->setImageData(_currentimg);
48 //mwxwidget->Refresh();
53 /*bbSetOutputGreyLevel(greylevel);
54 bbSetOutputValue(value);
55 bbSetOutputGreyLevelColors(greylevelcolors);
57 bbSetOutputGreen(green);
58 bbSetOutputBlue(blue);*/
68 void TransferFunctionView::onColorChange(){
70 std::vector<double> greylevel;
71 std::vector<double> value;
73 std::vector<double> greylevelcolors;
74 std::vector<double> red;
75 std::vector<double> green;
76 std::vector<double> blue;
78 mwxwidget->GetValuesPointsFunction(greylevel, value);
79 mwxwidget->GetValuesColorPointsFunction(greylevelcolors,red, green,blue);
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;
87 _ctfun->RemoveAllPoints();
88 _ctfun->SetScaleToLinear ();
89 _ctfun->ClampingOff();
90 _ctfun->AllowDuplicateScalarsOn();
91 double w=mwxwidget->GetWindowLevel();
92 double c=mwxwidget->GetColorLevel();
94 if (greylevelcolors.size()>1)
96 double min = greylevelcolors[0];
97 double max = greylevelcolors[greylevelcolors.size()-1];
99 if (dif==0) dif=0.0001;
103 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
104 for(i = 0; i < greylevelcolors.size();i++)
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;
111 i=greylevelcolors.size()-1;
112 _ctfun->AddRGBPoint( greylevelcolors[i] , red[i],green[i], blue[i]);
115 bbSignalOutputModification();
118 bbSetOutputOpacityFunction(_tfun);
119 bbSetOutputColorFunction(_ctfun);
122 void TransferFunctionView::onSliderChange()
128 bbSignalOutputModification();
131 // bbSetOutputWindowLevel(mwxwidget->GetWindowLevel());
132 // bbSetOutputColorLevel(mwxwidget->GetColorLevel());
136 //-----------------------------------------------------
137 void TransferFunctionView::CreateWidget(wxWindow* parent)
139 bbtkDebugMessageInc("Core",9,"TransferFunctionView::CreateWxWindow()"<<std::endl);
141 mwxwidget = new HistogramDialogComboBox(parent);
144 HandlerTransferFunctionView* handler = new HandlerTransferFunctionView(this);
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);
149 bbtkDebugDecTab("Core",9);
150 bbSetOutputWidget( mwxwidget );
153 //-----------------------------------------------------
155 void TransferFunctionView::bbUserSetDefaultValues()
163 bbSetOutputOpacityFunction(0);
164 bbSetOutputColorFunction(0);
169 //-----------------------------------------------------------------
170 void TransferFunctionView::bbUserInitializeProcessing()
172 _tfun = vtkPiecewiseFunction::New();
173 _ctfun = vtkColorTransferFunction::New();
174 _ctfun->SetClamping(-1);
178 //-----------------------------------------------------------------
179 void TransferFunctionView::bbUserFinalizeProcessing()
184 //-----------------------------------------------------------------
187 HandlerTransferFunctionView::HandlerTransferFunctionView(TransferFunctionView* box)
192 HandlerTransferFunctionView::~HandlerTransferFunctionView()
196 void HandlerTransferFunctionView::onColorChange(wxCommandEvent& event)
198 _box->onColorChange();
201 void HandlerTransferFunctionView::onSliderChange(wxCommandEvent& event)
203 _box->onSliderChange();
209 // EO namespace bbcreaMaracasVisu