-// 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 slice;
- int width;
- long long dataSize;
-
- if (bbGetInputDirectionPlane()=="XY")
- {
- inputfilename=bbGetInputFileName();
- } // if XY
-
- if ((bbGetInputDirectionPlane()=="YZ") || (bbGetInputDirectionPlane()=="ZX"))
- {
- //-- 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
-
- 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)
- {
- 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) );
-}
-*/