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

Method GetTransform

Filters/General/vtkIntersectionPolyDataFilter.cxx:1825–1886  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1823}
1824
1825int vtkIntersectionPolyDataFilter::Impl::GetTransform(vtkTransform* transform, vtkPoints* points)
1826{
1827 double zaxis[3] = { 0, 0, 1 };
1828 double rotationAxis[3], normal[3], center[3], rotationAngle;
1829
1830 double pt0[3], pt1[3], pt2[3];
1831 points->GetPoint(0, pt0);
1832 points->GetPoint(1, pt1);
1833 points->GetPoint(2, pt2);
1834 vtkTriangle::ComputeNormal(pt0, pt1, pt2, normal);
1835
1836 double dotZAxis = vtkMath::Dot(normal, zaxis);
1837 if (fabs(1.0 - dotZAxis) < 1e-6)
1838 {
1839 // Aligned with z-axis
1840 rotationAxis[0] = 1.0;
1841 rotationAxis[1] = 0.0;
1842 rotationAxis[2] = 0.0;
1843 rotationAngle = 0.0;
1844 }
1845 else if (fabs(1.0 + dotZAxis) < 1e-6)
1846 {
1847 // Co-linear with z-axis, but reversed sense.
1848 // Aligned with z-axis
1849 rotationAxis[0] = 1.0;
1850 rotationAxis[1] = 0.0;
1851 rotationAxis[2] = 0.0;
1852 rotationAngle = 180.0;
1853 }
1854 else
1855 {
1856 // The general case
1857 vtkMath::Cross(normal, zaxis, rotationAxis);
1858 vtkMath::Normalize(rotationAxis);
1859 double dot = vtkMath::Dot(zaxis, normal);
1860 if (dot > 1.0)
1861 {
1862 dot = 1.0;
1863 }
1864 else if (dot < -1.0)
1865 {
1866 dot = -1.0;
1867 }
1868 rotationAngle = vtkMath::DegreesFromRadians(acos(dot));
1869 }
1870
1871 transform->PreMultiply();
1872 transform->Identity();
1873
1874 transform->RotateWXYZ(rotationAngle, rotationAxis[0], rotationAxis[1], rotationAxis[2]);
1875
1876 vtkTriangle::TriangleCenter(pt0, pt1, pt2, center);
1877 transform->Translate(-center[0], -center[1], -center[2]);
1878
1879 int zaxisdotsign = 1;
1880 if (dotZAxis < 0)
1881 {
1882 zaxisdotsign = -1;

Callers 2

GetLoopOrientationMethod · 0.95
SplitCellMethod · 0.45

Calls 9

RotateWXYZMethod · 0.80
ComputeNormalFunction · 0.50
DotFunction · 0.50
CrossFunction · 0.50
NormalizeFunction · 0.50
acosFunction · 0.50
GetPointMethod · 0.45
IdentityMethod · 0.45
TranslateMethod · 0.45

Tested by

no test coverage detected