]> Creatis software - creaVtk.git/blobdiff - bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx
#3389 creaVtk Feature New Normal - new box save_YZ_XZ_volume
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkReadMHDPlane.cxx
index e9634ee8169fbe19093cf0279f4ee95048cb31c0..3581966d4a7db99c5ac697035c1289a3e408dd59 100644 (file)
@@ -36,9 +36,12 @@ BBTK_BLACK_BOX_IMPLEMENTATION(ReadMHDPlane,bbtk::AtomicBlackBox);
 
 vtkImageData* ReadMHDPlane::CreateDefaultImage()
 {
+       vtkImageData *newImage = NULL;
+/*
+       newImage = vtkImageData::New();
        int i;
        int sizeX, sizeY, sizeZ;
-       sizeX = 200;
+       sizeX = 1;
        sizeY = sizeX;
        sizeZ = 1;
        vtkImageData *newImage = vtkImageData::New();
@@ -54,133 +57,142 @@ vtkImageData* ReadMHDPlane::CreateDefaultImage()
        newImage->AllocateScalars();
        newImage->Update();
 #else
-       newImage->AllocateScalars(VTK_UNSIGNED_CHAR,1);
+//     newImage->AllocateScalars(VTK_UNSIGNED_CHAR,1);
+       newImage->AllocateScalars(VTK_SHORT,1);
 #endif
-       memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*1 );
-       for (i=0; i<sizeX; i++)
-       {
-               newImage->SetScalarComponentFromDouble(i,i,0, 0, 255 );
-               newImage->SetScalarComponentFromDouble(i,sizeY-1-i,0, 0, 255 );
-       } // for i
+//     memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*sizeZ*sizeof(unsigned char) );
+       memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*sizeof(short) );
+//     for (i=0; i<sizeX; i++)
+//     {
+//             newImage->SetScalarComponentFromDouble(i,i                      ,0, 0, 255 );
+//             newImage->SetScalarComponentFromDouble(i,sizeY-1-i      ,0, 0, 255 );
+//     } // for i
+       newImage->Modified();
+*/
        return newImage;
 } 
 
 vtkImageData* ReadMHDPlane::ChangeOrientation(vtkImageData* imgOrg)
 {
-       int     width = bbGetInputWidth();
-       int     ext[6];
-       int     sizeXOrg, sizeYOrg,sizeZOrg;
-       int     sizeXDst, sizeYDst,sizeZDst;
-//EED 2017-01-01 Migration VTK7
-#if VTK_MAJOR_VERSION <= 5
-       imgOrg->GetWholeExtent(ext);
-#else
-       imgOrg->GetExtent(ext);
-#endif
-       int     sizeLine;
-       
-       sizeXOrg        = ext[1]-ext[0]+1;
-       sizeYOrg        = ext[3]-ext[2]+1;
-       sizeZOrg        = ext[5]-ext[4]+1;
+       vtkImageData *imgDst  = NULL;
 
-       if (bbGetInputDirectionPlane()=="XY")
-       {
-               sizeXDst        = ext[1]-ext[0]+1;
-               sizeYDst        = ext[3]-ext[2]+1;
-               sizeZDst        = width;
-       } // XY 
-       if (bbGetInputDirectionPlane()=="YZ") 
-       {
-               sizeXDst        = width;
-               sizeYDst        = ext[1]-ext[0]+1;
-               sizeZDst        = ext[3]-ext[2]+1;
-               sizeLine        = sizeYDst;
-       } // YZ
-       if (bbGetInputDirectionPlane()=="ZX")
+       if (imgOrg!=NULL)
        {
-               sizeXDst        = ext[1]-ext[0]+1;
-               sizeYDst        = width;
-               sizeZDst        = ext[3]-ext[2]+1;
-               sizeLine        = sizeXDst;
-       } // ZX
-       vtkImageData *imgDst  = vtkImageData::New();
-       imgDst->Initialize();
-       imgDst->SetSpacing( imgOrg->GetSpacing() );
-       imgDst->SetDimensions( sizeXDst,sizeYDst,sizeZDst );
-       imgDst->SetExtent(0,sizeXDst-1,0,sizeYDst-1,0,sizeZDst-1 );
-       
-//EED 2017-01-01 Migration VTK7
-#if VTK_MAJOR_VERSION <= 5
-       imgDst->SetWholeExtent(0,sizeXDst-1,0,sizeYDst-1,0,sizeZDst-1 );
-       imgDst->SetScalarType( imgOrg->GetScalarType() );
-       imgDst->SetNumberOfScalarComponents(1);
-       imgDst->AllocateScalars();
-       imgDst->Update();
-#else
-       imgDst->AllocateScalars(imgOrg->GetScalarType(),1);
-#endif
+               int     width;
+               int     ext[6];
+               int     sizeXOrg, sizeYOrg,sizeZOrg;
+               int     sizeXDst, sizeYDst,sizeZDst;
+       //EED 2017-01-01 Migration VTK7
+       #if VTK_MAJOR_VERSION <= 5
+               imgOrg->GetWholeExtent(ext);
+       #else
+               imgOrg->GetExtent(ext);
+       #endif
+               int     sizeLine;
+               
+               sizeXOrg        = ext[1]-ext[0]+1;
+               sizeYOrg        = ext[3]-ext[2]+1;
+               sizeZOrg        = ext[5]-ext[4]+1;
+       width=sizeZOrg;
+
+               if (bbGetInputDirectionPlane()=="XY")
+               {
+                       sizeXDst        = ext[1]-ext[0]+1;
+                       sizeYDst        = ext[3]-ext[2]+1;
+                       sizeZDst        = width;
+               } // XY 
+               if (bbGetInputDirectionPlane()=="YZ") 
+               {
+                       sizeXDst        = width;
+                       sizeYDst        = ext[1]-ext[0]+1;
+                       sizeZDst        = ext[3]-ext[2]+1;
+                       sizeLine        = sizeYDst;
+               } // YZ
+               if (bbGetInputDirectionPlane()=="ZX")
+               {
+                       sizeXDst        = ext[1]-ext[0]+1;
+                       sizeYDst        = width;
+                       sizeZDst        = ext[3]-ext[2]+1;
+                       sizeLine        = sizeXDst;
+               } // ZX
+               imgDst  = vtkImageData::New();
+               imgDst->Initialize();
+               imgDst->SetSpacing( imgOrg->GetSpacing() );
+               imgDst->SetDimensions( sizeXDst,sizeYDst,sizeZDst );
+               imgDst->SetExtent(0,sizeXDst-1,0,sizeYDst-1,0,sizeZDst-1 );
+               
+       //EED 2017-01-01 Migration VTK7
+       #if VTK_MAJOR_VERSION <= 5
+               imgDst->SetWholeExtent(0,sizeXDst-1,0,sizeYDst-1,0,sizeZDst-1 );
+               imgDst->SetScalarType( imgOrg->GetScalarType() );
+               imgDst->SetNumberOfScalarComponents(1);
+               imgDst->AllocateScalars();
+               imgDst->Update();
+       #else
+               imgDst->AllocateScalars(imgOrg->GetScalarType(),1);
+       #endif
 
-       char *ptrDst,*ptrOrg;
-       int sizeBytes = imgOrg->GetScalarSize();                
-       int sizeLineBytes = sizeLine*imgOrg->GetScalarSize();           
-       int xx,yy,zz;
+               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;
+               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() );
+               ptrOrg = (char*)( imgOrg->GetScalarPointer() );
 
