// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
+#include <StdPrs_HLRPolyShape.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
-#include <Graphic3d_ArrayOfPolylines.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
#include <Graphic3d_Group.hxx>
#include <HLRAlgo_EdgeIterator.hxx>
#include <HLRAlgo_EdgeStatus.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_Projector.hxx>
-#include <StdPrs_HLRPolyShape.hxx>
#include <StdPrs_WFShape.hxx>
#include <TColgp_SequenceOfPnt.hxx>
#include <TopAbs.hxx>
}
}
- TColgp_SequenceOfPnt HiddenPnts;
- TColgp_SequenceOfPnt SeenPnts;
-
if (aDrawer->IsAutoTriangulation())
{
const Standard_Boolean aRel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
S,reg1,regn,outl,intl));
}
}
-
- // storage in the group:
- HLRBRep_ListIteratorOfListOfBPoint ItB;
- if (aDrawer->DrawHiddenLine()) {
- for (ItB.Initialize(BiPntHid); ItB.More(); ItB.Next()) {
- const HLRBRep_BiPoint& BP = ItB.Value();
- if (!BP.RgNLine() || BP.OutLine()) {
- HiddenPnts.Append(BP.P1());
- HiddenPnts.Append(BP.P2());
+ // storage in the group
+ if (aDrawer->DrawHiddenLine())
+ {
+ Standard_Integer aNbHiddenSegments = 0;
+ for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
+ {
+ const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
+ if (!aBPnt.RgNLine()
+ || aBPnt.OutLine())
+ {
+ ++aNbHiddenSegments;
}
}
- }
+ if (aNbHiddenSegments > 0)
+ {
+ Handle(Graphic3d_ArrayOfSegments) aHiddenArray = new Graphic3d_ArrayOfSegments (aNbHiddenSegments * 2);
+ for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
+ {
+ const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
+ if (!aBPnt.RgNLine()
+ || aBPnt.OutLine())
+ {
+ aHiddenArray->AddVertex (aBPnt.P1());
+ aHiddenArray->AddVertex (aBPnt.P2());
+ }
+ }
- for (ItB.Initialize(BiPntVis); ItB.More(); ItB.Next()) {
- const HLRBRep_BiPoint& BP = ItB.Value();
- if (!BP.RgNLine() || BP.OutLine()) {
- SeenPnts.Append(BP.P1());
- SeenPnts.Append(BP.P2());
+ aGroup->SetPrimitivesAspect (aDrawer->HiddenLineAspect()->Aspect());
+ aGroup->AddPrimitiveArray (aHiddenArray);
}
}
-
- Standard_Integer nbVertices = HiddenPnts.Length();
- if(nbVertices > 0) {
- Handle(Graphic3d_ArrayOfPolylines) HiddenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
- for(int i=1; i<=nbVertices; i+=2) {
- HiddenArray->AddBound(2);
- HiddenArray->AddVertex(HiddenPnts.Value(i));
- HiddenArray->AddVertex(HiddenPnts.Value(i+1));
+ {
+ Standard_Integer aNbSeenSegments = 0;
+ for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
+ {
+ const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
+ if (!aBPnt.RgNLine()
+ || aBPnt.OutLine())
+ {
+ ++aNbSeenSegments;
+ }
}
- aGroup->SetPrimitivesAspect(aDrawer->HiddenLineAspect()->Aspect());
- aGroup->AddPrimitiveArray(HiddenArray);
- }
- nbVertices = SeenPnts.Length();
- if(nbVertices > 0) {
- Handle(Graphic3d_ArrayOfPolylines) SeenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
- for(int i=1; i<=nbVertices; i+=2) {
- SeenArray->AddBound(2);
- SeenArray->AddVertex(SeenPnts.Value(i));
- SeenArray->AddVertex(SeenPnts.Value(i+1));
+ if (aNbSeenSegments > 0)
+ {
+ Handle(Graphic3d_ArrayOfSegments) aSeenArray = new Graphic3d_ArrayOfSegments (aNbSeenSegments * 2);
+ for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
+ {
+ const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
+ if (!aBPnt.RgNLine()
+ || aBPnt.OutLine())
+ {
+ aSeenArray->AddVertex (aBPnt.P1());
+ aSeenArray->AddVertex (aBPnt.P2());
+ }
+ }
+ aGroup->SetPrimitivesAspect (aDrawer->SeenLineAspect()->Aspect());
+ aGroup->AddPrimitiveArray (aSeenArray);
}
- aGroup->SetPrimitivesAspect(aDrawer->SeenLineAspect()->Aspect());
- aGroup->AddPrimitiveArray(SeenArray);
}
}
}
#endif
-static Standard_Boolean MyHLRIsOn = Standard_False;
-
NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
static NCollection_DoubleMap <TCollection_AsciiString, Handle(AIS_InteractiveContext)> ViewerTest_myContexts;
static NCollection_DoubleMap <TCollection_AsciiString, Handle(Graphic3d_GraphicDriver)> ViewerTest_myDrivers;
//==============================================================================
static int Start_Rot = 0;
+Standard_Boolean HasHlrOnBeforeRotation = Standard_False;
int X_Motion = 0; // Current cursor position
int Y_Motion = 0;
int X_ButtonPress = 0; // Last ButtonPress position
// Set parameters for V3d_View and V3d_Viewer
const Handle (V3d_View) aV3dView = ViewerTest::CurrentView();
aV3dView->SetComputedMode(Standard_False);
- MyHLRIsOn = aV3dView->ComputedMode();
a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
if (toCreateViewer)
return 0;
}
+//! Parse HLR algo type.
+static Standard_Boolean parseHlrAlgoType (const char* theName,
+ Prs3d_TypeOfHLR& theType)
+{
+ TCollection_AsciiString aName (theName);
+ aName.LowerCase();
+ if (aName == "polyalgo")
+ {
+ theType = Prs3d_TOH_PolyAlgo;
+ }
+ else if (aName == "algo")
+ {
+ theType = Prs3d_TOH_Algo;
+ }
+ else
+ {
+ return Standard_False;
+ }
+ return Standard_True;
+}
+
//==============================================================================
//function : VHLR
//purpose : hidden lines removal algorithm
-//draw args: vhlr is_enabled={on|off} [show_hidden={1|0}]
//==============================================================================
static int VHLR (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (ViewerTest::CurrentView().IsNull())
+ const Handle(V3d_View) aView = ViewerTest::CurrentView();
+ const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+ if (aView.IsNull())
{
- di << argv[0] << ": Call vinit before this command, please.\n";
+ std::cerr << "Error: No opened viewer!\n";
return 1;
}
- if (argc < 2)
+ Standard_Boolean hasHlrOnArg = Standard_False;
+ Standard_Boolean hasShowHiddenArg = Standard_False;
+ Standard_Boolean isHLROn = Standard_False;
+ Standard_Boolean toShowHidden = aCtx->DefaultDrawer()->DrawHiddenLine();
+ Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
+ ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
+ for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
{
- di << argv[0] << ": Wrong number of command arguments.\n"
- << "Type help " << argv[0] << " for more information.\n";
- return 1;
+ TCollection_AsciiString anArg (argv[anArgIter]);
+ anArg.LowerCase();
+ if (anUpdateTool.parseRedrawMode (anArg))
+ {
+ continue;
+ }
+ else if (anArg == "-showhidden"
+ && anArgIter + 1 < argc
+ && ViewerTest::ParseOnOff (argv[anArgIter + 1], toShowHidden))
+ {
+ ++anArgIter;
+ hasShowHiddenArg = Standard_True;
+ continue;
+ }
+ else if ((anArg == "-type"
+ || anArg == "-algo"
+ || anArg == "-algotype")
+ && anArgIter + 1 < argc
+ && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
+ {
+ ++anArgIter;
+ continue;
+ }
+ else if (!hasHlrOnArg
+ && ViewerTest::ParseOnOff (argv[anArgIter], isHLROn))
+ {
+ hasHlrOnArg = Standard_True;
+ continue;
+ }
+ // old syntax
+ else if (!hasShowHiddenArg
+ && ViewerTest::ParseOnOff(argv[anArgIter], toShowHidden))
+ {
+ hasShowHiddenArg = Standard_True;
+ continue;
+ }
+ else
+ {
+ std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+ return 1;
+ }
}
-
- // Enable or disable HLR mode.
- Standard_Boolean isHLROn =
- (!strcasecmp (argv[1], "on")) ? Standard_True : Standard_False;
-
- if (isHLROn != MyHLRIsOn)
+ if (!hasHlrOnArg)
{
- MyHLRIsOn = isHLROn;
- ViewerTest::CurrentView()->SetComputedMode (MyHLRIsOn);
+ di << "HLR: " << aView->ComputedMode() << "\n";
+ di << "HiddenLine: " << aCtx->DefaultDrawer()->DrawHiddenLine() << "\n";
+ di << "HlrAlgo: ";
+ switch (aCtx->DefaultDrawer()->TypeOfHLR())
+ {
+ case Prs3d_TOH_NotSet: di << "NotSet\n"; break;
+ case Prs3d_TOH_PolyAlgo: di << "PolyAlgo\n"; break;
+ case Prs3d_TOH_Algo: di << "Algo\n"; break;
+ }
+ anUpdateTool.Invalidate();
+ return 0;
}
- // Show or hide hidden lines in HLR mode.
- Standard_Boolean isCurrentShowHidden
- = ViewerTest::GetAISContext()->DefaultDrawer()->DrawHiddenLine();
-
- Standard_Boolean isShowHidden =
- (argc == 3) ? (atoi(argv[2]) == 1 ? Standard_True : Standard_False)
- : isCurrentShowHidden;
-
-
- if (isShowHidden != isCurrentShowHidden)
+ Standard_Boolean toRecompute = Standard_False;
+ if (aTypeOfHLR != Prs3d_TOH_NotSet
+ && aTypeOfHLR != aCtx->DefaultDrawer()->TypeOfHLR())
{
- if (isShowHidden)
+ toRecompute = Standard_True;
+ aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
+ }
+ if (toShowHidden != aCtx->DefaultDrawer()->DrawHiddenLine())
+ {
+ toRecompute = Standard_True;
+ if (toShowHidden)
{
- ViewerTest::GetAISContext()->DefaultDrawer()->EnableDrawHiddenLine();
+ aCtx->DefaultDrawer()->EnableDrawHiddenLine();
}
else
{
- ViewerTest::GetAISContext()->DefaultDrawer()->DisableDrawHiddenLine();
+ aCtx->DefaultDrawer()->DisableDrawHiddenLine();
}
+ }
- // Redisplay shapes.
- if (MyHLRIsOn)
+ // redisplay shapes
+ if (aView->ComputedMode() && isHLROn && toRecompute)
+ {
+ AIS_ListOfInteractive aListOfShapes;
+ aCtx->DisplayedObjects (aListOfShapes);
+ for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
{
- AIS_ListOfInteractive aListOfShapes;
- ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
-
- for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
+ if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value()))
{
- Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value());
- if (aShape.IsNull())
- {
- continue;
- }
- ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
+ aCtx->Redisplay (aShape, Standard_False);
}
}
}
- ViewerTest::CurrentView()->Update();
+ aView->SetComputedMode (isHLROn);
return 0;
}
//purpose : change type of using HLR algorithm
//==============================================================================
-static int VHLRType (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static int VHLRType (Draw_Interpretor& , Standard_Integer argc, const char** argv)
{
- if (ViewerTest::CurrentView().IsNull())
- {
- di << argv[0] << ": Call vinit before this command, please.\n";
- return 1;
- }
-
- if (argc < 2)
+ const Handle(V3d_View) aView = ViewerTest::CurrentView();
+ const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+ if (aView.IsNull())
{
- di << argv[0] << ": Wrong number of command arguments.\n"
- << "Type help " << argv[0] << " for more information.\n";
+ std::cerr << "Error: No opened viewer!\n";
return 1;
}
- Prs3d_TypeOfHLR aTypeOfHLR =
- (!strcasecmp (argv[1], "algo")) ? Prs3d_TOH_Algo : Prs3d_TOH_PolyAlgo;
-
- if (argc == 2)
+ Prs3d_TypeOfHLR aTypeOfHLR = Prs3d_TOH_NotSet;
+ ViewerTest_AutoUpdater anUpdateTool (Handle(AIS_InteractiveContext)(), aView);
+ AIS_ListOfInteractive aListOfShapes;
+ for (Standard_Integer anArgIter = 1; anArgIter < argc; ++anArgIter)
{
- AIS_ListOfInteractive aListOfShapes;
- ViewerTest::GetAISContext()->DisplayedObjects (aListOfShapes);
- ViewerTest::GetAISContext()->DefaultDrawer()->SetTypeOfHLR(aTypeOfHLR);
- for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes);
- anIter.More(); anIter.Next())
+ TCollection_AsciiString anArg (argv[anArgIter]);
+ anArg.LowerCase();
+ if (anUpdateTool.parseRedrawMode (anArg))
{
- Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
- if (aShape.IsNull())
- continue;
- if (aShape->TypeOfHLR() != aTypeOfHLR)
- aShape->SetTypeOfHLR (aTypeOfHLR);
- if (MyHLRIsOn)
- ViewerTest::GetAISContext()->Redisplay (aShape, Standard_False);
+ continue;
}
- ViewerTest::CurrentView()->Update();
- return 0;
- }
- else
- {
- for (Standard_Integer i = 2; i < argc; ++i)
+ else if ((anArg == "-type"
+ || anArg == "-algo"
+ || anArg == "-algotype")
+ && anArgIter + 1 < argc
+ && parseHlrAlgoType (argv[anArgIter + 1], aTypeOfHLR))
+ {
+ ++anArgIter;
+ continue;
+ }
+ // old syntax
+ else if (aTypeOfHLR == Prs3d_TOH_NotSet
+ && parseHlrAlgoType (argv[anArgIter], aTypeOfHLR))
+ {
+ continue;
+ }
+ else
{
ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
- TCollection_AsciiString aName (argv[i]);
-
+ TCollection_AsciiString aName (argv[anArgIter]);
if (!aMap.IsBound2 (aName))
{
- di << argv[0] << ": Wrong shape name:" << aName.ToCString() << ".\n";
- continue;
+ std::cout << "Syntax error: Wrong shape name '" << aName << "'.\n";
+ return 1;
}
- Handle(AIS_Shape) anAISObject =
- Handle(AIS_Shape)::DownCast (aMap.Find2(aName));
- if (anAISObject.IsNull())
- continue;
- anAISObject->SetTypeOfHLR (aTypeOfHLR);
- if (MyHLRIsOn)
- ViewerTest::GetAISContext()->Redisplay (anAISObject, Standard_False);
+
+ Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aMap.Find2 (aName));
+ if (aShape.IsNull())
+ {
+ std::cout << "Syntax error: '" << aName << "' is not a shape presentation.\n";
+ return 1;
+ }
+ aListOfShapes.Append (aShape);
+ continue;
}
- ViewerTest::CurrentView()->Update();
+ }
+ if (aTypeOfHLR == Prs3d_TOH_NotSet)
+ {
+ std::cout << "Syntax error: wrong number of arguments!\n";
+ return 1;
+ }
+
+ const Standard_Boolean isGlobal = aListOfShapes.IsEmpty();
+ if (isGlobal)
+ {
+ aCtx->DisplayedObjects (aListOfShapes);
+ aCtx->DefaultDrawer()->SetTypeOfHLR (aTypeOfHLR);
}
+ for (AIS_ListIteratorOfListOfInteractive anIter(aListOfShapes); anIter.More(); anIter.Next())
+ {
+ Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anIter.Value());
+ if (aShape.IsNull())
+ {
+ continue;
+ }
+
+ const bool toUpdateShape = aShape->TypeOfHLR() != aTypeOfHLR
+ && aView->ComputedMode();
+ if (!isGlobal
+ || aShape->TypeOfHLR() != aTypeOfHLR)
+ {
+ aShape->SetTypeOfHLR (aTypeOfHLR);
+ }
+ if (toUpdateShape)
+ {
+ aCtx->Redisplay (aShape, Standard_False);
+ }
+ }
return 0;
}
}
ViewerTest::CurrentView (aView);
- // Update degenerate mode
- MyHLRIsOn = ViewerTest::CurrentView()->ComputedMode();
ViewerTest::SetAISContext (anAISContext);
- TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ");
- aTitle = aTitle + theViewName + "(*)";
+ TCollection_AsciiString aTitle = TCollection_AsciiString("3D View - ") + theViewName + "(*)";
SetWindowTitle (ViewerTest::CurrentView()->Window(), aTitle.ToCString());
-#if defined(_WIN32) || defined(__WIN32__)
+#if defined(_WIN32)
VT_GetWindow() = Handle(WNT_Window)::DownCast(ViewerTest::CurrentView()->Window());
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
VT_GetWindow() = Handle(Cocoa_Window)::DownCast(ViewerTest::CurrentView()->Window());
else if (!strcasecmp (buf_ret, "H"))
{
// HLR
- cout << "HLR" << endl;
+ std::cout << "HLR" << std::endl;
aView->SetComputedMode (!aView->ComputedMode());
- MyHLRIsOn = aView->ComputedMode();
+ aView->Redraw();
}
else if (!strcasecmp (buf_ret, "P"))
{
void VT_ProcessButton3Press()
{
Start_Rot = 1;
- if (MyHLRIsOn)
+ HasHlrOnBeforeRotation = ViewerTest::CurrentView()->ComputedMode();
+ if (HasHlrOnBeforeRotation)
{
ViewerTest::CurrentView()->SetComputedMode (Standard_False);
}
if (Start_Rot)
{
Start_Rot = 0;
- if (MyHLRIsOn)
+ if (HasHlrOnBeforeRotation)
{
+ HasHlrOnBeforeRotation = Standard_False;
ViewerTest::CurrentView()->SetComputedMode (Standard_True);
+ ViewerTest::CurrentView()->Redraw();
}
}
}
" ts, tt - translation for s and t texture coordinates\n"
" rot - texture rotation angle in degrees",
__FILE__, VTextureEnv, group);
- theCommands.Add("vhlr" ,
- "is_enabled={on|off} [show_hidden={1|0}]"
- " - Hidden line removal algorithm:"
- " - is_enabled: if is on HLR algorithm is applied\n"
- " - show_hidden: if equals to 1, hidden lines are drawn as dotted ones.\n",
+ theCommands.Add("vhlr",
+ "vhlr {on|off} [-showHidden={1|0}] [-algoType={algo|polyAlgo}] [-noupdate]"
+ "\n\t\t: Hidden Line Removal algorithm."
+ "\n\t\t: -showHidden if set ON, hidden lines are drawn as dotted ones"
+ "\n\t\t: -algoType type of HLR algorithm.\n",
__FILE__,VHLR,group);
- theCommands.Add("vhlrtype" ,
- "algo_type={algo|polyalgo} [shape_1 ... shape_n]"
- " - Changes the type of HLR algorithm using for shapes."
- " - algo_type: if equals to algo, exact HLR algorithm is applied;\n"
- " if equals to polyalgo, polygonal HLR algorithm is applied."
- "If shapes are not given HLR algoithm of given type is applied"
- " to all shapes in the view\n",
+ theCommands.Add("vhlrtype",
+ "vhlrtype {algo|polyAlgo} [shape_1 ... shape_n] [-noupdate]"
+ "\n\t\t: Changes the type of HLR algorithm using for shapes:"
+ "\n\t\t: 'algo' - exact HLR algorithm is applied"
+ "\n\t\t: 'polyAlgo' - polygonal HLR algorithm is applied"
+ "\n\t\t: If shapes are not given - option is applied to all shapes in the view",
__FILE__,VHLRType,group);
theCommands.Add("vclipplane",
"vclipplane planeName [{0|1}]"