Defeaturing

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
Chris_G
Posts: 1165
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Defeaturing

Post by Chris_G » Fri Jun 29, 2018 3:02 pm

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 710 times
User avatar
DeepSOIC
Posts: 7167
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Defeaturing

Post by DeepSOIC » Fri Jun 29, 2018 3:25 pm

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
User avatar
Chris_G
Posts: 1165
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Defeaturing

Post by Chris_G » Fri Jun 29, 2018 3:29 pm

DeepSOIC wrote:
Fri Jun 29, 2018 3:25 pm
See my answer on GitHub
Great ! thanks.
User avatar
DeepSOIC
Posts: 7167
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Defeaturing

Post by DeepSOIC » Fri Jun 29, 2018 3:31 pm

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.
User avatar
Chris_G
Posts: 1165
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Defeaturing

Post by Chris_G » Fri Jun 29, 2018 4:20 pm

Thanks for the help, Victor. Much appreciated.
Option 2 seems simpler, so I'll probably give a try at it first.
User avatar
easyw-fc
Posts: 2692
Joined: Thu Jul 09, 2015 9:34 am

Re: Defeaturing

Post by easyw-fc » Fri Jun 29, 2018 4:21 pm

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
User avatar
Chris_G
Posts: 1165
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Defeaturing

Post by Chris_G » Fri Jun 29, 2018 4:31 pm

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.
User avatar
Chris_G
Posts: 1165
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Defeaturing

Post by Chris_G » 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, 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 ) ?
User avatar
easyw-fc
Posts: 2692
Joined: Thu Jul 09, 2015 9:34 am

Re: Defeaturing

Post by easyw-fc » Tue Jul 03, 2018 1:35 pm

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
User avatar
Chris_G
Posts: 1165
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Defeaturing

Post by Chris_G » Tue Jul 03, 2018 1:57 pm

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
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests