From 68556f75f93d8a9f8e9b84e472a8bfc8ec285994 Mon Sep 17 00:00:00 2001 From: kgv Date: Tue, 4 Aug 2020 10:38:58 +0300 Subject: [PATCH] 0031698: Visualization, Graphic3d_Aspects - provide stipple line factor parameter [OCCT 7.2.0 backport] Added Graphic3d_AspectLine3d::LineStippleFactor() property. Added -stippleFactor argument to vaspects command. --- src/Graphic3d/Graphic3d_AspectLine3d.cxx | 2 ++ src/Graphic3d/Graphic3d_AspectLine3d.hxx | 15 ++++++++++ src/OpenGl/OpenGl_PrimitiveArray.cxx | 4 +-- src/ViewerTest/ViewerTest.cxx | 35 +++++++++++++++++++++++- tests/v3d/glsl/stipple_line2 | 4 +-- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Graphic3d/Graphic3d_AspectLine3d.cxx b/src/Graphic3d/Graphic3d_AspectLine3d.cxx index bb760f3017..921e803f8e 100644 --- a/src/Graphic3d/Graphic3d_AspectLine3d.cxx +++ b/src/Graphic3d/Graphic3d_AspectLine3d.cxx @@ -25,6 +25,7 @@ Graphic3d_AspectLine3d::Graphic3d_AspectLine3d() : myColor (Quantity_NOC_YELLOW), myType (Aspect_TOL_SOLID), myWidth (1.0f), + myLineFactor (1), myLinePattern (0xFFFF) { // @@ -40,6 +41,7 @@ Graphic3d_AspectLine3d::Graphic3d_AspectLine3d (const Quantity_Color& theColor : myColor (theColor), myType (theType), myWidth ((float )theWidth), + myLineFactor (1), myLinePattern (DefaultLinePatternForType (theType)) { if (myWidth <= 0.0f) diff --git a/src/Graphic3d/Graphic3d_AspectLine3d.hxx b/src/Graphic3d/Graphic3d_AspectLine3d.hxx index abf0cd7f22..6a5cd740b5 100644 --- a/src/Graphic3d/Graphic3d_AspectLine3d.hxx +++ b/src/Graphic3d/Graphic3d_AspectLine3d.hxx @@ -107,6 +107,19 @@ public: return Aspect_TOL_USERDEFINED; } + //! Return a multiplier for each bit in the line stipple pattern within [1, 256] range; 1 by default. + uint16_t LineStippleFactor() const { return myLineFactor; } + + //! Set a multiplier for each bit in the line stipple pattern. + void SetLineStippleFactor (uint16_t theFactor) + { + if (theFactor == 0 || theFactor > 256) + { + throw Standard_OutOfRange ("Graphic3d_Aspects::SetLineStippleFactor(), bad factor value"); + } + myLineFactor = theFactor; + } + //! Return line width. Standard_ShortReal Width() const { return myWidth; } @@ -141,6 +154,7 @@ public: return myProgram == theOther.myProgram && myType == theOther.myType + && myLineFactor == theOther.myLineFactor && myLinePattern == theOther.myLinePattern && myColor == theOther.myColor && myWidth == theOther.myWidth; @@ -165,6 +179,7 @@ protected: Quantity_ColorRGBA myColor; Aspect_TypeOfLine myType; Standard_ShortReal myWidth; + uint16_t myLineFactor; uint16_t myLinePattern; }; diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 5de66282ce..d967534b5f 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -475,7 +475,7 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo myVboAttribs->BindPositionAttribute (aGlContext); aGlContext->SetColor4fv (theEdgeColour); - aGlContext->SetLineStipple(anAspect->Aspect()->LinePattern()); + aGlContext->SetLineStipple((float )anAspect->Aspect()->LineStippleFactor(), anAspect->Aspect()->LinePattern()); aGlContext->SetLineWidth (anAspect->Aspect()->Width()); if (!myVboIndices.IsNull()) @@ -835,7 +835,7 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace if (myDrawMode == GL_LINES || myDrawMode == GL_LINE_STRIP) { - aCtx->SetLineStipple(anAspectLine->Aspect()->LinePattern()); + aCtx->SetLineStipple((float )anAspectLine->Aspect()->LineStippleFactor(), anAspectLine->Aspect()->LinePattern()); aCtx->SetLineWidth (anAspectLine->Aspect()->Width()); } diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 26eb4d4741..3ca6389f2f 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -1664,6 +1664,7 @@ struct ViewerTest_AspectsChangeSet Standard_Integer ToSetTypeOfLine; uint16_t StippleLinePattern; + uint16_t StippleLineFactor; Standard_Integer ToSetTypeOfMarker; Aspect_TypeOfMarker TypeOfMarker; @@ -1710,6 +1711,7 @@ struct ViewerTest_AspectsChangeSet LineWidth (1.0), ToSetTypeOfLine (0), StippleLinePattern(0xFFFF), + StippleLineFactor (1), ToSetTypeOfMarker (0), TypeOfMarker (Aspect_TOM_PLUS), ToSetMarkerSize (0), @@ -2129,6 +2131,25 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, { aChangeSet->ToSetTypeOfLine = -1; } + else if (anArg == "-setstipplelinefactor" + || anArg == "-setstipplefactor" + || anArg == "-setlinefactor" + || anArg == "-stipplelinefactor" + || anArg == "-stipplefactor" + || anArg == "-linefactor") + { + if (aChangeSet->ToSetTypeOfLine == -1) + { + std::cout << "Error: -setStippleLineFactor requires -setLineType\n"; + return 1; + } + if (++anArgIter >= theArgNb) + { + std::cout << "Error: wrong syntax at " << anArg << "\n"; + return 1; + } + aChangeSet->StippleLineFactor = (uint16_t )Draw::Atoi (theArgVec[anArgIter]); + } else if (anArg == "-setmarkertype" || anArg == "-setpointtype") { @@ -2340,6 +2361,7 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, aChangeSet->LineWidth = 1.0; aChangeSet->ToSetTypeOfLine = -1; aChangeSet->StippleLinePattern = 0xFFFF; + aChangeSet->StippleLineFactor = 1; aChangeSet->ToSetTypeOfMarker = -1; aChangeSet->TypeOfMarker = Aspect_TOM_PLUS; aChangeSet->ToSetMarkerSize = -1; @@ -2493,10 +2515,15 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, if (aChangeSet->ToSetTypeOfLine != 0) { aDrawer->LineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->LineAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->WireAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->WireAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->FreeBoundaryAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->UnFreeBoundaryAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->SeenLineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->SeenLineAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); } if (aChangeSet->ToSetTypeOfMarker != 0) { @@ -2671,10 +2698,15 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, if (aChangeSet->ToSetTypeOfLine != 0) { aDrawer->LineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->LineAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->WireAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->WireAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->FreeBoundaryAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->UnFreeBoundaryAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); aDrawer->SeenLineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern); + aDrawer->SeenLineAspect()->Aspect()->SetLineStippleFactor (aChangeSet->StippleLineFactor); toRedisplay = Standard_True; } if (aChangeSet->ToSetTypeOfMarker != 0) @@ -6254,7 +6286,8 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) "\n\t\t: [-setMaterial MatName] [-unsetMaterial]" "\n\t\t: [-setTransparency Transp] [-unsetTransparency]" "\n\t\t: [-setWidth LineWidth] [-unsetWidth]" - "\n\t\t: [-setLineType {solid|dash|dot|dotDash|0xHexPattern}] [-unsetLineType]" + "\n\t\t: [-setLineType {solid|dash|dot|dotDash|0xHexPattern} [-stippleFactor factor]]" + "\n\t\t: [-unsetLineType]" "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]" "\n\t\t: [-unsetMarkerType]" "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]" diff --git a/tests/v3d/glsl/stipple_line2 b/tests/v3d/glsl/stipple_line2 index ba3a3ba33c..d9e45e3c38 100644 --- a/tests/v3d/glsl/stipple_line2 +++ b/tests/v3d/glsl/stipple_line2 @@ -10,6 +10,6 @@ vclear vinit View1 vdisplay -dispMode 0 b1 b2 vfit -vaspects b1 -setLineWidth 4 -setLineType FF00 -setColor RED -vaspects b2 -setLineWidth 4 -setLineType 00FF -setColor GREEN +vaspects b1 -setLineWidth 4 -setLineType FF00 -setColor RED -setStippleLineFactor 2 +vaspects b2 -setLineWidth 4 -setLineType 00FF -setColor GREEN -setStippleLineFactor 2 vdump $::imagedir/${::casename}_glsl.png