]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkBoxWidget.cxx
#3289 creaVtk Feature New Normal - bbcreaVtkBoxWidget init box
[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
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                 _box->bbSignalOutputModification(std::string("ImplicitFunction"));
38         }
39  };
40
41
42
43 void BoxWidget::Process()
44 {
45
46 // THE MAIN PROCESSING METHOD BODY
47 //   Here we simply set the input 'In' value to the output 'Out'
48 //   And print out the output value
49 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
50 //    void bbSet{Input|Output}NAME(const TYPE&)
51 //    const TYPE& bbGet{Input|Output}NAME() const 
52 //    Where :
53 //    * NAME is the name of the input/output
54 //      (the one provided in the attribute 'name' of the tag 'input')
55 //    * TYPE is the C++ type of the input/output
56 //      (the one provided in the attribute 'type' of the tag 'input')
57 //    bbSetOutputOut( bbGetInputIn() );
58 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
59   
60
61         if ( bbGetInputRenderer()!=NULL )
62         {
63                 if (firsttime==true)
64                 {       
65                         firsttime       = false;
66                         boxWidget       = vtkBoxWidget::New();
67                         planes          = vtkPlanes::New();
68                         boxWidget->SetInteractor(  bbGetInputRenderer()->GetRenderWindow()->GetInteractor() );
69                         boxWidget->SetPlaceFactor(1.25);
70                         if (bbGetInputImageInitSize()!=NULL)
71                         {
72                                 int ext[6];
73                                 bbGetInputImageInitSize()->GetExtent( ext );
74                                 double spc[3];
75                                 bbGetInputImageInitSize()->GetSpacing( spc );
76                                 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] );
77                         } else {
78                                 boxWidget->PlaceWidget(0,500,0,500,0,500);
79                         }// if   ImageInitSize  
80                         boxWidget->GetPlanes( planes );
81                 } // if firsttime
82          
83         //  boxWidget->SetProp3D(coneActor);
84                 bbBoxWidgetCallback *callback = bbBoxWidgetCallback::New();
85                 callback->SetBox( this );
86                 boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
87
88                 if (bbGetInputActive()==true)
89                 {
90                         boxWidget->On();
91                 }  else {
92                         boxWidget->Off();
93                 } // if Active
94                 bbSetOutputImplicitFunction( planes );
95         } else {
96                 printf("EED Warnning! BoxWidget::Process vtkRenderer not set.\n");
97         }// vtkRenderer != NULL
98
99 }
100 //===== 
101 // 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)
102 //===== 
103 void BoxWidget::bbUserSetDefaultValues()
104 {
105
106 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
107 //    Here we initialize the input 'In' to 0
108         firsttime=true;
109     bbSetInputRenderer(NULL);
110     bbSetInputActive( false );
111     bbSetInputImageInitSize(NULL);
112 }
113 //===== 
114 // 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)
115 //===== 
116 void BoxWidget::bbUserInitializeProcessing()
117 {
118
119 //  THE INITIALIZATION METHOD BODY :
120 //    Here does nothing 
121 //    but this is where you should allocate the internal/output pointers 
122 //    if any 
123
124   
125 }
126 //===== 
127 // 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)
128 //===== 
129 void BoxWidget::bbUserFinalizeProcessing()
130 {
131
132 //  THE FINALIZATION METHOD BODY :
133 //    Here does nothing 
134 //    but this is where you should desallocate the internal/output pointers 
135 //    if any
136   
137 }
138 }
139 // EO namespace bbcreaVtk
140
141