GetIndexFromMouseClick()
{
LeftEyeIndex[0] = 60;
LeftEyeIndex[1] = 127;
LeftEyeIndex[2] = 93;
return LeftEyeIndex;
}
int
main(int, char *[])
{
constexpr unsigned int Dimension = 3;
auto image = ImageType::New();
constexpr ImageType::SizeType size = {
{ 200, 200, 200 }
};
constexpr ImageType::IndexType start = {
{ 0, 0, 0 }
};
ImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
image->SetRegions(region);
image->Allocate(true);
ImageType::SpacingType spacing;
spacing[0] = 0.33;
spacing[1] = 0.33;
spacing[2] = 1.20;
image->SetSpacing(spacing);
const ImageType::SpacingType & sp = image->GetSpacing();
std::cout << "Spacing = ";
std::cout << sp[0] << ", " << sp[1] << ", " << sp[2] << std::endl;
constexpr ImageType::PointType newOrigin{};
image->SetOrigin(newOrigin);
const ImageType::PointType & origin = image->GetOrigin();
std::cout << "Origin = ";
std::cout << origin[0] << ", " << origin[1] << ", " << origin[2]
<< std::endl;
ImageType::DirectionType direction;
direction.SetIdentity();
image->SetDirection(direction);
const ImageType::DirectionType & direct = image->GetDirection();
std::cout << "Direction = " << std::endl;
std::cout << direct << std::endl;
ImageType::IndexType pixelIndex;
const bool isInside =
image->TransformPhysicalPointToIndex(point, pixelIndex);
if (isInside)
{
ImageType::PixelType pixelValue = image->GetPixel(pixelIndex);
pixelValue += 5;
image->SetPixel(pixelIndex, pixelValue);
}
const ImageType::IndexType LeftEyeIndex = GetIndexFromMouseClick();
ImageType::PointType LeftEyePoint;
image->TransformIndexToPhysicalPoint(LeftEyeIndex, LeftEyePoint);
std::cout << "===========================================" << std::endl;
std::cout << "The Left Eye Location is " << LeftEyePoint << std::endl;
using MatrixType =
const ImageType::SpacingType & ImageSpacing = image->GetSpacing();
SpacingMatrix(0, 0) = ImageSpacing[0];
SpacingMatrix(1, 1) = ImageSpacing[1];
SpacingMatrix(2, 2) = ImageSpacing[2];
const ImageType::DirectionType & ImageDirectionCosines =
image->GetDirection();
const ImageType::PointType & ImageOrigin = image->GetOrigin();
LeftEyeIndexVector[0] = LeftEyeIndex[0];
LeftEyeIndexVector[1] = LeftEyeIndex[1];
LeftEyeIndexVector[2] = LeftEyeIndex[2];
const ImageType::PointType LeftEyePointByHand =
ImageOrigin + ImageDirectionCosines * SpacingMatrix * LeftEyeIndexVector;
std::cout << "===========================================" << std::endl;
std::cout << "Spacing:: " << std::endl << SpacingMatrix << std::endl;
std::cout << "===========================================" << std::endl;
std::cout << "DirectionCosines:: " << std::endl
<< ImageDirectionCosines << std::endl;
std::cout << "===========================================" << std::endl;
std::cout << "Origin:: " << std::endl << ImageOrigin << std::endl;
std::cout << "===========================================" << std::endl;
std::cout << "The Left Eye Location is " << LeftEyePointByHand << std::endl;
if ((LeftEyePointByHand - LeftEyePoint).GetNorm() < 0.01F)
{
std::cout << "===========================================" << std::endl;
std::cout << "Two results are identical as expected!" << std::endl;
std::cout << "The Left Eye from TransformIndexToPhysicalPoint is "
<< LeftEyePoint << std::endl;
std::cout << "The Left Eye from Math is " << LeftEyePointByHand
<< std::endl;
}
return EXIT_SUCCESS;
}
Templated n-dimensional image class.
Index< VImageDimension > IndexType
A templated class holding a M x N size Matrix.
A templated class holding a geometric point in n-Dimensional space.
A templated class holding a n-Dimensional vector.
ImageBaseType::SpacingType VectorType
ImageBaseType::PointType PointType
constexpr TContainer MakeFilled(typename TContainer::const_reference value)
*par Constraints *The filter image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents