239 | 239 |
ret[1][3] = m_header.qoffset_y;
|
240 | 240 |
ret[2][3] = m_header.qoffset_z;
|
241 | 241 |
} else {
|
242 | |
cerr << "found quaternion with length greater than 1 in nifti header" << endl;
|
|
242 |
cerr << "warning: found quaternion with length greater than 1 in nifti header, using ANALYZE coordinates!" << endl;
|
243 | 243 |
ret[0][0] = m_header.pixdim[1];
|
244 | 244 |
ret[1][1] = m_header.pixdim[2];
|
245 | 245 |
ret[2][2] = m_header.pixdim[3];
|
246 | 246 |
}
|
247 | 247 |
} else {//fall back to analyze and complain
|
248 | |
cerr << "no sform or qform code found, using ANALYZE coordinates!" << endl;
|
|
248 |
cerr << "warning: no sform or qform code found, using ANALYZE coordinates!" << endl;
|
249 | 249 |
ret[0][0] = m_header.pixdim[1];
|
250 | 250 |
ret[1][1] = m_header.pixdim[2];
|
251 | 251 |
ret[2][2] = m_header.pixdim[3];
|
|
265 | 265 |
case NIFTI_UNITS_MM:
|
266 | 266 |
break;
|
267 | 267 |
default:
|
268 | |
cerr << "unrecognized spatial unit in nifti header" << endl;
|
|
268 |
cerr << "warning: unrecognized spatial unit in nifti header" << endl;
|
269 | 269 |
}
|
270 | 270 |
return ret.getMatrix();
|
|
271 |
}
|
|
272 |
|
|
273 |
double NiftiHeader::getTimeStep() const
|
|
274 |
{
|
|
275 |
int timeUnit = XYZT_TO_TIME(m_header.xyzt_units);
|
|
276 |
double ret = m_header.pixdim[4];
|
|
277 |
switch (timeUnit)
|
|
278 |
{
|
|
279 |
case NIFTI_UNITS_USEC:
|
|
280 |
ret /= 1000000.0;
|
|
281 |
break;
|
|
282 |
case NIFTI_UNITS_MSEC:
|
|
283 |
ret /= 1000.0;
|
|
284 |
break;
|
|
285 |
default:
|
|
286 |
cerr << "warning: non-time units code " + AString_number(timeUnit) + " used in nifti header, pretending units are seconds" << endl;
|
|
287 |
case NIFTI_UNITS_SEC:
|
|
288 |
break;
|
|
289 |
}
|
|
290 |
return ret;
|
271 | 291 |
}
|
272 | 292 |
|
273 | 293 |
AString NiftiHeader::toString() const
|
|
387 | 407 |
for (; i < 16; ++i) m_header.intent_name[i] = '\0';
|
388 | 408 |
}
|
389 | 409 |
|
|
410 |
void NiftiHeader::setDescription(const char descrip[80])
|
|
411 |
{
|
|
412 |
int i;//custom strncpy-like code to fill nulls to the end
|
|
413 |
for (i = 0; i < 80 && descrip[i] != '\0'; ++i) m_header.descrip[i] = descrip[i];
|
|
414 |
for (; i < 80; ++i) m_header.descrip[i] = '\0';
|
|
415 |
}
|
|
416 |
|
390 | 417 |
void NiftiHeader::setSForm(const vector<vector<float> >& sForm)
|
391 | 418 |
{
|
392 | 419 |
CiftiAssert(sForm.size() >= 3);//programmer error to pass badly sized matrix
|
|
396 | 423 |
CiftiAssert(sForm[i].size() >= 4);//ditto
|
397 | 424 |
if (sForm[i].size() < 4) throw CiftiException("internal error: setSForm matrix badly sized");
|
398 | 425 |
}
|
399 | |
m_header.xyzt_units = SPACE_TIME_TO_XYZT(NIFTI_UNITS_MM, NIFTI_UNITS_SEC);//overwrite whatever units we read in
|
|
426 |
int timeUnit = XYZT_TO_TIME(m_header.xyzt_units);
|
|
427 |
m_header.xyzt_units = SPACE_TIME_TO_XYZT(NIFTI_UNITS_MM, timeUnit);//overwrite whatever spatial unit we read in
|
400 | 428 |
for (int i = 0; i < 4; i++)
|
401 | 429 |
{
|
402 | 430 |
m_header.srow_x[i] = sForm[0][i];
|
|
443 | 471 |
m_header.qoffset_y = sForm[1][3];
|
444 | 472 |
m_header.qoffset_z = sForm[2][3];
|
445 | 473 |
}
|
|
474 |
}
|
|
475 |
|
|
476 |
void NiftiHeader::setTimeStep(const double& seconds)
|
|
477 |
{
|
|
478 |
int spaceUnit = XYZT_TO_SPACE(m_header.xyzt_units);//save the current space units so we don't clobber it...
|
|
479 |
m_header.xyzt_units = SPACE_TIME_TO_XYZT(spaceUnit, NIFTI_UNITS_SEC);//overwrite the time part of the units with seconds
|
|
480 |
m_header.pixdim[4] = seconds;
|
446 | 481 |
}
|
447 | 482 |
|
448 | 483 |
void NiftiHeader::clearDataScaling()
|