Skip to content

Commit

Permalink
Slightly refactor the base framework; introduce finder of base faces …
Browse files Browse the repository at this point in the history
…in AAG.
  • Loading branch information
sslyadnev committed May 27, 2020
1 parent 8b48356 commit 36f2bab
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Log_ActiveScript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

> load-brep /home/ssv/work/temp/feature5.brep; fit; set-as-var f
> load-step /home/ssv/work/step-inspector/data/tests-main/11kfaces.stp; fit
> find-isomorphisms f -noconvex
> find-isomorphisms f -noconvex -nobase
25 changes: 25 additions & 0 deletions src/asiAlgo/features/asiAlgo_AAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,31 @@ bool asiAlgo_AAG::SetNodeAttribute(const int node,

//-----------------------------------------------------------------------------

bool asiAlgo_AAG::FindBaseOnly(TColStd_PackedMapOfInteger& resultFaceIds) const
{
for ( asiAlgo_AdjacencyMx::t_mx::Iterator it( m_neighborsStack.top().mx );
it.More(); it.Next() )
{
const int fid = it.Key();

// Get face to check the number of wires.
const TopoDS_Face& face = this->GetFace(fid);

// Get the number of wires.
TopTools_IndexedMapOfShape wires;
TopExp::MapShapes(face, TopAbs_WIRE, wires);
//
const int numWires = wires.Extent();

if ( numWires > 1 )
resultFaceIds.Add(fid);
}

return resultFaceIds.Extent() > 0;
}

//-----------------------------------------------------------------------------

bool asiAlgo_AAG::FindConvexOnly(TColStd_PackedMapOfInteger& resultFaceIds) const
{
TColStd_PackedMapOfInteger traversed;
Expand Down
46 changes: 26 additions & 20 deletions src/asiAlgo/features/asiAlgo_AAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ class asiAlgo_AAG : public Standard_Transient
//! for adjacency relation.
struct t_arc
{
int F1; //!< First face.
int F2; //!< Second face.
t_topoId F1; //!< First face.
t_topoId F2; //!< Second face.

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

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

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

//! Node attributes.
typedef NCollection_DataMap<int, t_attr_set> t_node_attributes;
typedef NCollection_DataMap<t_topoId, t_attr_set> t_node_attributes;

//---------------------------------------------------------------------------

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

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

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

//! Returns face ID.
//! \param[in] face face of interest.
//! \return face ID.
asiAlgo_EXPORT int
asiAlgo_EXPORT t_topoId
GetFaceId(const TopoDS_Shape& face) const;

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

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

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

//! Returns neighbor faces for the given face of interest with additional
//! filter on edges realizing the neighborhood.
//! \param[in] face_idx index of the face of interest.
//! \param[in] edge_ids indices of edges of interest.
//! \return indices of the neighbor faces.
asiAlgo_EXPORT TColStd_PackedMapOfInteger
GetNeighborsThru(const int face_idx,
GetNeighborsThru(const t_topoId face_idx,
const TColStd_PackedMapOfInteger& edge_ids);

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

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

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

//! Returns attribute associated with the given graph node.
//! \param[in] node ID of the graph node of interest.
//! \param[in] attr_id ID of the attribute to access.
//! \return attribute associated with the given node.
asiAlgo_EXPORT Handle(asiAlgo_FeatureAttr)
GetNodeAttribute(const int node,
GetNodeAttribute(const t_topoId node,
const Standard_GUID& attr_id) const;

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

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

//! Finds base faces, i.e., the faces having inner loops.
//! \param[out] resultFaceIds IDs of the found faces (if any).
//! \return true if anything has been found, false -- otherwise.
asiAlgo_EXPORT bool
FindBaseOnly(TColStd_PackedMapOfInteger& resultFaceIds) const;

//! Searches for the faces having ALL neighbors attributed with convex links.
//! \param[out] resultFaceIds IDs of the found faces (if any).
//! \return true if anything has been found, false -- otherwise.
Expand Down Expand Up @@ -737,7 +743,7 @@ class asiAlgo_AAG : public Standard_Transient
//! \param[in] fid face ID in question.
//! \return attribute.
template<typename t_attr_type>
Handle(t_attr_type) ATTR_NODE(const int fid) const
Handle(t_attr_type) ATTR_NODE(const t_topoId fid) const
{
return Handle(t_attr_type)::DownCast( this->GetNodeAttribute( fid, t_attr_type::GUID() ) );
}
Expand Down Expand Up @@ -809,7 +815,7 @@ class asiAlgo_AAG : public Standard_Transient
//! \param[in,out] out target output stream.
//! \param[in] whitespace num of spaces to prefix each row.
asiAlgo_EXPORT void
dumpNodeJSON(const int node,
dumpNodeJSON(const t_topoId node,
const bool isFirst,
Standard_OStream& out,
const int whitespace = 0) const;
Expand Down
3 changes: 2 additions & 1 deletion src/asiUI/utils/asiUI_BatchFacilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class asiUI_BatchFacilities : public Standard_Transient
public:

//! \return single instance of facilities.
static Handle(asiUI_BatchFacilities) Instance();
asiUI_EXPORT static Handle(asiUI_BatchFacilities)
Instance();

protected:

Expand Down
58 changes: 46 additions & 12 deletions src/asiUI/viewers/asiUI_ViewerPartListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <asiAlgo_Utils.h>

// asiEngine includes
#include <asiEngine_IV.h>
#include <asiEngine_Part.h>

// asiVisu includes
Expand Down Expand Up @@ -78,13 +79,15 @@ asiUI_ViewerPartListener::asiUI_ViewerPartListener(asiUI_ViewerPart*
ActAPI_ProgressEntry progress,
ActAPI_PlotterEntry plotter)
//
: asiUI_Viewer3dListener (wViewerPart, model, progress, plotter),
m_wViewerDomain (wViewerDomain),
m_wViewerHost (wViewerHost),
m_pSaveBREPAction (nullptr),
m_pShowNormsAction (nullptr),
m_pInvertFacesAction (nullptr),
m_pShowOriContour (nullptr)
: asiUI_Viewer3dListener (wViewerPart, model, progress, plotter),
m_wViewerDomain (wViewerDomain),
m_wViewerHost (wViewerHost),
m_pSaveBREPAction (nullptr),
m_pShowNormsAction (nullptr),
m_pInvertFacesAction (nullptr),
m_pShowOriContourAction (nullptr),
m_pCopyAsStringAction (nullptr),
m_pSetAsVariableAction (nullptr)
{}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -286,19 +289,20 @@ void asiUI_ViewerPartListener::populateMenu(QMenu& menu)
if ( m_pViewer->PrsMgr()->IsPresentable( STANDARD_TYPE(asiData_FaceNormsNode) ) )
m_pShowNormsAction = menu.addAction("Show face normals");
if ( m_pViewer->PrsMgr()->IsPresentable( STANDARD_TYPE(asiData_FaceContourNode) ) )
m_pShowOriContour = menu.addAction("Show face oriented contour");
m_pShowOriContourAction = menu.addAction("Show face oriented contour");
//
m_pInvertFacesAction = menu.addAction("Invert faces");
}

menu.addSeparator();
//
m_pSaveBREPAction = menu.addAction("Save to BREP...");
m_pSaveBREPAction = menu.addAction("Save to BREP...");
m_pSetAsVariableAction = menu.addAction("Set as variable");

// Add items which work for single-element selection.
if ( faceIndices.Extent() == 1 || edgeIndices.Extent() == 1 )
{
m_pCopyAsString = menu.addAction("Copy as JSON");
m_pCopyAsStringAction = menu.addAction("Copy as JSON");
}
}
}
Expand Down Expand Up @@ -355,7 +359,7 @@ void asiUI_ViewerPartListener::executeAction(QAction* pAction)
//---------------------------------------------------------------------------
// ACTION: copy as string
//---------------------------------------------------------------------------
else if ( pAction == m_pCopyAsString )
else if ( pAction == m_pCopyAsStringAction )
{
// Get highlighted sub-shapes.
TopTools_IndexedMapOfShape selected;
Expand Down Expand Up @@ -421,7 +425,7 @@ void asiUI_ViewerPartListener::executeAction(QAction* pAction)
//---------------------------------------------------------------------------
// ACTION: show oriented contour
//---------------------------------------------------------------------------
else if ( pAction == m_pShowOriContour )
else if ( pAction == m_pShowOriContourAction )
{
TIMER_NEW
TIMER_GO
Expand Down Expand Up @@ -475,4 +479,34 @@ void asiUI_ViewerPartListener::executeAction(QAction* pAction)
m_pViewer->PrsMgr()->Actualize(part_n);
m_pViewer->PrsMgr()->Actualize( m_model->GetPartNode()->GetNormsRepresentation() );
}

//---------------------------------------------------------------------------
// ACTION: set as variable
//---------------------------------------------------------------------------
if ( pAction == m_pSetAsVariableAction )
{
// Get highlighted sub-shapes
TopTools_IndexedMapOfShape selected;
asiEngine_Part( m_model, m_pViewer->PrsMgr() ).GetHighlightedSubShapes(selected);

// Prepare a shape to set as a variable
TopoDS_Shape shape2Var;
//
if ( selected.Extent() == 1 )
shape2Var = selected(1);
else
{
// Put selected shapes to a compound
TopoDS_Compound comp;
BRep_Builder().MakeCompound(comp);
//
for ( int k = 1; k <= selected.Extent(); ++k )
BRep_Builder().Add( comp, selected(k) );
//
shape2Var = comp;
}

// Add variable via the imperative plotter
m_plotter.DRAW_SHAPE(shape2Var, Color_Yellow, "var");
}
}
5 changes: 3 additions & 2 deletions src/asiUI/viewers/asiUI_ViewerPartListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ protected slots:
QAction* m_pSaveBREPAction;
QAction* m_pShowNormsAction;
QAction* m_pInvertFacesAction;
QAction* m_pShowOriContour;
QAction* m_pCopyAsString;
QAction* m_pShowOriContourAction;
QAction* m_pCopyAsStringAction;
QAction* m_pSetAsVariableAction;

};

Expand Down
14 changes: 14 additions & 0 deletions src/cmdEngine/cmdEngine_Inspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,20 @@ int ENGINE_FindIsomorphisms(const Handle(asiTcl_Interp)& interp,
TColStd_PackedMapOfInteger convexOnlyFaces;
G->FindConvexOnly(convexOnlyFaces);
G->PushSubgraphX(convexOnlyFaces);

interp->GetProgress().SendLogMessage( LogInfo(Normal) << "Num. of convex faces to exclude: %1."
<< convexOnlyFaces.Extent() );
isReduced = true;
}
//
if ( interp->HasKeyword(argc, argv, "nobase") )
{
TColStd_PackedMapOfInteger baseOnlyFaces;
G->FindBaseOnly(baseOnlyFaces);
G->PushSubgraphX(baseOnlyFaces);

interp->GetProgress().SendLogMessage( LogInfo(Normal) << "Num. of base faces to exclude: %1."
<< baseOnlyFaces.Extent() );
isReduced = true;
}

Expand Down
2 changes: 0 additions & 2 deletions src/exe/ui/exe_CommonFacilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class exe_CommonFacilities : public asiUI_CommonFacilities
public:

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

//! Visualization facilities.
struct t_prs
Expand Down
6 changes: 3 additions & 3 deletions src/exe/ui/exe_MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ void exe_MainWindow::createDockWindows()

// Initialize and connect progress listener.
cf->Logger = new asiUI_Logger(Widgets.wLogger);
cf->ProgressListener = new asiUI_ProgressListener(statusBar,
cf->Progress.Access(),
cf->Logger);
cf->ProgressListener = new asiUI_ProgressListener( statusBar,
cf->Progress.Access(),
Handle(asiUI_Logger)::DownCast(cf->Logger) );
cf->ProgressListener->Connect();

/* ==================================
Expand Down

0 comments on commit 36f2bab

Please sign in to comment.