SelectMgr_SortCriterion::Normal, SelectBasics_PickResult::SurfaceNormal() - added new property.
SelectMgr_RectangularFrustum::Overlaps() for triangle sets new normal property.
gp_GTrsf::GetMat4() - added conversion into NCollection_Mat4 similar to gp_Trsf::GetMat4().
{
myDepth = RealLast();
myObjPickedPnt = gp_Pnt (RealLast(), 0.0, 0.0);
+ myNormal.SetValues (0.0f, 0.0f, 0.0f);
}
//! Return depth along picking ray.
//! Set distance to geometry center.
void SetDistToGeomCenter (Standard_Real theDistToCenter) { myDistToCenter = theDistToCenter; }
+ //! Return (unnormalized) surface normal at picked point or zero vector if undefined.
+ //! WARNING! Normal is defined in local coordinate system and should be translated into World System before usage!
+ const NCollection_Vec3<float>& SurfaceNormal() const { return myNormal; }
+
+ //! Set surface normal at picked point.
+ void SetSurfaceNormal (const NCollection_Vec3<float>& theNormal) { myNormal = theNormal; }
+
+ //! Set surface normal at picked point.
+ void SetSurfaceNormal (const gp_Vec& theNormal)
+ {
+ myNormal.SetValues ((float )theNormal.X(), (float )theNormal.Y(), (float )theNormal.Z());
+ }
+
private:
- gp_Pnt myObjPickedPnt; //!< User-picked selection point onto object
- Standard_Real myDepth; //!< Depth to detected point
- Standard_Real myDistToCenter; //!< Distance from 3d projection user-picked selection point to entity's geometry center
+ gp_Pnt myObjPickedPnt; //!< User-picked selection point onto object
+ NCollection_Vec3<float> myNormal; //!< surface normal
+ Standard_Real myDepth; //!< Depth to detected point
+ Standard_Real myDistToCenter; //!< Distance from 3d projection user-picked selection point to entity's geometry center
};
#endif // _SelectBasics_PickResult_HeaderFile
const gp_XYZ aDiff = myNearPickedPnt.XYZ() - thePnt1.XYZ();
thePickResult.SetDepth (aTriangleNormal.Dot (aDiff) * myScale);
thePickResult.SetPickedPoint (thePnt1);
+ thePickResult.SetSurfaceNormal (aTriangleNormal);
return !theClipRange.IsClipped (thePickResult.Depth());
}
{
thePickResult.SetDepth (myNearPickedPnt.Distance (aPtOnPlane) * myScale);
thePickResult.SetPickedPoint (aPtOnPlane);
+ thePickResult.SetSurfaceNormal (aTriangleNormal);
return !theClipRange.IsClipped (thePickResult.Depth());
}
#ifndef _SelectMgr_SortCriterion_HeaderFile
#define _SelectMgr_SortCriterion_HeaderFile
+#include <Graphic3d_Vec3.hxx>
#include <Graphic3d_ZLayerId.hxx>
#include <Precision.hxx>
#include <Select3D_SensitiveEntity.hxx>
Handle(Select3D_SensitiveEntity) Entity; //!< detected entity
gp_Pnt Point; //!< 3D point
+ Graphic3d_Vec3 Normal; //!< surface normal or 0 vector if undefined
Standard_Real Depth; //!< distance from the view plane to the entity
Standard_Real MinDist; //!< distance from the clicked point to the entity on the view plane
Standard_Real Tolerance; //!< tolerance used for selecting candidates
return;
}
+ bool hasNormal = false;
if (thePickResult.HasPickedPoint())
{
- theCriterion.Point = thePickResult.PickedPoint();
+ theCriterion.Point = thePickResult.PickedPoint();
+ theCriterion.Normal = thePickResult.SurfaceNormal();
+ const float aNormLen2 = theCriterion.Normal.SquareModulus();
+ if (aNormLen2 > ShortRealEpsilon())
+ {
+ hasNormal = true;
+ theCriterion.Normal *= 1.0f / sqrtf (aNormLen2);
+ }
}
else if (!thePickResult.IsValid())
{
}
if (anInvTrsf.Form() != gp_Identity)
{
- anInvTrsf.Inverted().Transforms (theCriterion.Point.ChangeCoord());
+ const gp_GTrsf anInvInvTrsd = anInvTrsf.Inverted();
+ anInvInvTrsd.Transforms (theCriterion.Point.ChangeCoord());
+ if (hasNormal)
+ {
+ Graphic3d_Mat4d aMat4;
+ anInvInvTrsd.GetMat4 (aMat4);
+ const Graphic3d_Vec4d aNormRes = aMat4 * Graphic3d_Vec4d (Graphic3d_Vec3d (theCriterion.Normal), 0.0);
+ theCriterion.Normal = Graphic3d_Vec3 (aNormRes.xyz());
+ }
}
if (mySelectingVolumeMgr.Camera().IsNull())
GetMapOfAIS().Find1 (anObj, aName);
aName.LeftJustify (20, ' ');
char anInfoStr[512];
- Sprintf (anInfoStr,
- " Depth: %g Distance: %g Point: %g %g %g",
- aPickData.Depth,
- aPickData.MinDist,
- aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
+ if (aPickData.Normal.SquareModulus() > ShortRealEpsilon())
+ {
+ Sprintf (anInfoStr,
+ " Depth: %g Distance: %g Point: %g %g %g Normal: %g %g %g",
+ aPickData.Depth,
+ aPickData.MinDist,
+ aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z(),
+ aPickData.Normal.x(), aPickData.Normal.y(), aPickData.Normal.z());
+ }
+ else
+ {
+ Sprintf (anInfoStr,
+ " Depth: %g Distance: %g Point: %g %g %g",
+ aPickData.Depth,
+ aPickData.MinDist,
+ aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
+ }
theDI << " " << aName
<< anInfoStr
<< " (" << anEntity->DynamicType()->Name() << ")"
gp_Trsf Trsf() const;
+ //! Convert transformation to 4x4 matrix.
+ template<class T>
+ void GetMat4 (NCollection_Mat4<T>& theMat) const
+ {
+ if (shape == gp_Identity)
+ {
+ theMat.InitIdentity();
+ return;
+ }
+
+ theMat.SetValue (0, 0, static_cast<T> (Value (1, 1)));
+ theMat.SetValue (0, 1, static_cast<T> (Value (1, 2)));
+ theMat.SetValue (0, 2, static_cast<T> (Value (1, 3)));
+ theMat.SetValue (0, 3, static_cast<T> (Value (1, 4)));
+ theMat.SetValue (1, 0, static_cast<T> (Value (2, 1)));
+ theMat.SetValue (1, 1, static_cast<T> (Value (2, 2)));
+ theMat.SetValue (1, 2, static_cast<T> (Value (2, 3)));
+ theMat.SetValue (1, 3, static_cast<T> (Value (2, 4)));
+ theMat.SetValue (2, 0, static_cast<T> (Value (3, 1)));
+ theMat.SetValue (2, 1, static_cast<T> (Value (3, 2)));
+ theMat.SetValue (2, 2, static_cast<T> (Value (3, 3)));
+ theMat.SetValue (2, 3, static_cast<T> (Value (3, 4)));
+ theMat.SetValue (3, 0, static_cast<T> (0));
+ theMat.SetValue (3, 1, static_cast<T> (0));
+ theMat.SetValue (3, 2, static_cast<T> (0));
+ theMat.SetValue (3, 3, static_cast<T> (1));
+ }
+
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
-
-
-
-protected:
-
-
-
-
-
private:
-
-
gp_Mat matrix;
gp_XYZ loc;
gp_TrsfForm shape;
Standard_Real scale;
-
};