1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
20 #include "vvToolTest.h"
21 #include "vvSlicerManager.h"
23 #include "vvToolInputSelectorWidget.h"
26 #include "clitkBinarizeImageGenericFilter.h"
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>
39 //------------------------------------------------------------------------------
40 // Create the tool and automagically (I like this word) insert it in
41 // the main window menu.
43 //------------------------------------------------------------------------------
46 //------------------------------------------------------------------------------
47 void vvToolTest::Initialize()
48 { cout << __func__ << endl;
50 SetToolMenuName("Test");
51 SetToolIconFilename(":/common/icons/binarize.png");
52 SetToolTip("try to display a sphere.");
54 //------------------------------------------------------------------------------
57 //------------------------------------------------------------------------------
58 vvToolTest::vvToolTest(vvMainWindowBase * parent, Qt::WindowFlags f)
59 :vvToolWidgetBase(parent,f),
60 vvToolBase<vvToolTest>(parent),
62 { cout << __func__ << endl;
65 // Connect signals & slots
68 mFilter = clitk::BinarizeImageGenericFilter::New();
70 // Set how many inputs are needed for this tool
71 AddInputSelector("Select one image", mFilter);
73 //------------------------------------------------------------------------------
76 //------------------------------------------------------------------------------
77 vvToolTest::~vvToolTest()
78 { cout << __func__ << endl;
80 //------------------------------------------------------------------------------
83 //------------------------------------------------------------------------------
85 void vvToolTest::InteractiveDisplayToggled(bool b)
86 { cout << __func__ << endl;
87 mInteractiveDisplayIsEnabled = b;
88 if (!mInteractiveDisplayIsEnabled) {
91 for(unsigned int i=0; i<mImageContour.size(); i++) {
92 mImageContour[i]->ShowActors();
93 if (mRadioButtonLowerThan->isChecked())
94 mImageContourLower[i]->ShowActors();
96 if (mCurrentSlicerManager)
97 mCurrentSlicerManager->Render();
101 //------------------------------------------------------------------------------
104 //------------------------------------------------------------------------------
106 //------------------------------------------------------------------------------
109 //------------------------------------------------------------------------------
110 bool vvToolTest::close()
111 { cout << __func__ << endl;
112 return vvToolWidgetBase::close();
114 //------------------------------------------------------------------------------
117 //------------------------------------------------------------------------------
119 //------------------------------------------------------------------------------
122 //------------------------------------------------------------------------------
123 void vvToolTest::reject()
124 { cout << __func__ << endl;
125 // DD("vvToolBinarize::reject");
126 return vvToolWidgetBase::reject();
128 //------------------------------------------------------------------------------
131 //------------------------------------------------------------------------------
133 //------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------
138 //------------------------------------------------------------------------------
141 //------------------------------------------------------------------------------
143 void vvToolTest::InputIsSelected(vvSlicerManager * m)
144 { cout << __func__ << endl;
145 mCurrentSlicerManager = m;
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);
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);
172 //sphereRenderer->AddActor(sphereActor); //mettre le vvSlicer
175 //this->qvtkWidgetLeft->GetRenderWindow()->AddRenderer(leftRenderer);
181 // VTK objects for interactive display
184 //connect(mThresholdSlider1, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT1()));
186 connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
187 connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
189 connect(mCurrentSlicerManager,SIGNAL(UpdateOrientation(int,int)),this,SLOT(UpdateSlice(int, int)));
191 // connect(mCurrentSlicerManager, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int)));
192 //InteractiveDisplayToggled(mInteractiveDisplayIsEnabled);
194 //------------------------------------------------------------------------------
197 //------------------------------------------------------------------------------
198 // void vvToolBinarize::LeftButtonReleaseEvent(int slicer) {
199 // DD("LeftButtonReleaseEvent");
200 // for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
202 // mCurrentSlicerManager->GetSlicer(i)->GetRenderWindow()->Render();
205 //------------------------------------------------------------------------------
208 //------------------------------------------------------------------------------
209 void vvToolTest::apply()
210 { cout << __func__ << endl;
211 if (!mCurrentSlicerManager) close();
212 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
213 //GetArgsInfoFromGUI();
220 QApplication::restoreOverrideCursor();
223 //------------------------------------------------------------------------------
225 //------------------------------------------------------------------------------
226 void vvToolTest::UpdateSlice(int slicer,int slices)
227 { cout << __func__ << endl;
230 //------------------------------------------------------------------------------
232 //------------------------------------------------------------------------------
233 void vvToolTest::Update(int slicer)
234 { cout << __func__ << endl;
235 if (!mCurrentSlicerManager) close();
236 mCurrentSlicerManager->Render();
237 //mImageContour[slicer]->Update(mThresholdSlider1->GetValue());
239 //------------------------------------------------------------------------------
241 //------------------------------------------------------------------------------
242 /* void vvToolTest::GetArgsInfoFromGUI()
243 { cout << __func__ << endl;
245 /* //KEEP THIS FOR READING GGO FROM FILE
247 std::string a = "toto";
248 char * const* argv = new char*;
250 struct cmdline_parser_params p;
251 p.check_required = 0;
252 int good = cmdline_parser_ext(argc, argv, &args_info, &p);
255 /* cmdline_parser_clitkBinarizeImage_init(&mArgsInfo); // Initialisation to default
256 bool inverseBGandFG = false;
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 ");
269 mArgsInfo.fg_arg = mFGSlider->GetValue();
270 mArgsInfo.bg_arg = mBGSlider->GetValue();
272 if (inverseBGandFG) {
273 mArgsInfo.fg_arg = mFGSlider->GetValue();
274 mArgsInfo.bg_arg = mBGSlider->GetValue();
276 mArgsInfo.fg_given = 1;
277 mArgsInfo.bg_given = 1;
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";
284 mArgsInfo.verbose_flag = false;
286 // // Required (even if not used)
287 // mArgsInfo.input_given = 0;
288 // mArgsInfo.output_given = 0;
290 // mArgsInfo.input_arg = new char;
291 // mArgsInfo.output_arg = new char;
293 //------------------------------------------------------------------------------
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);
304 mCurrentSlicerManager->Render();
306 //------------------------------------------------------------------------------