]> Creatis software - creaVtk.git/blobdiff - bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx
#2711 creaVtk Feature New Normal - new Box ReadMHDPlane
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkReadMHDPlane.cxx
index f7a1d106928f6fd5d8cf0231025acda495676914..800b0be4e3a34b77e9f7ba6056a3d7bcb9a4b263 100644 (file)
@@ -59,123 +59,122 @@ vtkImageData* ReadMHDPlane::CreateDefaultImage()
        return newImage;
 } 
 
-
-void ReadMHDPlane::ReadNormalMHD()
+vtkImageData* ReadMHDPlane::ChangeOrientation(vtkImageData* imgOrg)
 {
-// THE MAIN PROCESSING METHOD BODY
-//   Here we simply set the input 'In' value to the output 'Out'
-//   And print out the output value
-// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
-//    void bbSet{Input|Output}NAME(const TYPE&)
-//    const TYPE& bbGet{Input|Output}NAME() const 
-//    Where :
-//    * NAME is the name of the input/output
-//      (the one provided in the attribute 'name' of the tag 'input')
-//    * TYPE is the C++ type of the input/output
-//      (the one provided in the attribute 'type' of the tag 'input')
-
-//    bbSetOutputOut( bbGetInputIn() );
-//    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
-
-       std::string inputfilename;
+       int     width = bbGetInputWidth();
+       int     ext[6];
+       int     sizeXOrg, sizeYOrg,sizeZOrg;
+       int     sizeXDst, sizeYDst,sizeZDst;
+       imgOrg->GetWholeExtent(ext);
+       int     sizeLine;
+       
+       sizeXOrg        = ext[1]-ext[0]+1;
+       sizeYOrg        = ext[3]-ext[2]+1;
+       sizeZOrg        = ext[5]-ext[4]+1;
 
        if (bbGetInputDirectionPlane()=="XY")
        {
-               inputfilename=bbGetInputFileName();
-       } // if XY
-
-
-       if ((bbGetInputDirectionPlane()=="YZ") || (bbGetInputDirectionPlane()=="ZX"))
+               sizeXDst        = ext[1]-ext[0]+1;
+               sizeYDst        = ext[3]-ext[2]+1;
+               sizeZDst        = width;
+       } // XY 
+       if (bbGetInputDirectionPlane()=="YZ") 
        {
-
-               //-- Split FileName
-               std::size_t found               =       bbGetInputFileName().find_last_of("/\\");
-               std::string path                =       bbGetInputFileName().substr(0,found+1);
-               std::string filename    =       bbGetInputFileName().substr(found+1);
-#ifdef _WIN32
-               path=path+"YZ_ZX\\";
-#else
-               path=path+"YZ_ZX/";
-#endif
-       
-       
-               if (bbGetInputDirectionPlane()=="YZ") 
-               { 
-                       inputfilename = path+filename+"_YZ.mhd";  
-               } // if YZ
-
-               if (bbGetInputDirectionPlane()=="ZX")
-               {
-                       inputfilename = path+filename+"_ZX.mhd";
-               } // XZ
-       } // if YZ || XZ
-
-       vtkImageData *newImage;
-       long long int newHeaderSize;
-    std::string newFileName=inputfilename+"-OneSlice";
-
-    int sx,sy,sz;
-    char mystring[250];
-    char strTmp[20];
-       bool ok=true;
-    FILE *ffIn = fopen(inputfilename.c_str(),"r");
-       if (ffIn!=NULL)
+               sizeXDst        = width;
+               sizeYDst        = ext[1]-ext[0]+1;
+               sizeZDst        = ext[3]-ext[2]+1;
+               sizeLine        = sizeYDst;
+       } // YZ
+       if (bbGetInputDirectionPlane()=="ZX")
        {
-           FILE *ffOut = fopen(newFileName.c_str(),"w");
+               sizeXDst        = ext[1]-ext[0]+1;
+               sizeYDst        = width;
+               sizeZDst        = ext[3]-ext[2]+1;
+               sizeLine        = sizeXDst;
+       } // ZX
+       vtkImageData *imgDst  = vtkImageData::New();
+       imgDst->Initialize();
+       imgDst->SetScalarType( imgOrg->GetScalarType() );
+       imgDst->SetSpacing( imgOrg->GetSpacing() );
+       imgDst->SetDimensions( sizeXDst,sizeYDst,sizeZDst );
+       imgDst->SetWholeExtent(0,sizeXDst-1,0,sizeYDst-1,0,sizeZDst-1 );
+       imgDst->SetExtent(0,sizeXDst-1,0,sizeYDst-1,0,sizeZDst-1 );
+       imgDst->SetNumberOfScalarComponents(1);
+       imgDst->AllocateScalars();
+       imgDst->Update();
+
+       char *ptrDst,*ptrOrg;
+       int sizeBytes = imgOrg->GetScalarSize();                
+       int sizeLineBytes = sizeLine*imgOrg->GetScalarSize();           
+       int xx,yy,zz;
+
+       long int sizeXDstBytes          = sizeXDst*sizeBytes;
+       long int sizeXYDstBytes         = sizeXDst*sizeYDst*sizeBytes;
+       long int sizeXYDstBytes2        = sizeXDst*sizeYDst*sizeBytes*2;
+       long int sizeXYZDstBytes        = sizeXDst*sizeYDst*sizeZDst*sizeBytes;
+       long int sizeXYZDstBytes1       = sizeXDst*sizeYDst*(sizeZDst-1)*sizeBytes;
+
+       ptrOrg = (char*)( imgOrg->GetScalarPointer() );
 
