| 156 | |
| 157 | template < typename TPixel, unsigned int VImageDimension > |
| 158 | void DoInternalImageConversion( |
| 159 | const itk::Image< TPixel, VImageDimension > *image, |
| 160 | InternalImageType::Pointer& internalImage) |
| 161 | { |
| 162 | typedef itk::Image< TPixel, VImageDimension > ImageType; |
| 163 | |
| 164 | //check if image fit to geometry |
| 165 | |
| 166 | // Make sure that spacing are the same |
| 167 | typename ImageType::SpacingType imageSpacing = image->GetSpacing(); |
| 168 | typename ImageType::PointType zeroPoint; zeroPoint.Fill(0.0); |
| 169 | if ((zeroPoint + imageSpacing).SquaredEuclideanDistanceTo((zeroPoint + relevantSpacing)) > |
| 170 | 1e-6) // for the dumper we are not as strict as mitk normally would be (mitk::eps) |
| 171 | { |
| 172 | mitkThrow() << "Images need to have same spacing! (Image spacing: " << imageSpacing |
| 173 | << "; relevant spacing: " << relevantSpacing << ")"; |
| 174 | } |
| 175 | |
| 176 | // Make sure that orientation of mask and image are the same |
| 177 | typename ImageType::DirectionType imageDirection = image->GetDirection(); |
| 178 | for (unsigned int i = 0; i < imageDirection.RowDimensions; ++i) |
| 179 | { |
| 180 | for (unsigned int j = 0; j < imageDirection.ColumnDimensions; ++j) |
| 181 | { |
| 182 | double differenceDirection = imageDirection[i][j] - relevantDirection[i][j]; |
| 183 | if (fabs(differenceDirection) > 1e-6) // SD: 1e6 wird hier zum zweiten mal als Magic Number benutzt -> Konstante |
| 184 | { |
| 185 | // for the dumper we are not as strict as mitk normally would be (mitk::eps) |
| 186 | mitkThrow() << "Images need to have same direction! (Image direction: " |
| 187 | << imageDirection << "; relevant direction: " << relevantDirection << ")"; |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // Make sure that origin of mask and image are the same |
| 193 | typename ImageType::PointType imageOrigin = image->GetOrigin(); |
| 194 | if (imageOrigin.SquaredEuclideanDistanceTo(relevantOrigin) > 1e-6) |
| 195 | { |
| 196 | // for the dumper we are not as strict as mitk normally would be (mitk::eps) |
| 197 | mitkThrow() << "Image need to have same spacing! (Image spacing: " |
| 198 | << imageSpacing << "; relevant spacing: " << relevantOrigin << ")"; |
| 199 | } |
| 200 | |
| 201 | typename ImageType::RegionType imageRegion = image->GetLargestPossibleRegion(); |
| 202 | |
| 203 | if (!imageRegion.IsInside(relevantRegion) && imageRegion != relevantRegion) |
| 204 | { |
| 205 | mitkThrow() << "Images need to have same region! (Image region: " |
| 206 | << imageRegion << "; relevant region: " << relevantRegion << ")"; |
| 207 | } |
| 208 | |
| 209 | //convert to internal image |
| 210 | typedef itk::ExtractImageFilter<ImageType, ImageType> ExtractFilterType; |
| 211 | typename ExtractFilterType::Pointer extractFilter = ExtractFilterType::New(); |
| 212 | typedef itk::CastImageFilter<ImageType, InternalImageType> CastFilterType; |
| 213 | typename CastFilterType::Pointer castFilter = CastFilterType::New(); |
| 214 | |
| 215 | extractFilter->SetInput(image); |