1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-05 11:24:17 +03:00

0030146: Visualization - exception during attempt to display Edge without geometry

StdPrs_ToolRFace no skips curves with NULL curves.
Code has been cleaned up from duplicated checks, redundant casts
and dummy Adaptor2d_Curve2dPtr typedef.

StdSelect_BRepSelectionTool::GetSensitiveForFace() now catches
Standard_NullObject exception to skip invalid Edges.
This commit is contained in:
kgv 2018-09-20 11:40:19 +03:00 committed by bugmaster
parent c39bb31bac
commit 4ba5491a50
17 changed files with 188 additions and 208 deletions

View File

@ -1,23 +0,0 @@
// Created on: 1992-10-08
// Created by: Isabelle GRIGNON
// Copyright (c) 1992-1999 Matra Datavision
// Copyright (c) 1999-2014 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 _Adaptor2d_Curve2dPtr_HeaderFile
#define _Adaptor2d_Curve2dPtr_HeaderFile
class Adaptor2d_Curve2d;
typedef Adaptor2d_Curve2d* Adaptor2d_Curve2dPtr;
#endif // _Adaptor2d_Curve2dPtr_HeaderFile

View File

@ -1,6 +1,5 @@
Adaptor2d_Curve2d.cxx
Adaptor2d_Curve2d.hxx
Adaptor2d_Curve2dPtr.hxx
Adaptor2d_GenHCurve2d.gxx
Adaptor2d_GenHCurve2d.lxx
Adaptor2d_HCurve2d.cxx

View File

@ -74,6 +74,18 @@ BRepAdaptor_Curve::BRepAdaptor_Curve(const TopoDS_Edge& E,
Initialize(E,F);
}
//=======================================================================
//function : Reset
//purpose :
//=======================================================================
void BRepAdaptor_Curve::Reset()
{
myCurve.Reset();
myConSurf.Nullify();
myEdge.Nullify();
myTrsf = gp_Trsf();
}
//=======================================================================
//function : Initialize
//purpose :

View File

@ -87,6 +87,9 @@ public:
//! the face.
Standard_EXPORT BRepAdaptor_Curve(const TopoDS_Edge& E, const TopoDS_Face& F);
//! Reset currently loaded curve (undone Load()).
Standard_EXPORT void Reset();
//! Sets the Curve <me> to acces to the geometry of
//! edge <E>.
Standard_EXPORT void Initialize (const TopoDS_Edge& E);

View File

@ -168,6 +168,19 @@ Geom2dAdaptor_Curve::Geom2dAdaptor_Curve(const Handle(Geom2d_Curve)& theCrv,
Load(theCrv, theUFirst, theULast);
}
//=======================================================================
//function : Reset
//purpose :
//=======================================================================
void Geom2dAdaptor_Curve::Reset()
{
myTypeCurve = GeomAbs_OtherCurve;
myCurve.Nullify();
myCurveCache.Nullify();
myNestedEvaluator.Nullify();
myBSplineCurve.Nullify();
myFirst = myLast = 0.0;
}
//=======================================================================
//function : Load

View File

@ -69,6 +69,9 @@ public:
//! ConstructionError is raised if Ufirst>Ulast
Standard_EXPORT Geom2dAdaptor_Curve(const Handle(Geom2d_Curve)& C, const Standard_Real UFirst, const Standard_Real ULast);
//! Reset currently loaded curve (undone Load()).
Standard_EXPORT void Reset();
void Load (const Handle(Geom2d_Curve)& C);
//! ConstructionError is raised if Ufirst>Ulast

View File

@ -124,6 +124,19 @@ GeomAbs_Shape GeomAdaptor_Curve::LocalContinuity(const Standard_Real U1,
}
}
//=======================================================================
//function : Reset
//purpose :
//=======================================================================
void GeomAdaptor_Curve::Reset()
{
myTypeCurve = GeomAbs_OtherCurve;
myCurve.Nullify();
myNestedEvaluator.Nullify();
myBSplineCurve.Nullify();
myCurveCache.Nullify();
myFirst = myLast = 0.0;
}
//=======================================================================
//function : Load

View File

@ -71,6 +71,9 @@ public:
//! ConstructionError is raised if Ufirst>Ulast
GeomAdaptor_Curve(const Handle(Geom_Curve)& C, const Standard_Real UFirst, const Standard_Real ULast);
//! Reset currently loaded curve (undone Load()).
Standard_EXPORT void Reset();
void Load (const Handle(Geom_Curve)& C);
//! ConstructionError is raised if Ufirst>Ulast