-       while(!feof(ffIn))
-       {
-           strcpy(mystring,"\n");
-                       fgets(mystring,250,ffIn);
-               if (strncmp("NDims",mystring,5)==0) {strcpy(mystring,"NDims = 2\n");}
-               if (strncmp("DimSize",mystring,6)==0) 
-                       {
-                               sscanf(mystring,"%s %s %d %d %d",strTmp, strTmp, &sx, &sy,&sz);
-                               sprintf(mystring,"DimSize = %d %d\n",sx,sy);
-                       newHeaderSize = (long long int)sx*(long long int)sy*(long long int)bbGetInputSlice();
-                               if (bbGetInputSlice()>=sz) {ok=false;}
-                       } // if
-               if (strncmp("ElementType = MET_CHAR",mystring,22)==0)   { newHeaderSize=newHeaderSize*1; }
-               if (strncmp("ElementType = MET_UCHAR",mystring,23)==0)  { newHeaderSize=newHeaderSize*1; }
-               if (strncmp("ElementType = MET_USHORT",mystring,24)==0) { newHeaderSize=newHeaderSize*2; }
-               if (strncmp("ElementType = MET_SHORT",mystring,23)==0)  { newHeaderSize=newHeaderSize*2; }
-               if (strncmp("ElementType = MET_FLOAT",mystring,23)==0)  { newHeaderSize=newHeaderSize*4; }
-               if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0)  { newHeaderSize=newHeaderSize*4; }
-               if (strncmp("Offset",mystring,6)==0) {strcpy(mystring,"Offset = 0 0 0\n");}
-               if (strncmp("HeaderSize",mystring,10)==0) {strcpy(mystring,"");}
-               if (strncmp("ElementDataFile",mystring,15)==0) 
-                       {
-                               fprintf(ffOut,"HeaderSize = %lld\n\n", newHeaderSize );
-                       } // if
-               fprintf(ffOut,mystring); 
-       } // while
-               fclose(ffIn);
-               fclose(ffOut);
+       if (bbGetInputDirectionPlane()=="XY")
+       {
+               memcpy ( imgDst->GetScalarPointer(), ptrOrg , sizeXDst*sizeYDst*sizeZDst*(imgOrg->GetScalarSize()) );
+       } // if XY
 
