1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0023200: Visualization - prevent multiple triangulating of a shape that already has been triangulated

Add new flag IsAutoTriangulated to Prs3d_Drawer. It is True by default.
If this flag is True automatic re-triangulation with deflection-check logic will be applied.
Else this feature will be disable and triangulation is expected to be computed by application itself.

Change the syntax of vdefalts command.
Add new parameter -autoTriang for check of AutoTriangulated functionality.

Adjust camera position in test case bugs/xde/bug23969
This commit is contained in:
osa
2015-03-05 14:48:42 +03:00
committed by bugmaster
parent 5149c3f34b
commit 4c5133866b
19 changed files with 280 additions and 76 deletions

View File

@@ -308,16 +308,19 @@ void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
if (theMode == AIS_Shaded)
{
// compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
|| (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
if (myDrawer->IsAutoTriangulation())
{
BRepTools::Clean (myshape);
// compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
|| (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
{
BRepTools::Clean (myshape);
}
StdPrs_ShadedShape::Tessellate (myshape, myDrawer);
}
StdPrs_ShadedShape::Tessellate (myshape, myDrawer);
}
TopoDS_Compound anOpened, aClosed;

View File

@@ -225,7 +225,8 @@ void AIS_ConnectedInteractive::Compute (const Handle(Prs3d_Projector)& theProjec
// process HLRAngle and HLRDeviationCoefficient()
Standard_Real aPrevAngle = myDrawer->HLRAngle();
Standard_Real aNewAngle = aDefaultDrawer->HLRAngle();
if (Abs (aNewAngle - aPrevAngle) > Precision::Angular())
if (myDrawer->IsAutoTriangulation() &&
Abs (aNewAngle - aPrevAngle) > Precision::Angular())
{
BRepTools::Clean (theShape);
}

View File

@@ -165,13 +165,16 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
}
case 1:
{
Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
|| (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
if (myDrawer->IsAutoTriangulation())
{
BRepTools::Clean (myshape);
Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (anAngleNew, anAnglePrev);
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew, aCoeffPrev);
if ((isOwnDeviationAngle && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
|| (isOwnDeviationCoefficient && Abs (aCoeffNew - aCoeffPrev) > Precision::Confusion()))
{
BRepTools::Clean (myshape);
}
}
//shading only on face...
@@ -259,20 +262,18 @@ void AIS_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,
Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
// coefficients for calculation
Standard_Real prevangle, newangle ,prevcoeff,newcoeff ;
Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle(newangle,prevangle);
Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient(newcoeff,prevcoeff);
if (((Abs (newangle - prevangle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
((Abs (newcoeff - prevcoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient)) {
#ifdef OCCT_DEBUG
cout << "AIS_Shape : compute"<<endl;
cout << "newangle : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
#endif
if (myDrawer->IsAutoTriangulation())
{
// coefficients for calculation
Standard_Real aPrevAngle, aNewAngle, aPrevCoeff, aNewCoeff;
Standard_Boolean isOwnHLRDeviationAngle = OwnHLRDeviationAngle (aNewAngle, aPrevAngle);
Standard_Boolean isOwnHLRDeviationCoefficient = OwnHLRDeviationCoefficient (aNewCoeff, aPrevCoeff);
if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnHLRDeviationAngle) ||
((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnHLRDeviationCoefficient))
{
BRepTools::Clean(SH);
}
}
{
try {
@@ -381,7 +382,6 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
// POP protection against crash in low layers
Standard_Real aDeflection = Prs3d::GetDeflection(shape, myDrawer);
Standard_Boolean autoTriangulation = Standard_True;
try {
OCC_CATCH_SIGNALS
StdSelect_BRepSelectionTool::Load(aSelection,
@@ -390,7 +390,7 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
TypOfSel,
aDeflection,
myDrawer->HLRAngle(),
autoTriangulation);
myDrawer->IsAutoTriangulation());
} catch ( Standard_Failure ) {
// cout << "a Shape should be incorrect : A Selection on the Bnd is activated "<<endl;
if ( aMode == 0 ) {

View File

@@ -429,16 +429,20 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
case AIS_Shaded:
case 3: // texture mapping on triangulation
{
Standard_Real prevangle;
Standard_Real newangle;
Standard_Real prevcoeff;
Standard_Real newcoeff;
if (myDrawer->IsAutoTriangulation())
{
Standard_Real aPrevAngle;
Standard_Real aNewAngle;
Standard_Real aPrevCoeff;
Standard_Real aNewCoeff;
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle(newangle,prevangle);
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(newcoeff,prevcoeff);
if (((Abs (newangle - prevangle) > Precision::Angular()) && isOwnDeviationAngle) ||
((Abs (newcoeff - prevcoeff) > Precision::Confusion()) && isOwnDeviationCoefficient)) {
BRepTools::Clean (myshape);
Standard_Boolean isOwnDeviationAngle = OwnDeviationAngle (aNewAngle, aPrevAngle);
Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient (aNewCoeff,aPrevCoeff);
if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnDeviationAngle) ||
((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnDeviationCoefficient))
{
BRepTools::Clean (myshape);
}
}
if (myshape.ShapeType() > TopAbs_FACE)

View File

@@ -50,6 +50,8 @@ Prs3d_Drawer::Prs3d_Drawer()
myHasOwnHLRDeviationAngle (Standard_False),
myIsoOnPlane (Standard_False),
myHasOwnIsoOnPlane (Standard_False),
myIsAutoTriangulated (Standard_True),
myHasOwnIsAutoTriangulated (Standard_False),
myHasOwnUIsoAspect (Standard_False),
myHasOwnVIsoAspect (Standard_False),
@@ -229,6 +231,17 @@ void Prs3d_Drawer::SetHLRAngle (const Standard_Real theAngle)
myHasOwnHLRDeviationAngle = Standard_True;
}
// =======================================================================
// function : SetAutoTriangulation
// purpose :
// =======================================================================
void Prs3d_Drawer::SetAutoTriangulation (const Standard_Boolean theIsEnabled)
{
myHasOwnIsAutoTriangulated = Standard_True;
myIsAutoTriangulated = theIsEnabled;
}
// =======================================================================
// function : FreeBoundaryAspect
// purpose :
@@ -1027,6 +1040,7 @@ void Prs3d_Drawer::ClearLocalAttributes()
myHasOwnDeviationAngle = Standard_False;
myHasOwnHLRDeviationAngle = Standard_False;
myHasOwnIsoOnPlane = Standard_False;
myHasOwnIsAutoTriangulated = Standard_False;
myHasOwnWireDraw = Standard_False;
myHasOwnShadingAspectGlobal = Standard_False;
myHasOwnLineArrowDraw = Standard_False;

View File

@@ -309,6 +309,23 @@ public:
: 0.0;
}
//! Sets IsAutoTriangulated on or off by setting the parameter theIsEnabled to true or false.
//! If this flag is True automatic re-triangulation with deflection-check logic will be applied.
//! Else this feature will be disable and triangulation is expected to be computed by application itself
//! and no shading presentation at all if unavailable.
Standard_EXPORT void SetAutoTriangulation (const Standard_Boolean theIsEnabled);
//! Returns True if automatic triangulation is enabled.
Standard_Boolean IsAutoTriangulation() const
{
return HasOwnIsAutoTriangulation() || myLink.IsNull()
? myIsAutoTriangulated
: myLink->IsAutoTriangulation();
}
//! Returns true if the drawer has IsoOnPlane setting active.
Standard_Boolean HasOwnIsAutoTriangulation() const { return myHasOwnIsAutoTriangulated; }
//! Defines the attributes which are used when drawing an
//! U isoparametric curve of a face. Defines the number
//! of U isoparametric curves to be drawn for a single face.
@@ -840,6 +857,8 @@ protected:
Standard_Real myPreviousHLRDeviationAngle;
Standard_Boolean myIsoOnPlane;
Standard_Boolean myHasOwnIsoOnPlane;
Standard_Boolean myIsAutoTriangulated;
Standard_Boolean myHasOwnIsAutoTriangulated;
Handle(Prs3d_IsoAspect) myUIsoAspect;
Standard_Boolean myHasOwnUIsoAspect;

View File

@@ -64,9 +64,12 @@ void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation,
TColgp_SequenceOfPnt HiddenPnts;
TColgp_SequenceOfPnt SeenPnts;
const Standard_Boolean rel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
Standard_Real def = rel? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation();
BRepMesh_IncrementalMesh mesh(aShape, def, rel, aDrawer->HLRAngle());
if (aDrawer->IsAutoTriangulation())
{
const Standard_Boolean aRel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
Standard_Real aDef = aRel ? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation();
BRepMesh_IncrementalMesh mesh(aShape, aDef, aRel, aDrawer->HLRAngle());
}
Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape);

View File

@@ -33,6 +33,7 @@
#include <Precision.hxx>
#include <Prs3d.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_ShadingAspect.hxx>
@@ -40,6 +41,7 @@
#include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Triangulation.hxx>
#include <StdPrs_ToolShadedShape.hxx>
#include <StdPrs_WFDeflectionShape.hxx>
#include <StdPrs_WFShape.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
@@ -105,6 +107,42 @@ namespace
}
}
//! Computes special wireframe presentation for faces without triangulation.
void wireframeNoTriangFacesFromShape (const Handle(Prs3d_Presentation)& thePrs,
const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawer)
{
TopoDS_Compound aCompoundWF;
BRep_Builder aBuilder;
aBuilder.MakeCompound (aCompoundWF);
TopLoc_Location aLoc;
Standard_Boolean hasElement = Standard_False;
for (TopExp_Explorer aShapeIter(theShape, TopAbs_FACE); aShapeIter.More(); aShapeIter.Next())
{
const TopoDS_Face& aFace = TopoDS::Face (aShapeIter.Current());
const Handle(Poly_Triangulation) aTriang = BRep_Tool::Triangulation (aFace, aLoc);
if (aTriang.IsNull())
{
hasElement = Standard_True;
aBuilder.Add (aCompoundWF, aFace);
}
}
if (hasElement)
{
Standard_Integer aPrevUIsoNb = theDrawer->UIsoAspect()->Number();
Standard_Integer aPrevVIsoNb = theDrawer->VIsoAspect()->Number();
theDrawer->UIsoAspect()->SetNumber (5);
theDrawer->VIsoAspect()->SetNumber (5);
StdPrs_WFDeflectionShape::Add (thePrs, aCompoundWF, theDrawer);
theDrawer->UIsoAspect()->SetNumber (aPrevUIsoNb);
theDrawer->VIsoAspect()->SetNumber (aPrevVIsoNb);
}
}
//! Gets triangulation of every face of shape and fills output array of triangles
static Handle(Graphic3d_ArrayOfTriangles) fillTriangles (const TopoDS_Shape& theShape,
const Standard_Boolean theHasTexels,
@@ -504,8 +542,15 @@ void StdPrs_ShadedShape::Add (const Handle (Prs3d_Presentation)& thePrs,
// add wireframe presentation for isolated edges and vertices
wireframeFromShape (thePrs, theShape, theDrawer);
// Triangulation completeness is important for "open-closed" analysis - perform tessellation beforehand
Tessellate (theShape, theDrawer);
// Use automatic re-triangulation with deflection-check logic only if this feature is enable
if (theDrawer->IsAutoTriangulation())
{
// Triangulation completeness is important for "open-closed" analysis - perform tessellation beforehand
Tessellate (theShape, theDrawer);
}
// add special wireframe presentation for faces without triangulation
wireframeNoTriangFacesFromShape (thePrs, theShape, theDrawer);
// The shape types listed below need advanced analysis as potentially containing
// both closed and open parts. Solids are also included, because they might

View File

@@ -6620,44 +6620,74 @@ static int VDefaults (Draw_Interpretor& theDi,
<< "AbsoluteDeflection: " << aDefParams->MaximalChordialDeviation() << "\n";
}
theDi << "AngularDeflection: " << (180.0 * aDefParams->HLRAngle() / M_PI) << "\n";
theDi << "AutoTriangulation: " << (aDefParams->IsAutoTriangulation() ? "on" : "off") << "\n";
return 0;
}
for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
{
TCollection_AsciiString anArg (theArgVec[anArgIter]);
TCollection_AsciiString aKey, aValue;
if (!ViewerTest::SplitParameter (anArg, aKey, aValue)
|| aValue.IsEmpty())
{
std::cerr << "Error, wrong syntax at: '" << anArg.ToCString() << "'!\n";
return 1;
}
aKey.UpperCase();
if (aKey == "ABSDEFL"
|| aKey == "ABSOLUTEDEFLECTION"
|| aKey == "DEFL"
|| aKey == "DEFLECTION")
anArg.UpperCase();
if (anArg == "-ABSDEFL"
|| anArg == "-ABSOLUTEDEFLECTION"
|| anArg == "-DEFL"
|| anArg == "-DEFLECTION")
{
if (++anArgIter >= theArgsNb)
{
std::cout << "Error: wrong syntax at " << anArg << "\n";
return 1;
}
aDefParams->SetTypeOfDeflection (Aspect_TOD_ABSOLUTE);
aDefParams->SetMaximalChordialDeviation (aValue.RealValue());
aDefParams->SetMaximalChordialDeviation (Draw::Atof (theArgVec[anArgIter]));
}
else if (aKey == "RELDEFL"
|| aKey == "RELATIVEDEFLECTION"
|| aKey == "DEVCOEFF"
|| aKey == "DEVIATIONCOEFF"
|| aKey == "DEVIATIONCOEFFICIENT")
else if (anArg == "-RELDEFL"
|| anArg == "-RELATIVEDEFLECTION"
|| anArg == "-DEVCOEFF"
|| anArg == "-DEVIATIONCOEFF"
|| anArg == "-DEVIATIONCOEFFICIENT")
{
if (++anArgIter >= theArgsNb)
{
std::cout << "Error: wrong syntax at " << anArg << "\n";
return 1;
}
aDefParams->SetTypeOfDeflection (Aspect_TOD_RELATIVE);
aDefParams->SetDeviationCoefficient (aValue.RealValue());
aDefParams->SetDeviationCoefficient (Draw::Atof (theArgVec[anArgIter]));
}
else if (aKey == "ANGDEFL"
|| aKey == "ANGULARDEFL"
|| aKey == "ANGULARDEFLECTION")
else if (anArg == "-ANGDEFL"
|| anArg == "-ANGULARDEFL"
|| anArg == "-ANGULARDEFLECTION")
{
if (++anArgIter >= theArgsNb)
{
std::cout << "Error: wrong syntax at " << anArg << "\n";
return 1;
}
// currently HLRDeviationAngle is used instead of DeviationAngle in most places
aDefParams->SetHLRAngle (M_PI * aValue.RealValue() / 180.0);
aDefParams->SetHLRAngle (M_PI * Draw::Atof (theArgVec[anArgIter]) / 180.0);
}
if (anArg == "-AUTOTR"
|| anArg == "-AUTOTRIANG"
|| anArg == "-AUTOTRIANGULATION")
{
if (++anArgIter >= theArgsNb)
{
std::cout << "Error: wrong syntax at " << anArg << "\n";
return 1;
}
TCollection_AsciiString aValue (theArgVec[anArgIter]);
aValue.LowerCase();
if (aValue == "on"
|| aValue == "1")
{
aDefParams->SetAutoTriangulation (Standard_True);
}
else if (aValue == "off"
|| aValue == "0")
{
aDefParams->SetAutoTriangulation (Standard_False);
}
}
else
{
@@ -7969,8 +7999,11 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
" this command sets texture details mode for the specified view.\n"
, __FILE__, VSetTextureMode, group);
theCommands.Add("vdefaults",
"vdefaults [absDefl=value] [devCoeff=value] [angDefl=value]",
__FILE__, VDefaults, group);
"vdefaults [-absDefl value]"
"\n\t\t: [-devCoeff value]"
"\n\t\t: [-angDefl value]"
"\n\t\t: [-autoTriang {off/on | 0/1}]"
, __FILE__, VDefaults, group);
theCommands.Add("vlight",
"tool to manage light sources, without arguments shows list of lights."
"\n Main commands: "