------------------------------------------------------------------------------ Update the reslice matrix, which is the slice-to-data matrix.
| 573 | //------------------------------------------------------------------------------ |
| 574 | // Update the reslice matrix, which is the slice-to-data matrix. |
| 575 | void vtkImageResliceMapper::UpdateResliceMatrix(vtkRenderer* ren, vtkImageSlice* prop) |
| 576 | { |
| 577 | // Save the old matrix |
| 578 | double* matrixElements = *this->ResliceMatrix->Element; |
| 579 | double oldMatrixElements[16]; |
| 580 | vtkMatrix4x4::DeepCopy(oldMatrixElements, matrixElements); |
| 581 | |
| 582 | // Get world-to-data matrix from the prop matrix |
| 583 | this->UpdateWorldToDataMatrix(prop); |
| 584 | |
| 585 | // Check if prop matrix is orthonormal |
| 586 | bool propMatrixIsOrthonormal = false; |
| 587 | vtkMatrix4x4* propMatrix = nullptr; |
| 588 | if (!this->InternalResampleToScreenPixels) |
| 589 | { |
| 590 | static double tol = 1e-12; |
| 591 | propMatrix = prop->GetMatrix(); |
| 592 | double* row0 = propMatrix->Element[0]; |
| 593 | double* row1 = propMatrix->Element[1]; |
| 594 | double* row2 = propMatrix->Element[2]; |
| 595 | propMatrixIsOrthonormal = |
| 596 | (fabs(vtkMath::Dot(row0, row0) - 1.0) < tol && fabs(vtkMath::Dot(row1, row1) - 1.0) < tol && |
| 597 | fabs(vtkMath::Dot(row2, row2) - 1.0) < tol && fabs(vtkMath::Dot(row0, row1)) < tol && |
| 598 | fabs(vtkMath::Dot(row0, row2)) < tol && fabs(vtkMath::Dot(row1, row2)) < tol); |
| 599 | } |
| 600 | |
| 601 | // Compute SliceToWorld matrix from camera if prop matrix is not |
| 602 | // orthonormal or if InternalResampleToScreenPixels is set |
| 603 | if (this->InternalResampleToScreenPixels || !propMatrixIsOrthonormal) |
| 604 | { |
| 605 | this->UpdateSliceToWorldMatrix(ren->GetActiveCamera()); |
| 606 | vtkMatrix4x4::Multiply4x4( |
| 607 | this->WorldToDataMatrix, this->SliceToWorldMatrix, this->ResliceMatrix); |
| 608 | vtkMatrix4x4::Invert(this->ResliceMatrix, this->DataToSliceMatrix); |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | // Get the matrices used to compute the reslice matrix |
| 613 | vtkMatrix4x4* resliceMatrix = this->ResliceMatrix; |
| 614 | vtkMatrix4x4* viewMatrix = ren->GetActiveCamera()->GetViewTransformMatrix(); |
| 615 | |
| 616 | // Get slice plane in world coords by passing null as the matrix |
| 617 | double wplane[4]; |
| 618 | this->GetSlicePlaneInDataCoords(nullptr, wplane); |
| 619 | |
| 620 | // Check whether normal is facing towards camera, the "ndop" is |
| 621 | // the negative of the direction of projection for the camera |
| 622 | double* ndop = viewMatrix->Element[2]; |
| 623 | double dotprod = vtkMath::Dot(ndop, wplane); |
| 624 | |
| 625 | // Get slice plane in data coords by passing the prop matrix, flip |
| 626 | // normal to face the camera |
| 627 | double plane[4]; |
| 628 | this->GetSlicePlaneInDataCoords(propMatrix, plane); |
| 629 | if (dotprod < 0) |
| 630 | { |
| 631 | plane[0] = -plane[0]; |
| 632 | plane[1] = -plane[1]; |
no test coverage detected