-               if (ok==true)
+       if (bbGetInputDirectionPlane()=="ZX")
+       {
+               ptrDst = (char*)( imgDst->GetScalarPointer(0,0,sizeYOrg-00-1) );
+               for( zz=0 ; zz<sizeZOrg ; zz++)
                {
-                       vtkMetaImageReader * reader = vtkMetaImageReader::New();
-                       reader->SetFileName( newFileName.c_str() );
-                       reader->Update();
-                       newImage = reader->GetOutput();
-               } // if ok
-       } else {
-               ok=false;
-               printf("EED ERROR: Problem openin:%s\n", inputfilename.c_str() );
-       }
-
-       if (ok==false)
+//                     ptrDst=(char*)( imgDst->GetScalarPointer(0,zz,sizeYOrg-00-1) );
+                       for( yy=0 ; yy<sizeYOrg ; yy++)
+                       {
+//                             ptrOrg=(char*)( imgOrg->GetScalarPointer(0,yy,zz) );
+//                             ptrDst=(char*)( imgDst->GetScalarPointer(0,zz,sizeYOrg-yy-1) );
+                               memcpy ( ptrDst, ptrOrg , sizeLineBytes );
+                               ptrOrg = ptrOrg + sizeLineBytes;
+                               ptrDst = ptrDst - sizeXYDstBytes;
+                       } // for yy 
+                       ptrDst = ptrDst + sizeXDstBytes;
+                       ptrDst = ptrDst + sizeXYZDstBytes;
+               } // for zz 
+       } // ZX
+
+       if (bbGetInputDirectionPlane()=="YZ")
        {
-               newImage=CreateDefaultImage();
-       } // if ok
-
-       bbSetOutputOut( newImage );
-
+               ptrDst = (char*)( imgDst->GetScalarPointer(0,0,sizeYOrg-0-1) );
+               for( zz=0 ; zz<sizeZOrg ; zz++)
+               {
+                       ptrDst=(char*)( imgDst->GetScalarPointer(zz,0,sizeYOrg-0-1) );
+                       for( yy=0 ; yy<sizeYOrg ; yy++)
+                       {
+//                             ptrDst=(char*)( imgDst->GetScalarPointer(zz,0,sizeYOrg-yy-1) );
+                               for( xx=0 ; xx<sizeXOrg ; xx++)
+                               {
+//                                     ptrOrg=(char*)( imgOrg->GetScalarPointer(xx,yy,zz) );
+//                                     ptrDst=(char*)( imgDst->GetScalarPointer(zz,xx,sizeYOrg-yy-1) );
+                                       memcpy ( ptrDst, ptrOrg , sizeBytes );
+                                       ptrOrg+= sizeBytes;
+                                       ptrDst+= sizeXDstBytes;
+                               } /// for xx
+                               ptrDst = ptrDst - sizeXYDstBytes2;
+                       } // for yy 
+                       ptrDst = ptrDst + sizeXYZDstBytes;
+//                     ptrDst++;
+               } // for zz 
+       } // ZX
+
+       return imgDst;
 }
 
