Page 1 of 3

Defeaturing

Posted: Fri Jun 29, 2018 3:02 pm
by Chris_G
Hi,
I am giving a try at implementing OCC Defeaturing.
My first test works on TopoShapeSolidPyImp : https://github.com/tomate44/FreeCAD/commits/defeaturing
However, I suppose TopoShapeSolid is not the right place to add this feature, since this algo is supposed to work on Solids, Compsolids, and "compounds of solids". It is probably wrong to duplicate the same code in 3 places.
How and where should I move it ?

This is currently only for python (...PyImp).
If the feature was to be added in the Part Gui, it must be first added in App/TopoShape.cpp, right ?

One thing slightly annoying is that I cannot call the python method directly on a shape :

Code: Select all

obj.Shape.removeFaces([6,7,9])
>>> ReferenceError: This object is immutable, you can not set any attribute or call a non const method
I have to call it on a copy of the shape :

Code: Select all

obj1.Shape.copy().removeFaces([6,7,9])
<Solid object at 0x55a990c314f0>


Below, a test solid (left) and the results of 3 defeaturing :

Code: Select all

Part.show(sh.removeFaces([6]))
Part.show(sh.removeFaces([7,8,14]))
Part.show(sh.removeFaces([10,11,12,13,15]))
defeaturing.png
defeaturing.png (20.12 KiB) Viewed 830 times

Re: Defeaturing

Posted: Fri Jun 29, 2018 3:25 pm
by DeepSOIC
Chris_G wrote:
Fri Jun 29, 2018 3:02 pm
One thing slightly annoying is that I cannot call the python method directly on a shape :
See my answer on GitHub

https://github.com/tomate44/FreeCAD/com ... 923d3881dc

Re: Defeaturing

Posted: Fri Jun 29, 2018 3:29 pm
by Chris_G
DeepSOIC wrote:
Fri Jun 29, 2018 3:25 pm
See my answer on GitHub
Great ! thanks.

Re: Defeaturing

Posted: Fri Jun 29, 2018 3:31 pm
by DeepSOIC
Chris_G wrote:
Fri Jun 29, 2018 3:02 pm
However, I suppose TopoShapeSolid is not the right place to add this feature, since this algo is supposed to work on Solids, Compsolids, and "compounds of solids". It is probably wrong to duplicate the same code in 3 places.
How and where should I move it ?
Implement main stuff in TopoShape.cpp and add three replicas of python translators.
OR
implement it in TopoShapePyImp, that method will then appear for all shape types. Simply test the shape type, and throw an error if it's wrong (or let OCC do it for you :mrgreen: )

I would prefer the second one, with error-throwing business left to OCC. Who knows, maybe they will implement defeaturing for wires too.

Re: Defeaturing

Posted: Fri Jun 29, 2018 4:20 pm
by Chris_G
Thanks for the help, Victor. Much appreciated.
Option 2 seems simpler, so I'll probably give a try at it first.

Re: Defeaturing

Posted: Fri Jun 29, 2018 4:21 pm
by easyw-fc
Chris_G wrote:
Fri Jun 29, 2018 3:02 pm
Hi,
I am giving a try at implementing OCC Defeaturing.
Hi Chris, that is great! :D
Do you need the OCC7.3 or your code can work also with 7.2?
Are you going to PR these tools, after your test?

I made some python tests here, but having the OCC defeaturing tools would help so much! :D

Thx
Maurice

Re: Defeaturing

Posted: Fri Jun 29, 2018 4:31 pm
by Chris_G
easyw-fc wrote:
Fri Jun 29, 2018 4:21 pm
Do you need the OCC7.3 or your code can work also with 7.2?
OCC 7.3 required.
easyw-fc wrote:
Fri Jun 29, 2018 4:21 pm
Are you going to PR these tools, after your test?
Yes, of course ... I mean, if I am able to produce "mergeable" code :lol:
easyw-fc wrote:
Fri Jun 29, 2018 4:21 pm
I made some python tests here, but having the OCC defeaturing tools would help so much! :D
I saw your tests. Great results, already ! But I suppose re-using OCC work would be the easiest for us.

Re: Defeaturing

Posted: Tue Jul 03, 2018 1:14 pm
by Chris_G
So ... here is a new branch : https://github.com/tomate44/FreeCAD/com ... featuring3
I will make a PR tomorrow, but if someone want to comment and give its opinion or advice before ...

- OCC Defeaturing is implemented in TopoShape.cpp
- python binding is added to TopoShapePy
- the Gui part is added CommandSimple.cpp

Here are a few things that are not great :
- as the method is added to TopoShape, it becomes available to all toposhapes, whereas it should only be available to "solid" shapes (solid, compsolid, compound of solids)
- the icon isn't really good
- sometimes, the tool goes into endless computation (I think the OCC tool is guilty here, but it is not great anyway)
- often, when the tool fails, it returns a copy of the input shape. I have added a check at the Gui level to prevent the creation of uneeded features in that case :

Code: Select all

sh = App.getDocument('defeaturing').Defeatured.Shape
nsh = sh.defeaturing([sh.Face8,sh.Face9,sh.Face7,])
if not sh.isPartner(nsh):
	defeat = App.ActiveDocument.addObject('Part::Feature','Defeatured').Shape = nsh
	Gui.ActiveDocument.Defeatured.hide()
else:
	FreeCAD.Console.PrintError('Defeaturing failed\n')
But maybe this check could be made earlier in the code (in TopoShape.cpp, and raise an exception if the output shape is partner to the input ) ?

Re: Defeaturing

Posted: Tue Jul 03, 2018 1:35 pm
by easyw-fc
Chris_G wrote:
Tue Jul 03, 2018 1:14 pm
So ... here is a new branch : https://github.com/tomate44/FreeCAD/com ... featuring3
I will make a PR tomorrow...
Great! :D
May be it is a dumb question, in which way can I test it in Ubuntu? and in Windoze? (OCC7.3 based)
Thanks a lot! this is a great improvement for STEP reworking.

Maurice

Re: Defeaturing

Posted: Tue Jul 03, 2018 1:57 pm
by Chris_G
easyw-fc wrote:
Tue Jul 03, 2018 1:35 pm
May be it is a dumb question, in which way can I test it in Ubuntu? and in Windoze? (OCC7.3 based)
Can you compile FreeCAD master ?
If yes, then this should be simple :

Code: Select all

git clone https://github.com/tomate44/FreeCAD.git FC-ChrisG
cd ./FC-ChrisG
git checkout defeaturing3
mkdir ./build
cd ./build
cmake .. (with your usual options)
make -j8
./bin/FreeCAD