1 /*=========================================================================
3 Module: $RCSfile: bbkwTransferFunctionEditor.cxx,v $
5 Date: $Date: 2008/12/18 11:54:57 $
6 Version: $Revision: 1.3 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
33 * \brief Short description in one line
42 #include "bbkwTransferFunctionEditor.h"
43 #include "bbkwPackage.h"
44 //#include "bbtkUtilities.h"
46 #include "vtkKWPiecewiseFunctionEditor.h"
47 #include "vtkPointData.h"
49 //#include "vtkKWScale.h"
50 #include "vtkObjectFactory.h"
51 #include "vtkCommand.h"
56 //--------------------------------------------------------------------------
57 //-------------------------------------------------------------------------
58 // KwBlackBox implementation
59 //--------------------------------------------------------------------------
60 //--------------------------------------------------------------------------
62 //--------------------------------------------------------------------------
63 BBTK_BLACK_BOX_IMPLEMENTATION(TransferFunctionEditor,bbtk::KWBlackBox);
64 BBTK_ADD_BLACK_BOX_TO_PACKAGE(kw,TransferFunctionEditor);
66 //--------------------------------------------------------------------------
67 void TransferFunctionEditor::bbUserConstructor()
71 bbSetInputTitle("Transfer function");
75 //--------------------------------------------------------------------------
76 void TransferFunctionEditor::Process()
78 // bbSetOutputOut( bbGetInputIn() );
79 vtkPiecewiseFunction* f = bbGetOutputOut();
82 f = vtkPiecewiseFunction::New();
86 //--------------------------------------------------------------------------
88 //--------------------------------------------------------------------------
89 void TransferFunctionEditor::CreateWidget(vtkKWFrame* parent)
91 vtkPiecewiseFunction* f = bbGetOutputOut();
94 f = vtkPiecewiseFunction::New();
98 vtkKWPiecewiseFunctionEditor *w = vtkKWPiecewiseFunctionEditor::New();
100 w->AddObserver(vtkKWPiecewiseFunctionEditor::FunctionChangedEvent,this);
101 w->SetParent((vtkKWWidget*)parent);
104 w->SetBorderWidth(2);
105 w->SetReliefToGroove();
108 // w->ExpandCanvasWidthOff();
109 // w->ExpandCanvasHeightOn();
110 // w->SetCanvasWidth(450);
111 w->SetCanvasHeight( parent->GetHeight() - 100 );
112 w->SetLabelText(bbGetInputTitle().c_str());
113 w->SetBalloonHelpString("Edit the transfer function");
114 w->LockEndPointsParameterOn();
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();
127 if ( bbGetInputIn()!=NULL )
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 );
139 f->AddPoint(0.0, 0.0);
140 f->AddPoint(1.0, 1.0);
143 w->SetPiecewiseFunction(f);
145 w->ParameterTicksVisibilityOn();
146 w->ComputeValueTicksFromHistogramOn();
147 w->SetParameterTicksFormat( w->GetMidPointGuidelineValueFormat());
153 //--------------------------------------------------------------------------
155 //--------------------------------------------------------------------------
156 void TransferFunctionEditor::OnChange()
159 std::cout << "TransferFunctionEditor::OnChange()" << std::endl;
162 void TransferFunctionEditor::Execute(vtkObject* caller, unsigned long , void*)
164 bbSignalOutputModification("Out");
165 // std::cout << "$$$$$$$$$$$$ TransferFunctionEditor CB $$$$$$$$$$$$"<<std::endl;
168 vtkKWScale* scale = (vtkKWScale*)caller;
169 bbSetOutputOut( scale->GetValue() );
170 bbSetInputIn( scale->GetValue() );
171 // and signal that the output has changed
172 bbSignalOutputModification("Out");
175 //--------------------------------------------------------------------------
181 #endif // USE_KWWIDGETS