------------------------------------------------------------------------------
| 87 | |
| 88 | //------------------------------------------------------------------------------ |
| 89 | void vtkNIFTIImageHeader::SetHeader(const nifti_1_header* hdr) |
| 90 | { |
| 91 | // clear all fields (in case supplied header is Analyze 7.5) |
| 92 | this->Initialize(); |
| 93 | |
| 94 | // check if header is NIfTI (vs. Analyze 7.5) |
| 95 | bool isnifti = (hdr->magic[0] == 'n' && (hdr->magic[1] == '+' || hdr->magic[1] == 'i') && |
| 96 | hdr->magic[2] == '1' && hdr->magic[3] == '\0'); |
| 97 | |
| 98 | if (isnifti) |
| 99 | { |
| 100 | memcpy(this->Magic, hdr->magic, sizeof(hdr->magic)); |
| 101 | } |
| 102 | this->VoxOffset = static_cast<vtkTypeInt64>(hdr->vox_offset); |
| 103 | this->DataType = hdr->datatype; |
| 104 | this->BitPix = hdr->bitpix; |
| 105 | for (int i = 0; i < 8; i++) |
| 106 | { |
| 107 | this->Dim[i] = hdr->dim[i]; |
| 108 | this->PixDim[i] = hdr->pixdim[i]; |
| 109 | } |
| 110 | if (isnifti) |
| 111 | { |
| 112 | this->IntentCode = hdr->intent_code; |
| 113 | strncpy(this->IntentName, hdr->intent_name, sizeof(this->IntentName)); |
| 114 | this->IntentP1 = hdr->intent_p1; |
| 115 | this->IntentP2 = hdr->intent_p2; |
| 116 | this->IntentP3 = hdr->intent_p3; |
| 117 | this->SclSlope = hdr->scl_slope; |
| 118 | this->SclInter = hdr->scl_inter; |
| 119 | } |
| 120 | this->CalMin = hdr->cal_min; |
| 121 | this->CalMax = hdr->cal_max; |
| 122 | if (isnifti) |
| 123 | { |
| 124 | this->SliceDuration = hdr->slice_duration; |
| 125 | this->TOffset = hdr->toffset; |
| 126 | this->SliceStart = hdr->slice_start; |
| 127 | this->SliceEnd = hdr->slice_end; |
| 128 | this->SliceCode = hdr->slice_code; |
| 129 | } |
| 130 | this->XYZTUnits = hdr->xyzt_units; |
| 131 | this->DimInfo = hdr->dim_info; |
| 132 | strncpy(this->Descrip, hdr->descrip, sizeof(this->Descrip)); |
| 133 | strncpy(this->AuxFile, hdr->aux_file, sizeof(this->AuxFile)); |
| 134 | if (isnifti) |
| 135 | { |
| 136 | this->QFormCode = hdr->qform_code; |
| 137 | this->SFormCode = hdr->sform_code; |
| 138 | this->QuaternB = hdr->quatern_b; |
| 139 | this->QuaternC = hdr->quatern_c; |
| 140 | this->QuaternD = hdr->quatern_d; |
| 141 | this->QOffsetX = hdr->qoffset_x; |
| 142 | this->QOffsetY = hdr->qoffset_y; |
| 143 | this->QOffsetZ = hdr->qoffset_z; |
| 144 | for (int i = 0; i < 4; i++) |
| 145 | { |
| 146 | this->SRowX[i] = hdr->srow_x[i]; |