1 #include <creaImageIOGimmickView.h>
2 #include <creaImageIOSystem.h>
6 //======================================================================
8 GimmickView::GimmickView(Gimmick* gimmick, int threads)
12 GimmickDebugMessage(1,"GimmickView::GimmickView"
14 // Start the threads ...
17 //======================================================================
19 //======================================================================
21 GimmickView::~GimmickView()
23 GimmickDebugMessage(1,"GimmickView::~GimmickView"
26 //======================================================================
28 //======================================================================
29 /// Initializes the view :
30 /// Creates the TreeViews for all the TreeHandler of the Controller
32 void GimmickView::Initialize()
35 //======================================================================
37 //======================================================================
39 void GimmickView::Finalize()
43 //======================================================================
45 //======================================================================
46 /// Create the tree views
47 void GimmickView::CreateTreeViews()
49 GimmickMessage(2,"Creating the tree views"<<std::endl);
50 Gimmick::TreeHandlerMapType::const_iterator i;
51 for (i = mGimmick->GetTreeHandlerMap().begin();
52 i!= mGimmick->GetTreeHandlerMap().end();
55 this->CreateTreeView(i->second);
58 //======================================================================
60 //======================================================================
61 /// Updates the TreeView of given name from level l to bottom
62 /// (calls the virtual method TreeView::Update())
63 void GimmickView::UpdateTreeViewLevel(const std::string& t, int l)
65 TreeViewMapType::iterator i;
66 i = GetTreeViewMap().find(t);
67 if ( i == GetTreeViewMap().end() )
69 GimmickError("INTERNAL ERROR : GimmickView::UpdateTreeView : '"
70 <<t<<"' is not in TreeViewMap");
72 i->second->UpdateLevel(l);
74 //======================================================================
75 ///Validates the dimension compliance of the images with the maximum and
76 ///minimum given, and between their sizes
77 bool GimmickView::ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim)
79 GimmickMessage(2,"Validating selected"<<std::endl);
85 std::vector<tree::Node*>::iterator i;
90 //Validation between image sizes
91 for (i=sel.begin(); i!=sel.end() && valid; ++i)
95 row=(*i)->GetAttribute("D0028_0010");
96 col=(*i)->GetAttribute("D0028_0011");
97 plane=(*i)->GetAttribute("D0028_0012");
98 level=(*i)->GetLevel();
103 if(((*i)->GetAttribute("D0028_0010"))!=row ||
104 ((*i)->GetAttribute("D0028_0011"))!=col ||
105 ((*i)->GetAttribute("D0028_0012"))!=plane)
107 mMessage="The selected images are not compatible.";
113 //Dimention validation
114 //Compatibility with maximum
122 std::istringstream t(s);
131 if(plane==""){planes=1;}
135 else if (cols>1) dim=2;
136 else if (rows>1) dim=1;
140 mMessage="Unknown image dimension : cannot select !";
143 else if (dim>max_dim)
145 mMessage="Selecting ";
147 mMessage+="D images is not allowed !";
150 if ( dim == max_dim )
152 mMessage="Cannot add this image to selection : would result in a ";
154 mMessage+="D image!";
158 if ( dim < min_dim && sel.size()<2 )
160 GimmickDebugMessage(2, "State Check: Dim: "
165 mMessage="Cannot build the selection as it would result in a ";
167 mMessage+="D image, and the minimum is ";
176 mMessage="Cannot have 0 images selected";
181 mMessage="Selection OK !";
183 SetMessage(mMessage);
187 //======================================================================
189 //======================================================================
190 ///Reads Images (Non Threaded)
191 void GimmickView::ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dimension)
194 // Create the output data
198 // Only one image : give it
199 vtkImageData* out = vtkImageData::New();
200 GimmickMessage(1, "State Check: Full Filename: "
201 <<im.front()->GetAttribute("FullFileName")
203 out->ShallowCopy(mReader.GetImage(im.front()->GetAttribute("FullFileName")));
207 else if (im.size()>1)
209 vtkImageData* first = mReader.GetImage( im.front()->GetAttribute("FullFileName"));
213 vtkImageData* out = vtkImageData::New();
214 out->CopyStructure(first);
215 out->SetScalarType(first->GetScalarType());
217 first->GetExtent(ext);
220 // LG : TODO : Z Spacing ?
222 out->AllocateScalars();
224 //first->Print(std::cout);
225 // out->Print(std::cout);
228 first->GetDimensions(dim);
229 unsigned long imsize =
230 ( (unsigned long)first->GetScalarPointer(0,1,0)
231 - (unsigned long)first->GetScalarPointer(0,0,0))
235 std::vector<tree::Node*>::iterator it;
236 for (it=im.begin(); it!=im.end(); ++it)
238 //std::cout << "copying slice "<<slice <<std::endl;
239 vtkImageData* cur = mReader.GetImage( (*it)->GetAttribute("FullFileName"));
241 void* src = cur->GetScalarPointer(0,0,0);
242 void* dst = out->GetScalarPointer(0,0,slice);
243 // std::cout << "src="<<src<<std::endl;
244 // std::cout << "dst="<<dst<<std::endl;
245 // std::cout << "siz="<<imsize<<std::endl;
246 memcpy(dst,src,imsize);
255 std::vector<tree::Node*>::iterator it;
256 for (it=im.begin(); it!=im.end(); ++it)
258 vtkImageData* out = vtkImageData::New();
259 out->ShallowCopy(mReader.GetImage((*it)->GetAttribute("FullFileName")));
268 } // EO namespace creaImageIO