Shape.fix() wiki / explanation / tutorial ?

Need help, or want to share a macro? Post here!
paullee
Posts: 1690
Joined: Wed May 04, 2016 3:58 pm

Shape.fix() wiki / explanation / tutorial ?

Postby paullee » Wed Oct 09, 2019 6:05 pm

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
Posts: 1430
Joined: Thu Oct 18, 2018 9:18 pm

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

Postby vocx » Wed Oct 09, 2019 6:34 pm

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.
wandererfan
Posts: 2982
Joined: Tue Nov 06, 2012 5:42 pm

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

Postby wandererfan » Wed Oct 09, 2019 6:44 pm

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
Posts: 1690
Joined: Wed May 04, 2016 3:58 pm

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

Postby paullee » Wed Oct 09, 2019 11:16 pm

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 .
wandererfan
Posts: 2982
Joined: Tue Nov 06, 2012 5:42 pm

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

Postby wandererfan » Wed Oct 09, 2019 11:40 pm

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
Posts: 1690
Joined: Wed May 04, 2016 3:58 pm

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

Postby paullee » Thu Oct 10, 2019 5:09 pm

Thanks digging out this piece of information ! :)