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()
37 if(bbGetInputIn()!=NULL)
40 // if(_currentimg != bbGetInputIn())
42 _currentimg = bbGetInputIn();
43 //mwxwidget->initializeHistogram(_currentimg);
44 mwxwidget->setImageData(_currentimg);
45 //mwxwidget->Refresh();
50 bbSetOutputGreyLevel(greylevel);
51 bbSetOutputValue(value);
52 bbSetOutputGreyLevelColors(greylevelcolors);
54 bbSetOutputGreen(green);
55 bbSetOutputBlue(blue);
60 void TransferFunctionView::onColorChange()
63 std::vector<double> greylevel;
64 std::vector<double> value;
66 std::vector<double> greylevelcolors;
67 std::vector<double> red;
68 std::vector<double> green;
69 std::vector<double> blue;
71 mwxwidget->GetValuesPointsFunction(greylevel, value);
72 mwxwidget->GetValuesColorPointsFunction(greylevelcolors,red, green,blue);
75 _tfun->RemoveAllPoints();
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;
81 _ctfun->RemoveAllPoints();
82 _ctfun->SetScaleToLinear ();
83 _ctfun->ClampingOff();
84 _ctfun->AllowDuplicateScalarsOn();
85 double w=mwxwidget->GetWindowLevel();
86 double c=mwxwidget->GetColorLevel();
88 if (greylevelcolors.size()>1)
90 double min = greylevelcolors[0];
91 double max = greylevelcolors[greylevelcolors.size()-1];
93 if (dif==0) dif=0.0001;
97 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
98 for(i = 0; i < greylevelcolors.size();i++)
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;
105 i=greylevelcolors.size()-1;
106 _ctfun->AddRGBPoint( greylevelcolors[i] , red[i],green[i], blue[i]);
109 //EED 2017-01-01 Migration VTK7
110 #if VTK_MAJOR_VERSION <= 5
115 bbSetOutputOpacityFunction(_tfun);
116 bbSetOutputColorFunction(_ctfun );
117 bbSetOutputActive( mwxwidget->GetActive() );
119 bbSignalOutputModification();
123 void TransferFunctionView::onSliderChange()
126 bbSignalOutputModification();
127 // bbSetOutputWindowLevel(mwxwidget->GetWindowLevel());
128 // bbSetOutputColorLevel(mwxwidget->GetColorLevel());
132 //-----------------------------------------------------
133 void TransferFunctionView::CreateWidget(wxWindow* parent)
135 bbtkDebugMessageInc("Core",9,"TransferFunctionView::CreateWxWindow()"<<std::endl);
136 mwxwidget = new HistogramDialogComboBox(parent);
137 HandlerTransferFunctionView* handler = new HandlerTransferFunctionView(this);
138 // parent->Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction) (&HandlerTransferFunctionView::onActive),NULL,handler);
139 parent->Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction) (&HandlerTransferFunctionView::onColorChange),NULL,handler);
140 parent->Connect(mwxwidget->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) (&HandlerTransferFunctionView::onSliderChange),NULL,handler);
141 bbSetOutputWidget( mwxwidget );
142 bbtkDebugDecTab("Core",9);
145 //-----------------------------------------------------
147 void TransferFunctionView::bbUserSetDefaultValues()
153 bbSetOutputOpacityFunction(0);
154 bbSetOutputColorFunction(0);
157 //-----------------------------------------------------------------
158 void TransferFunctionView::bbUserInitializeProcessing()
160 _tfun = vtkPiecewiseFunction::New();
161 _ctfun = vtkColorTransferFunction::New();
162 _ctfun->SetClamping(-1);
166 //-----------------------------------------------------------------
167 void TransferFunctionView::bbUserFinalizeProcessing()
171 //-----------------------------------------------------------------
172 HandlerTransferFunctionView::HandlerTransferFunctionView(TransferFunctionView* box)
177 HandlerTransferFunctionView::~HandlerTransferFunctionView()
181 void HandlerTransferFunctionView::onColorChange(wxCommandEvent& event)
183 _box->onColorChange();
186 void HandlerTransferFunctionView::onSliderChange(wxCommandEvent& event)
188 _box->onSliderChange();
193 // EO namespace bbcreaMaracasVisu