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