From 50cc4b75144e380a3de98478b01390882914a33a Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Wed, 14 Oct 2015 13:53:46 +0200 Subject: [PATCH] #2711 creaVtk Feature New Normal - new Box ReadMHDPlane --- .../src/bbcreaVtkReadMHDPlane.cxx | 124 ++++++++++-------- 1 file changed, 69 insertions(+), 55 deletions(-) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx index 5436547..c5c2dcd 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx @@ -34,67 +34,81 @@ void ReadMHDPlane::Process() - + vtkImageData *newImage; long int newHeaderSize; - std::string newFileName=bbGetInputFileName()+"-OneSlice"; + std::string newFileName=bbGetInputFileName()+"-OneSlice"; - int sx,sy; + int sx,sy,sz; char mystring[250]; char strTmp[20]; - FILE *ffOut = fopen(newFileName.c_str(),"w+"); + bool ok=true; FILE *ffIn = fopen(bbGetInputFileName().c_str(),"r+"); - - 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) + 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) {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 = sx*sy*bbGetInputSlice(); + if (bbGetInputSlice()>=sz) {ok=false;} + } // if + 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*2; } + 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 = %ld\n\n", newHeaderSize ); + } // if + fprintf(ffOut,mystring); + } // while + fclose(ffIn); + fclose(ffOut); + + if (ok==true) + { + vtkMetaImageReader * reader = vtkMetaImageReader::New(); + reader->SetFileName( newFileName.c_str() ); + reader->Update(); + newImage = reader->GetOutput(); + } // if ok + } else { + ok=false; + } + + if (ok==false) { - sscanf(mystring,"%s %s %d %d",strTmp, strTmp, &sx, &sy); - sprintf(mystring,"DimSize = %d %d\n",sx,sy); - newHeaderSize = sx*sy*bbGetInputSlice(); - } - 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*2; } - 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 = %ld\n\n", newHeaderSize ); - } - fprintf(ffOut,mystring); - } - -/* - fprintf(ff,"ObjectType = Image\n"); - fprintf(ff,"NDims = 2\n"); - fprintf(ff,"BinaryData = True\n"); - fprintf(ff,"BinaryDataByteOrderMSB = False\n"); - fprintf(ff,"CompressedData = False\n"); - fprintf(ff,"TransformMatrix = 1 0 0 0 1 0 0 0 1\n"); - fprintf(ff,"CenterOfRotation = 0 0 0\n"); - fprintf(ff,"ElementSpacing = 0.7 0.7 0.7\n"); - fprintf(ff,"DimSize = 512 512\n"); - fprintf(ff,"AnatomicalOrientation = ???\n"); - fprintf(ff,"ElementType = MET_SHORT\n"); - fprintf(ff,"ElementNumberOfChannels = 1\n"); - fprintf(ff,"Offset = 0 0 0\n"); - fprintf(ff,"HeaderSize = %ld\n", newHeaderSize ); - fprintf(ff,"ElementDataFile = inspi1_ana.raw\n"); -*/ - - fclose(ffIn); - fclose(ffOut); - - - vtkMetaImageReader * reader = vtkMetaImageReader::New(); - reader->SetFileName( newFileName.c_str() ); - reader->Update(); - - bbSetOutputOut( reader->GetOutput() ); - + int i,j; + int sizeX, sizeY, sizeZ; + sizeX = 200; + sizeY = sizeX; + sizeZ = 1; + 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 ); + 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 + } // if ok + + bbSetOutputOut( newImage ); } //===== -- 2.47.1