Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:48:32

0001 // Created on: 2014-05-22
0002 // Created by: Varvara POSKONINA
0003 // Copyright (c) 2005-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _SelectMgr_SelectingVolumeManager_HeaderFile
0017 #define _SelectMgr_SelectingVolumeManager_HeaderFile
0018 
0019 #include <SelectBasics_SelectingVolumeManager.hxx>
0020 
0021 #include <SelectMgr_BaseIntersector.hxx>
0022 #include <SelectMgr_VectorTypes.hxx>
0023 #include <SelectMgr_ViewClipRange.hxx>
0024 
0025 //! This class is used to switch between active selecting volumes depending
0026 //! on selection type chosen by the user.
0027 //! The sample of correct selection volume initialization procedure:
0028 //! @code
0029 //!   aMgr.InitPointSelectingVolume (aMousePos);
0030 //!   aMgr.SetPixelTolerance (aTolerance);
0031 //!   aMgr.SetCamera (aCamera);
0032 //!   aMgr.SetWindowSize (aWidth, aHeight);
0033 //!   aMgr.BuildSelectingVolume();
0034 //! @endcode
0035 class SelectMgr_SelectingVolumeManager : public SelectBasics_SelectingVolumeManager
0036 {
0037 public:
0038 
0039   //! Creates instances of all available selecting volume types
0040   Standard_EXPORT SelectMgr_SelectingVolumeManager();
0041 
0042   virtual ~SelectMgr_SelectingVolumeManager() {}
0043 
0044   //! Creates, initializes and activates rectangular selecting frustum for point selection
0045   Standard_EXPORT void InitPointSelectingVolume (const gp_Pnt2d& thePoint);
0046 
0047   //! Creates, initializes and activates rectangular selecting frustum for box selection
0048   Standard_EXPORT void InitBoxSelectingVolume (const gp_Pnt2d& theMinPt,
0049                                                const gp_Pnt2d& theMaxPt);
0050 
0051   //! Creates, initializes and activates set of triangular selecting frustums for polyline selection
0052   Standard_EXPORT void InitPolylineSelectingVolume (const TColgp_Array1OfPnt2d& thePoints);
0053 
0054   //! Creates and activates axis selector for point selection
0055   Standard_EXPORT void InitAxisSelectingVolume (const gp_Ax1& theAxis);
0056 
0057   //! Sets as active the custom selecting volume
0058   Standard_EXPORT void InitSelectingVolume (const Handle(SelectMgr_BaseIntersector)& theVolume);
0059 
0060   //! Builds previously initialized selecting volume.
0061   Standard_EXPORT void BuildSelectingVolume();
0062 
0063   //! Returns active selecting volume that was built during last
0064   //! run of OCCT selection mechanism
0065   const Handle(SelectMgr_BaseIntersector)& ActiveVolume() const { return myActiveSelectingVolume; }
0066 
0067   // Returns active selection type (point, box, polyline)
0068   Standard_EXPORT virtual Standard_Integer GetActiveSelectionType() const Standard_OVERRIDE;
0069 
0070   //! IMPORTANT: Scaling makes sense only for frustum built on a single point!
0071   //!            Note that this method does not perform any checks on type of the frustum.
0072   //!
0073   //! Returns a copy of the frustum resized according to the scale factor given
0074   //! and transforms it using the matrix given.
0075   //! There are no default parameters, but in case if:
0076   //!    - transformation only is needed: @theScaleFactor must be initialized as any negative value;
0077   //!    - scale only is needed: @theTrsf must be set to gp_Identity.
0078   //! Builder is an optional argument that represents corresponding settings for re-constructing transformed
0079   //! frustum from scratch. Can be null if reconstruction is not expected furthermore.
0080   Standard_EXPORT virtual SelectMgr_SelectingVolumeManager ScaleAndTransform (const Standard_Integer theScaleFactor,
0081                                                                               const gp_GTrsf& theTrsf,
0082                                                                               const Handle(SelectMgr_FrustumBuilder)& theBuilder) const;
0083 
0084 public:
0085 
0086   //! Returns current camera definition.
0087   Standard_EXPORT const Handle(Graphic3d_Camera)& Camera() const;
0088 
0089   //! Updates camera projection and orientation matrices in all selecting volumes
0090   //! Note: this method should be called after selection volume building
0091   //! else exception will be thrown
0092   Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera) theCamera);
0093 
0094   //! Updates viewport in all selecting volumes
0095   //! Note: this method should be called after selection volume building
0096   //! else exception will be thrown
0097   Standard_EXPORT void SetViewport (const Standard_Real theX,
0098                                     const Standard_Real theY,
0099                                     const Standard_Real theWidth,
0100                                     const Standard_Real theHeight);
0101 
0102   //! Updates pixel tolerance in all selecting volumes
0103   //! Note: this method should be called after selection volume building
0104   //! else exception will be thrown
0105   Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTolerance);
0106 
0107   //! Returns window size
0108   Standard_EXPORT void WindowSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
0109 
0110   //! Updates window size in all selecting volumes
0111   //! Note: this method should be called after selection volume building
0112   //! else exception will be thrown
0113   Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
0114 
0115 
0116   //! SAT intersection test between defined volume and given axis-aligned box
0117   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theBoxMin,
0118                                                         const SelectMgr_Vec3& theBoxMax,
0119                                                         SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0120 
0121   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
0122   //! with minimum corner at point theMinPt and maximum at point theMaxPt
0123   Standard_EXPORT  virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theBoxMin,
0124                                                          const SelectMgr_Vec3& theBoxMax,
0125                                                          Standard_Boolean*     theInside = NULL) const Standard_OVERRIDE;
0126 
0127   //! Intersection test between defined volume and given point
0128   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt,
0129                                                           SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0130 
0131   //! Intersection test between defined volume and given point
0132   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt) const Standard_OVERRIDE;
0133 
0134   //! SAT intersection test between defined volume and given ordered set of points,
0135   //! representing line segments. The test may be considered of interior part or
0136   //! boundary line defined by segments depending on given sensitivity type
0137   Standard_EXPORT virtual Standard_Boolean OverlapsPolygon (const TColgp_Array1OfPnt& theArrayOfPts,
0138                                                             Standard_Integer theSensType,
0139                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0140 
0141   //! Checks if line segment overlaps selecting frustum
0142   Standard_EXPORT virtual Standard_Boolean OverlapsSegment (const gp_Pnt& thePnt1,
0143                                                             const gp_Pnt& thePnt2,
0144                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0145 
0146   //! SAT intersection test between defined volume and given triangle. The test may
0147   //! be considered of interior part or boundary line defined by triangle vertices
0148   //! depending on given sensitivity type
0149   Standard_EXPORT  virtual Standard_Boolean OverlapsTriangle (const gp_Pnt& thePnt1,
0150                                                               const gp_Pnt& thePnt2,
0151                                                               const gp_Pnt& thePnt3,
0152                                                               Standard_Integer theSensType,
0153                                                               SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0154 
0155   //! Intersection test between defined volume and given sphere
0156   Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
0157                                                            const Standard_Real theRadius,
0158                                                            SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0159 
0160   //! Intersection test between defined volume and given sphere
0161   Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
0162                                                            const Standard_Real theRadius,
0163                                                            Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
0164 
0165   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
0166   //! and theTopRad, height theHeight and transformation to apply theTrsf.
0167   Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
0168                                                              const Standard_Real theTopRad,
0169                                                              const Standard_Real theHeight,
0170                                                              const gp_Trsf& theTrsf,
0171                                                              const Standard_Boolean theIsHollow,
0172                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0173 
0174   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
0175   //! and theTopRad, height theHeight and transformation to apply theTrsf.
0176   Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
0177                                                              const Standard_Real theTopRad,
0178                                                              const Standard_Real theHeight,
0179                                                              const gp_Trsf& theTrsf,
0180                                                              const Standard_Boolean theIsHollow,
0181                                                              Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
0182 
0183   //! Returns true if selecting volume is overlapped by circle with radius theRadius,
0184   //! boolean theIsFilled and transformation to apply theTrsf.
0185   //! The position and orientation of the circle are specified
0186   //! via theTrsf transformation for gp::XOY() with center in gp::Origin().
0187   Standard_EXPORT virtual Standard_Boolean OverlapsCircle (const Standard_Real theBottomRad,
0188                                                            const gp_Trsf& theTrsf,
0189                                                            const Standard_Boolean theIsFilled,
0190                                                            SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0191 
0192   //! Returns true if selecting volume is overlapped by circle with radius theRadius,
0193   //! boolean theIsFilled and transformation to apply theTrsf.
0194   //! The position and orientation of the circle are specified
0195   //! via theTrsf transformation for gp::XOY() with center in gp::Origin().
0196   Standard_EXPORT virtual Standard_Boolean OverlapsCircle (const Standard_Real theBottomRad,
0197                                                            const gp_Trsf& theTrsf,
0198                                                            const Standard_Boolean theIsFilled,
0199                                                            Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
0200 
0201   //! Measures distance between 3d projection of user-picked
0202   //! screen point and given point theCOG
0203   Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) const Standard_OVERRIDE;
0204 
0205   //! Calculates the point on a view ray that was detected during the run of selection algo by given depth.
0206   //! Throws exception if active selection type is not Point.
0207   Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
0208 
0209   //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the algorithm will
0210   //! mark both included and overlapped entities as matched
0211   Standard_EXPORT virtual void AllowOverlapDetection (const Standard_Boolean theIsToAllow);
0212 
0213   Standard_EXPORT virtual Standard_Boolean IsOverlapAllowed() const Standard_OVERRIDE;
0214 
0215   //! Return view clipping planes.
0216   const Handle(Graphic3d_SequenceOfHClipPlane)& ViewClipping() const { return myViewClipPlanes; }
0217 
0218   //! Return object clipping planes.
0219   const Handle(Graphic3d_SequenceOfHClipPlane)& ObjectClipping() const { return myObjectClipPlanes; }
0220 
0221   //! Valid for point selection only!
0222   //! Computes depth range for clipping planes.
0223   //! @param theViewPlanes  [in] global view planes
0224   //! @param theObjPlanes   [in] object planes
0225   //! @param theWorldSelMgr [in] selection volume in world space for computing clipping plane ranges
0226   Standard_EXPORT void SetViewClipping (const Handle(Graphic3d_SequenceOfHClipPlane)& theViewPlanes,
0227                                         const Handle(Graphic3d_SequenceOfHClipPlane)& theObjPlanes,
0228                                         const SelectMgr_SelectingVolumeManager* theWorldSelMgr);
0229 
0230   //! Copy clipping planes from another volume manager.
0231   Standard_EXPORT void SetViewClipping (const SelectMgr_SelectingVolumeManager& theOther);
0232 
0233   //! Return clipping range.
0234   const SelectMgr_ViewClipRange& ViewClipRanges() const { return myViewClipRange; }
0235 
0236   //! Set clipping range.
0237   void SetViewClipRanges (const SelectMgr_ViewClipRange& theRange) { myViewClipRange = theRange; }
0238 
0239   //! A set of helper functions that return rectangular selecting frustum data
0240   Standard_EXPORT const gp_Pnt* GetVertices() const;
0241 
0242   //! Valid only for point and rectangular selection.
0243   //! Returns projection of 2d mouse picked point or projection
0244   //! of center of 2d rectangle (for point and rectangular selection
0245   //! correspondingly) onto near view frustum plane
0246   Standard_EXPORT virtual gp_Pnt GetNearPickedPnt() const Standard_OVERRIDE;
0247 
0248   //! Valid only for point and rectangular selection.
0249   //! Returns projection of 2d mouse picked point or projection
0250   //! of center of 2d rectangle (for point and rectangular selection
0251   //! correspondingly) onto far view frustum plane
0252   Standard_EXPORT virtual gp_Pnt GetFarPickedPnt() const Standard_OVERRIDE;
0253 
0254   //! Valid only for point and rectangular selection.
0255   //! Returns view ray direction
0256   Standard_EXPORT virtual gp_Dir GetViewRayDirection() const Standard_OVERRIDE;
0257 
0258   //! Checks if it is possible to scale current active selecting volume
0259   Standard_EXPORT virtual Standard_Boolean IsScalableActiveVolume() const Standard_OVERRIDE;
0260 
0261   //! Returns mouse coordinates for Point selection mode.
0262   //! @return infinite point in case of unsupport of mouse position for this active selection volume.
0263   Standard_EXPORT virtual gp_Pnt2d GetMousePosition() const Standard_OVERRIDE;
0264 
0265   //! Stores plane equation coefficients (in the following form:
0266   //! Ax + By + Cz + D = 0) to the given vector
0267   Standard_EXPORT virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE;
0268 
0269   //! Dumps the content of me into the stream
0270   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0271 
0272 public:
0273 
0274   Standard_DEPRECATED("Deprecated method - InitPointSelectingVolume() and Build() methods should be used instead")
0275   Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& thePoint);
0276 
0277   Standard_DEPRECATED("Deprecated method - InitBoxSelectingVolume() and Build() should be used instead")
0278   Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& theMinPt,
0279                                              const gp_Pnt2d& theMaxPt);
0280 
0281   Standard_DEPRECATED("Deprecated method - InitPolylineSelectingVolume() and Build() should be used instead")
0282   Standard_EXPORT void BuildSelectingVolume (const TColgp_Array1OfPnt2d& thePoints);
0283 
0284 private:
0285   Handle(SelectMgr_BaseIntersector)      myActiveSelectingVolume;
0286   Handle(Graphic3d_SequenceOfHClipPlane) myViewClipPlanes;                  //!< view clipping planes
0287   Handle(Graphic3d_SequenceOfHClipPlane) myObjectClipPlanes;                //!< object clipping planes
0288   SelectMgr_ViewClipRange                myViewClipRange;
0289   Standard_Boolean                       myToAllowOverlap;                  //!< Defines if partially overlapped entities will me detected or not
0290 };
0291 
0292 #endif