]> Creatis software - creaVtk.git/blobdiff - bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx
#3223 creaVtk Feature New Normal - vtk8itk4wx3-mingw64
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkReadMHDPlane.cxx
index 1662b1a7f1d4af0cce800c798a60ca392c59a7fc..02ae564046763bcacde94b725ca679d459af1fdf 100644 (file)
@@ -13,8 +13,9 @@
 #include <sys/types.h>
 
 #if defined(_WIN32)
+       #include <share.h> 
 #else
-#include <unistd.h>
+       #include <unistd.h>
 #endif // defined(_WIN32)
 
 #include <stdlib.h>
@@ -42,14 +43,21 @@ vtkImageData* ReadMHDPlane::CreateDefaultImage()
        sizeZ = 1;
        vtkImageData *newImage = vtkImageData::New();
        newImage->Initialize();
-       newImage->SetScalarTypeToUnsignedChar();
        newImage->SetSpacing( 1,1,1 );
        newImage->SetDimensions(  sizeX,sizeY,sizeZ );
-       newImage->SetWholeExtent(0,  sizeX-1,0,sizeY-1,0,sizeZ-1 );
        newImage->SetExtent(0,  sizeX-1,0,sizeY-1,0,sizeZ-1 );
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+       newImage->SetWholeExtent(0,  sizeX-1,0,sizeY-1,0,sizeZ-1 );
+       newImage->SetScalarTypeToUnsignedChar();
        newImage->SetNumberOfScalarComponents(1);
        newImage->AllocateScalars();
        newImage->Update();
+#else
+       newImage->AllocateScalars(VTK_UNSIGNED_CHAR,1);
+#endif
+
        memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*1 );
        for (i=0; i<sizeX; i++)
        {
@@ -183,6 +191,9 @@ void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane)
        float           ox=-1,oy=-1,oz=-1;
        long int        headersize=0;
        vtkImageData *newImage=NULL;
+
+       int imageType;
+
        char mystring[250];
        char strTmp[30];
        char strTmp2[30];
@@ -203,24 +214,28 @@ void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane)
                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 = 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 = 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_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);                }
+
+                       
+
+                       if (strncmp("ElementType = MET_CHAR",mystring,22)==0)                   { imageType =VTK_CHAR;                   dataSize=sizeof(char);                  }
+                       if (strncmp("ElementType = VTK_CHAR",mystring,22)==0)                   { imageType =VTK_CHAR;                   dataSize=sizeof(char);                  }
+                       if (strncmp("ElementType = MET_UCHAR",mystring,23)==0)                  { imageType =VTK_UNSIGNED_CHAR;  dataSize=sizeof(unsigned char); }
+                       if (strncmp("ElementType = VTK_UNSIGNED_CHAR",mystring,31)==0)  { imageType =VTK_UNSIGNED_CHAR;  dataSize=sizeof(unsigned char); }
+                       if (strncmp("ElementType = MET_USHORT",mystring,24)==0)                 { imageType =VTK_UNSIGNED_SHORT; dataSize=sizeof(unsigned short);}
+                       if (strncmp("ElementType = VTK_UNSIGNED_SHORT",mystring,32)==0) { imageType =VTK_UNSIGNED_SHORT; dataSize=sizeof(unsigned short);}
+                       if (strncmp("ElementType = MET_SHORT",mystring,23)==0)                  { imageType =VTK_SHORT;                  dataSize=sizeof(short);                 }
+                       if (strncmp("ElementType = VTK_SHORT",mystring,23)==0)                  { imageType =VTK_SHORT;                  dataSize=sizeof(short);                 }
+                       if (strncmp("ElementType = MET_UINT",mystring,22)==0)                   { imageType =VTK_UNSIGNED_INT;   dataSize=sizeof(unsigned int);  }
+                       if (strncmp("ElementType = VTK_UNSIGNED_INT",mystring,30)==0)   { imageType =VTK_UNSIGNED_INT;   dataSize=sizeof(unsigned int);  }
+                       if (strncmp("ElementType = MET_INT",mystring,21)==0)                    { imageType =VTK_INT;                    dataSize=sizeof(int);                   }
+                       if (strncmp("ElementType = VTK_INT",mystring,21)==0)                    { imageType =VTK_INT;                    dataSize=sizeof(int);                   }
+                       if (strncmp("ElementType = MET_FLOAT",mystring,23)==0)                  { imageType =VTK_FLOAT;                  dataSize=sizeof(float);                 }
+                       if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0)                  { imageType =VTK_FLOAT;                  dataSize=sizeof(float);                 }
+                       if (strncmp("ElementType = MET_LONG",mystring,22)==0)                   { imageType =VTK_LONG;                   dataSize=sizeof(long);                  }
+                       if (strncmp("ElementType = VTK_LONG",mystring,22)==0)                   { imageType =VTK_LONG;                   dataSize=sizeof(long);                  }
+                       if (strncmp("ElementType = MET_DOUBLE",mystring,24)==0)                 { imageType =VTK_DOUBLE;                 dataSize=sizeof(double);                }
+                       if (strncmp("ElementType = VTK_DOUBLE",mystring,24)==0)                 { imageType =VTK_DOUBLE;                 dataSize=sizeof(double);                }
+
        } // while
                fclose(ffIn);
                newImage->Initialize();
@@ -248,11 +263,20 @@ void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane)
                { 
                        newImage->SetSpacing( spcX,spcY,spcZ );
                        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 );
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+                       newImage->SetWholeExtent(0,  dimX-1,0,dimY-1,0,width-1 );
                        newImage->SetNumberOfScalarComponents(1);
+                       newImage->SetScalarType(imageType);
                        newImage->AllocateScalars();
                        newImage->Update();
+#else
+                       newImage->AllocateScalars( imageType,1 );
+#endif
+
+
                        pos = dimX*dimY*(long long)slice*dataSize;
 #if defined(_WIN32)
                        if (_lseeki64( fd, pos, SEEK_SET ) < 0)
@@ -274,11 +298,18 @@ void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane)
                { 
                        newImage->SetSpacing( spcX,spcZ,spcY );
                        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 );
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+                       newImage->SetWholeExtent(0,  dimX-1,0,dimZ-1,0,width-1 );
                        newImage->SetNumberOfScalarComponents(1);
+                       newImage->SetScalarType(imageType);
                        newImage->AllocateScalars();
                        newImage->Update();
+#else
+                       newImage->AllocateScalars( imageType, 1);
+#endif
+
                        int iWidth;
                        for (iWidth=0;iWidth<width;iWidth++)
                        {
@@ -289,11 +320,18 @@ void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane)
                { 
                        newImage->SetSpacing( spcY,spcZ,spcX );
                        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 );
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+                       newImage->SetWholeExtent(0,  dimY-1,0,dimZ-1,0,width-1 );
                        newImage->SetNumberOfScalarComponents(1);
+                       newImage->SetScalarType(imageType);
                        newImage->AllocateScalars();
                        newImage->Update();
+#else
+                       newImage->AllocateScalars( imageType ,1 );
+#endif
+
                        int iWidth;
                        for (iWidth=0;iWidth<width;iWidth++)
                        {