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

0032281: Visualization - add Select3D_SensitiveCylinder

- implemented Select3D_SensitiveCylinder class performing an analytical intersection with an untriangulated cone/cylinder
- added tests
This commit is contained in:
mkrylova
2021-07-05 15:06:50 +03:00
committed by bugmaster
parent 8a77384b0c
commit 9dd8af261f
32 changed files with 1568 additions and 4 deletions

View File

@@ -13,6 +13,8 @@ Select3D_SensitiveCircle.cxx
Select3D_SensitiveCircle.hxx
Select3D_SensitiveCurve.cxx
Select3D_SensitiveCurve.hxx
Select3D_SensitiveCylinder.cxx
Select3D_SensitiveCylinder.hxx
Select3D_SensitiveEntity.cxx
Select3D_SensitiveEntity.hxx
Select3D_SensitiveFace.cxx

View File

@@ -0,0 +1,104 @@
// Created on: 2021-04-19
// Created by: Maria KRYLOVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Select3D_SensitiveCylinder.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveCylinder, Select3D_SensitiveEntity)
//==================================================
// Function: Select3D_SensitiveSphere
// Purpose :
//==================================================
Select3D_SensitiveCylinder::Select3D_SensitiveCylinder (const Handle(SelectMgr_EntityOwner)& theOwnerId,
const Standard_Real theBottomRad,
const Standard_Real theTopRad,
const Standard_Real theHeight,
const gp_Trsf& theTrsf)
: Select3D_SensitiveEntity (theOwnerId),
myTrsf (theTrsf),
myBottomRadius (theBottomRad),
myTopRadius (theTopRad),
myHeight (theHeight)
{
}
//==================================================
// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveCylinder::Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult)
{
if (theMgr.GetActiveSelectionType() != SelectMgr_SelectionType_Point)
{
if (!theMgr.IsOverlapAllowed())
{
bool isInside = true;
return theMgr.OverlapsCylinder (myBottomRadius, myTopRadius, myHeight, myTrsf, &isInside) && isInside;
}
else
{
return theMgr.OverlapsCylinder (myBottomRadius, myTopRadius, myHeight, myTrsf, NULL);
}
}
if (!theMgr.OverlapsCylinder (myBottomRadius, myTopRadius, myHeight, myTrsf, thePickResult))
{
return false;
}
thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter (CenterOfGeometry()));
return true;
}
//==================================================
// Function: GetConnected
// Purpose :
//==================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCylinder::GetConnected()
{
Handle(Select3D_SensitiveEntity) aNewEntity = new Select3D_SensitiveCylinder (myOwnerId, myBottomRadius,
myTopRadius, myHeight,
myTrsf);
return aNewEntity;
}
//==================================================
// Function: BoundingBox
// Purpose :
//==================================================
Select3D_BndBox3d Select3D_SensitiveCylinder::BoundingBox()
{
Standard_Real aMaxRad = Max (myBottomRadius, myTopRadius);
gp_Pnt aCenterBottom (0, 0, 0);
gp_Pnt aCenterTop (0, 0, myHeight);
aCenterBottom.Transform (myTrsf);
aCenterTop.Transform (myTrsf);
const SelectMgr_Vec3 aMinPnt (Min (aCenterBottom.X(), aCenterTop.X()) - aMaxRad,
Min (aCenterBottom.Y(), aCenterTop.Y()) - aMaxRad,
Min (aCenterBottom.Z(), aCenterTop.Z()) - aMaxRad);
const SelectMgr_Vec3 aMaxPnt (Max (aCenterBottom.X(), aCenterTop.X()) + aMaxRad,
Max (aCenterBottom.Y(), aCenterTop.Y()) + aMaxRad,
Max (aCenterBottom.Z(), aCenterTop.Z()) + aMaxRad);
return Select3D_BndBox3d (aMinPnt, aMaxPnt);
}
//==================================================
// Function: CenterOfGeometry
// Purpose :
//==================================================
gp_Pnt Select3D_SensitiveCylinder::CenterOfGeometry() const
{
return gp_Pnt (0, 0, myHeight / 2).Transformed (myTrsf);
}

View File

@@ -0,0 +1,64 @@
// Created on: 2021-04-19
// Created by: Maria KRYLOVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_SensitiveCylinder_HeaderFile
#define _Select3D_SensitiveCylinder_HeaderFile
#include <Select3D_SensitiveEntity.hxx>
//! A framework to define selection by a sensitive cylinder or cone.
class Select3D_SensitiveCylinder : public Select3D_SensitiveEntity
{
DEFINE_STANDARD_RTTIEXT (Select3D_SensitiveCylinder, Select3D_SensitiveEntity)
public:
//! Constructs a sensitive cylinder object defined by the owner theOwnerId,
//! @param[in] theBottomRad cylinder bottom radius
//! @param[in] theTopRad cylinder top radius
//! @param[in] theHeight cylinder height
Standard_EXPORT Select3D_SensitiveCylinder (const Handle(SelectMgr_EntityOwner)& theOwnerId,
const Standard_Real theBottomRad,
const Standard_Real theTopRad,
const Standard_Real theHeight,
const gp_Trsf& theTrsf);
//! Checks whether the cylinder overlaps current selecting volume
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
//! Returns the copy of this
Standard_EXPORT virtual Handle (Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
//! Returns bounding box of the cylinder.
//! If location transformation is set, it will be applied
Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
//! Always returns Standard_False
virtual Standard_Boolean ToBuildBVH() const Standard_OVERRIDE { return Standard_False; }
//! Returns the amount of points
virtual Standard_Integer NbSubElements() const Standard_OVERRIDE { return 1; }
//! Returns center of the cylinder with transformation applied
Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
protected:
gp_Trsf myTrsf; //!< cylinder transformation to apply
Standard_Real myBottomRadius; //!< cylinder bottom radius
Standard_Real myTopRadius; //!< cylinder top radius
Standard_Real myHeight; //!< cylinder height
};
#endif // _Select3D_SensitiveSphere_HeaderFile