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

Method UpdateSliceToWorldMatrix

Rendering/Image/vtkImageResliceMapper.cxx:497–571  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Update the SliceToWorld transformation matrix

Source from the content-addressed store, hash-verified

495//------------------------------------------------------------------------------
496// Update the SliceToWorld transformation matrix
497void vtkImageResliceMapper::UpdateSliceToWorldMatrix(vtkCamera* camera)
498{
499 // Get slice plane in world coords by passing null as the prop matrix
500 double plane[4];
501 this->GetSlicePlaneInDataCoords(nullptr, plane);
502
503 // Make sure normal is facing towards camera
504 vtkMatrix4x4* viewMatrix = camera->GetViewTransformMatrix();
505 double* ndop = viewMatrix->Element[2];
506 if (vtkMath::Dot(ndop, plane) < 0)
507 {
508 plane[0] = -plane[0];
509 plane[1] = -plane[1];
510 plane[2] = -plane[2];
511 plane[3] = -plane[3];
512 }
513
514 // The normal is the first three elements
515 double* normal = plane;
516
517 // The last element is -dot(normal, origin)
518 double dp = -plane[3];
519
520 // Compute rotation angle between camera axis and slice normal
521 double vec[3];
522 vtkMath::Cross(ndop, normal, vec);
523 double costheta = vtkMath::Dot(ndop, normal);
524 double sintheta = vtkMath::Norm(vec);
525 double theta = atan2(sintheta, costheta);
526 if (sintheta != 0)
527 {
528 vec[0] /= sintheta;
529 vec[1] /= sintheta;
530 vec[2] /= sintheta;
531 }
532 // convert to quaternion
533 costheta = cos(0.5 * theta);
534 sintheta = sin(0.5 * theta);
535 double quat[4];
536 quat[0] = costheta;
537 quat[1] = vec[0] * sintheta;
538 quat[2] = vec[1] * sintheta;
539 quat[3] = vec[2] * sintheta;
540 // convert to matrix
541 double mat[3][3];
542 vtkMath::QuaternionToMatrix3x3(quat, mat);
543
544 // Create a slice-to-world transform matrix
545 // The columns are v1, v2, normal
546 vtkMatrix4x4* sliceToWorld = this->SliceToWorldMatrix;
547
548 double v1[3], v2[3];
549 vtkMath::Multiply3x3(mat, viewMatrix->Element[0], v1);
550 vtkMath::Multiply3x3(mat, viewMatrix->Element[1], v2);
551
552 sliceToWorld->Element[0][0] = v1[0];
553 sliceToWorld->Element[1][0] = v1[1];
554 sliceToWorld->Element[2][0] = v1[2];

Callers 1

UpdateResliceMatrixMethod · 0.95

Calls 9

QuaternionToMatrix3x3Function · 0.85
DotFunction · 0.50
CrossFunction · 0.50
NormFunction · 0.50
cosFunction · 0.50
sinFunction · 0.50
Multiply3x3Function · 0.50

Tested by

no test coverage detected