本文整理汇总了C++中image::Pointer::SetClonedGeometry方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::SetClonedGeometry方法的具体用法?C++ Pointer::SetClonedGeometry怎么用?C++ Pointer::SetClonedGeometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::Pointer
的用法示例。
在下文中一共展示了Pointer::SetClonedGeometry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sliceIterator
//.........这里部分代码省略.........
extentInMM[1] = m_CurrentWorldPlaneGeometry->GetExtentInMM(1);
// The maximum extent is the lenght of the diagonal of the considered plane
double maxExtent = sqrt(extentInMM[0] * extentInMM[0] + extentInMM[1] * extentInMM[1]);
unsigned int xTranlation = (maxExtent - extentInMM[0]);
unsigned int yTranlation = (maxExtent - extentInMM[1]);
size[0] = (maxExtent + xTranlation) / newPixelSpacing[0];
size[1] = (maxExtent + yTranlation) / newPixelSpacing[1];
// Creating an ImageRegion Object
typename SliceImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
// Defining the image`s extent and origin by passing the region to it and allocating memory for it
resultSlice->SetRegions(region);
resultSlice->SetSpacing(pixelSpacing);
resultSlice->Allocate();
/*
* Here we create an new geometry so that the transformations are calculated correctly (our resulting slice has a
* different bounding box and spacing)
* The original current worldgeometry must be cloned because we have to keep the directions of the axis vector which
* represents the rotation
*/
right.Normalize();
bottom.Normalize();
// Here we translate the origin to adapt the new geometry to the previous calculated extent
origin[0] -= xTranlation * right[0] + yTranlation * bottom[0];
origin[1] -= xTranlation * right[1] + yTranlation * bottom[1];
origin[2] -= xTranlation * right[2] + yTranlation * bottom[2];
// Putting it together for the new geometry
mitk::BaseGeometry::Pointer newSliceGeometryTest =
dynamic_cast<BaseGeometry *>(m_CurrentWorldPlaneGeometry->Clone().GetPointer());
newSliceGeometryTest->ChangeImageGeometryConsideringOriginOffset(true);
// Workaround because of BUG (#6505)
newSliceGeometryTest->GetIndexToWorldTransform()->SetMatrix(
m_CurrentWorldPlaneGeometry->GetIndexToWorldTransform()->GetMatrix());
// Workaround end
newSliceGeometryTest->SetOrigin(origin);
ScalarType bounds[6] = {0, static_cast<ScalarType>(size[0]), 0, static_cast<ScalarType>(size[1]), 0, 1};
newSliceGeometryTest->SetBounds(bounds);
newSliceGeometryTest->SetSpacing(newPixelSpacing);
newSliceGeometryTest->Modified();
// Workaround because of BUG (#6505)
itk::MatrixOffsetTransformBase<mitk::ScalarType, 3, 3>::MatrixType tempTransform =
newSliceGeometryTest->GetIndexToWorldTransform()->GetMatrix();
// Workaround end
/*
* Now we iterate over the recently created slice.
* For each slice - pixel we check whether there is an according
* pixel in the input - image which can be set in the slice.
* In this way a slice is sampled out of the input - image regrading to the given PlaneGeometry
*/
Point3D currentSliceIndexPointIn2D;
Point3D currentImageWorldPointIn3D;
typename InputImageType::IndexType inputIndex;
SliceIterator sliceIterator(resultSlice, resultSlice->GetLargestPossibleRegion());
sliceIterator.GoToBegin();
while (!sliceIterator.IsAtEnd())
{
/*
* Here we add 0.5 to to assure that the indices are correctly transformed.
* (Because of the 0.5er Bug)
*/
currentSliceIndexPointIn2D[0] = sliceIterator.GetIndex()[0] + 0.5;
currentSliceIndexPointIn2D[1] = sliceIterator.GetIndex()[1] + 0.5;
currentSliceIndexPointIn2D[2] = 0;
newSliceGeometryTest->IndexToWorld(currentSliceIndexPointIn2D, currentImageWorldPointIn3D);
m_ImageGeometry->WorldToIndex(currentImageWorldPointIn3D, inputIndex);
if (m_ImageGeometry->IsIndexInside(inputIndex))
{
resultSlice->SetPixel(sliceIterator.GetIndex(), inputImage->GetPixel(inputIndex));
}
else
{
resultSlice->SetPixel(sliceIterator.GetIndex(), 0);
}
++sliceIterator;
}
Image::Pointer resultImage = ImageToImageFilter::GetOutput();
GrabItkImageMemory(resultSlice, resultImage, nullptr, false);
resultImage->SetClonedGeometry(newSliceGeometryTest);
// Workaround because of BUG (#6505)
resultImage->GetGeometry()->GetIndexToWorldTransform()->SetMatrix(tempTransform);
// Workaround end
}