-void ReadMHDPlane::Read64lseek()
+void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane)
 {
-
+       int             slice;
+       int             width;
+       width = bbGetInputWidth();
+       if (width<=0 ) { width=1; }
+       slice = bbGetInputSlice();
+       if (slice<0 ) { slice=0; }
        int             dimX=-1,dimY=-1,dimZ=-1;
        int             dim=-1;
        std::string formattype("VOID");
@@ -183,86 +182,78 @@ void ReadMHDPlane::Read64lseek()
        float           spcX=-1,spcY=-1,spcZ=-1;
        float           ox=-1,oy=-1,oz=-1;
        long int        headersize=0;
-
        vtkImageData *newImage=NULL;
-
        char mystring[250];
        char strTmp[30];
        char strTmp2[30];
-       FILE *ffIn      = fopen(bbGetInputFileName().c_str(),"r");
+       FILE *ffIn      = fopen( fileNameIn.c_str() , "r");
        long long dataSize;
-
        if (ffIn!=NULL)
        {
                newImage = vtkImageData::New();
-
                while(!feof(ffIn))
                {
            strcpy(mystring,"\n");
                        fgets(mystring,250,ffIn);
-               if (strncmp("NDims",mystring,5)==0)                     { sscanf(mystring,"%s %s %d"            ,strTmp, strTmp, &dim);                                 }
-               if (strncmp("DimSize",mystring,6)==0)                   { sscanf(mystring,"%s %s %d %d %d"      ,strTmp, strTmp, &dimX, &dimY,&dimZ);   } 
+               if (strncmp("NDims",mystring,5)==0)                     { sscanf(mystring,"%s %s %d"            ,strTmp, strTmp, &dim);                                                                 }
+               if (strncmp("DimSize",mystring,6)==0)                   { sscanf(mystring,"%s %s %d %d %d"      ,strTmp, strTmp, &dimX, &dimY,&dimZ);                                   
                        if (strncmp("ElementType",mystring,11)==0)              { sscanf(mystring,"%s %s %s"            ,strTmp, strTmp, strTmp2); formattype=strTmp2;                  }
-                       if (strncmp("ElementSpacing",mystring,11)==0)   { sscanf(mystring,"%s %s %f %f %f"      ,strTmp, strTmp, &spcX,&spcY,&spcZ);    }
-               if (strncmp("Offset",mystring,6)==0)                    { sscanf(mystring,"%s %s %f %f %f"      ,strTmp, strTmp, &ox, &oy, &oz);                }
-               if (strncmp("HeaderSize",mystring,10)==0)               { sscanf(mystring,"%s %s %ld"           ,strTmp, strTmp, &headersize);                  }
+                       if (strncmp("ElementSpacing",mystring,14)==0)   { sscanf(mystring,"%s %s %f %f %f"      ,strTmp, strTmp, &spcX,&spcY,&spcZ);                                    }
+                       if (strncmp("ElementSize",mystring,11)==0)              { sscanf(mystring,"%s %s %f %f %f"      ,strTmp, strTmp, &spcX,&spcY,&spcZ);                                    }
+               if (strncmp("Offset",mystring,6)==0)                    { sscanf(mystring,"%s %s %f %f %f"      ,strTmp, strTmp, &ox, &oy, &oz);                                                }
+               if (strncmp("HeaderSize",mystring,10)==0)               { sscanf(mystring,"%s %s %ld"           ,strTmp, strTmp, &headersize);                                                  }
                        if (strncmp("ElementDataFile",mystring,15)==0)  { sscanf(mystring,"%s %s %s"            ,strTmp, strTmp, strTmp2); elementdatafile=strTmp2;             }
-
-               if (strncmp("ElementType = MET_CHAR",mystring,22)==0)   { newImage->SetScalarTypeToChar();                      dataSize=sizeof(char);                  }
-               if (strncmp("ElementType = VTK_CHAR",mystring,22)==0)   { newImage->SetScalarTypeToChar();                      dataSize=sizeof(char);                  }
-               if (strncmp("ElementType = MET_UCHAR",mystring,23)==0)  { newImage->SetScalarTypeToUnsignedChar();      dataSize=sizeof(unsigned char); }
+               if (strncmp("ElementType = MET_CHAR",mystring,22)==0)                   { newImage->SetScalarTypeToChar();                      dataSize=sizeof(char);                  }
+               if (strncmp("ElementType = VTK_CHAR",mystring,22)==0)                   { newImage->SetScalarTypeToChar();                      dataSize=sizeof(char);                  }
+               if (strncmp("ElementType = MET_UCHAR",mystring,23)==0)                  { newImage->SetScalarTypeToUnsignedChar();      dataSize=sizeof(unsigned char); }
                if (strncmp("ElementType = VTK_UNSIGNED_CHAR",mystring,31)==0)  { newImage->SetScalarTypeToUnsignedChar();      dataSize=sizeof(unsigned char); }
-               if (strncmp("ElementType = MET_USHORT",mystring,24)==0) { newImage->SetScalarTypeToUnsignedShort();     dataSize=sizeof(unsigned short);}
+               if (strncmp("ElementType = MET_USHORT",mystring,24)==0)                 { newImage->SetScalarTypeToUnsignedShort();     dataSize=sizeof(unsigned short);}
                if (strncmp("ElementType = VTK_UNSIGNED_SHORT",mystring,32)==0) { newImage->SetScalarTypeToUnsignedShort();     dataSize=sizeof(unsigned short);}
-               if (strncmp("ElementType = MET_SHORT",mystring,23)==0)  { newImage->SetScalarTypeToShort();                     dataSize=sizeof(short);                 }
-               if (strncmp("ElementType = VTK_SHORT",mystring,23)==0)  { newImage->SetScalarTypeToShort();                     dataSize=sizeof(short);                 }
-               if (strncmp("ElementType = MET_FLOAT",mystring,23)==0)  { newImage->SetScalarTypeToFloat();                     dataSize=sizeof(float);                 }
-               if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0)  { newImage->SetScalarTypeToFloat();                     dataSize=sizeof(float);                 }
-               if (strncmp("ElementType = MET_DOUBLE",mystring,24)==0) { newImage->SetScalarTypeToDouble();            dataSize=sizeof(double);                }
-               if (strncmp("ElementType = VTK_DOUBLE",mystring,24)==0) { newImage->SetScalarTypeToDouble();            dataSize=sizeof(double);                }
-
+               if (strncmp("ElementType = MET_SHORT",mystring,23)==0)                  { newImage->SetScalarTypeToShort();                     dataSize=sizeof(short);                 }
+               if (strncmp("ElementType = VTK_SHORT",mystring,23)==0)                  { newImage->SetScalarTypeToShort();                     dataSize=sizeof(short);                 }
+               if (strncmp("ElementType = MET_UINT",mystring,22)==0)                   { newImage->SetScalarTypeToUnsignedInt();       dataSize=sizeof(unsigned int);  }
+               if (strncmp("ElementType = VTK_UNSIGNED_INT",mystring,30)==0)   { newImage->SetScalarTypeToUnsignedInt();       dataSize=sizeof(unsigned int);  }
+               if (strncmp("ElementType = MET_INT",mystring,21)==0)                    { newImage->SetScalarTypeToInt();                       dataSize=sizeof(int);                   }
+               if (strncmp("ElementType = VTK_INT",mystring,21)==0)                    { newImage->SetScalarTypeToInt();                       dataSize=sizeof(int);                   }
+               if (strncmp("ElementType = MET_FLOAT",mystring,23)==0)                  { newImage->SetScalarTypeToFloat();                     dataSize=sizeof(float);                 }
+               if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0)                  { newImage->SetScalarTypeToFloat();                     dataSize=sizeof(float);                 }
+               if (strncmp("ElementType = MET_LONG",mystring,22)==0)                   { newImage->SetScalarTypeToLong();                      dataSize=sizeof(long);                  }
+               if (strncmp("ElementType = VTK_LONG",mystring,22)==0)                   { newImage->SetScalarTypeToLong();                      dataSize=sizeof(long);                  }
+               if (strncmp("ElementType = MET_DOUBLE",mystring,24)==0)                 { newImage->SetScalarTypeToDouble();            dataSize=sizeof(double);                }
+               if (strncmp("ElementType = VTK_DOUBLE",mystring,24)==0)                 { newImage->SetScalarTypeToDouble();            dataSize=sizeof(double);                }
        } // while
                fclose(ffIn);
-
                newImage->Initialize();
-
-
-               int fd;
-               long long ret;
+               int             fd;
+               long long       ret;
                std::size_t found;
                std::string filename;
-               found                                   =       bbGetInputFileName().find_last_of("/\\");
-               filename                                = bbGetInputFileName().substr(0,found+1) + elementdatafile ;
-               long long pos;
-
-               long long lsize                 = dimX*dimY*1 *dataSize;
-
-
+               found                                   = fileNameIn.find_last_of("/\\");
+               filename                                = fileNameIn.substr(0,found+1) + elementdatafile ;
+               long long       pos;
+               long long lsize                 = dimX*dimY*width *dataSize;
 #if defined(_WIN32)
                   _sopen_s( &fd, filename.c_str(), _O_RDONLY, _SH_DENYNO, 0 );
 #else
                fd = open ( filename.c_str() ,  O_RDONLY|O_LARGEFILE );
 #endif // defined(_WIN32)
-
-
-
                if (fd < 0)
                {
-                       printf("EED ReadMHDPlane::Read64lseek \n");
+                       printf("EED ReadMHDPlane::Read64lseek   WARNNING! raw file not exist\n");
                        fprintf(stderr, "%s\n", strerror(errno));
-                       exit(1);
-               }
-
-               if (bbGetInputDirectionPlane()=="XY"
+                       newImage=CreateDefaultImage();
+//                     exit(1);
+               }       
+               if ((plane=="XY") && (fd>=0)
                { 
                        newImage->SetSpacing( spcX,spcY,spcZ );
-                       newImage->SetDimensions(  dimX,dimY,1 );
-                       newImage->SetWholeExtent(0,  dimX-1,0,dimY-1,0,0 );
-                       newImage->SetExtent(0,  dimX-1,0,dimY-1,0,0 );
+                       newImage->SetDimensions(  dimX,dimY,width );
+                       newImage->SetWholeExtent(0,  dimX-1,0,dimY-1,0,width-1 );
+                       newImage->SetExtent(0,  dimX-1,0,dimY-1,0,width-1 );
                        newImage->SetNumberOfScalarComponents(1);
                        newImage->AllocateScalars();
                        newImage->Update();
-                       pos = dimX*dimY*(long long)bbGetInputSlice()*dataSize;
+                       pos = dimX*dimY*(long long)slice*dataSize;
 #if defined(_WIN32)
                        if (_lseeki64( fd, pos, SEEK_SET ) < 0)
 #else
@@ -273,87 +264,41 @@ void ReadMHDPlane::Read64lseek()
                                fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
                                exit(1);
                        }
-
                        if ((ret = read(fd, newImage->GetScalarPointer() , lsize)) < 0) 
                        {
                                fprintf(stderr, "Failed reading: %s\n", strerror(errno));
                                exit(1);
                        }
                }  // if PLANE XY
-
-               if (bbGetInputDirectionPlane()=="XZ") 
+               if ((plane=="ZX") && (fd>=0))
                { 
-                       long long int j;
                        newImage->SetSpacing( spcX,spcZ,spcY );
-                       newImage->SetDimensions(  dimX,dimZ,1 );
-                       newImage->SetWholeExtent(0,  dimX-1,0,dimZ-1,0,0 );
-                       newImage->SetExtent(0,  dimX-1,0,dimZ-1,0,0 );
+                       newImage->SetDimensions(  dimX,dimZ,width );
+                       newImage->SetWholeExtent(0,  dimX-1,0,dimZ-1,0,width-1 );
+                       newImage->SetExtent(0,  dimX-1,0,dimZ-1,0,width-1 );
                        newImage->SetNumberOfScalarComponents(1);
                        newImage->AllocateScalars();
                        newImage->Update();
-                       long long sizeBytesPlane = dimX*dimY*dataSize;
-                       pos = dimX*(long long int)bbGetInputSlice()*dataSize;
-                       char *pImage = (char*)(newImage->GetScalarPointer());
-                       for (j=0;j<dimZ;j++)
+                       int iWidth;
+                       for (iWidth=0;iWidth<width;iWidth++)
                        {
-#if defined(_WIN32)
-                               if (_lseeki64( fd, pos + j*sizeBytesPlane , SEEK_SET ) < 0)
-#else
-                               if (lseek64(fd, pos + j*sizeBytesPlane , SEEK_SET) < 0) 
-#endif // defined(_WIN32)
-                               {
-                                       printf("EED ReadMHDPlane::Read64lseek \n");
-                                       fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
-                                       exit(1);
-                               }
-
-                               if ((ret = read(fd, pImage , dimX*dataSize)) < 0) 
-                               {
-                                       fprintf(stderr, "Failed reading: %s\n", strerror(errno));
-                                       exit(1);
-                               }
-                               pImage = pImage+dimX*dataSize;
-                       } // for j
+                               copy_ZX_plane(fd,newImage,slice+iWidth,iWidth,dimX,dimY,dimZ,dataSize);
+                       }
                }  // if PLANE XZ
