interactive selection of STL model triangles and edit ASCII STL file
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
interactive selection of STL model triangles and edit ASCII STL file
I want to create a system that imports, edits and exports ASCII STL files (CAD file). Let me explain what I need and so what I mean as editing an STL file. I want to use an example. Consider the following STL file:
solid my_created_solid
facet normal 1.217327e-001 -6.162551e-002 -9.906480e-001
outer loop
vertex 9.211285e-002 8.592563e-002 1.910523e-001
vertex 9.977442e-002 8.592563e-002 1.921054e-001
vertex 9.954187e-002 8.500294e-002 1.921164e-001
endloop
endfacet
facet normal 1.519745e-001 -3.081203e-002 -9.879041e-001
outer loop
vertex 9.954187e-002 8.500294e-002 1.921164e-001
vertex 9.210512e-002 8.500294e-002 1.910942e-001
vertex 9.211285e-002 8.592563e-002 1.910523e-001
endloop
endfacet
endsolid
If you know the structure of a STL file, in this specific case, it is composed of two triangles (2 lists of points) and their relative normals. What I need is the GUI that let me pick some specific triangles and create a file like this:
solid I_part
facet normal 1.217327e-001 -6.162551e-002 -9.906480e-001
outer loop
vertex 9.211285e-002 8.592563e-002 1.910523e-001
vertex 9.977442e-002 8.592563e-002 1.921054e-001
vertex 9.954187e-002 8.500294e-002 1.921164e-001
endloop
endfacet
endsolid
solid II_part
facet normal 1.519745e-001 -3.081203e-002 -9.879041e-001
outer loop
vertex 9.954187e-002 8.500294e-002 1.921164e-001
vertex 9.210512e-002 8.500294e-002 1.910942e-001
vertex 9.211285e-002 8.592563e-002 1.910523e-001
endloop
endfacet
endsolid
Practically I need to select the triangles to put in I_part and those in II_part by mouse clicking.
So I'm thinking to use Freecad GUI to do that. Is it possible to select just some triangles? Could you suggest which functions/classes it uses to return the selected triangles? Could you give me some instructions or suggestions to start this applications? It's a research work, so I'm covering all useful information to get it easier. I used in the past FreeCAD for just small CAD editing, but never coded with it.
solid my_created_solid
facet normal 1.217327e-001 -6.162551e-002 -9.906480e-001
outer loop
vertex 9.211285e-002 8.592563e-002 1.910523e-001
vertex 9.977442e-002 8.592563e-002 1.921054e-001
vertex 9.954187e-002 8.500294e-002 1.921164e-001
endloop
endfacet
facet normal 1.519745e-001 -3.081203e-002 -9.879041e-001
outer loop
vertex 9.954187e-002 8.500294e-002 1.921164e-001
vertex 9.210512e-002 8.500294e-002 1.910942e-001
vertex 9.211285e-002 8.592563e-002 1.910523e-001
endloop
endfacet
endsolid
If you know the structure of a STL file, in this specific case, it is composed of two triangles (2 lists of points) and their relative normals. What I need is the GUI that let me pick some specific triangles and create a file like this:
solid I_part
facet normal 1.217327e-001 -6.162551e-002 -9.906480e-001
outer loop
vertex 9.211285e-002 8.592563e-002 1.910523e-001
vertex 9.977442e-002 8.592563e-002 1.921054e-001
vertex 9.954187e-002 8.500294e-002 1.921164e-001
endloop
endfacet
endsolid
solid II_part
facet normal 1.519745e-001 -3.081203e-002 -9.879041e-001
outer loop
vertex 9.954187e-002 8.500294e-002 1.921164e-001
vertex 9.210512e-002 8.500294e-002 1.910942e-001
vertex 9.211285e-002 8.592563e-002 1.910523e-001
endloop
endfacet
endsolid
Practically I need to select the triangles to put in I_part and those in II_part by mouse clicking.
So I'm thinking to use Freecad GUI to do that. Is it possible to select just some triangles? Could you suggest which functions/classes it uses to return the selected triangles? Could you give me some instructions or suggestions to start this applications? It's a research work, so I'm covering all useful information to get it easier. I used in the past FreeCAD for just small CAD editing, but never coded with it.
Re: interactive selection of STL model triangles and edit ASCII STL file
Is it intended to write out several solids into a single STL file? I know that some applications do this too but I wonder if this is covered by the format specification.solid I_part
facet normal 1.217327e-001 -6.162551e-002 -9.906480e-001
outer loop
vertex 9.211285e-002 8.592563e-002 1.910523e-001
vertex 9.977442e-002 8.592563e-002 1.921054e-001
vertex 9.954187e-002 8.500294e-002 1.921164e-001
endloop
endfacet
endsolid
solid II_part
facet normal 1.519745e-001 -3.081203e-002 -9.879041e-001
outer loop
vertex 9.954187e-002 8.500294e-002 1.921164e-001
vertex 9.210512e-002 8.500294e-002 1.910942e-001
vertex 9.211285e-002 8.592563e-002 1.910523e-001
endloop
endfacet
endsolid
In which language? C++ or Python?So I'm thinking to use Freecad GUI to do that. Is it possible to select just some triangles? Could you suggest which functions/classes it uses to return the selected triangles?
Re: interactive selection of STL model triangles and edit ASCII STL file
Which software does this? I think it is not covered by the format specifications but it's not a my problem
What you want
I want to understand the possibility and how to do that
Re: interactive selection of STL model triangles and edit ASCII STL file
I was unsure about this since you wrote solid I_part and solid II_part in one block and that's why I asked. About the SW I don't know which one this does but in the past I saw Ascii STL files with multiple solids definition.Which software does this? I think it is not covered by the format specifications but it's not a my problem
OK, then I explain it in C++.What you want
I want to understand the possibility and how to do that
Here you will find an example. What you basically need is a C++ function with this interface:
void myCallbackFunc(void * ud, SoEventCallback * n)
You then have to register it for a certain event. In your case a mouse-click event will be fine.
Code: Select all
Gui::Document* doc = Gui::Application::Instance->activeDocument();
Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), myCallbackFunc);
}
From this pointer you get an SoDetail pointer where you have to verify that it's an SoFaceDetail. If the test succeeds you get an index number which refers to the triangle in the mesh data structure. An example how to access this triangle you will find here.
Re: interactive selection of STL model triangles and edit ASCII STL file
Thanks for your useful information
Now I'm sure that I can do what I want with FreeCAD.
But now I need to understand how to create my first FreeCAD application.
Could please guide me in download, install correctly the FreeCAD library and dependencies, and how to create my first application with it?
After that I'll start to study classes and functions to create the application I need.
Waiting for your reply...
Thanks again!
Now I'm sure that I can do what I want with FreeCAD.
But now I need to understand how to create my first FreeCAD application.
Could please guide me in download, install correctly the FreeCAD library and dependencies, and how to create my first application with it?
After that I'll start to study classes and functions to create the application I need.
Waiting for your reply...
Thanks again!
Re: interactive selection of STL model triangles and edit ASCII STL file
In order to do this you need to build FreeCAD directly from the source code. Dependent on your OS one of the following links is what you should study:Could please guide me in download, install correctly the FreeCAD library and dependencies, and how to create my first application with it?
https://www.freecadweb.org/wiki/CompileOnWindows
https://www.freecadweb.org/wiki/CompileOnUnix
https://www.freecadweb.org/wiki/CompileOnMac
But maybe it's easier for you to do this in Python because therefore you can use your installed FreeCAD version and write a little macro. The idea is basically the same, it's just the syntax that is different.
Code: Select all
list_of_indexes = []
def myCallbackFunc(event_cb):
event = event_cb.getEvent()
if event.getButton() == coin.SoMouseButtonEvent.BUTTON1 and event.getState() == coin.SoMouseButtonEvent.DOWN:
pp = event_cb.getPickedPoint()
if not pp is None:
detail = pp.getDetail()
if detail.isOfType(coin.SoFaceDetail.getClassTypeId()):
face_detail = coin.cast(detail, str(detail.getTypeId().getName()))
index = face_detail.getFaceIndex()
global list_of_ibdexes
list_of_indexes.append(index)
cbfunc = Gui.ActiveDocument.ActiveView.addEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), myCallbackFunc)
# click the triangles you need
# ...
Gui.ActiveDocument.ActiveView.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), cbfunc)
mesh = App.ActiveDocument.ActiveObject.Mesh
submesh=mesh.meshFromSegment(list_of_indexes)
submesh.write("mymesh.stl","AST")
Re: interactive selection of STL model triangles and edit ASCII STL file
Actually I'm a bit confused
What it's not clear is if I need to build FreeCAD from the source code or just download the release version and do the script in Python?
I've understood that they are two different equivalent options.
If it is the second option valid (install release version and create a script in python), how to use that? Is there a guide about how to use Python script in the FreeCAD GUI for released version?
Thanks
What it's not clear is if I need to build FreeCAD from the source code or just download the release version and do the script in Python?
I've understood that they are two different equivalent options.
If it is the second option valid (install release version and create a script in python), how to use that? Is there a guide about how to use Python script in the FreeCAD GUI for released version?
Thanks
Re: interactive selection of STL model triangles and edit ASCII STL file
If you use Python it suffices to use the release version. If you want to use C++ you have to get the source code and build FreeCAD from there. Then you have to write your own workbench and therefore you need the header files and library files in order to build your code.What it's not clear is if I need to build FreeCAD from the source code or just download the release version and do the script in Python?
Maybe somewhere in the Wiki. The easiest is to put the script into the macro folder (see the destination folder when opening Macro > Macros...). Then under Tools > Customize > Macro tab you can associate the macro with a command which can be added to custom toolbars.If it is the second option valid (install release version and create a script in python), how to use that? Is there a guide about how to use Python script in the FreeCAD GUI for released version?
Edit:
https://www.freecadweb.org/wiki/Macros
https://www.freecadweb.org/wiki/Interface_Customization
Re: interactive selection of STL model triangles and edit ASCII STL file
Thanks a lot
I want to try both the solutions to experiment the best one.
About the creation of macros I'm stuck in display mesh on FreeCAD. What I mean is:
Moreover I tried to install source of FreeCAD.
I got the following problems:
What's the problem with those libraries?
Is the command above enough to completely install all dependencies on Ubuntu 14.04 machine?
Thanks
I want to try both the solutions to experiment the best one.
About the creation of macros I'm stuck in display mesh on FreeCAD. What I mean is:
- I import the STL file
- I create the macro with your updated code
- The problem is that I don't see the mesh on the 3D navigation panel so I cannot see the triangles, plus how to activate the python command line editor?
Moreover I tried to install source of FreeCAD.
I got the following problems:
Code: Select all
sudo apt install build-essential cmake python python-matplotlib libtool libcoin80-dev libsoqt4-dev libxerces-c-dev libboost-dev libboost-filesystem-dev libboost-regex-dev libboost-program-options-devlibboost-signals-dev libboost-thread-dev libboost-python-dev libqt4-dev libqt4-opengl-dev qt4-dev-tools python-dev python-pyside pyside-tools libeigen3-dev libqtwebkit-dev libshiboken-dev libpyside-dev libode-dev swig libzipios++-dev libfreetype6 libfreetype6-dev liboce-foundation-dev liboce-modeling-dev liboce-ocaf-dev liboce-visualization-dev liboce-ocaf-lite-dev libsimage-dev checkinstall python-pivy python-qt4 doxygen libspnav-dev oce-draw liboce-foundation-dev liboce-foundation10 liboce-foundation8 liboce-modeling-dev liboce-modeling10 liboce-modeling8 liboce-ocaf-dev liboce-ocaf-lite-dev liboce-ocaf-lite10 liboce-ocaf-lite8 liboce-ocaf10 liboce-ocaf8 liboce-visualization-dev liboce-visualization10 liboce-visualization8 libmedc-dev libvtk6-dev libproj-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package liboce-foundation10
E: Unable to locate package liboce-modeling10
E: Unable to locate package liboce-ocaf-lite10
E: Unable to locate package liboce-ocaf10
E: Unable to locate package liboce-visualization10
Is the command above enough to completely install all dependencies on Ubuntu 14.04 machine?
Thanks
Re: interactive selection of STL model triangles and edit ASCII STL file
Those are the names in 16.04 if I'm not mistaken. Instead of specifying the oce packages individually, you can just install these packages:
Code: Select all
liboce-foundation-dev
liboce-modeling-dev
liboce-ocaf-dev
liboce-ocaf-lite-dev
liboce-visualization-dev