]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkBoxWidget.cxx
#3523 Add to BoxWidget box Transform option
[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     
117     bbSetOutputBox_BoxWidget( this );
118
119     printf("EED  BoxWidget::Process A\n");
120
121     
122 }
123 //=====
124 // 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)
125 //=====
126 void BoxWidget::bbUserSetDefaultValues()
127 {
128     //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
129     //    Here we initialize the input 'In' to 0
130     firsttime=true;
131     bbSetInputRenderer(NULL);
132     bbSetInputTransformIn(NULL);
133     bbSetInputActive( false );
134     bbSetInputInitBoxChangeImage( false );
135     bbSetInputImageInitSize(NULL);
136     bbSetOutputTransformOut(NULL);
137 }
138
139 //=====
140 // 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)
141 //=====
142 void BoxWidget::bbUserInitializeProcessing()
143 {
144     //  THE INITIALIZATION METHOD BODY :
145     //    Here does nothing
146     //    but this is where you should allocate the internal/output pointers
147     //    if any
148 }
149
150 //=====
151 // 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)
152 //=====
153 void BoxWidget::bbUserFinalizeProcessing()
154 {
155     
156     //  THE FINALIZATION METHOD BODY :
157     //    Here does nothing
158     //    but this is where you should desallocate the internal/output pointers
159     //    if any
160 }
161
162 } // EO namespace bbcreaVtk
163
164