]> Creatis software - bbtk.git/blob - packages/kw/src/bbkwTransferFunctionEditor.cxx
Feature #1774
[bbtk.git] / packages / kw / src / bbkwTransferFunctionEditor.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbkwTransferFunctionEditor.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:05 $
33   Version:   $Revision: 1.4 $
34 =========================================================================*/
35
36
37 /**
38  * \file 
39  * \brief Short description in one line
40  *
41  * Long 
42  * description
43  *  
44  */
45
46 #ifdef USE_KWWIDGETS
47
48 #include "bbkwTransferFunctionEditor.h"
49 #include "bbkwPackage.h"
50 //#include "bbtkUtilities.h"
51
52 #include "vtkKWPiecewiseFunctionEditor.h"
53 #include "vtkPointData.h"
54
55 //#include "vtkKWScale.h"
56 #include "vtkObjectFactory.h"
57 #include "vtkCommand.h"
58
59 namespace bbkw
60 {
61
62   //--------------------------------------------------------------------------
63   //-------------------------------------------------------------------------
64   // KwBlackBox implementation
65   //--------------------------------------------------------------------------
66   //--------------------------------------------------------------------------
67
68    //--------------------------------------------------------------------------
69   BBTK_BLACK_BOX_IMPLEMENTATION(TransferFunctionEditor,bbtk::KWBlackBox);
70   BBTK_ADD_BLACK_BOX_TO_PACKAGE(kw,TransferFunctionEditor);
71   
72   //--------------------------------------------------------------------------
73   void TransferFunctionEditor::bbUserConstructor() 
74   { 
75     bbSetInputIn(0);
76     bbSetOutputOut(0);
77     bbSetInputTitle("Transfer function");
78     bbSetOutputWidget(0);
79   }
80   
81  //--------------------------------------------------------------------------
82   void TransferFunctionEditor::Process() 
83   {
84     //    bbSetOutputOut( bbGetInputIn() );
85     vtkPiecewiseFunction* f = bbGetOutputOut();
86     if (!f) 
87       { 
88         f = vtkPiecewiseFunction::New();
89         bbSetOutputOut(f);
90       }
91   }
92   //--------------------------------------------------------------------------
93
94   //--------------------------------------------------------------------------
95   void TransferFunctionEditor::CreateWidget(vtkKWFrame* parent) 
96   {
97     vtkPiecewiseFunction* f = bbGetOutputOut();
98     if (!f) 
99       { 
100         f = vtkPiecewiseFunction::New();
101         bbSetOutputOut(f);
102       }
103
104     vtkKWPiecewiseFunctionEditor *w = vtkKWPiecewiseFunctionEditor::New();
105     bbSetOutputWidget(w);
106     w->AddObserver(vtkKWPiecewiseFunctionEditor::FunctionChangedEvent,this);
107     w->SetParent((vtkKWWidget*)parent);
108     w->Create();
109
110     w->SetBorderWidth(2);
111     w->SetReliefToGroove();
112     w->SetPadX(2);
113     w->SetPadY(2);
114     //    w->ExpandCanvasWidthOff();
115     //    w->ExpandCanvasHeightOn();
116   //    w->SetCanvasWidth(450);
117     w->SetCanvasHeight( parent->GetHeight() - 100 );
118     w->SetLabelText(bbGetInputTitle().c_str());
119     w->SetBalloonHelpString("Edit the transfer function");
120     w->LockEndPointsParameterOn();
121
122     w->PointIndexVisibilityOff();
123     w->SelectedPointIndexVisibilityOff();
124     w->MidPointVisibilityOff();
125     w->PointGuidelineVisibilityOff();
126     w->MidPointGuidelineVisibilityOff();
127     w->MidPointGuidelineValueVisibilityOff();
128     w->SetMidPointGuidelineValueFormat("%-#6.0f");
129     w->MidPointEntryVisibilityOff();
130     w->SharpnessEntryVisibilityOff();
131     w->SetLabelPositionToTop();
132
133     if ( bbGetInputIn()!=NULL ) 
134       {
135         vtkKWHistogram *h = vtkKWHistogram::New();
136         h->BuildHistogram( bbGetInputIn()->GetPointData()->GetScalars(), 0);
137         double *range = h->GetRange();
138         f->AddPoint(range[0], 0.0 );
139         f->AddPoint(range[1], 1.0 );
140         w->SetHistogram(h);
141         h->Delete();
142       }
143     else 
144       {
145         f->AddPoint(0.0, 0.0);
146         f->AddPoint(1.0, 1.0);  
147       }
148
149     w->SetPiecewiseFunction(f);
150
151     w->ParameterTicksVisibilityOn();
152     w->ComputeValueTicksFromHistogramOn();
153     w->SetParameterTicksFormat( w->GetMidPointGuidelineValueFormat());
154
155     w->Delete();
156     f->Delete();
157   
158   }
159   //--------------------------------------------------------------------------
160
161   //--------------------------------------------------------------------------
162       void TransferFunctionEditor::OnChange()
163
164       {
165         std::cout << "TransferFunctionEditor::OnChange()" << std::endl;
166       }
167   
168   void TransferFunctionEditor::Execute(vtkObject* caller, unsigned long , void*)
169   {
170     bbSignalOutputModification("Out");    
171     //  std::cout << "$$$$$$$$$$$$ TransferFunctionEditor CB $$$$$$$$$$$$"<<std::endl;
172     
173     /*
174     vtkKWScale* scale = (vtkKWScale*)caller;
175     bbSetOutputOut( scale->GetValue() );
176     bbSetInputIn( scale->GetValue() );
177     // and signal that the output has changed
178     bbSignalOutputModification("Out");    
179     */
180   } 
181   //--------------------------------------------------------------------------
182   
183
184
185 } //namespace bbkw
186
187 #endif // USE_KWWIDGETS
188
189