]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkBoxWidget.cxx
d0c60503176be0aa224a520ba9c567212497ce69
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkBoxWidget.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaVtkBoxWidget.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkRenderWindow.h"
8 #include "vtkCommand.h"
9 #include <vtkTransform.h>
10
11 namespace bbcreaVtk
12 {
13
14 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,BoxWidget)
15 BBTK_BLACK_BOX_IMPLEMENTATION(BoxWidget,bbtk::AtomicBlackBox);
16 //=====
17 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
18 //=====
19
20 class bbBoxWidgetCallback : public vtkCommand
21 {
22 public:
23     BoxWidget *_box;
24     static bbBoxWidgetCallback *New()
25     {
26         return new bbBoxWidgetCallback;
27     }
28     void SetBox( BoxWidget* box )
29     {
30         _box=box;
31     }
32     
33     void Execute(vtkObject *caller, unsigned long, void*) override
34     {
35         vtkBoxWidget *vtkwidget = reinterpret_cast<vtkBoxWidget*>(caller);
36         vtkwidget->GetPlanes( _box->planes );
37         vtkwidget->GetTransform( _box->transformOut );
38 //        _box->bbSignalOutputModification(std::string("ImplicitFunction"));
39         //        _box->bbSignalOutputModification(std::string("TransformOut"));
40         _box->bbSignalOutputModification();
41     }
42 };
43
44 //-----------------------------------------------------
45 //-----------------------------------------------------
46 //-----------------------------------------------------
47 //-----------------------------------------------------
48
49
50
51 void BoxWidget::SetTransform( vtkLinearTransform* transform )
52 {
53     if ( bbGetInputImageInitSize()!=NULL)
54     {
55         int     ext[6];
56         double  spc[3];
57         bbGetInputImageInitSize()->GetExtent( ext );
58         bbGetInputImageInitSize()->GetSpacing( spc );
59         boxWidget->PlaceWidget( ext[0]*spc[0] , ext[1]*spc[0] , ext[2]*spc[1] , ext[3]*spc[1] , ext[4]*spc[2] , ext[5]*spc[2] );
60         if (transform!=NULL)
61         {
62             boxWidget->SetTransform( (vtkTransform*)transform );
63             boxWidget->Modified();
64             boxWidget->GetPlanes( planes );
65         } // if
66     } else {
67         boxWidget->PlaceWidget(0,500,0,500,0,500);
68     }// if   ImageInitSize
69 }
70
71 void BoxWidget::Process()
72 {
73     
74     // THE MAIN PROCESSING METHOD BODY
75     //   Here we simply set the input 'In' value to the output 'Out'
76     //   And print out the output value
77     // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
78     //    void bbSet{Input|Output}NAME(const TYPE&)
79     //    const TYPE& bbGet{Input|Output}NAME() const
80     //    Where :
81     //    * NAME is the name of the input/output
82     //      (the one provided in the attribute 'name' of the tag 'input')
83     //    * TYPE is the C++ type of the input/output
84     //      (the one provided in the attribute 'type' of the tag 'input')
85     //    bbSetOutputOut( bbGetInputIn() );
86     //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
87     if ( bbGetInputRenderer()!=NULL )
88     {
89         if (firsttime==true)
90         {
91             firsttime   = false;
92             boxWidget   = vtkBoxWidget::New();
93             planes              = vtkPlanes::New();
94             transformOut= vtkTransform::New();
95             boxWidget->SetInteractor(  bbGetInputRenderer()->GetRenderWindow()->GetInteractor() );
96             SetTransform( bbGetInputTransformIn() );
97         } // if firsttime
98
99         //  boxWidget->SetProp3D(coneActor);
100         bbBoxWidgetCallback *callback = bbBoxWidgetCallback::New();
101         callback->SetBox( this );
102         boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
103         
104         if (bbGetInputActive()==true)
105         {
106             boxWidget->On();
107         }  else {
108             boxWidget->Off();
109         } // if Active
110         bbSetOutputImplicitFunction( planes );
111         boxWidget->GetTransform(transformOut);
112         bbSetOutputTransformOut( transformOut );
113     } else {
114         printf("EED Warnning! BoxWidget::Process vtkRenderer not set.\n");
115     }// vtkRenderer != NULL    
116     bbSetOutputBox_BoxWidget( this );
117 }
118 //=====
119 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
120 //=====
121 void BoxWidget::bbUserSetDefaultValues()
122 {
123     //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
124     //    Here we initialize the input 'In' to 0
125     firsttime=true;
126     bbSetInputRenderer(NULL);
127     bbSetInputTransformIn(NULL);
128     bbSetInputActive( false );
129     bbSetInputInitBoxChangeImage( false );
130     bbSetInputImageInitSize(NULL);
131     bbSetOutputTransformOut(NULL);
132 }
133
134 //=====
135 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
136 //=====
137 void BoxWidget::bbUserInitializeProcessing()
138 {
139     //  THE INITIALIZATION METHOD BODY :
140     //    Here does nothing
141     //    but this is where you should allocate the internal/output pointers
142     //    if any
143 }
144
145 //=====
146 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
147 //=====
148 void BoxWidget::bbUserFinalizeProcessing()
149 {
150     
151     //  THE FINALIZATION METHOD BODY :
152     //    Here does nothing
153     //    but this is where you should desallocate the internal/output pointers
154     //    if any
155 }
156
157 } // EO namespace bbcreaVtk
158
159