X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src2%2FcreaImageIOGimmickView.cpp;h=a1c29cea8c6fc223e86d69bb716c5b9f70a2cc1a;hb=71fb12908befc37ecb6021743cfc0704049db6e8;hp=d7f04de80ca379fd6097674744548d7bef261b66;hpb=fcfe92562365cb738cf919d095d2f8d3608ec389;p=creaImageIO.git diff --git a/src2/creaImageIOGimmickView.cpp b/src2/creaImageIOGimmickView.cpp index d7f04de..a1c29ce 100644 --- a/src2/creaImageIOGimmickView.cpp +++ b/src2/creaImageIOGimmickView.cpp @@ -1,34 +1,343 @@ #include #include +#include "boost/filesystem.hpp" + +namespace fs = boost::filesystem; + namespace creaImageIO { + //====================================================================== // CTor - GimmickView::GimmickView(Gimmick* gimmick) + GimmickView::GimmickView(Gimmick* gimmick, int threads) + : mGimmick(gimmick), + mReader(threads) { GimmickDebugMessage(1,"GimmickView::GimmickView" <GetTreeHandlerMap().begin(); + i!= mGimmick->GetTreeHandlerMap().end(); + ++i) + { + this->CreateTreeView(i->second); + } + } + //====================================================================== + + //====================================================================== + /// Updates the TreeView of given name from level l to bottom + /// (calls the virtual method TreeView::Update()) + void GimmickView::UpdateTreeViewLevel(const std::string& t, int l) + { + TreeViewMapType::iterator i; + i = GetTreeViewMap().find(t); + if ( i == GetTreeViewMap().end() ) + { + GimmickError("INTERNAL ERROR : GimmickView::UpdateTreeView : '" + <second->UpdateLevel(l); + } + //====================================================================== + ///Validates the dimension compliance of the images with the maximum and + ///minimum given, and between their sizes + bool GimmickView::ValidateSelected (std::vector& sel, int min_dim, int max_dim) + { + GimmickMessage(2,"Validating selected"<0) + { + std::vector::iterator i; + std::string row; + std::string col; + std::string plane; + + //Validation between image sizes + for (i=sel.begin(); i!=sel.end() && valid; ++i) + { + if(i==sel.begin()) + { + row=(*i)->GetAttribute("D0028_0010"); + col=(*i)->GetAttribute("D0028_0011"); + plane=(*i)->GetAttribute("D0028_0012"); + level=(*i)->GetLevel(); + + } + else + { + if(((*i)->GetAttribute("D0028_0010"))!=row || + ((*i)->GetAttribute("D0028_0011"))!=col || + ((*i)->GetAttribute("D0028_0012"))!=plane) + { + mMessage="The selected images are not compatible."; + valid=false; + } + } + } + + //Dimention validation + //Compatibility with maximum and minimum + if(valid) + { + + int rows; + int cols; + int planes; + std::string s; + std::istringstream t(s); + s=row; + t >> rows; + if(row==""){rows=1;} + s=col; + t >> cols; + if(col==""){cols=1;} + s=plane; + t >> planes; + if(plane==""){planes=1;} + + int dim = 0; + if (planes>1) dim=3; + else if (cols>1) dim=2; + else if (rows>1) dim=1; + + if (dim == 0) + { + mMessage="Unknown image dimension : cannot select !"; + valid= false; + } + else if (dim>max_dim) + { + mMessage="Selecting "; + mMessage+=dim; + mMessage+="D images is not allowed !"; + valid= false; + } + if ( dim == max_dim ) + { + mMessage="Cannot add this image to selection : would result in a "; + mMessage+=(dim+1); + mMessage+="D image!"; + + valid= false; + } + if ( dim < min_dim && sel.size()<2 ) + { + GimmickDebugMessage(2, "State Check: Dim: " + <& s,std::vector im, int dimension) + { + + // Create the output data + if (im.size()==1) + { + + // Only one image : give it + vtkImageData* out = vtkImageData::New(); + GimmickMessage(1, "State Check: Full Filename: " + <GetAttribute("FullFileName") + <ShallowCopy(mReader.GetImage(im.front()->GetAttribute("FullFileName"))); + s.push_back( out ); + } + + else if (im.size()>1) + { + vtkImageData* first = mReader.GetImage( im.front()->GetAttribute("FullFileName")); + if (dimension==2) + { + // n2D to 3D + vtkImageData* out = vtkImageData::New(); + out->CopyStructure(first); + out->SetScalarType(first->GetScalarType()); + int ext[6]; + first->GetExtent(ext); + ext[5] = im.size(); + out->SetExtent(ext); + // LG : TODO : Z Spacing ? + + out->AllocateScalars(); + + //first->Print(std::cout); + // out->Print(std::cout); + + int dim[3]; + first->GetDimensions(dim); + unsigned long imsize = + ( (unsigned long)first->GetScalarPointer(0,1,0) + - (unsigned long)first->GetScalarPointer(0,0,0)) + *dim[1]; + + int slice = 0; + std::vector::iterator it; + for (it=im.begin(); it!=im.end(); ++it) + { + //std::cout << "copying slice "<GetAttribute("FullFileName")); + + void* src = cur->GetScalarPointer(0,0,0); + void* dst = out->GetScalarPointer(0,0,slice); + // std::cout << "src="<GetAttribute("FullFileName")] = t; + mReader.Request(this,n->GetAttribute("FullFileName"),prio); + } + //====================================================================== + + //====================================================================== + void GimmickView:: + OnMultiThreadImageReaderEvent(const std::string& filename, + MultiThreadImageReaderUser::EventType e, + vtkImageData* image) + { + GimmickDebugMessage(7, + "MultiThreadImageReader event : "<second); + e.image = image; + mImageEventQueue.push_back(e); + mImageEventMap.erase(i); + } + } + else if (e==Error) + { + std::string mess="ERROR: MultiThreadImageReader: Cannot read image in file "; + mess+=filename; + mess+="\n"; + GimmickMessage(1,mess); + } + + else if (e==ImageUnloaded) + { + std::string mess="Unloaded image in file "; + mess+=filename; + mess+="\n"; + GimmickMessage(1,mess); + } + } + + //==================================================================== + + //==================================================================== + void GimmickView::ConnectValidationObserver(ValidationCallbackType callback) + { + mValidationSignal.connect(callback); + } + } // EO namespace creaImageIO