Shape.fix() wiki / explanation / tutorial ?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Shape.fix() wiki / explanation / tutorial ?

Post by paullee »

Hi, fail to find detailed explanation how and what exactly this function found in ArchWall.py works

Code: Select all

sh.fix(0.1,0,1) # fixes self-intersecting wires
Python console return below tips:-

Code: Select all

Tries to fix a broken shape. True is returned if the operation succeeded. False otherwise.
fix(working precision, minimum precision, maximum precision)
Any ideas?

Thanks.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Shape.fix() wiki / explanation / tutorial ?

Post by vocx »

paullee wrote: Wed Oct 09, 2019 6:05 pm ...

Code: Select all

Tries to fix a broken shape. True is returned if the operation succeeded. False otherwise.
fix(working precision, minimum precision, maximum precision)
This is a function of Part::TopoShape, which is the internal object that Part creates to hold the geometry.

The Python implementation is in src/Mod/Part/App/TopoShapePyImp.cpp, which just calls the corresponding Part function in src/Mod/Part/App/TopoShape.cpp

But as you see, it calls other classes and functions, like ShapeFix_Shape. This function seems to come from # include <ShapeFix_Shape.hxx>, which means it comes from OpenCASCADE directly. Then to really know what it does, you need to search OCCT documentation.

ShapeFix_Shape Class Reference
ShapeFix_Shape Class Reference wrote: ShapeFix_Shape::Perform ( const Handle< Message_ProgressIndicator > & theProgress = 0 )

Iterates on sub- shape and performs fixes.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
wandererfan
Veteran
Posts: 6320
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Shape.fix() wiki / explanation / tutorial ?

Post by wandererfan »

vocx wrote: Wed Oct 09, 2019 6:34 pm But as you see, it calls other classes and functions, like ShapeFix_Shape. This function seems to come from # include <ShapeFix_Shape.hxx>, which means it comes from OpenCASCADE directly. Then to really know what it does, you need to search OCCT documentation.

ShapeFix_Shape Class Reference
After the parameters are set in ShapeFix_Shape, the real work is done here:
https://www.opencascade.com/doc/occt-7. ... _wire.html.

Off the top of my head, it removes gaps between edges to make the wire continuous, removes tiny edges and arranges the edges in nose to tail order.
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: Shape.fix() wiki / explanation / tutorial ?

Post by paullee »

Thanks both :)

Though I do not know C++. At least have some idea what the codes do. Can't find / under how precision should be set .
User avatar
wandererfan
Veteran
Posts: 6320
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Shape.fix() wiki / explanation / tutorial ?

Post by wandererfan »

paullee wrote: Wed Oct 09, 2019 11:16 pm Though I do not know C++. At least have some idea what the codes do. Can't find / under how precision should be set .
From here:
Prec – basic precision.
maxTol – maximum allowed tolerance. All problems will be detected for cases when a dimension of invalidity is larger than the basic precision or a tolerance of sub-shape on that problem is detected. The maximum tolerance value limits the increasing tolerance for fixing a problem such as fix of not connected and self-intersected wires. If a value larger than the maximum allowed tolerance is necessary for correcting a detected problem the problem can not be fixed. The maximal tolerance is not taking into account during computation of tolerance of edges in ShapeFix_SameParameter() method and ShapeFix_Edge::FixVertexTolerance() method. See Repairing tool for edges for details.
minTol – minimal allowed tolerance. It defines the minimal allowed length of edges. Detected edges having length less than the specified minimal tolerance will be removed if ModifyTopologyMode in Repairing tool for wires is set to true. See Repairing tool for wires for details.
In your example:

Code: Select all

Prec = 0.1
minTol = 0
maxTol = 1
sh.fix(Prec, minTol, maxTol) # fixes self-intersecting wires
I'm not sure what Prec does, but 0 for minTol means no short edges are going to be removed. 1 mm for maxTol sounds huge.
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: Shape.fix() wiki / explanation / tutorial ?

Post by paullee »

Thanks digging out this piece of information ! :)
Post Reply