Skip to content

Commit 36f2bab

Browse files
committed
Slightly refactor the base framework; introduce finder of base faces in AAG.
1 parent 8b48356 commit 36f2bab

File tree

9 files changed

+120
-41
lines changed

9 files changed

+120
-41
lines changed

Log_ActiveScript.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515

1616
> load-brep /home/ssv/work/temp/feature5.brep; fit; set-as-var f
1717
> load-step /home/ssv/work/step-inspector/data/tests-main/11kfaces.stp; fit
18-
> find-isomorphisms f -noconvex
18+
> find-isomorphisms f -noconvex -nobase

src/asiAlgo/features/asiAlgo_AAG.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,31 @@ bool asiAlgo_AAG::SetNodeAttribute(const int node,
676676

677677
//-----------------------------------------------------------------------------
678678

679+
bool asiAlgo_AAG::FindBaseOnly(TColStd_PackedMapOfInteger& resultFaceIds) const
680+
{
681+
for ( asiAlgo_AdjacencyMx::t_mx::Iterator it( m_neighborsStack.top().mx );
682+
it.More(); it.Next() )
683+
{
684+
const int fid = it.Key();
685+
686+
// Get face to check the number of wires.
687+
const TopoDS_Face& face = this->GetFace(fid);
688+
689+
// Get the number of wires.
690+
TopTools_IndexedMapOfShape wires;
691+
TopExp::MapShapes(face, TopAbs_WIRE, wires);
692+
//
693+
const int numWires = wires.Extent();
694+
695+
if ( numWires > 1 )
696+
resultFaceIds.Add(fid);
697+
}
698+
699+
return resultFaceIds.Extent() > 0;
700+
}
701+
702+
//-----------------------------------------------------------------------------
703+
679704
bool asiAlgo_AAG::FindConvexOnly(TColStd_PackedMapOfInteger& resultFaceIds) const
680705
{
681706
TColStd_PackedMapOfInteger traversed;

src/asiAlgo/features/asiAlgo_AAG.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ class asiAlgo_AAG : public Standard_Transient
116116
//! for adjacency relation.
117117
struct t_arc
118118
{
119-
int F1; //!< First face.
120-
int F2; //!< Second face.
119+
t_topoId F1; //!< First face.
120+
t_topoId F2; //!< Second face.
121121

122122
//! ctor default.
123123
t_arc() : F1(0), F2(0) {}
124124

125125
//! ctor with parameters.
126-
t_arc(const int _F1, const int _F2) : F1(_F1), F2(_F2) {}
126+
t_arc(const t_topoId _F1, const t_topoId _F2) : F1(_F1), F2(_F2) {}
127127

128128
//! \return hash code for the arc.
129129
static int HashCode(const t_arc& arc, const int upper)
@@ -280,7 +280,7 @@ class asiAlgo_AAG : public Standard_Transient
280280
typedef NCollection_DataMap<t_arc, Handle(asiAlgo_FeatureAttr), t_arc> t_arc_attributes;
281281

282282
//! Node attributes.
283-
typedef NCollection_DataMap<int, t_attr_set> t_node_attributes;
283+
typedef NCollection_DataMap<t_topoId, t_attr_set> t_node_attributes;
284284

285285
//---------------------------------------------------------------------------
286286

@@ -398,7 +398,7 @@ class asiAlgo_AAG : public Standard_Transient
398398
//!
399399
//! \sa PopSubgraph() method to pop the created sub-graph from the stack.
400400
asiAlgo_EXPORT void
401-
PushSubgraphX(const int face2Exclude);
401+
PushSubgraphX(const t_topoId face2Exclude);
402402

403403
//! \brief Pops the top sub-graph from the internal stack.
404404
//!
@@ -435,7 +435,7 @@ class asiAlgo_AAG : public Standard_Transient
435435
//! \param[in] face_idx face index.
436436
//! \return true/false.
437437
asiAlgo_EXPORT bool
438-
HasFace(const int face_idx) const;
438+
HasFace(const t_topoId face_idx) const;
439439

440440
//! Returns true if the passed face is in graph.
441441
//! \param[in] face face to check.
@@ -447,12 +447,12 @@ class asiAlgo_AAG : public Standard_Transient
447447
//! \param[in] face_idx face index.
448448
//! \return topological face.
449449
asiAlgo_EXPORT const TopoDS_Face&
450-
GetFace(const int face_idx) const;
450+
GetFace(const t_topoId face_idx) const;
451451

452452
//! Returns face ID.
453453
//! \param[in] face face of interest.
454454
//! \return face ID.
455-
asiAlgo_EXPORT int
455+
asiAlgo_EXPORT t_topoId
456456
GetFaceId(const TopoDS_Shape& face) const;
457457

458458
//! Checks whether the given face has any neighbors recorded in the AAG.
@@ -461,29 +461,29 @@ class asiAlgo_AAG : public Standard_Transient
461461
//! \param[in] face_idx face index.
462462
//! \return true in case if at least one neighbor presents, false -- otherwise.
463463
asiAlgo_EXPORT bool
464-
HasNeighbors(const int face_idx) const;
464+
HasNeighbors(const t_topoId face_idx) const;
465465

466466
//! Returns neighbors for the face having the given internal index.
467467
//! \param[in] face_idx face index.
468468
//! \return indices of the neighbor faces.
469469
asiAlgo_EXPORT const TColStd_PackedMapOfInteger&
470-
GetNeighbors(const int face_idx) const;
470+
GetNeighbors(const t_topoId face_idx) const;
471471

472472
//! Returns only those neighbor faces which share the given edge with the
473473
//! passed face of interest.
474474
//! \param[in] face_idx ID of the face of interest.
475475
//! \param[in] edge common edge.
476476
//! \return indices of the neighbor faces sharing the given edge.
477477
asiAlgo_EXPORT TColStd_PackedMapOfInteger
478-
GetNeighborsThru(const int face_idx, const TopoDS_Edge& edge);
478+
GetNeighborsThru(const t_topoId face_idx, const TopoDS_Edge& edge);
479479

480480
//! Returns neighbor faces for the given face of interest with additional
481481
//! filter on edges realizing the neighborhood.
482482
//! \param[in] face_idx index of the face of interest.
483483
//! \param[in] edge_ids indices of edges of interest.
484484
//! \return indices of the neighbor faces.
485485
asiAlgo_EXPORT TColStd_PackedMapOfInteger
486-
GetNeighborsThru(const int face_idx,
486+
GetNeighborsThru(const t_topoId face_idx,
487487
const TColStd_PackedMapOfInteger& edge_ids);
488488

489489
//! Returns only those neighbor faces which do not share the given edges with
@@ -492,7 +492,7 @@ class asiAlgo_AAG : public Standard_Transient
492492
//! \param[in] xEdges edge where neighborhood is restricted.
493493
//! \return indices of the neighbor faces not sharing the given edges.
494494
asiAlgo_EXPORT TColStd_PackedMapOfInteger
495-
GetNeighborsThruX(const int face_idx, const TColStd_PackedMapOfInteger& xEdges);
495+
GetNeighborsThruX(const t_topoId face_idx, const TColStd_PackedMapOfInteger& xEdges);
496496

497497
//! Returns full collection of neighbor faces.
498498
//! \return neighborhood data.
@@ -625,7 +625,7 @@ class asiAlgo_AAG : public Standard_Transient
625625
//! \param[in] node ID of the graph node to check.
626626
//! \return true/false.
627627
asiAlgo_EXPORT bool
628-
HasNodeAttributes(const int node) const;
628+
HasNodeAttributes(const t_topoId node) const;
629629

630630
//! Accessor for the entire collection of nodal attributes.
631631
//! \return attributes associated with all graph node.
@@ -636,14 +636,14 @@ class asiAlgo_AAG : public Standard_Transient
636636
//! \param[in] node ID of the graph node of interest.
637637
//! \return attributes associated with the given graph node.
638638
asiAlgo_EXPORT const t_attr_set&
639-
GetNodeAttributes(const int node) const;
639+
GetNodeAttributes(const t_topoId node) const;
640640

641641
//! Returns attribute associated with the given graph node.
642642
//! \param[in] node ID of the graph node of interest.
643643
//! \param[in] attr_id ID of the attribute to access.
644644
//! \return attribute associated with the given node.
645645
asiAlgo_EXPORT Handle(asiAlgo_FeatureAttr)
646-
GetNodeAttribute(const int node,
646+
GetNodeAttribute(const t_topoId node,
647647
const Standard_GUID& attr_id) const;
648648

649649
//! Removes attribute with the passed GUID from the given graph node.
@@ -652,7 +652,7 @@ class asiAlgo_AAG : public Standard_Transient
652652
//! \return true if the attribute was removed, false -- otherwise (e.g., if
653653
//! such attribute does not exist).
654654
asiAlgo_EXPORT bool
655-
RemoveNodeAttribute(const int node,
655+
RemoveNodeAttribute(const t_topoId node,
656656
const Standard_GUID& attr_id);
657657

658658
//! Removes all attributes assigned to nodes.
@@ -669,9 +669,15 @@ class asiAlgo_AAG : public Standard_Transient
669669
//! \param[in] node ID of the graph node of interest.
670670
//! \param[in] attr attribute to set.
671671
asiAlgo_EXPORT bool
672-
SetNodeAttribute(const int node,
672+
SetNodeAttribute(const t_topoId node,
673673
const Handle(asiAlgo_FeatureAttr)& attr);
674674

675+
//! Finds base faces, i.e., the faces having inner loops.
676+
//! \param[out] resultFaceIds IDs of the found faces (if any).
677+
//! \return true if anything has been found, false -- otherwise.
678+
asiAlgo_EXPORT bool
679+
FindBaseOnly(TColStd_PackedMapOfInteger& resultFaceIds) const;
680+
675681
//! Searches for the faces having ALL neighbors attributed with convex links.
676682
//! \param[out] resultFaceIds IDs of the found faces (if any).
677683
//! \return true if anything has been found, false -- otherwise.
@@ -737,7 +743,7 @@ class asiAlgo_AAG : public Standard_Transient
737743
//! \param[in] fid face ID in question.
738744
//! \return attribute.
739745
template<typename t_attr_type>
740-
Handle(t_attr_type) ATTR_NODE(const int fid) const
746+
Handle(t_attr_type) ATTR_NODE(const t_topoId fid) const
741747
{
742748
return Handle(t_attr_type)::DownCast( this->GetNodeAttribute( fid, t_attr_type::GUID() ) );
743749
}
@@ -809,7 +815,7 @@ class asiAlgo_AAG : public Standard_Transient
809815
//! \param[in,out] out target output stream.
810816
//! \param[in] whitespace num of spaces to prefix each row.
811817
asiAlgo_EXPORT void
812-
dumpNodeJSON(const int node,
818+
dumpNodeJSON(const t_topoId node,
813819
const bool isFirst,
814820
Standard_OStream& out,
815821
const int whitespace = 0) const;

src/asiUI/utils/asiUI_BatchFacilities.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class asiUI_BatchFacilities : public Standard_Transient
6868
public:
6969

7070
//! \return single instance of facilities.
71-
static Handle(asiUI_BatchFacilities) Instance();
71+
asiUI_EXPORT static Handle(asiUI_BatchFacilities)
72+
Instance();
7273

7374
protected:
7475

src/asiUI/viewers/asiUI_ViewerPartListener.cpp

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <asiAlgo_Utils.h>
4343

4444
// asiEngine includes
45+
#include <asiEngine_IV.h>
4546
#include <asiEngine_Part.h>
4647

4748
// asiVisu includes
@@ -78,13 +79,15 @@ asiUI_ViewerPartListener::asiUI_ViewerPartListener(asiUI_ViewerPart*
7879
ActAPI_ProgressEntry progress,
7980
ActAPI_PlotterEntry plotter)
8081
//
81-
: asiUI_Viewer3dListener (wViewerPart, model, progress, plotter),
82-
m_wViewerDomain (wViewerDomain),
83-
m_wViewerHost (wViewerHost),
84-
m_pSaveBREPAction (nullptr),
85-
m_pShowNormsAction (nullptr),
86-
m_pInvertFacesAction (nullptr),
87-
m_pShowOriContour (nullptr)
82+
: asiUI_Viewer3dListener (wViewerPart, model, progress, plotter),
83+
m_wViewerDomain (wViewerDomain),
84+
m_wViewerHost (wViewerHost),
85+
m_pSaveBREPAction (nullptr),
86+
m_pShowNormsAction (nullptr),
87+
m_pInvertFacesAction (nullptr),
88+
m_pShowOriContourAction (nullptr),
89+
m_pCopyAsStringAction (nullptr),
90+
m_pSetAsVariableAction (nullptr)
8891
{}
8992

9093
//-----------------------------------------------------------------------------
@@ -286,19 +289,20 @@ void asiUI_ViewerPartListener::populateMenu(QMenu& menu)
286289
if ( m_pViewer->PrsMgr()->IsPresentable( STANDARD_TYPE(asiData_FaceNormsNode) ) )
287290
m_pShowNormsAction = menu.addAction("Show face normals");
288291
if ( m_pViewer->PrsMgr()->IsPresentable( STANDARD_TYPE(asiData_FaceContourNode) ) )
289-
m_pShowOriContour = menu.addAction("Show face oriented contour");
292+
m_pShowOriContourAction = menu.addAction("Show face oriented contour");
290293
//
291294
m_pInvertFacesAction = menu.addAction("Invert faces");
292295
}
293296

294297
menu.addSeparator();
295298
//
296-
m_pSaveBREPAction = menu.addAction("Save to BREP...");
299+
m_pSaveBREPAction = menu.addAction("Save to BREP...");
300+
m_pSetAsVariableAction = menu.addAction("Set as variable");
297301

298302
// Add items which work for single-element selection.
299303
if ( faceIndices.Extent() == 1 || edgeIndices.Extent() == 1 )
300304
{
301-
m_pCopyAsString = menu.addAction("Copy as JSON");
305+
m_pCopyAsStringAction = menu.addAction("Copy as JSON");
302306
}
303307
}
304308
}
@@ -355,7 +359,7 @@ void asiUI_ViewerPartListener::executeAction(QAction* pAction)
355359
//---------------------------------------------------------------------------
356360
// ACTION: copy as string
357361
//---------------------------------------------------------------------------
358-
else if ( pAction == m_pCopyAsString )
362+
else if ( pAction == m_pCopyAsStringAction )
359363
{
360364
// Get highlighted sub-shapes.
361365
TopTools_IndexedMapOfShape selected;
@@ -421,7 +425,7 @@ void asiUI_ViewerPartListener::executeAction(QAction* pAction)
421425
//---------------------------------------------------------------------------
422426
// ACTION: show oriented contour
423427
//---------------------------------------------------------------------------
424-
else if ( pAction == m_pShowOriContour )
428+
else if ( pAction == m_pShowOriContourAction )
425429
{
426430
TIMER_NEW
427431
TIMER_GO
@@ -475,4 +479,34 @@ void asiUI_ViewerPartListener::executeAction(QAction* pAction)
475479
m_pViewer->PrsMgr()->Actualize(part_n);
476480
m_pViewer->PrsMgr()->Actualize( m_model->GetPartNode()->GetNormsRepresentation() );
477481
}
482+
483+
//---------------------------------------------------------------------------
484+
// ACTION: set as variable
485+
//---------------------------------------------------------------------------
486+
if ( pAction == m_pSetAsVariableAction )
487+
{
488+
// Get highlighted sub-shapes
489+
TopTools_IndexedMapOfShape selected;
490+
asiEngine_Part( m_model, m_pViewer->PrsMgr() ).GetHighlightedSubShapes(selected);
491+
492+
// Prepare a shape to set as a variable
493+
TopoDS_Shape shape2Var;
494+
//
495+
if ( selected.Extent() == 1 )
496+
shape2Var = selected(1);
497+
else
498+
{
499+
// Put selected shapes to a compound
500+
TopoDS_Compound comp;
501+
BRep_Builder().MakeCompound(comp);
502+
//
503+
for ( int k = 1; k <= selected.Extent(); ++k )
504+
BRep_Builder().Add( comp, selected(k) );
505+
//
506+
shape2Var = comp;
507+
}
508+
509+
// Add variable via the imperative plotter
510+
m_plotter.DRAW_SHAPE(shape2Var, Color_Yellow, "var");
511+
}
478512
}

src/asiUI/viewers/asiUI_ViewerPartListener.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ protected slots:
9090
QAction* m_pSaveBREPAction;
9191
QAction* m_pShowNormsAction;
9292
QAction* m_pInvertFacesAction;
93-
QAction* m_pShowOriContour;
94-
QAction* m_pCopyAsString;
93+
QAction* m_pShowOriContourAction;
94+
QAction* m_pCopyAsStringAction;
95+
QAction* m_pSetAsVariableAction;
9596

9697
};
9798

src/cmdEngine/cmdEngine_Inspection.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,6 +3239,20 @@ int ENGINE_FindIsomorphisms(const Handle(asiTcl_Interp)& interp,
32393239
TColStd_PackedMapOfInteger convexOnlyFaces;
32403240
G->FindConvexOnly(convexOnlyFaces);
32413241
G->PushSubgraphX(convexOnlyFaces);
3242+
3243+
interp->GetProgress().SendLogMessage( LogInfo(Normal) << "Num. of convex faces to exclude: %1."
3244+
<< convexOnlyFaces.Extent() );
3245+
isReduced = true;
3246+
}
3247+
//
3248+
if ( interp->HasKeyword(argc, argv, "nobase") )
3249+
{
3250+
TColStd_PackedMapOfInteger baseOnlyFaces;
3251+
G->FindBaseOnly(baseOnlyFaces);
3252+
G->PushSubgraphX(baseOnlyFaces);
3253+
3254+
interp->GetProgress().SendLogMessage( LogInfo(Normal) << "Num. of base faces to exclude: %1."
3255+
<< baseOnlyFaces.Extent() );
32423256
isReduced = true;
32433257
}
32443258

src/exe/ui/exe_CommonFacilities.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class exe_CommonFacilities : public asiUI_CommonFacilities
5555
public:
5656

5757
Handle(asiUI_IStatusBar) StatusBar; //!< Status bar of the main window.
58-
Handle(asiUI_Logger) Logger; //!< Logger.
59-
Handle(asiTcl_Interp) Interp; //!< Tcl interpreter.
6058

6159
//! Visualization facilities.
6260
struct t_prs

src/exe/ui/exe_MainWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ void exe_MainWindow::createDockWindows()
403403

404404
// Initialize and connect progress listener.
405405
cf->Logger = new asiUI_Logger(Widgets.wLogger);
406-
cf->ProgressListener = new asiUI_ProgressListener(statusBar,
407-
cf->Progress.Access(),
408-
cf->Logger);
406+
cf->ProgressListener = new asiUI_ProgressListener( statusBar,
407+
cf->Progress.Access(),
408+
Handle(asiUI_Logger)::DownCast(cf->Logger) );
409409
cf->ProgressListener->Connect();
410410

411411
/* ==================================

0 commit comments

Comments
 (0)