2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
4 #include "bbcreaVtkReadMHDPlane.h"
5 #include "bbcreaVtkPackage.h"
10 #define _LARGEFILE64_SOURCE
13 #include <sys/types.h>
18 #endif // defined(_WIN32)
29 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ReadMHDPlane)
30 BBTK_BLACK_BOX_IMPLEMENTATION(ReadMHDPlane,bbtk::AtomicBlackBox);
32 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
36 vtkImageData* ReadMHDPlane::CreateDefaultImage()
39 int sizeX, sizeY, sizeZ;
43 vtkImageData *newImage = vtkImageData::New();
44 newImage->Initialize();
45 newImage->SetScalarTypeToUnsignedChar();
46 newImage->SetSpacing( 1,1,1 );
47 newImage->SetDimensions( sizeX,sizeY,sizeZ );
48 newImage->SetWholeExtent(0, sizeX-1,0,sizeY-1,0,sizeZ-1 );
49 newImage->SetExtent(0, sizeX-1,0,sizeY-1,0,sizeZ-1 );
50 newImage->SetNumberOfScalarComponents(1);
51 newImage->AllocateScalars();
53 memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*1 );
54 for (i=0; i<sizeX; i++)
56 newImage->SetScalarComponentFromDouble(i,i,0, 0, 255 );
57 newImage->SetScalarComponentFromDouble(i,sizeY-1-i,0, 0, 255 );
63 void ReadMHDPlane::ReadNormalMHD()
65 // THE MAIN PROCESSING METHOD BODY
66 // Here we simply set the input 'In' value to the output 'Out'
67 // And print out the output value
68 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
69 // void bbSet{Input|Output}NAME(const TYPE&)
70 // const TYPE& bbGet{Input|Output}NAME() const
72 // * NAME is the name of the input/output
73 // (the one provided in the attribute 'name' of the tag 'input')
74 // * TYPE is the C++ type of the input/output
75 // (the one provided in the attribute 'type' of the tag 'input')
77 // bbSetOutputOut( bbGetInputIn() );
78 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
80 std::string inputfilename;
85 if (bbGetInputDirectionPlane()=="XY")
87 inputfilename=bbGetInputFileName();
90 if ((bbGetInputDirectionPlane()=="YZ") || (bbGetInputDirectionPlane()=="ZX"))
93 std::size_t found = bbGetInputFileName().find_last_of("/\\");
94 std::string path = bbGetInputFileName().substr(0,found+1);
95 std::string filename = bbGetInputFileName().substr(found+1);
101 if (bbGetInputDirectionPlane()=="YZ")
103 inputfilename = path+filename+"_YZ.mhd";
106 if (bbGetInputDirectionPlane()=="ZX")
108 inputfilename = path+filename+"_ZX.mhd";
112 width = bbGetInputWidth();
113 if (width<=0 ) { width=1; }
115 slice = bbGetInputSlice();
116 if (slice<0 ) { slice=0; }
118 vtkImageData *newImage;
119 long long newHeaderSize;
120 std::string newFileName=inputfilename+"-OneSlice";
126 FILE *ffIn = fopen(inputfilename.c_str(),"r");
129 FILE *ffOut = fopen(newFileName.c_str(),"w");
132 strcpy(mystring,"\n");
133 fgets(mystring,250,ffIn);
134 if (strncmp("NDims",mystring,5)==0)
138 strcpy(mystring,"NDims = 2\n");
140 strcpy(mystring,"NDims = 3\n");
143 if (strncmp("DimSize",mystring,6)==0)
145 sscanf(mystring,"%s %s %d %d %d",strTmp, strTmp, &sx, &sy,&sz);
148 sprintf(mystring,"DimSize = %d %d\n",sx,sy);
150 sprintf(mystring,"DimSize = %d %d %d\n",sx,sy,width);
152 newHeaderSize = (long long int)sx*(long long int)sy*(long long int)slice;
153 if (bbGetInputSlice()>=sz) {ok=false;}
155 if (strncmp("ElementType = MET_CHAR",mystring,22)==0) { dataSize=sizeof(char); }
156 if (strncmp("ElementType = VTK_CHAR",mystring,22)==0) { dataSize=sizeof(char); }
157 if (strncmp("ElementType = MET_UCHAR",mystring,23)==0) { dataSize=sizeof(unsigned char); }
158 if (strncmp("ElementType = VTK_UNSIGNED_CHAR",mystring,31)==0) { dataSize=sizeof(unsigned char); }
159 if (strncmp("ElementType = MET_USHORT",mystring,24)==0) { dataSize=sizeof(unsigned short); }
160 if (strncmp("ElementType = VTK_UNSIGNED_SHORT",mystring,32)==0) { dataSize=sizeof(unsigned short); }
161 if (strncmp("ElementType = MET_SHORT",mystring,23)==0) { dataSize=sizeof(short); }
162 if (strncmp("ElementType = VTK_SHORT",mystring,23)==0) { dataSize=sizeof(short); }
163 if (strncmp("ElementType = MET_UINT",mystring,22)==0) { dataSize=sizeof(unsigned int); }
164 if (strncmp("ElementType = VTK_UNSIGNED_INT",mystring,30)==0) { dataSize=sizeof(unsigned int); }
165 if (strncmp("ElementType = MET_INT",mystring,21)==0) { dataSize=sizeof(int); }
166 if (strncmp("ElementType = VTK_INT",mystring,21)==0) { dataSize=sizeof(int); }
167 if (strncmp("ElementType = MET_FLOAT",mystring,23)==0) { dataSize=sizeof(float); }
168 if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0) { dataSize=sizeof(float); }
169 if (strncmp("ElementType = MET_LONG",mystring,22)==0) { dataSize=sizeof(long); }
170 if (strncmp("ElementType = VTK_LONG",mystring,22)==0) { dataSize=sizeof(long); }
171 if (strncmp("ElementType = MET_DOUBLE",mystring,24)==0) { dataSize=sizeof(double); }
172 if (strncmp("ElementType = VTK_DOUBLE",mystring,24)==0) { dataSize=sizeof(double); }
173 newHeaderSize=newHeaderSize*dataSize;
174 if (strncmp("Offset",mystring,6)==0) {strcpy(mystring,"Offset = 0 0 0\n");}
175 if (strncmp("HeaderSize",mystring,10)==0) {strcpy(mystring,"");}
176 if (strncmp("ElementDataFile",mystring,15)==0)
178 fprintf(ffOut,"HeaderSize = %lld\n\n", newHeaderSize );
180 fprintf(ffOut,mystring);
186 vtkMetaImageReader * reader = vtkMetaImageReader::New();
187 reader->SetFileName( newFileName.c_str() );
189 newImage = reader->GetOutput();
193 printf("EED ERROR: Problem openin:%s\n", inputfilename.c_str() );
197 newImage=CreateDefaultImage();
200 bbSetOutputOut( newImage );
201 bbSetOutputOut2( ChangeOrientation(newImage) );
205 vtkImageData* ReadMHDPlane::ChangeOrientation(vtkImageData* img)
208 int sizeX, sizeY,sizeZ;
209 img->GetWholeExtent(ext);
211 if (bbGetInputDirectionPlane()=="XY")
213 sizeX = ext[1]-ext[0]+1;
214 sizeY = ext[3]-ext[2]+1;
217 if (bbGetInputDirectionPlane()=="YZ")
220 sizeY = ext[1]-ext[0]+1;
221 sizeZ = ext[3]-ext[2]+1;
224 if (bbGetInputDirectionPlane()=="ZX")
226 sizeX = ext[1]-ext[0]+1;
228 sizeZ = ext[3]-ext[2]+1;
231 vtkImageData *newImageOrinted = vtkImageData::New();
232 newImageOrinted->Initialize();
233 newImageOrinted->SetScalarType( img->GetScalarType() );
234 newImageOrinted->SetSpacing( img->GetSpacing() );
235 newImageOrinted->SetDimensions( sizeX,sizeY,sizeZ );
236 newImageOrinted->SetWholeExtent(0,sizeX-1,0,sizeY-1,0,sizeZ-1 );
237 newImageOrinted->SetExtent(0,sizeX-1,0,sizeY-1,0,sizeZ-1 );
238 newImageOrinted->SetNumberOfScalarComponents(1);
239 newImageOrinted->AllocateScalars();
240 newImageOrinted->Update();
241 if (bbGetInputDirectionPlane()=="XY")
243 memcpy ( newImageOrinted->GetScalarPointer(), img->GetScalarPointer(), sizeX*sizeY*sizeZ*img->GetScalarSize() );
246 int dimY=ext[3]-ext[2]+1;
247 int sizeByte=sizeLine*img->GetScalarSize();
248 char *ptrDst=(char*)(newImageOrinted->GetScalarPointer()) + sizeByte*dimY;
249 char *ptrOrg=(char*)(img->GetScalarPointer());
250 for (yy=0 ; yy<dimY; yy++)
252 ptrDst=ptrDst-sizeByte;
253 memcpy ( ptrDst, ptrOrg , sizeByte );
254 ptrOrg=ptrOrg+sizeByte;
257 return newImageOrinted;
261 void ReadMHDPlane::Read64lseek()
265 width = bbGetInputWidth();
266 if (width<=0 ) { width=1; }
267 slice = bbGetInputSlice();
268 if (slice<0 ) { slice=0; }
269 int dimX=-1,dimY=-1,dimZ=-1;
271 std::string formattype("VOID");
272 std::string elementdatafile("VOID");
273 float spcX=-1,spcY=-1,spcZ=-1;
274 float ox=-1,oy=-1,oz=-1;
275 long int headersize=0;
276 vtkImageData *newImage=NULL;
280 FILE *ffIn = fopen(bbGetInputFileName().c_str(),"r");
284 newImage = vtkImageData::New();
287 strcpy(mystring,"\n");
288 fgets(mystring,250,ffIn);
289 if (strncmp("NDims",mystring,5)==0) { sscanf(mystring,"%s %s %d" ,strTmp, strTmp, &dim); }
290 if (strncmp("DimSize",mystring,6)==0) { sscanf(mystring,"%s %s %d %d %d" ,strTmp, strTmp, &dimX, &dimY,&dimZ); }
291 if (strncmp("ElementType",mystring,11)==0) { sscanf(mystring,"%s %s %s" ,strTmp, strTmp, strTmp2); formattype=strTmp2; }
292 if (strncmp("ElementSpacing",mystring,14)==0) { sscanf(mystring,"%s %s %f %f %f" ,strTmp, strTmp, &spcX,&spcY,&spcZ); }
293 if (strncmp("ElementSize",mystring,11)==0) { sscanf(mystring,"%s %s %f %f %f" ,strTmp, strTmp, &spcX,&spcY,&spcZ); }
294 if (strncmp("Offset",mystring,6)==0) { sscanf(mystring,"%s %s %f %f %f" ,strTmp, strTmp, &ox, &oy, &oz); }
295 if (strncmp("HeaderSize",mystring,10)==0) { sscanf(mystring,"%s %s %ld" ,strTmp, strTmp, &headersize); }
296 if (strncmp("ElementDataFile",mystring,15)==0) { sscanf(mystring,"%s %s %s" ,strTmp, strTmp, strTmp2); elementdatafile=strTmp2; }
297 if (strncmp("ElementType = MET_CHAR",mystring,22)==0) { newImage->SetScalarTypeToChar(); dataSize=sizeof(char); }
298 if (strncmp("ElementType = VTK_CHAR",mystring,22)==0) { newImage->SetScalarTypeToChar(); dataSize=sizeof(char); }
299 if (strncmp("ElementType = MET_UCHAR",mystring,23)==0) { newImage->SetScalarTypeToUnsignedChar(); dataSize=sizeof(unsigned char); }
300 if (strncmp("ElementType = VTK_UNSIGNED_CHAR",mystring,31)==0) { newImage->SetScalarTypeToUnsignedChar(); dataSize=sizeof(unsigned char); }
301 if (strncmp("ElementType = MET_USHORT",mystring,24)==0) { newImage->SetScalarTypeToUnsignedShort(); dataSize=sizeof(unsigned short);}
302 if (strncmp("ElementType = VTK_UNSIGNED_SHORT",mystring,32)==0) { newImage->SetScalarTypeToUnsignedShort(); dataSize=sizeof(unsigned short);}
303 if (strncmp("ElementType = MET_SHORT",mystring,23)==0) { newImage->SetScalarTypeToShort(); dataSize=sizeof(short); }
304 if (strncmp("ElementType = VTK_SHORT",mystring,23)==0) { newImage->SetScalarTypeToShort(); dataSize=sizeof(short); }
305 if (strncmp("ElementType = MET_UINT",mystring,22)==0) { newImage->SetScalarTypeToUnsignedInt(); dataSize=sizeof(unsigned int); }
306 if (strncmp("ElementType = VTK_UNSIGNED_INT",mystring,30)==0) { newImage->SetScalarTypeToUnsignedInt(); dataSize=sizeof(unsigned int); }
307 if (strncmp("ElementType = MET_INT",mystring,21)==0) { newImage->SetScalarTypeToInt(); dataSize=sizeof(int); }
308 if (strncmp("ElementType = VTK_INT",mystring,21)==0) { newImage->SetScalarTypeToInt(); dataSize=sizeof(int); }
309 if (strncmp("ElementType = MET_FLOAT",mystring,23)==0) { newImage->SetScalarTypeToFloat(); dataSize=sizeof(float); }
310 if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0) { newImage->SetScalarTypeToFloat(); dataSize=sizeof(float); }
311 if (strncmp("ElementType = MET_LONG",mystring,22)==0) { newImage->SetScalarTypeToLong(); dataSize=sizeof(long); }
312 if (strncmp("ElementType = VTK_LONG",mystring,22)==0) { newImage->SetScalarTypeToLong(); dataSize=sizeof(long); }
313 if (strncmp("ElementType = MET_DOUBLE",mystring,24)==0) { newImage->SetScalarTypeToDouble(); dataSize=sizeof(double); }
314 if (strncmp("ElementType = VTK_DOUBLE",mystring,24)==0) { newImage->SetScalarTypeToDouble(); dataSize=sizeof(double); }
317 newImage->Initialize();
321 std::string filename;
322 found = bbGetInputFileName().find_last_of("/\\");
323 filename = bbGetInputFileName().substr(0,found+1) + elementdatafile ;
325 long long lsize = dimX*dimY*width *dataSize;
327 _sopen_s( &fd, filename.c_str(), _O_RDONLY, _SH_DENYNO, 0 );
329 fd = open ( filename.c_str() , O_RDONLY|O_LARGEFILE );
330 #endif // defined(_WIN32)
333 printf("EED ReadMHDPlane::Read64lseek WARNNING! raw file not exist\n");
334 fprintf(stderr, "%s\n", strerror(errno));
335 newImage=CreateDefaultImage();
338 if ((bbGetInputDirectionPlane()=="XY") && (fd>=0))
340 newImage->SetSpacing( spcX,spcY,spcZ );
341 newImage->SetDimensions( dimX,dimY,width );
342 newImage->SetWholeExtent(0, dimX-1,0,dimY-1,0,width-1 );
343 newImage->SetExtent(0, dimX-1,0,dimY-1,0,width-1 );
344 newImage->SetNumberOfScalarComponents(1);
345 newImage->AllocateScalars();
347 pos = dimX*dimY*(long long)slice*dataSize;
349 if (_lseeki64( fd, pos, SEEK_SET ) < 0)
351 if (lseek64(fd, pos, SEEK_SET) < 0)
352 #endif // defined(_WIN32)
354 printf("EED ReadMHDPlane::Read64lseek \n");
355 fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
358 if ((ret = read(fd, newImage->GetScalarPointer() , lsize)) < 0)
360 fprintf(stderr, "Failed reading: %s\n", strerror(errno));
364 if ((bbGetInputDirectionPlane()=="ZX") && (fd>=0))
366 newImage->SetSpacing( spcX,spcZ,spcY );
367 newImage->SetDimensions( dimX,dimZ,width );
368 newImage->SetWholeExtent(0, dimX-1,0,dimZ-1,0,width-1 );
369 newImage->SetExtent(0, dimX-1,0,dimZ-1,0,width-1 );
370 newImage->SetNumberOfScalarComponents(1);
371 newImage->AllocateScalars();
374 for (iWidth=0;iWidth<width;iWidth++)
376 copy_ZX_plane(fd,newImage,slice+iWidth,iWidth,dimX,dimY,dimZ,dataSize);
379 if ((bbGetInputDirectionPlane()=="YZ") && (fd>=0))
381 newImage->SetSpacing( spcY,spcZ,spcX );
382 newImage->SetDimensions( dimY,dimZ,width );
383 newImage->SetWholeExtent(0, dimY-1,0,dimZ-1,0,width-1 );
384 newImage->SetExtent(0, dimY-1,0,dimZ-1,0,width-1 );
385 newImage->SetNumberOfScalarComponents(1);
386 newImage->AllocateScalars();
389 for (iWidth=0;iWidth<width;iWidth++)
391 copy_YZ_plane(fd,newImage,slice+iWidth,iWidth,dimX,dimY,dimZ,dataSize);
398 #endif // defined(_WIN32)
400 newImage=CreateDefaultImage();
402 bbSetOutputOut( newImage );
403 bbSetOutputOut2( ChangeOrientation(newImage) );
407 void ReadMHDPlane::Read64lseek(std::string fileNameIn, std::string plane)
411 width = bbGetInputWidth();
412 if (width<=0 ) { width=1; }
413 slice = bbGetInputSlice();
414 if (slice<0 ) { slice=0; }
415 int dimX=-1,dimY=-1,dimZ=-1;
417 std::string formattype("VOID");
418 std::string elementdatafile("VOID");
419 float spcX=-1,spcY=-1,spcZ=-1;
420 float ox=-1,oy=-1,oz=-1;
421 long int headersize=0;
422 vtkImageData *newImage=NULL;
426 FILE *ffIn = fopen( fileNameIn.c_str() , "r");
430 newImage = vtkImageData::New();
433 strcpy(mystring,"\n");
434 fgets(mystring,250,ffIn);
435 if (strncmp("NDims",mystring,5)==0) { sscanf(mystring,"%s %s %d" ,strTmp, strTmp, &dim); }
436 if (strncmp("DimSize",mystring,6)==0) { sscanf(mystring,"%s %s %d %d %d" ,strTmp, strTmp, &dimX, &dimY,&dimZ); }
437 if (strncmp("ElementType",mystring,11)==0) { sscanf(mystring,"%s %s %s" ,strTmp, strTmp, strTmp2); formattype=strTmp2; }
438 if (strncmp("ElementSpacing",mystring,14)==0) { sscanf(mystring,"%s %s %f %f %f" ,strTmp, strTmp, &spcX,&spcY,&spcZ); }
439 if (strncmp("ElementSize",mystring,11)==0) { sscanf(mystring,"%s %s %f %f %f" ,strTmp, strTmp, &spcX,&spcY,&spcZ); }
440 if (strncmp("Offset",mystring,6)==0) { sscanf(mystring,"%s %s %f %f %f" ,strTmp, strTmp, &ox, &oy, &oz); }
441 if (strncmp("HeaderSize",mystring,10)==0) { sscanf(mystring,"%s %s %ld" ,strTmp, strTmp, &headersize); }
442 if (strncmp("ElementDataFile",mystring,15)==0) { sscanf(mystring,"%s %s %s" ,strTmp, strTmp, strTmp2); elementdatafile=strTmp2; }
443 if (strncmp("ElementType = MET_CHAR",mystring,22)==0) { newImage->SetScalarTypeToChar(); dataSize=sizeof(char); }
444 if (strncmp("ElementType = VTK_CHAR",mystring,22)==0) { newImage->SetScalarTypeToChar(); dataSize=sizeof(char); }
445 if (strncmp("ElementType = MET_UCHAR",mystring,23)==0) { newImage->SetScalarTypeToUnsignedChar(); dataSize=sizeof(unsigned char); }
446 if (strncmp("ElementType = VTK_UNSIGNED_CHAR",mystring,31)==0) { newImage->SetScalarTypeToUnsignedChar(); dataSize=sizeof(unsigned char); }
447 if (strncmp("ElementType = MET_USHORT",mystring,24)==0) { newImage->SetScalarTypeToUnsignedShort(); dataSize=sizeof(unsigned short);}
448 if (strncmp("ElementType = VTK_UNSIGNED_SHORT",mystring,32)==0) { newImage->SetScalarTypeToUnsignedShort(); dataSize=sizeof(unsigned short);}
449 if (strncmp("ElementType = MET_SHORT",mystring,23)==0) { newImage->SetScalarTypeToShort(); dataSize=sizeof(short); }
450 if (strncmp("ElementType = VTK_SHORT",mystring,23)==0) { newImage->SetScalarTypeToShort(); dataSize=sizeof(short); }
451 if (strncmp("ElementType = MET_UINT",mystring,22)==0) { newImage->SetScalarTypeToUnsignedInt(); dataSize=sizeof(unsigned int); }
452 if (strncmp("ElementType = VTK_UNSIGNED_INT",mystring,30)==0) { newImage->SetScalarTypeToUnsignedInt(); dataSize=sizeof(unsigned int); }
453 if (strncmp("ElementType = MET_INT",mystring,21)==0) { newImage->SetScalarTypeToInt(); dataSize=sizeof(int); }
454 if (strncmp("ElementType = VTK_INT",mystring,21)==0) { newImage->SetScalarTypeToInt(); dataSize=sizeof(int); }
455 if (strncmp("ElementType = MET_FLOAT",mystring,23)==0) { newImage->SetScalarTypeToFloat(); dataSize=sizeof(float); }
456 if (strncmp("ElementType = VTK_FLOAT",mystring,23)==0) { newImage->SetScalarTypeToFloat(); dataSize=sizeof(float); }
457 if (strncmp("ElementType = MET_LONG",mystring,22)==0) { newImage->SetScalarTypeToLong(); dataSize=sizeof(long); }
458 if (strncmp("ElementType = VTK_LONG",mystring,22)==0) { newImage->SetScalarTypeToLong(); dataSize=sizeof(long); }
459 if (strncmp("ElementType = MET_DOUBLE",mystring,24)==0) { newImage->SetScalarTypeToDouble(); dataSize=sizeof(double); }
460 if (strncmp("ElementType = VTK_DOUBLE",mystring,24)==0) { newImage->SetScalarTypeToDouble(); dataSize=sizeof(double); }
463 newImage->Initialize();
467 std::string filename;
468 found = fileNameIn.find_last_of("/\\");
469 filename = fileNameIn.substr(0,found+1) + elementdatafile ;
471 long long lsize = dimX*dimY*width *dataSize;
473 _sopen_s( &fd, filename.c_str(), _O_RDONLY, _SH_DENYNO, 0 );
475 fd = open ( filename.c_str() , O_RDONLY|O_LARGEFILE );
476 #endif // defined(_WIN32)
479 printf("EED ReadMHDPlane::Read64lseek WARNNING! raw file not exist\n");
480 fprintf(stderr, "%s\n", strerror(errno));
481 newImage=CreateDefaultImage();
484 if ((plane=="XY") && (fd>=0))
486 newImage->SetSpacing( spcX,spcY,spcZ );
487 newImage->SetDimensions( dimX,dimY,width );
488 newImage->SetWholeExtent(0, dimX-1,0,dimY-1,0,width-1 );
489 newImage->SetExtent(0, dimX-1,0,dimY-1,0,width-1 );
490 newImage->SetNumberOfScalarComponents(1);
491 newImage->AllocateScalars();
493 pos = dimX*dimY*(long long)slice*dataSize;
495 if (_lseeki64( fd, pos, SEEK_SET ) < 0)
497 if (lseek64(fd, pos, SEEK_SET) < 0)
498 #endif // defined(_WIN32)
500 printf("EED ReadMHDPlane::Read64lseek \n");
501 fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
504 if ((ret = read(fd, newImage->GetScalarPointer() , lsize)) < 0)
506 fprintf(stderr, "Failed reading: %s\n", strerror(errno));
510 if ((plane=="ZX") && (fd>=0))
512 newImage->SetSpacing( spcX,spcZ,spcY );
513 newImage->SetDimensions( dimX,dimZ,width );
514 newImage->SetWholeExtent(0, dimX-1,0,dimZ-1,0,width-1 );
515 newImage->SetExtent(0, dimX-1,0,dimZ-1,0,width-1 );
516 newImage->SetNumberOfScalarComponents(1);
517 newImage->AllocateScalars();
520 for (iWidth=0;iWidth<width;iWidth++)
522 copy_ZX_plane(fd,newImage,slice+iWidth,iWidth,dimX,dimY,dimZ,dataSize);
525 if ((plane=="YZ") && (fd>=0))
527 newImage->SetSpacing( spcY,spcZ,spcX );
528 newImage->SetDimensions( dimY,dimZ,width );
529 newImage->SetWholeExtent(0, dimY-1,0,dimZ-1,0,width-1 );
530 newImage->SetExtent(0, dimY-1,0,dimZ-1,0,width-1 );
531 newImage->SetNumberOfScalarComponents(1);
532 newImage->AllocateScalars();
535 for (iWidth=0;iWidth<width;iWidth++)
537 copy_YZ_plane(fd,newImage,slice+iWidth,iWidth,dimX,dimY,dimZ,dataSize);
544 #endif // defined(_WIN32)
546 newImage=CreateDefaultImage();
548 bbSetOutputOut( newImage );
549 bbSetOutputOut2( ChangeOrientation(newImage) );
553 void ReadMHDPlane::copy_YZ_plane(int fd,vtkImageData *newImage,int slice,int iWidth,int dimX,int dimY,int dimZ,int dataSize)
559 long long sizeBytesPlane = dimX*dimY*dataSize;
565 pos = ((long long int)slice+iWidth + i*dimX + j*dimX*dimY)*dataSize ;
567 if (_lseeki64( fd, pos , SEEK_SET ) < 0)
569 if (lseek64(fd, pos , SEEK_SET) < 0)
570 #endif // defined(_WIN32)
572 printf("EED ReadMHDPlane::Read64lseek \n");
573 fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
577 pImage=(char*)(newImage->GetScalarPointer(i, dimZ-1-j,iWidth ));
578 if ((ret = read(fd, pImage , dataSize)) < 0)
580 fprintf(stderr, "Failed reading: %s\n", strerror(errno));
588 void ReadMHDPlane::copy_ZX_plane(int fd,vtkImageData *newImage,int slice,int iWidth,int dimX,int dimY,int dimZ,int dataSize)
593 pos = dimX*(long long int)slice*dataSize;
594 long long sizeBytesPlane = dimX*dimY*dataSize;
595 char *pImage = (char*)( newImage->GetScalarPointer(0,0,iWidth) );
596 for (j=dimZ-1;j>=0;j--)
599 if (_lseeki64( fd, pos + j*sizeBytesPlane , SEEK_SET ) < 0)
601 if (lseek64(fd, pos + j*sizeBytesPlane , SEEK_SET) < 0)
602 #endif // defined(_WIN32)
604 printf("EED ReadMHDPlane::Read64lseek \n");
605 fprintf(stderr, "Failed seeking to %lld, %s\n", pos, strerror(errno));
609 if ((ret = read(fd, pImage , dimX*dataSize)) < 0)
611 fprintf(stderr, "Failed reading: %s\n", strerror(errno));
614 pImage = pImage+dimX*dataSize;
620 void ReadMHDPlane::Process()
622 if (bbGetInputType()==0)
625 std::string inputfilename;
626 std::size_t found = bbGetInputFileName().find_last_of("/\\");
627 std::string path = bbGetInputFileName().substr(0,found+1);
628 std::string filename = bbGetInputFileName().substr(found+1);
634 if (bbGetInputDirectionPlane()=="XY") { inputfilename = bbGetInputFileName(); } // if XY
635 if (bbGetInputDirectionPlane()=="YZ") { inputfilename = path+filename+"_YZ.mhd"; } // if YZ
636 if (bbGetInputDirectionPlane()=="ZX") { inputfilename = path+filename+"_ZX.mhd"; } // if XZ
637 Read64lseek( inputfilename ,"XY");
640 if (bbGetInputType()==1)
642 Read64lseek( bbGetInputFileName(), bbGetInputDirectionPlane() );
647 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
649 void ReadMHDPlane::bbUserSetDefaultValues()
652 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
653 // Here we initialize the input 'In' to 0
654 bbSetInputFileName("");
658 bbSetInputDirectionPlane("XY");
662 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
664 void ReadMHDPlane::bbUserInitializeProcessing()
667 // THE INITIALIZATION METHOD BODY :
669 // but this is where you should allocate the internal/output pointers
675 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
677 void ReadMHDPlane::bbUserFinalizeProcessing()
680 // THE FINALIZATION METHOD BODY :
682 // but this is where you should desallocate the internal/output pointers
687 // EO namespace bbcreaVtk