Youtube lessons

David

Active CAD practitioner
Here is some snippet:
BRepAlgoAPI_Cut aBuilder;
...
aBuilder->Build();
ShapeUpgrade_UnifySameDomain shapeUpgrade_aWorkPiece(aWorkPieceCopy); // important after Boolean operation
shapeUpgrade_aWorkPiece.Build(); //so far normal Cut Operation
BRepAlgoAPI_Section asect(aWorkPiece, aTool, Standard_False); // getting the intersection
asect.Approximation(Standard_True);
asect.Build();
TopoDS_Shape aInterface = asect.Shape();

//doing HLR to get the projection of the aInterface on a plane
myAlgo->Add(aInterface);
myAlgo->Update();
HLRBRep_HLRToShape aHLRToShape(myAlgo);
TopoDS_Shape aProjectedContactFace; //projected shape of contact
aProjectedContactFace = aHLRToShape.VCompound(); //visible projected shapes are used
ShapeFixIt(aProjectedContactFace); //some healing
Handle(TopTools_HSequenceOfShape) EdgesQ = new TopTools_HSequenceOfShape(); // exploring all Edges
Handle(TopTools_HSequenceOfShape) Wires = new TopTools_HSequenceOfShape(); // to create Wires
TopExp_Explorer anEdgeExplorer(aProjectedContactFace, TopAbs_EDGE);
while (anEdgeExplorer.More())
{
TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current());
ShapeFixIt(anEdge); //some healing
EdgesQ->Append(anEdge);
anEdgeExplorer.Next();
}
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(EdgesQ, 5.0, false, Wires); // 5.0 worked frequently
Handle(TopTools_HSequenceOfShape) ClosedWires = new TopTools_HSequenceOfShape();
Handle(TopTools_HSequenceOfShape) OpenWires = new TopTools_HSequenceOfShape();
ShapeAnalysis_FreeBounds::SplitWires(Wires, 1.0, false, ClosedWires, OpenWires);
//from here onwards we only use the ClosedWires for further area calculation (making faces and then asking MassPropoerties).

Problem still is: the projected Contact Face (aProjectedContactFace) looks like a scattered out contour but the ConnectEdgesToWires is able to get a closed wire from it.
 

Attachments

  • face.jpg
    face.jpg
    36.4 KB · Views: 6

Quaoar

Administrator
Staff member
@David do you mean that ConnectEdgesToWires does not do the job? I would expect that HLR ends up with an unsorted result, possibly containing overlapping edges and all kinds of handling geometries. This kind of issue is pretty similar to what one may face, e.g., after reading a DXF drawing. Do you need to recover an outer contour as a single WIRE? Could there be any inner contours? What is this projection used for later on?

Update: if you tell more about your use case, it will help.
 
Last edited:

David

Active CAD practitioner
@Quaoar: that is exactly my problem. I would need a single outer contours as a single WIRE, but I get overlapping edges and all kind of geometries.
What I need is just to show the projection to the user and to calculate its area. Any idea ?

By the way, I forgot to mention, that I highly appreciate your excellent youtube videos and your efforts like this forum. This brings OCCT really a big step furhter in acceptance.
 

Quaoar

Administrator
Staff member
@David if all you need is a single contour and the corresponding covered area, what if you discretize the input first (using GCPnt package) and then recover a K-neighbors hull (you'll have to implement one or you can use some existing 3-rd party)? You will naturally lose all analytical geometries and inner contours but from what you're saying, I understood that's kinda Ok. Won't this work?
 

karim

CAD community veteran
I wonder if anybody else feels the need for more lessons on the TDataStd_* types ? I think some more explanations in this direction can be very helpful.
 

Quaoar

Administrator
Staff member
@karim Fair enough. I added your proposal to the list, although I'm having a hard time trying to allocate time for lessons. Hopefully, that's only till the end of the year.
 

David

Active CAD practitioner
@David if all you need is a single contour and the corresponding covered area, what if you discretize the input first (using GCPnt package) and then recover a K-neighbors hull (you'll have to implement one or you can use some existing 3-rd party)? You will naturally lose all analytical geometries and inner contours but from what you're saying, I understood that's kinda Ok. Won't this work?
I used the K-neighbors approach for the concave hull without any third party library (to keep it simple). But I realized it is slow due to the incremental increase of neighbours if not all points had been considered. And secondly, it did not find solutions in a lot of cases where a high number of internal points existed. Therefore I used successfull another implementation based on a paper from M. Duckham, L. Kulik, M. F. Worboys, and A. Galton. "Efficient generation of simple polygons for characterizing the shape of a set of points in the plane". Pattern Recognition, 41:3224–3236, 2008.. The paper uses the term characteristic shape to refer to the shapes generated by the algorithm. The concavity of the shape depends on a scalar ranging from 0 to 1 called the chi factor. A value of 0 leads to the most concave, and 1 leads to the convex hull.
There is already a c++ version based on this paper under: https://github.com/senhorsolar/concavehull/blob/main/src/concavehull.hpp.
 

rajendrasp79

Looking around for some CAD
I would love to understand in depth selection of entities in OCC. How can we select entities and how can we add manipulators to help drag/rotate/ etc? As an example Solidworks has this UI (coordinate system) to help with dragging the model. Is that available in OCC and if not, how can we add it?

1643634505798.png
 

natalia

Moderator
Staff member
Hi guys

The sample how select, detect and use OCCT manipulator is now available in 'extras_viewerManipulator' of https://gitlab.com/ssv/lessons/-/tree/viewerManipulator

Some snapshot how it works is:

occt_manipulator.gif

AIS_Manipulator is an object that attached to other OCCT presentations and changes transformation of them depending on the selected part of the manipulator. The main ‘magic’ of it is implemented in ‘ProcessDragging’ method. We need to call it when the mouse events are processed.

In the sample above the ViewerInteractor class is responsible for this. The mousePressEvent/mouseMoveEvent/mouseReleaseEvent methods there either call processing the drag by presentation or perform the viewer action like pan/rotate/zoom or select the clicked object.


Also, a sample how to use this manipulator is available by a ‘vmanipulator’ DRAW command of OCCT with implementation in ViewerTest.
 
Top