]> Creatis software - clitk.git/blob - vv/vvToolTest.cxx
Merge branch 'VTK6_Qt5_Overlay4D' into VTK6_Qt5_Binarize
[clitk.git] / vv / vvToolTest.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 // vv
20 #include "vvToolTest.h"
21 #include "vvSlicerManager.h"
22 #include "vvSlicer.h"
23 #include "vvToolInputSelectorWidget.h"
24
25 // clitk
26 #include "clitkBinarizeImageGenericFilter.h"
27
28 // vtk
29 #include <vtkImageActor.h>
30 #include <vtkCamera.h>
31 #include <vtkImageClip.h>
32 #include <vtkRenderWindow.h>
33 #include <vtkPolyDataMapper.h>
34 #include <vtkRenderer.h>
35 #include <vtkSphereSource.h>
36 #include <vtkProperty.h>
37
38
39 //------------------------------------------------------------------------------
40 // Create the tool and automagically (I like this word) insert it in
41 // the main window menu.
42 ADD_TOOL(vvToolTest);
43 //------------------------------------------------------------------------------
44
45
46 //------------------------------------------------------------------------------
47 void vvToolTest::Initialize()
48 { cout << __func__ << endl;
49   SetToolName("Test");
50   SetToolMenuName("Test");
51   SetToolIconFilename(":/common/icons/binarize.png");
52   SetToolTip("try to display a sphere.");
53 }
54 //------------------------------------------------------------------------------
55
56
57 //------------------------------------------------------------------------------
58 vvToolTest::vvToolTest(vvMainWindowBase * parent, Qt::WindowFlags f)
59   :vvToolWidgetBase(parent,f),
60    vvToolBase<vvToolTest>(parent),
61    Ui::vvToolTest()
62 { cout << __func__ << endl;
63   // GUI Initialization
64
65   // Connect signals & slots
66   
67   // Main filter
68   mFilter = clitk::BinarizeImageGenericFilter::New();
69
70   // Set how many inputs are needed for this tool
71   AddInputSelector("Select one image", mFilter);
72 }
73 //------------------------------------------------------------------------------
74
75
76 //------------------------------------------------------------------------------
77 vvToolTest::~vvToolTest()
78 { cout << __func__ << endl;
79 }
80 //------------------------------------------------------------------------------
81
82
83 //------------------------------------------------------------------------------
84 /*
85 void vvToolTest::InteractiveDisplayToggled(bool b)
86 { cout << __func__ << endl;
87   mInteractiveDisplayIsEnabled = b;
88   if (!mInteractiveDisplayIsEnabled) {
89     RemoveVTKObjects();
90   } else {
91     for(unsigned int i=0; i<mImageContour.size(); i++) {
92       mImageContour[i]->ShowActors();
93       if (mRadioButtonLowerThan->isChecked())
94         mImageContourLower[i]->ShowActors();
95     }
96     if (mCurrentSlicerManager)
97       mCurrentSlicerManager->Render();
98   }
99 }
100 */
101 //------------------------------------------------------------------------------
102
103
104 //------------------------------------------------------------------------------
105
106 //------------------------------------------------------------------------------
107
108
109 //------------------------------------------------------------------------------
110 bool vvToolTest::close()
111 { cout << __func__ << endl;
112   return vvToolWidgetBase::close();
113 }
114 //------------------------------------------------------------------------------
115
116
117 //------------------------------------------------------------------------------
118
119 //------------------------------------------------------------------------------
120
121
122 //------------------------------------------------------------------------------
123 void vvToolTest::reject()
124 { cout << __func__ << endl;
125   // DD("vvToolBinarize::reject");
126   return vvToolWidgetBase::reject();
127 }
128 //------------------------------------------------------------------------------
129
130
131 //------------------------------------------------------------------------------
132
133 //------------------------------------------------------------------------------
134
135
136 //------------------------------------------------------------------------------
137
138 //------------------------------------------------------------------------------
139
140
141 //------------------------------------------------------------------------------
142
143 void vvToolTest::InputIsSelected(vvSlicerManager * m)
144 { cout << __func__ << endl;
145   mCurrentSlicerManager = m;
146
147
148   vtkSmartPointer<vtkSphereSource> sphereSource = 
149       vtkSmartPointer<vtkSphereSource>::New();
150   sphereSource->SetCenter(0, 0, 0);
151   //sphereSource->SetCenter(235.351, 175.781, 141.0);
152   sphereSource->SetRadius(10.0);
153   sphereSource->Update();
154   vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
155       vtkSmartPointer<vtkPolyDataMapper>::New();
156   sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
157   vtkSmartPointer<vtkActor> sphereActor = 
158       vtkSmartPointer<vtkActor>::New();
159   sphereActor->SetMapper(sphereMapper);
160   sphereActor->GetProperty()->SetColor(1.0, 0.0, 0.0);
161   sphereActor->GetProperty()->SetOpacity(0.995);
162   sphereActor->SetPosition(235.351, 175.781, -10);
163   
164   
165   // VTK Renderer
166   vtkSmartPointer<vtkRenderer> sphereRenderer = 
167       vtkSmartPointer<vtkRenderer>::New();
168   // Add Actor to renderer
169   for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
170     mCurrentSlicerManager->GetSlicer(i)->GetRenderer()->AddActor(sphereActor);
171   }
172   //sphereRenderer->AddActor(sphereActor); //mettre le vvSlicer
173    
174   // VTK/Qt wedded
175   //this->qvtkWidgetLeft->GetRenderWindow()->AddRenderer(leftRenderer);
176  
177  
178  
179  
180
181   // VTK objects for interactive display
182   valueChangedT1();
183
184   //connect(mThresholdSlider1, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT1()));
185
186   connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
187   connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
188   
189   connect(mCurrentSlicerManager,SIGNAL(UpdateOrientation(int,int)),this,SLOT(UpdateSlice(int, int)));
190
191   //  connect(mCurrentSlicerManager, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int)));
192   //InteractiveDisplayToggled(mInteractiveDisplayIsEnabled);
193 }
194 //------------------------------------------------------------------------------
195
196
197 //------------------------------------------------------------------------------
198 // void vvToolBinarize::LeftButtonReleaseEvent(int slicer) {
199 //   DD("LeftButtonReleaseEvent");
200 //   for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
201 //     if (i == slicer);
202 //     mCurrentSlicerManager->GetSlicer(i)->GetRenderWindow()->Render();
203 //   }
204 // }
205 //------------------------------------------------------------------------------
206
207
208 //------------------------------------------------------------------------------
209 void vvToolTest::apply()
210 { cout << __func__ << endl;
211   if (!mCurrentSlicerManager) close();
212   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
213   //GetArgsInfoFromGUI();  
214   
215   // Main filter
216
217
218
219   // Output
220   QApplication::restoreOverrideCursor();
221   close();
222 }
223 //------------------------------------------------------------------------------
224
225 //------------------------------------------------------------------------------
226 void vvToolTest::UpdateSlice(int slicer,int slices)
227 { cout << __func__ << endl;
228   Update(slicer);
229 }
230 //------------------------------------------------------------------------------
231
232 //------------------------------------------------------------------------------
233 void vvToolTest::Update(int slicer)
234 { cout << __func__ << endl;
235   if (!mCurrentSlicerManager) close();
236   mCurrentSlicerManager->Render();
237   //mImageContour[slicer]->Update(mThresholdSlider1->GetValue());
238 }
239 //------------------------------------------------------------------------------
240
241 //------------------------------------------------------------------------------
242 /* void vvToolTest::GetArgsInfoFromGUI()
243 { cout << __func__ << endl;
244
245   /* //KEEP THIS FOR READING GGO FROM FILE
246      int argc=1;
247      std::string a = "toto";
248      char * const* argv = new char*;
249      //a.c_str();
250      struct cmdline_parser_params p;
251      p.check_required = 0;
252      int good = cmdline_parser_ext(argc, argv, &args_info, &p);
253      DD(good);
254   */
255 /*  cmdline_parser_clitkBinarizeImage_init(&mArgsInfo); // Initialisation to default
256   bool inverseBGandFG = false;
257
258   mArgsInfo.lower_given = 1;
259   mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
260   if (mRadioButtonLowerThan->isChecked()) {
261     mArgsInfo.upper_given = 1;
262     mArgsInfo.upper_arg = mThresholdSlider2->GetValue();
263     if (mArgsInfo.upper_arg<mArgsInfo.lower_arg) {
264       mArgsInfo.upper_given = 0;
265       DD("TODO : lower thres greater than greater thres ! Ignoring ");
266     }
267   }
268
269   mArgsInfo.fg_arg = mFGSlider->GetValue();
270   mArgsInfo.bg_arg = mBGSlider->GetValue();
271
272   if (inverseBGandFG) {
273     mArgsInfo.fg_arg = mFGSlider->GetValue();
274     mArgsInfo.bg_arg = mBGSlider->GetValue();
275   }
276   mArgsInfo.fg_given = 1;
277   mArgsInfo.bg_given = 1;
278
279   if (mCheckBoxUseBG->isChecked()) {
280     if (mCheckBoxUseFG->isChecked()) mArgsInfo.mode_arg = (char*)"both";
281     else mArgsInfo.mode_arg = (char*)"BG";
282   } else mArgsInfo.mode_arg = (char*)"FG";
283
284   mArgsInfo.verbose_flag = false;
285
286   // // Required (even if not used)
287   // mArgsInfo.input_given = 0;
288   // mArgsInfo.output_given = 0;
289
290   // mArgsInfo.input_arg = new char;
291   // mArgsInfo.output_arg = new char;
292 } */
293 //------------------------------------------------------------------------------
294
295
296 //------------------------------------------------------------------------------
297 void vvToolTest::valueChangedT1()
298 { cout << __func__ << endl;
299   //  DD("valueChangedT1");
300   if (!mCurrentSlicerManager) close();
301   for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
302     //mImageContour[i]->Update(v);
303   }
304   mCurrentSlicerManager->Render();
305 }
306 //------------------------------------------------------------------------------