]> Creatis software - clitk.git/blob - vv/vvToolBase.h
almost finished the work on multiple components
[clitk.git] / vv / vvToolBase.h
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolBase.h,v $
5   Language:  C++
6   Date:      $Date: 2010/02/09 14:19:32 $
7   Version:   $Revision: 1.2 $
8   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
9
10   Copyright (C) 2008
11   Léon Bérard cancer center  http://oncora1.lyon.fnclcc.fr
12   CREATIS                    http://www.creatis.insa-lyon.fr
13
14   This program is free software: you can redistribute it and/or modify
15   it under the terms of the GNU General Public License as published by
16   the Free Software Foundation, version 3 of the License.
17
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26   =========================================================================*/
27
28 #ifndef VVTOOLBASE_H
29 #define VVTOOLBASE_H
30
31 #include "vvToolCreatorBase.h"
32 #include "vvToolInputSelectorWidget.h"
33 #include "clitkImageToImageGenericFilter.h"
34
35 //------------------------------------------------------------------------------
36 template<class ToolType>
37 class vvToolBase {
38 public:
39   static void Initialize();  // can't be virtual, must be overwritten
40   void UpdateInfoFromMainWindow();
41   vvMainWindowToolInfo * mMainWindowToolInfo;
42
43   static void SetToolName(QString n) { vvToolCreator<ToolType>::mSingleton->mToolName = n; }
44   static void SetToolMenuName(QString n) { vvToolCreator<ToolType>::mSingleton->mToolMenuName = n; }
45   static void SetToolIconFilename(QString n) { vvToolCreator<ToolType>::mSingleton->mToolIconFilename = n; }
46   static void SetToolTip(QString n) { vvToolCreator<ToolType>::mSingleton->mToolTip = n; }
47
48   void InitializeListOfInputImages();
49   void InitializeListOfInputImages(vvToolInputSelectorWidget * w, 
50                                    clitk::ImageToImageGenericFilterBase * f);
51   std::vector<vvSlicerManager*> mSlicerManagersCompatible;
52   unsigned int mCurrentIndex;
53
54   vvImage::Pointer mCurrentImage;
55   vvSlicerManager * mCurrentSliceManager;
56   clitk::ImageToImageGenericFilterBase * mFilter;
57
58 };
59 //------------------------------------------------------------------------------
60
61
62 //------------------------------------------------------------------------------
63 template<class ToolType>
64 void vvToolBase<ToolType>::UpdateInfoFromMainWindow() { 
65   mMainWindowToolInfo = vvToolCreator<ToolType>::mSingleton->mMainWindow->GetInfoForTool(); 
66 }
67 //------------------------------------------------------------------------------
68
69
70 //------------------------------------------------------------------------------  
71 template<class ToolType>
72 void vvToolBase<ToolType>::Initialize() {
73   SetToolName("Unnamed tool");
74   SetToolMenuName("Unnamed tool");
75   SetToolIconFilename("");
76   SetToolTip("Unamed tool.");
77 }
78 //------------------------------------------------------------------------------    
79
80
81 //------------------------------------------------------------------------------
82 template<class ToolType>
83 void vvToolBase<ToolType>::InitializeListOfInputImages(vvToolInputSelectorWidget * w, 
84                                                        clitk::ImageToImageGenericFilterBase * f) {
85   mFilter = f;
86   InitializeListOfInputImages();
87   w->Initialize(mSlicerManagersCompatible, mCurrentIndex);
88   w->SetToolTip(mFilter->GetAvailableImageTypes().c_str());
89 }
90 //------------------------------------------------------------------------------
91
92 //------------------------------------------------------------------------------
93 template<class ToolType>
94 void vvToolBase<ToolType>::InitializeListOfInputImages() {
95   UpdateInfoFromMainWindow();
96
97   std::vector<vvSlicerManager*> & mSlicerManagers = *mMainWindowToolInfo->mSlicerManagers;
98   mCurrentIndex = mMainWindowToolInfo->mSlicerManagerCurrentIndex;
99   DD("InputUpdate");
100   DD(mCurrentIndex);
101   // HERE : Check if image is ok (dimension, type etc ...)
102
103   if (mFilter) {
104     mFilter->PrintAvailableImageTypes();
105     
106   }
107   else {
108     /// if not set, do not check filter type
109     std::cerr << "*** ERROR, set mFilter member in the vvTool class before calling InitializeListOfInputImages" << std::endl;
110     exit(0);
111   }
112
113   //unsigned int previousIndex = mInputSequenceBox->mCurrentIndex();
114   mSlicerManagersCompatible.clear();
115   // mInputSequenceBox->clear();
116   for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
117     
118     vvImage * image = mSlicerManagers[i]->GetImage();
119     
120     if (mFilter->CheckImageType(image->GetNumberOfDimensions(),
121                 image->GetNumberOfScalarComponents(),
122                 image->GetScalarTypeAsString())) {
123       mSlicerManagersCompatible.push_back(mSlicerManagers[i]);
124       if (mCurrentIndex == i) {
125         mCurrentIndex = mSlicerManagersCompatible.size()-1;
126       }
127     }
128     else {
129       std::cerr << mSlicerManagers[i]->GetFileName().c_str() << " not compatible image" << std::endl;
130       if (mCurrentIndex == i) {
131         mCurrentIndex = 0;
132       }
133     }
134   }  
135 }
136 //------------------------------------------------------------------------------
137
138
139 #endif
140