View File

@ -387,12 +387,7 @@ void StdPrs_Isolines::addOnSurface (const Handle(BRepAdaptor_HSurface)& theSurfa
for (anEdgeTool.Init(); anEdgeTool.More(); anEdgeTool.Next())
{
TopAbs_Orientation anOrientation = anEdgeTool.Orientation();
if (anOrientation != TopAbs_FORWARD && anOrientation != TopAbs_REVERSED)
{
continue;
}
Adaptor2d_Curve2dPtr anEdgeCurve = anEdgeTool.Value();
const Adaptor2d_Curve2d* anEdgeCurve = &anEdgeTool.Value();
if (anEdgeCurve->GetType() != GeomAbs_Line)
{
GCPnts_QuasiUniformDeflection aSampler (*anEdgeCurve, aSamplerDeflection);

View File

@ -12,12 +12,11 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdPrs_ToolRFace.hxx>
#include <Adaptor2d_Curve2d.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_HSurface.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <StdPrs_ToolRFace.hxx>
#include <TopoDS.hxx>
//=======================================================================
@ -25,6 +24,7 @@
//purpose :
//=======================================================================
StdPrs_ToolRFace::StdPrs_ToolRFace()
: myHasNullCurves (Standard_False)
{
}
@ -32,94 +32,39 @@ StdPrs_ToolRFace::StdPrs_ToolRFace()
//function : StdPrs_ToolRFace
//purpose :
//=======================================================================
StdPrs_ToolRFace::StdPrs_ToolRFace(const Handle(BRepAdaptor_HSurface)& aSurface) :
myFace(((BRepAdaptor_Surface*)&(aSurface->Surface()))->Face())
StdPrs_ToolRFace::StdPrs_ToolRFace (const Handle(BRepAdaptor_HSurface)& theSurface)
: myFace (theSurface->ChangeSurface().Face()),
myHasNullCurves (Standard_False)
{
myFace.Orientation(TopAbs_FORWARD);
}
//=======================================================================
//function : IsOriented
//function : next
//purpose :
//=======================================================================
Standard_Boolean StdPrs_ToolRFace::IsOriented () const {
return Standard_True;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void StdPrs_ToolRFace::Init()
void StdPrs_ToolRFace::next()
{
myExplorer.Init(myFace,TopAbs_EDGE);
if (myExplorer.More()) {
Standard_Real U1,U2;
const Handle(Geom2d_Curve)& C =
BRep_Tool::CurveOnSurface(TopoDS::Edge(myExplorer.Current()),
myFace,
U1,U2);
DummyCurve.Load(C,U1,U2);
}
}
//=======================================================================
//function : More
//purpose :
//=======================================================================
Standard_Boolean StdPrs_ToolRFace::More() const
{
return myExplorer.More();
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void StdPrs_ToolRFace::Next()
{
myExplorer.Next();
if (myExplorer.More()) {
Standard_Real aParamU1, aParamU2;
for (; myExplorer.More(); myExplorer.Next())
{
// skip INTERNAL and EXTERNAL edges
while (myExplorer.More() && (myExplorer.Current().Orientation() == TopAbs_INTERNAL
|| myExplorer.Current().Orientation() == TopAbs_EXTERNAL))
myExplorer.Next();
if (myExplorer.More()) {
Standard_Real U1,U2;
const Handle(Geom2d_Curve)& C =
BRep_Tool::CurveOnSurface(TopoDS::Edge(myExplorer.Current()),
myFace,
U1,U2);
if ( !C.IsNull() )
DummyCurve.Load(C,U1,U2);
if (myExplorer.Current().Orientation() != TopAbs_FORWARD
&& myExplorer.Current().Orientation() != TopAbs_REVERSED)
{
continue;
}
if (Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface (TopoDS::Edge (myExplorer.Current()), myFace, aParamU1, aParamU2))
{
myCurve.Load (aCurve, aParamU1, aParamU2);
return;
}
else
{
myHasNullCurves = Standard_True;
}
}
myCurve.Reset();
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
Adaptor2d_Curve2dPtr StdPrs_ToolRFace::Value() const
{
return (Adaptor2d_Curve2dPtr)&DummyCurve;
}
//=======================================================================
//function : Orientation
//purpose :
//=======================================================================
TopAbs_Orientation StdPrs_ToolRFace::Orientation () const {
return myExplorer.Current().Orientation();
}

View File

@ -24,60 +24,64 @@
#include <TopoDS_Face.hxx>
#include <TopExp_Explorer.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Standard_Boolean.hxx>
#include <Adaptor2d_Curve2dPtr.hxx>
#include <TopAbs_Orientation.hxx>
class BRepAdaptor_HSurface;
//! Iterator over 2D curves restricting a face (skipping internal/external edges).
//! In addition, the algorithm skips NULL curves - IsInvalidGeometry() can be checked if this should be handled within algorithm.
class StdPrs_ToolRFace
{
public:
DEFINE_STANDARD_ALLOC
//! Empty constructor.
Standard_EXPORT StdPrs_ToolRFace();
//! Constructor with initialization.
Standard_EXPORT StdPrs_ToolRFace(const Handle(BRepAdaptor_HSurface)& aSurface);
Standard_EXPORT Standard_Boolean IsOriented() const;
//! Return TRUE indicating that iterator looks only for oriented edges.
Standard_Boolean IsOriented() const { return Standard_True; }
Standard_EXPORT void Init();
//! Move iterator to the first element.
void Init()
{
myExplorer.Init (myFace, TopAbs_EDGE);
next();
}
Standard_EXPORT Standard_Boolean More() const;
Standard_EXPORT void Next();
Standard_EXPORT Adaptor2d_Curve2dPtr Value() const;
Standard_EXPORT TopAbs_Orientation Orientation() const;
protected:
//! Return TRUE if iterator points to the curve.
Standard_Boolean More() const { return myExplorer.More(); }
//! Go to the next curve in the face.
void Next()
{
myExplorer.Next();
next();
}
//! Return current curve.
const Adaptor2d_Curve2d& Value() const { return myCurve; }
//! Return current edge orientation.
TopAbs_Orientation Orientation() const { return myExplorer.Current().Orientation(); }
//! Return TRUE if NULL curves have been skipped.
Standard_Boolean IsInvalidGeometry() const { return myHasNullCurves; }
private:
//! Find nearest valid item for the iterator.
Standard_EXPORT void next();
private:
TopoDS_Face myFace;
TopExp_Explorer myExplorer;
Geom2dAdaptor_Curve DummyCurve;
Geom2dAdaptor_Curve myCurve;
Standard_Boolean myHasNullCurves;
};
#endif // _StdPrs_ToolRFace_HeaderFile

View File

@ -146,8 +146,7 @@ void StdPrs_WFDeflectionRestrictedFace::Add
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
TopAbs_Orientation Orient = ToolRst.Orientation();
if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
if (TheRCurve->GetType() != GeomAbs_Line) {
GCPnts_QuasiUniformDeflection UDP(*TheRCurve, ddefle);
if (UDP.IsDone()) {
@ -181,7 +180,6 @@ void StdPrs_WFDeflectionRestrictedFace::Add
}
}
}
}
#ifdef OCCT_DEBUG
else {
cout << "Cannot evaluate curve on surface"<<endl;
@ -385,7 +383,7 @@ Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
UMax = VMax = RealFirst();
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
u = TheRCurve->FirstParameter();
v = TheRCurve->LastParameter();
step = ( v - u) / nbPoints;
@ -438,8 +436,7 @@ Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
gp_Pnt dummypnt;
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
TopAbs_Orientation Orient = ToolRst.Orientation();
if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
GCPnts_QuasiUniformDeflection UDP(*TheRCurve, Deflection);
if (UDP.IsDone()) {
Standard_Integer NumberOfPoints = UDP.NbPoints();
@ -463,7 +460,6 @@ Standard_Boolean StdPrs_WFDeflectionRestrictedFace::Match
}
#endif
}
}
// draw the isos

View File

@ -55,8 +55,8 @@ void StdPrs_WFRestrictedFace::Add
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
BndLib_Add2dCurve::Add(*aRCurve, Precision::PConfusion(), aBndBox);
const Adaptor2d_Curve2d& aRCurve = aToolRst.Value();
BndLib_Add2dCurve::Add(aRCurve, Precision::PConfusion(), aBndBox);
}
if (!aBndBox.IsVoid())
aBndBox.Get(aUMin, aVMin, aUMax, aVMax);
@ -116,9 +116,7 @@ void StdPrs_WFRestrictedFace::Add
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
TopAbs_Orientation anOrientation = aToolRst.Orientation();
if (anOrientation == TopAbs_FORWARD || anOrientation == TopAbs_REVERSED)
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
anU1 = aRCurve->FirstParameter();
anU2 = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line)
@ -145,7 +143,6 @@ void StdPrs_WFRestrictedFace::Add
anIsoBuild.Trim(aPoint2,aPoint1);
}
}
}
// Draw the isos
Adaptor3d_IsoCurve anIsoCurve;
@ -243,7 +240,7 @@ Standard_Boolean StdPrs_WFRestrictedFace::Match
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
anU = aRCurve->FirstParameter();
aV = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line)
@ -319,9 +316,7 @@ Standard_Boolean StdPrs_WFRestrictedFace::Match
for (aToolRst.Init(); aToolRst.More(); aToolRst.Next())
{
TopAbs_Orientation Orient = aToolRst.Orientation();
if (Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED)
{
Adaptor2d_Curve2dPtr aRCurve = aToolRst.Value();
const Adaptor2d_Curve2d* aRCurve = &aToolRst.Value();
anU1 = aRCurve->FirstParameter();
anU2 = aRCurve->LastParameter();
if (aRCurve->GetType() != GeomAbs_Line) {
@ -346,7 +341,6 @@ Standard_Boolean StdPrs_WFRestrictedFace::Match
anIsoBuild.Trim(aPoint2,aPoint1);
}
}
}
// Draw the isos