-
-
-               if (bbGetInputDirectionPlane()=="YZ") 
+               if ((plane=="YZ") && (fd>=0))
                { 
-                       long long int j;
-                       long long int i;
                        newImage->SetSpacing( spcY,spcZ,spcX );
-                       newImage->SetDimensions(  dimY,dimZ,1 );
-                       newImage->SetWholeExtent(0,  dimY-1,0,dimZ-1,0,0 );
-                       newImage->SetExtent(0,  dimY-1,0,dimZ-1,0,0 );
+                       newImage->SetDimensions(  dimY,dimZ,width );
+                       newImage->SetWholeExtent(0,  dimY-1,0,dimZ-1,0,width-1 );
+                       newImage->SetExtent(0,  dimY-1,0,dimZ-1,0,width-1 );
                        newImage->SetNumberOfScalarComponents(1);
                        newImage->AllocateScalars();
                        newImage->Update();
-                       long long sizeBytesPlane = dimX*dimY*dataSize;
-                       char *pImage;
-                       for (j=0;j<dimZ;j++)
+                       int iWidth;
+                       for (iWidth=0;iWidth<width;iWidth++)
                        {
-                               for (i=0;i<dimY;i++)
-                               {
-                                       pos = ((long long int)bbGetInputSlice() + i*dimX + j*dimX*dimY)*dataSize ;
-#if defined(_WIN32)
-                                       if (_lseeki64( fd, pos , SEEK_SET ) < 0)
-#else
-                                       if (lseek64(fd, pos , SEEK_SET) < 0) 
-#endif // defined(_WIN32)
-                                       {
-                                               printf("EED ReadMHDPlane::Read64lseek \n");
-                                               fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
-                                               exit(1);
-                                       }
-
-                                       pImage=(char*)(newImage->GetScalarPointer(i, j,0 ));
-                                       if ((ret = read(fd, pImage , dataSize)) < 0) 
-                                       {
-                                               fprintf(stderr, "Failed reading: %s\n", strerror(errno));
-                                               exit(1);
-                                       }
-                               }
-                       } // for j
+                               copy_YZ_plane(fd,newImage,slice+iWidth,iWidth,dimX,dimY,dimZ,dataSize);
+                       }
                }  // if PLANE YZ       
 #if defined(_WIN32)
                _close (fd);
@@ -363,65 +308,141 @@ void ReadMHDPlane::Read64lseek()
        } else {
                newImage=CreateDefaultImage();
        } // if  ffIn
-
        bbSetOutputOut( newImage );
-
+       bbSetOutputOut2( ChangeOrientation(newImage) );
 }
 
 
-void ReadMHDPlane::Process()
+void ReadMHDPlane::copy_YZ_plane(int fd,vtkImageData *newImage,int slice,int iWidth,int dimX,int dimY,int dimZ,int dataSize)
 {
-       if (bbGetInputType()==0)
+       long long int j;
+       long long int i;
+       long long       ret;
+       long long       pos;
+       long long sizeBytesPlane = dimX*dimY*dataSize;
+       char *pImage;
+       for (j=0;j<dimZ;j++)
        {
-               ReadNormalMHD();
-       }       
+               for (i=0;i<dimY;i++)
+               {
+                       pos = ((long long int)slice+iWidth + i*dimX + j*dimX*dimY)*dataSize ;
+#if defined(_WIN32)
+                       if (_lseeki64( fd, pos , SEEK_SET ) < 0)
+#else
+                       if (lseek64(fd, pos , SEEK_SET) < 0) 
+#endif // defined(_WIN32)
+                       {
+                               printf("EED ReadMHDPlane::Read64lseek \n");
+                               fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
+                               exit(1);
+                       }
+
+                       pImage=(char*)(newImage->GetScalarPointer(i, dimZ-1-j,iWidth ));
+                       if ((ret = read(fd, pImage , dataSize)) < 0) 
+                       {
+                               fprintf(stderr, "Failed reading: %s\n", strerror(errno));
+                               exit(1);
+                       }
+                       } // for i
+               } // for j
+}
 
