X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=bbtk_creaVtk_PKG%2Fsrc%2FbbcreaVtkReadMHDPlane.cxx;h=3581966d4a7db99c5ac697035c1289a3e408dd59;hb=8eabea73801eaefdfd58f678bc22c64b385a42f5;hp=48b16035f6e37fc03ab52f1aff6c9413a54d0f1d;hpb=cf0bc4afad6916bb3f3e9d7865ad1c2b19112aea;p=creaVtk.git diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx index 48b1603..3581966 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx @@ -13,8 +13,9 @@ #include #if defined(_WIN32) + #include #else -#include + #include #endif // defined(_WIN32) #include @@ -35,377 +36,169 @@ 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(); newImage->Initialize(); - newImage->SetScalarTypeToUnsignedChar(); newImage->SetSpacing( 1,1,1 ); newImage->SetDimensions( sizeX,sizeY,sizeZ ); + 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->SetExtent(0, sizeX-1,0,sizeY-1,0,sizeZ-1 ); + newImage->SetScalarTypeToUnsignedChar(); newImage->SetNumberOfScalarComponents(1); newImage->AllocateScalars(); newImage->Update(); - memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*1 ); - for (i=0; iSetScalarComponentFromDouble(i,i,0, 0, 255 ); - newImage->SetScalarComponentFromDouble(i,sizeY-1-i,0, 0, 255 ); - } // for i +#else +// newImage->AllocateScalars(VTK_UNSIGNED_CHAR,1); + newImage->AllocateScalars(VTK_SHORT,1); +#endif +// memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*sizeZ*sizeof(unsigned char) ); + memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*sizeof(short) ); +// for (i=0; iSetScalarComponentFromDouble(i,i ,0, 0, 255 ); +// newImage->SetScalarComponentFromDouble(i,sizeY-1-i ,0, 0, 255 ); +// } // for i + newImage->Modified(); +*/ return newImage; } -/* EED Borrame -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 = " <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") - { - inputfilename = path+filename+"_YZ.mhd"; - } // if YZ - - if (bbGetInputDirectionPlane()=="ZX") { - inputfilename = path+filename+"_ZX.mhd"; - } // XZ - } // if YZ || XZ - - width = bbGetInputWidth(); - if (width<=0 ) { width=1; } - - slice = bbGetInputSlice(); - if (slice<0 ) { slice=0; } - - vtkImageData *newImage; - long long 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) - { - FILE *ffOut = fopen(newFileName.c_str(),"w"); - while(!feof(ffIn)) - { - strcpy(mystring,"\n"); - fgets(mystring,250,ffIn); - if (strncmp("NDims",mystring,5)==0) - { - if (width==1) - { - strcpy(mystring,"NDims = 2\n"); - } else { - strcpy(mystring,"NDims = 3\n"); - } - } - if (strncmp("DimSize",mystring,6)==0) - { - sscanf(mystring,"%s %s %d %d %d",strTmp, strTmp, &sx, &sy,&sz); - if (width==1) - { - sprintf(mystring,"DimSize = %d %d\n",sx,sy); - } else { - sprintf(mystring,"DimSize = %d %d %d\n",sx,sy,width); - } - newHeaderSize = (long long int)sx*(long long int)sy*(long long int)slice; - if (bbGetInputSlice()>=sz) {ok=false;} - } // if - if (strncmp("ElementType = MET_CHAR",mystring,22)==0) { dataSize=sizeof(char); } - if (strncmp("ElementType = VTK_CHAR",mystring,22)==0) { dataSize=sizeof(char); } - if (strncmp("ElementType = MET_UCHAR",mystring,23)==0) { dataSize=sizeof(unsigned char); } - if (strncmp("ElementType = VTK_UNSIGNED_CHAR",mystring,31)==0) { dataSize=sizeof(unsigned char); } - if (strncmp("ElementType = MET_USHORT",mystring,24)==0) { dataSize=sizeof(unsigned short); } - if (strncmp("ElementType = VTK_UNSIGNED_SHORT",mystring,32)==0) { dataSize=sizeof(unsigned short); } - if (strncmp("ElementType = MET_SHORT",mystring,23)==0) { dataSize=sizeof(short); } - if (strncmp("ElementType = VTK_SHORT",mystring,23)==0) { dataSize=sizeof(short); } - if (strncmp("ElementType = MET_UINT",mystring,22)==0) { dataSize=sizeof(unsigned int); } - if (strncmp("ElementType = VTK_UNSIGNED_INT",mystring,30)==0) { dataSize=sizeof(unsigned int); } - if (strncmp("ElementType = MET_INT",mystring,21)==0) { dataSize=sizeof(int); } - if (strncmp("ElementType = VTK_INT",mystring,21)==0) { dataSize=sizeof(int); } - if (strncmp("ElementType = MET_FLOAT",mystring,23)==0) { dataSize=sizeof(float); } - if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0) { dataSize=sizeof(float); } - if (strncmp("ElementType = MET_LONG",mystring,22)==0) { dataSize=sizeof(long); } - if (strncmp("ElementType = VTK_LONG",mystring,22)==0) { dataSize=sizeof(long); } - if (strncmp("ElementType = MET_DOUBLE",mystring,24)==0) { dataSize=sizeof(double); } - if (strncmp("ElementType = VTK_DOUBLE",mystring,24)==0) { dataSize=sizeof(double); } - newHeaderSize=newHeaderSize*dataSize; - 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 (ok==true) + sizeXDst = width; + sizeYDst = ext[1]-ext[0]+1; + sizeZDst = ext[3]-ext[2]+1; + sizeLine = sizeYDst; + } // YZ + if (bbGetInputDirectionPlane()=="ZX") { - 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 ffIn - if (ok==false) - { - newImage=CreateDefaultImage(); - } // if ok - - bbSetOutputOut( newImage ); - bbSetOutputOut2( ChangeOrientation(newImage) ); -} -*/ - -vtkImageData* ReadMHDPlane::ChangeOrientation(vtkImageData* img) -{ - int ext[6]; - int sizeX, sizeY,sizeZ; - img->GetWholeExtent(ext); - int sizeLine; - if (bbGetInputDirectionPlane()=="XY") - { - sizeX = ext[1]-ext[0]+1; - sizeY = ext[3]-ext[2]+1; - sizeZ = 1; - } // XY - if (bbGetInputDirectionPlane()=="YZ") - { - sizeX = 1; - sizeY = ext[1]-ext[0]+1; - sizeZ = ext[3]-ext[2]+1; - sizeLine = sizeY; - } // YZ - if (bbGetInputDirectionPlane()=="ZX") - { - sizeX = ext[1]-ext[0]+1; - sizeY = 1; - sizeZ = ext[3]-ext[2]+1; - sizeLine = sizeX; - } // ZX - vtkImageData *newImageOrinted = vtkImageData::New(); - newImageOrinted->Initialize(); - newImageOrinted->SetScalarType( img->GetScalarType() ); - newImageOrinted->SetSpacing( img->GetSpacing() ); - newImageOrinted->SetDimensions( sizeX,sizeY,sizeZ ); - newImageOrinted->SetWholeExtent(0,sizeX-1,0,sizeY-1,0,sizeZ-1 ); - newImageOrinted->SetExtent(0,sizeX-1,0,sizeY-1,0,sizeZ-1 ); - newImageOrinted->SetNumberOfScalarComponents(1); - newImageOrinted->AllocateScalars(); - newImageOrinted->Update(); - if (bbGetInputDirectionPlane()=="XY") - { - memcpy ( newImageOrinted->GetScalarPointer(), img->GetScalarPointer(), sizeX*sizeY*sizeZ*img->GetScalarSize() ); - } else { - int yy; - int dimY=ext[3]-ext[2]+1; - int sizeByte=sizeLine*img->GetScalarSize(); - char *ptrDst=(char*)(newImageOrinted->GetScalarPointer()) + sizeByte*dimY; - char *ptrOrg=(char*)(img->GetScalarPointer()); - for (yy=0 ; yyInitialize(); + 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; + + 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() ); + + if (bbGetInputDirectionPlane()=="XY") { - ptrDst=ptrDst-sizeByte; - memcpy ( ptrDst, ptrOrg , sizeByte ); - ptrOrg=ptrOrg+sizeByte; - }// for - } - return newImageOrinted; -} + memcpy ( imgDst->GetScalarPointer(), ptrOrg , sizeXDst*sizeYDst*sizeZDst*(imgOrg->GetScalarSize()) ); + } // if XY -/* EED Borrame -void ReadMHDPlane::Read64lseek() -{ - 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"); - std::string elementdatafile("VOID"); - 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"); - 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("ElementType",mystring,11)==0) { sscanf(mystring,"%s %s %s" ,strTmp, strTmp, strTmp2); formattype=strTmp2; } - 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 = 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); } - } // while - fclose(ffIn); - newImage->Initialize(); - 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*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) + if (bbGetInputDirectionPlane()=="ZX") { - printf("EED ReadMHDPlane::Read64lseek WARNNING! raw file not exist\n"); - fprintf(stderr, "%s\n", strerror(errno)); - newImage=CreateDefaultImage(); -// exit(1); - } - if ((bbGetInputDirectionPlane()=="XY") && (fd>=0)) - { - 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 ); - newImage->SetNumberOfScalarComponents(1); - newImage->AllocateScalars(); - newImage->Update(); - pos = dimX*dimY*(long long)slice*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); - } - if ((ret = read(fd, newImage->GetScalarPointer() , lsize)) < 0) - { - fprintf(stderr, "Failed reading: %s\n", strerror(errno)); - exit(1); - } - } // if PLANE XY - if ((bbGetInputDirectionPlane()=="ZX") && (fd>=0)) - { - 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 ); - newImage->SetNumberOfScalarComponents(1); - newImage->AllocateScalars(); - newImage->Update(); - int iWidth; - for (iWidth=0;iWidthGetScalarPointer(0,0,sizeYOrg-00-1) ); + for( zz=0 ; zz=0)) - { - 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 ); - newImage->SetNumberOfScalarComponents(1); - newImage->AllocateScalars(); - newImage->Update(); - int iWidth; - for (iWidth=0;iWidthGetScalarPointer(0,zz,sizeYOrg-00-1) ); + for( yy=0 ; yyGetScalarPointer(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 ; zzGetScalarPointer(zz,0,sizeYOrg-0-1) ); + for( yy=0 ; yyGetScalarPointer(zz,0,sizeYOrg-yy-1) ); + for( xx=0 ; xxGetScalarPointer(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; } -*/ void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane) { + int imageType; int slice; int width; width = bbGetInputWidth(); @@ -432,32 +225,32 @@ void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane) { 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("ElementType",mystring,11)==0) { sscanf(mystring,"%s %s %s" ,strTmp, strTmp, strTmp2); formattype=strTmp2; } - 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 = 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("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,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) { 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(); @@ -485,11 +278,21 @@ 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->SetScalarType( imageType ); + newImage->SetWholeExtent(0, dimX-1,0,dimY-1,0,width-1 ); newImage->SetNumberOfScalarComponents(1); 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) @@ -511,11 +314,20 @@ 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->SetScalarType( imageType ); + newImage->SetWholeExtent(0, dimX-1,0,dimZ-1,0,width-1 ); newImage->SetNumberOfScalarComponents(1); newImage->AllocateScalars(); newImage->Update(); +#else + newImage->AllocateScalars(imageType,1); +#endif + int iWidth; for (iWidth=0;iWidthSetSpacing( 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->SetScalarType( imageType ); + newImage->SetWholeExtent(0, dimY-1,0,dimZ-1,0,width-1 ); newImage->SetNumberOfScalarComponents(1); newImage->AllocateScalars(); newImage->Update(); +#else + newImage->AllocateScalars(imageType,1); +#endif + int iWidth; for (iWidth=0;iWidth