MCPcopy Create free account
hub / github.com/Kitware/VTK / ApplyIndexToPhysicalMatrix

Method ApplyIndexToPhysicalMatrix

Common/DataModel/vtkImageData.cxx:1752–1819  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1750
1751//------------------------------------------------------------------------------
1752void vtkImageData::ApplyIndexToPhysicalMatrix(vtkMatrix4x4* sourceIndexToPhysicalMatrix)
1753{
1754 if (sourceIndexToPhysicalMatrix == nullptr)
1755 {
1756 vtkErrorMacro("Source IndexToPhysicalMatrix matrix is null");
1757 return;
1758 }
1759
1760 // Get origin, spacing, and direction from the source matrix
1761 double origin[3] = { sourceIndexToPhysicalMatrix->GetElement(0, 3),
1762 sourceIndexToPhysicalMatrix->GetElement(1, 3), sourceIndexToPhysicalMatrix->GetElement(2, 3) };
1763 double directionMatrixElements[9];
1764 double spacing[3];
1765 for (int i = 0; i < 3; i++)
1766 {
1767 double direction[3] = { sourceIndexToPhysicalMatrix->GetElement(0, i),
1768 sourceIndexToPhysicalMatrix->GetElement(1, i),
1769 sourceIndexToPhysicalMatrix->GetElement(2, i) };
1770 spacing[i] = vtkMath::Normalize(direction);
1771 directionMatrixElements[i] = direction[0];
1772 directionMatrixElements[3 + i] = direction[1];
1773 directionMatrixElements[6 + i] = direction[2];
1774 }
1775
1776 bool modified = false;
1777
1778 if ((this->Origin[0] != origin[0]) || (this->Origin[1] != origin[1]) ||
1779 (this->Origin[2] != origin[2]))
1780 {
1781 this->Origin[0] = origin[0];
1782 this->Origin[1] = origin[1];
1783 this->Origin[2] = origin[2];
1784 modified = true;
1785 }
1786
1787 if ((this->Spacing[0] != spacing[0]) || (this->Spacing[1] != spacing[1]) ||
1788 (this->Spacing[2] != spacing[2]))
1789 {
1790 this->Spacing[0] = spacing[0];
1791 this->Spacing[1] = spacing[1];
1792 this->Spacing[2] = spacing[2];
1793 modified = true;
1794 }
1795
1796 bool directionMatrixModified = false;
1797 double* currentDirectionMatrixElements = this->DirectionMatrix->GetData();
1798 for (int i = 0; i < 9; i++)
1799 {
1800 if (currentDirectionMatrixElements[i] != directionMatrixElements[i])
1801 {
1802 currentDirectionMatrixElements[i] = directionMatrixElements[i];
1803 directionMatrixModified = true;
1804 }
1805 }
1806 if (directionMatrixModified)
1807 {
1808 this->DirectionMatrix->Modified();
1809 modified = true;

Callers 2

DoOrientationTestFunction · 0.80

Calls 5

ComputeTransformsMethod · 0.95
BuildPointsMethod · 0.95
NormalizeFunction · 0.70
GetDataMethod · 0.45
ModifiedMethod · 0.45

Tested by 1

DoOrientationTestFunction · 0.64