-       if (bbGetInputType()==1)
+
+void ReadMHDPlane::copy_ZX_plane(int fd,vtkImageData *newImage,int slice,int iWidth,int dimX,int dimY,int dimZ,int dataSize)
+{
+       long long int j;
+       long long       ret;
+       long long       pos;
+       pos = dimX*(long long int)slice*dataSize;
+       long long sizeBytesPlane = dimX*dimY*dataSize;
+       char *pImage = (char*)( newImage->GetScalarPointer(0,0,iWidth) );
+       for (j=dimZ-1;j>=0;j--)
        {
-               Read64lseek();
-       }       
+#if defined(_WIN32)
+               if (_lseeki64( fd, pos + j*sizeBytesPlane , SEEK_SET ) < 0)
+#else
+               if (lseek64(fd, pos + j*sizeBytesPlane , SEEK_SET) < 0) 
+#endif // defined(_WIN32)
+               {
+                       printf("EED ReadMHDPlane::Read64lseek \n");
+                       fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
+                       exit(1);
+               }
+               if ((ret = read(fd, pImage , dimX*dataSize)) < 0) 
+               {
+                       fprintf(stderr, "Failed reading: %s\n", strerror(errno));
+                       exit(1);
+               }
+               pImage = pImage+dimX*dataSize;
+       } // for j
+}
 
