1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0026641: Visualization, TKOpenGl - handle correctly transformation persistence within perspective projection.

Add a new method AIS_InteractiveContext::SetTransformPersistence, which sets transform persistence to object and selection.
Add a new method SelectMgr_SelectionManager::UpdateSelection, which re-adds selectable object in BVHs in all viewer selectors.
Add a new method SelectMgr_ViewerSelector::MoveSelectableObject, which moves object from set of not transform persistence objects to set of transform persistence objects (or vice versa).
Add a new method Graphic3d_TransformUtils::Convert, which converts gp_Trsf to Graphic3d_Mat4.
Remove the method PrsMgr_PresentableObject::SetTransformPersistence(flag, point).
This commit is contained in:
isk
2016-07-05 13:32:52 +03:00
committed by bugmaster
parent fbad941bd4
commit 1d92133e83
20 changed files with 254 additions and 77 deletions

View File

@@ -158,25 +158,34 @@ void Graphic3d_TransformPers::Apply (NCollection_Mat4<T>& theProjection,
}
// Prevent zooming.
if (Flags & Graphic3d_TMF_ZoomPers)
if ((Flags == Graphic3d_TMF_TriedronPers)
|| (Flags & Graphic3d_TMF_ZoomPers))
{
const T aDet00 = (2.0f / theViewportWidth) / theProjection.GetValue(0, 0);
const T aDet11 = (2.0f / theViewportHeight) / theProjection.GetValue(1, 1);
const T aDet2 = Max (aDet00, aDet11);
const T aSize = static_cast<T> (1.0);
const Standard_Integer aViewport[4] = { 0, 0, theViewportHeight, theViewportHeight };
NCollection_Mat4<T> aWorldView;
aWorldView.InitIdentity();
theProjection.ChangeValue(0, 0) *= aDet00;
theProjection.ChangeValue(1, 1) *= aDet11;
theProjection.ChangeValue(2, 2) *= aDet2;
}
NCollection_Vec3<T> aWinCoordsRefPoint;
Graphic3d_TransformUtils::Project (static_cast<T> (Point.x()),
static_cast<T> (Point.y()),
static_cast<T> (Point.z()),
theWorldView, theProjection, aViewport,
aWinCoordsRefPoint.x(), aWinCoordsRefPoint.y(), aWinCoordsRefPoint.z());
if (Flags == Graphic3d_TMF_TriedronPers)
{
// Compute fixed-zoom multiplier. Actually function works ugly with TelPerspective!
const T aDet2 = static_cast<T> (0.002) / Max (theProjection.GetValue (1, 1), theProjection.GetValue (0, 0));
NCollection_Vec3<T> anUnProj1;
Graphic3d_TransformUtils::UnProject (aWinCoordsRefPoint.x(), aWinCoordsRefPoint.y(), aWinCoordsRefPoint.z(),
aWorldView, theProjection, aViewport,
anUnProj1.x(), anUnProj1.y(), anUnProj1.z());
theProjection.ChangeValue (0, 0) *= aDet2;
theProjection.ChangeValue (1, 1) *= aDet2;
theProjection.ChangeValue (2, 2) *= aDet2;
NCollection_Vec3<T> anUnProj2;
Graphic3d_TransformUtils::UnProject (aWinCoordsRefPoint.x(), aWinCoordsRefPoint.y() + aSize, aWinCoordsRefPoint.z(),
aWorldView, theProjection, aViewport,
anUnProj2.x(), anUnProj2.y(), anUnProj2.z());
const T aScale = (anUnProj2.y() - anUnProj1.y()) / aSize;
Graphic3d_TransformUtils::Scale (theWorldView, aScale, aScale, aScale);
}
// Prevent translation by nullifying translation component.
@@ -190,23 +199,6 @@ void Graphic3d_TransformPers::Apply (NCollection_Mat4<T>& theProjection,
theProjection.SetValue (2, 3, static_cast<T> (0.0));
}
// Prevent scaling-on-axis.
if (Flags & Graphic3d_TMF_ZoomPers)
{
NCollection_Vec3<T> aVecX = theWorldView.GetColumn (0).xyz();
NCollection_Vec3<T> aVecY = theWorldView.GetColumn (1).xyz();
NCollection_Vec3<T> aVecZ = theWorldView.GetColumn (2).xyz();
T aScaleX = aVecX.Modulus();
T aScaleY = aVecY.Modulus();
T aScaleZ = aVecZ.Modulus();
for (Standard_Integer anI = 0; anI < 3; ++anI)
{
theWorldView.ChangeValue (0, anI) /= aScaleX;
theWorldView.ChangeValue (1, anI) /= aScaleY;
theWorldView.ChangeValue (2, anI) /= aScaleZ;
}
}
// Prevent rotation by nullifying rotation component.
if (Flags & Graphic3d_TMF_RotatePers)
{

View File

@@ -41,6 +41,11 @@ namespace Graphic3d_TransformUtils
typedef Graphic3d_Vec4 Vec4;
};
//! Converts gp_Trsf to Graphic3d_Mat4.
template<class T>
static void Convert (const gp_Trsf& theTransformation,
typename MatrixType<T>::Mat4& theOut);
//! Constructs a 3D orthographic projection matrix.
template<class T>
static void Ortho (typename MatrixType<T>::Mat4& theOut,
@@ -112,6 +117,37 @@ namespace Graphic3d_TransformUtils
T theX,
T theY,
T theZ);
//! Returns scaling factor from 3x3 affine matrix.
template<class T>
static Standard_Real ScaleFactor (const typename MatrixType<T>::Mat4& theMatrix);
}
// =======================================================================
// function : Convert
// purpose :
// =======================================================================
template<class T>
void Graphic3d_TransformUtils::Convert (const gp_Trsf& theTransformation,
typename MatrixType<T>::Mat4& theOut)
{
theOut.InitIdentity();
// Copy a 3x3 submatrix.
theOut.ChangeValue (0, 0) = theTransformation.Value (1, 1);
theOut.ChangeValue (0, 1) = theTransformation.Value (1, 2);
theOut.ChangeValue (0, 2) = theTransformation.Value (1, 3);
theOut.ChangeValue (1, 0) = theTransformation.Value (2, 1);
theOut.ChangeValue (1, 1) = theTransformation.Value (2, 2);
theOut.ChangeValue (1, 2) = theTransformation.Value (2, 3);
theOut.ChangeValue (2, 0) = theTransformation.Value (3, 1);
theOut.ChangeValue (2, 1) = theTransformation.Value (3, 2);
theOut.ChangeValue (2, 2) = theTransformation.Value (3, 3);
// Add a translate component.
theOut.ChangeValue (0, 3) = theTransformation.TranslationPart().X();
theOut.ChangeValue (1, 3) = theTransformation.TranslationPart().Y();
theOut.ChangeValue (2, 3) = theTransformation.TranslationPart().Z();
}
// =======================================================================
@@ -449,4 +485,22 @@ static Standard_Boolean Graphic3d_TransformUtils::UnProject (const T
return Standard_True;
}
// =======================================================================
// function : ScaleFactor
// purpose :
// =======================================================================
template<class T>
static Standard_Real Graphic3d_TransformUtils::ScaleFactor (const typename MatrixType<T>::Mat4& theMatrix)
{
// The determinant of the matrix should give the scale factor (cubed).
const T aDeterminant = (theMatrix.GetValue (0, 0) * theMatrix.GetValue (1, 1) * theMatrix.GetValue (2, 2) +
theMatrix.GetValue (0, 1) * theMatrix.GetValue (1, 2) * theMatrix.GetValue (2, 0) +
theMatrix.GetValue (0, 2) * theMatrix.GetValue (1, 0) * theMatrix.GetValue (2, 1))
- (theMatrix.GetValue (0, 2) * theMatrix.GetValue (1, 1) * theMatrix.GetValue (2, 0) +
theMatrix.GetValue (0, 0) * theMatrix.GetValue (1, 2) * theMatrix.GetValue (2, 1) +
theMatrix.GetValue (0, 1) * theMatrix.GetValue (1, 0) * theMatrix.GetValue (2, 2));
return Pow (static_cast<Standard_Real> (aDeterminant), 1.0 / 3.0);
}
#endif // _Graphic3d_TransformUtils_HeaderFile