-       if (bbGetInputDirectionPlane()=="XY")
-       {
-               memcpy ( imgDst->GetScalarPointer(), ptrOrg , sizeXDst*sizeYDst*sizeZDst*(imgOrg->GetScalarSize()) );
-       } // if XY
+               if (bbGetInputDirectionPlane()=="XY")
+               {
+                       memcpy ( imgDst->GetScalarPointer(), ptrOrg , sizeXDst*sizeYDst*sizeZDst*(imgOrg->GetScalarSize()) );
+               } // if XY
 
-       if (bbGetInputDirectionPlane()=="ZX")
-       {
-               ptrDst = (char*)( imgDst->GetScalarPointer(0,0,sizeYOrg-00-1) );
-               for( zz=0 ; zz<sizeZOrg ; zz++)
+               if (bbGetInputDirectionPlane()=="ZX")
                {
-//                     ptrDst=(char*)( imgDst->GetScalarPointer(0,zz,sizeYOrg-00-1) );
-                       for( yy=0 ; yy<sizeYOrg ; yy++)
+                       ptrDst = (char*)( imgDst->GetScalarPointer(0,0,sizeYOrg-00-1) );
+                       for( zz=0 ; zz<sizeZOrg ; zz++)
                        {
-//                             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")
-       {
-               ptrDst = (char*)( imgDst->GetScalarPointer(0,0,sizeYOrg-0-1) );
-               for( zz=0 ; zz<sizeZOrg ; zz++)
+       //                      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")
                {
-                       ptrDst=(char*)( imgDst->GetScalarPointer(zz,0,sizeYOrg-0-1) );
-                       for( yy=0 ; yy<sizeYOrg ; yy++)
+                       ptrDst = (char*)( imgDst->GetScalarPointer(0,0,sizeYOrg-0-1) );
+                       for( zz=0 ; zz<sizeZOrg ; zz++)
                        {
-//                             ptrDst=(char*)( imgDst->GetScalarPointer(zz,0,sizeYOrg-yy-1) );
-                               for( xx=0 ; xx<sizeXOrg ; xx++)
+                               ptrDst=(char*)( imgDst->GetScalarPointer(zz,0,sizeYOrg-0-1) );
+                               for( yy=0 ; yy<sizeYOrg ; yy++)
                                {
-//                                     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
-
+       //                              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
+       } // if imgOrg
        return imgDst;
 }