+void ReadMHDPlane::Process()
+{
+       if (bbGetInputActive()==true)
+       {
+printf("EED ReadMHDPlane::Process %d \n", bbGetInputSlice() );
+               if (bbGetInputType()==0)
+               {
+                       //-- Split FileName
+                       std::string inputfilename;
+                       std::size_t found               =       bbGetInputFileName().find_last_of("/\\");
+                       std::string path                =       bbGetInputFileName().substr(0,found+1);
+                       std::string filename    =       bbGetInputFileName().substr(found+1);
+       #ifdef _WIN32
+                       path=path+"YZ_ZX\\";
+       #else
+                       path=path+"YZ_ZX/";
+       #endif
+                       if (bbGetInputDirectionPlane()=="XY") { inputfilename = bbGetInputFileName();           } // if XY
+                       if (bbGetInputDirectionPlane()=="YZ") { inputfilename = path+filename+"_YZ.mhd";        } // if YZ
+                       if (bbGetInputDirectionPlane()=="ZX") { inputfilename = path+filename+"_ZX.mhd";        } // if XZ
+                       Read64lseek( inputfilename ,"XY");
+               }       
+               if (bbGetInputType()==1)
+               {
+                       Read64lseek( bbGetInputFileName(), bbGetInputDirectionPlane() );
+               }       
+       } // if active
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void ReadMHDPlane::bbUserSetDefaultValues()
 {
-
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
+   bbSetInputActive(true);
    bbSetInputFileName("");
    bbSetInputSlice(0);
    bbSetInputType(1);
+   bbSetInputWidth(1);
    bbSetInputDirectionPlane("XY");
-  
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void ReadMHDPlane::bbUserInitializeProcessing()
 {
-
 //  THE INITIALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should allocate the internal/output pointers 
 //    if any 
-
-  
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void ReadMHDPlane::bbUserFinalizeProcessing()
 {
-
 //  THE FINALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should desallocate the internal/output pointers 
-//    if any
-  
-}
+//    if any 
 }
-// EO namespace bbcreaVtk
+
+} // EO namespace bbcreaVtk