View File

@ -621,7 +621,16 @@ Standard_Boolean StdSelect_BRepSelectionTool::GetSensitiveForFace (const TopoDS_
BRepAdaptor_Curve cu3d;
for (BRepTools_WireExplorer aWireExplorer (aWire); aWireExplorer.More(); aWireExplorer.Next())
{
try
{
OCC_CATCH_SIGNALS
cu3d.Initialize (aWireExplorer.Current());
}
catch (Standard_NullObject)
{
continue;
}
Standard_Real wf = 0.0, wl = 0.0;
BRep_Tool::Range (aWireExplorer.Current(), wf, wl);
if (Abs (wf - wl) <= Precision::Confusion())

View File

@ -144,8 +144,7 @@ void VrmlConverter_WFDeflectionRestrictedFace::Add
gp_Pnt dummypnt;
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
TopAbs_Orientation Orient = ToolRst.Orientation();
if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
if (TheRCurve->GetType() != GeomAbs_Line) {
GCPnts_QuasiUniformDeflection UDP(*TheRCurve, Deflection);
if (UDP.IsDone()) {
@ -179,7 +178,6 @@ void VrmlConverter_WFDeflectionRestrictedFace::Add
isobuild.Trim(P2,P1);
}
}
}
// draw the isos

View File

@ -52,8 +52,8 @@ void VrmlConverter_WFRestrictedFace::Add
Bnd_Box2d B;
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
BndLib_Add2dCurve::Add(*TheRCurve, Precision::PConfusion(), B);
const Adaptor2d_Curve2d& TheRCurve = ToolRst.Value();
BndLib_Add2dCurve::Add(TheRCurve, Precision::PConfusion(), B);
}
B.Get(UMin, VMin, UMax, VMax);
@ -97,8 +97,7 @@ void VrmlConverter_WFRestrictedFace::Add
for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
TopAbs_Orientation Orient = ToolRst.Orientation();
if ( Orient == TopAbs_FORWARD || Orient == TopAbs_REVERSED ) {
Adaptor2d_Curve2dPtr TheRCurve = ToolRst.Value();
const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
U1 = TheRCurve->FirstParameter();
U2 = TheRCurve->LastParameter();
if (TheRCurve->GetType() != GeomAbs_Line) {
@ -123,7 +122,6 @@ void VrmlConverter_WFRestrictedFace::Add
isobuild.Trim(P2,P1);
}
}
}
// draw the isos

18
tests/bugs/vis/bug30146 Normal file
View File

@ -0,0 +1,18 @@
puts "============="
puts "0030146: Visualization - e x c e p t i o n during attempt to display Edge without geometry"
puts "============="
pload MODELING VISUALIZATION
restore [locate_data_file CTO904_cts20176a.rle] a
incmesh a 0.1
tclean -geom a
vclear
vinit View1
vviewparams -scale 3.69 -proj 0.30 0.94 0.14 -up -0.46 0.013 0.88 -at 103.9 -59.94 -27.08
vdisplay -dispMode 0 a
vdump ${imagedir}/${casename}_wireframe.png
vdisplay -dispMode 1 a
vdump ${imagedir}/${casename}_shaded.png