18 #pragma warning ( disable : 4786 )
19 #pragma warning ( disable : 4284 ) // return type for 'identifier::operator ->'
23 #include <itksys/SystemTools.hxx>
80 return typeid(
short int);
85 return typeid(
short int);
90 return sizeof(
short int);
92 #ifdef __THIS_CODE_BELONGS_ELSEWHERE__
93 static void SwapZeroCornerToIRP(
const itk::IOCommon::ValidOriginFlags original,
short int *
const imageBuffer,
const int XDim,
const int YDim,
const int ZDim)
95 short int *** pntrs =
new (
short int **) [ZDim];
96 for (
int k=0;k<ZDim;k++)
98 pntrs[k] =
new (
short int *) [YDim];
99 for(
int j=0; j<YDim;j++)
101 pntrs[k][j] = &(imageBuffer[k*(XDim*YDim)+j*XDim]);
114 for (
int k=0;k<ZHalf;k++)
116 for(
int j=0; j<YDim;j++)
118 for(
int i=0; i<XDim;i++)
120 const short int temp = pntrs[k][j][i];
121 pntrs[k][j][i] = pntrs[ZDim-k-1][j][i];
122 pntrs[ZDim-k-1][j][i] = temp;
143 for (
int k=0;k<ZDim;k++)
145 for(
int j=0; j<YHalf;j++)
147 for(
int i=0; i<XDim;i++)
149 const short int temp = pntrs[k][j][i];
150 pntrs[k][j][i] = pntrs[k][YDim-j-1][i];
151 pntrs[k][YDim-j-1][i] = temp;
172 for (
int k=0;k<ZDim;k++)
174 for(
int j=0; j<YDim;j++)
176 for(
int i=0; i<XHalf;i++)
178 const short int temp = pntrs[k][j][i];
179 pntrs[k][j][i] = pntrs[k][j][XDim-i-1];
180 pntrs[k][j][XDim-i-1] = temp;
197 short int *img_buffer = (
short int *)buffer;
201 for(;it != itend; it++)
203 std::string curfilename = (*it)->GetImageFileName();
204 std::ifstream f(curfilename.c_str(),std::ios::binary | std::ios::in);
208 f.seekg ((*it)->GetSliceOffset(), std::ios::beg);
223 std::ofstream f2(
"test.img",std::ios::binary | std::ios::out);
255 std::string _imagePath =
256 itksys::SystemTools::CollapseFullPath(FileNameToRead.c_str());
258 FileNameToRead = _imagePath;
281 #if defined(ITKIO_DEPRECATED_METADATA_ORIENTATION)
295 strncpy(imagePath,_imagePath.c_str(),
sizeof(imagePath));
297 strncpy(imageMask,imagePath,
sizeof(imageMask));
300 char *lastslash = strrchr(imagePath,
'/');
301 if(lastslash ==
NULL)
303 strcpy(imagePath,
".");
310 if(Dir->Load(imagePath) == 0)
314 std::vector<std::string>::size_type i;
315 std::vector<std::string>::size_type numfiles;
319 for(i = 0, numfiles = Dir->GetNumberOfFiles(); i < numfiles; i++)
321 const char *curFname = Dir->GetFile(i);
323 sprintf(fullPath,
"%s/%s",imagePath,curFname);
329 else if (FileNameToRead == fullPath)
355 delete curImageHeader;
376 std::vector<double> dirx(3,0), diry(3,0), dirz(3,0);
433 size_t amount,
bool throw_exception)
435 f.seekg(Offset,std::ios::beg);
447 if( !this->ReadBufferAsBinary( f, (
void *)buf, amount ) )
462 bool throw_exception)
465 if (this->GetStringAt(f,Offset,(
char *)&tmp,
sizeof(
int),
466 throw_exception) == 0)
468 *ip = this->hdr2Int((
char *)&tmp);
478 bool throw_exception)
481 if (this->GetStringAt(f,Offset,(
char *)&tmp,
sizeof(
short),
482 throw_exception) == 0)
484 *ip = this->hdr2Short((
char *)&tmp);
494 bool throw_exception)
497 if (this->GetStringAt(f,Offset,(
char *)&tmp,
sizeof(
float),
498 throw_exception) == 0)
500 *ip = this->hdr2Float((
char *)&tmp);
510 bool throw_exception)
513 if (this->GetStringAt(f,Offset,(
char *)&tmp,
sizeof(
double),
514 throw_exception) == 0)
516 *ip = this->hdr2Double((
char *)&tmp);
527 memcpy (&shortValue, hdr,
sizeof(
short));
537 memcpy (&intValue, hdr,
sizeof(
int));
547 memcpy (&floatValue, hdr, 4);
558 memcpy (&doubleValue, hdr,
sizeof(
double));
561 return (doubleValue);
565 ::AddElementToList(
char const *
const filename,
const float sliceLocation,
const int offset,
const int XDim,
const int YDim,
const int Key1,
const int Key2 )
567 if(m_FilenameList->NumFiles() == 0)
569 m_FilenameList->SetXDim(XDim);
570 m_FilenameList->SetYDim(YDim);
571 m_FilenameList->SetKey1(Key1);
572 m_FilenameList->SetKey2(Key2);
574 else if(XDim != m_FilenameList->GetXDim() || YDim != m_FilenameList->GetYDim() )
578 else if (m_FilenameList->GetKey1() != Key1 || m_FilenameList->GetKey2() != Key2)
582 m_FilenameList->AddElementToList(filename,sliceLocation,
583 offset,XDim,YDim,0,Key1,Key2);
590 m_FilenameList->sortImageListAscend();
596 m_FilenameList->sortImageListDescend();
611 lclock = (timespec_t *) clock;
612 asciiTime = ctime (&(lclock->tv_sec));
614 time_t tclock = (time_t) *((
int *) clock);
615 asciiTime = ctime (&tclock);
618 strncpy (timeString, asciiTime, 64);
620 for (i = 0; i < 26; i++)
622 if (timeString[i] ==
'\n')
624 timeString[i] =
'\0';