Hello all
Is "https://github.com/kanzure/python-brlcad" avaliable with py3. Tried but returned with errors, so I tried with 2to3 and did some changes in "post_install.py" but probably also ctypesgen is not available in py3 ??
@scorp08 I don't think anyone has tried getting it to work with py3 yet. My guess is that it'll need to be switched to cffi or some other approach. There is a python binding that calls mged directly and avoids ctypesgen that may work better in the meantime.
@Sean , what is cffi ? Did you mean https://github.com/nmz787/python-brlcad-tcl this package
Yes, that one should still work just fine
https://cffi.readthedocs.io/en/latest/
I convert some issues to py3 for kanzure/python-brlcad but when it comes to parsing, ctypesgen is not compatible and seems that development is stopped. Currently I get error as "there is no optimize.lexer attribute". I do not know how to rewrite brlcad-python with cffi as it uses ctypesgen from beginning ?
@scorp08 if I recall correctly (and it may not be), the brlcad-python project was an evolution from invoking mged directly to using ctypesgen. towards what you're wanting to do, though, I'm not sure why it matters whether it uses ctypesgen from the beginning -- it uses it now and that's obviously a problem if you want to use python3.
if you can't do the conversion to cffi, you'd either have to use the python-brlcad-tcl version that runs mged or wait indefinitely for someone to work on py3 support or use python2.7. fixing ctypesgen is no small task as it worked by directly outputting python code, which needs to be generated differently for py3.
@Sean Thanks. How can I do conversion ? At leat once the starting point will be identified, rest will come through more easily.
You'd need to read up on ctypesgen
There are some hits here for ".lexer" https://github.com/davidjamesca/ctypesgen/pull/55/files?diff=split
"Merge in various changes from kanzure and olsonse"
Looks like these haven't been merged in and released, so you probably could try grabbing the unreleased code and running with that
There's also SWIG, but I think kanzure had some thoughts on why that would be harder to use
http://www.swig.org/Doc1.3/Python.html#Python_python3support
Although in swig's defense, it would have survived all py2 to py3 changes unlike ctypesgen ;)
I think the concerns he had with swig were that it would pass through the C api and not be as clean as the wrapped version from ctypesgen. I'd think it's be possible to wrap the output from swig just as neatly though, at least as neatly as the ctypesgen wrap.
@Nathan McCorkle , @Sean , I installed another repo of ctypesgen which is compatible with py3. Currently doing some conversion of brlcad-python to py3. Do I need to go for another dep. like ctypesgen or continue with it ?? What do you think ?
@scorp08 I don’t think so but I guess you’ll find out :). Have to just look through the imports and try it. Keep the updates coming!
I'm not sure, I never got kanzure's library to work even with Python2, or maybe it lacked hooks for the features I wanted to use. It was a lot less work to think about just wrapping command-line stuff with Python than all the work you're doing! I will gladly check your work as you progress though!! Let me know where your code lives and I'll grab your branch.
For writing a custom GUI for building 3D models, the command-line stuff I did is actually too slow, so I'm definitely interested.
We were just looking at mged's command-line performance a while back and noticed some massive slowness and room for optimization. Curious though what specifically you saw that was slow, whether it was the same issue or something else.
Frankly, I think the wrapped approach is still going to be about 1/10th the effort of any binary method. Of course, it'll b about a 1/10th performance tradeoff no matter what just from binary startup time, but still should be fast enough for 90% of cases. If we fixed the slowness we found, it'd probably be 98% of cases.
I manage to install to py3 but when I run an example below, returned with pointer error. Some help need related with brlcad.wdb
from brlcad.vmath import Transform
from brlcad.wdb import WDB
from brlcad import primitives
if __name__ == "__main__":
with WDB("test_wdb.g", "Test BRLCAD DB file") as brl_db:
brl_db.sphere(
"sph1.s",
center=(1, 2, 3),
radius=0.75
)
If you want , I can create a repo and you can edit the code
@scorp08 yeah throw it on github/etc and I'll give it a try.
@Sean I can't remember what I was trying to do, but it was pretty dumb... Something like using nirt to export an image (or maybe mged has a function like that, it's been a while and I haven't checked my local code), then taking that image (JPG/PNG/BMP) and displayed it in a Python GUI image-frame. Then if the user clicked and dragged, it would adjust the rotation, re-request an image to be exported from BRLCAD, then re-display. Super dumb, but quite low effort exerted. I think I was getting like 1FPS.
Ooooh, haha .. so basically using nirt to render an image?? Yeah.. that's crazy :)
Nowadays I m on a long road, I'll try to upload and focus on nextweek. Examples in brlcad-python git is working in my py3 but could not run rt_shoot inside the librt...
Are there any doc. for tcl bindings for qt (it seems that there is an example for treewidget) but could not find any project related with qt framework of brl_cad
Nowadays I m on a long road, I'll try to upload and focus on nextweek. Examples in brlcad-python git is working in my py3 but could not run rt_shoot inside the librt...
Any progress @scorp08 ?
Are there any doc. for tcl bindings for qt (it seems that there is an example for treewidget) but could not find any project related with qt framework of brl_cad
I assume you meant Tk bindings, and the answer is no. Regardless, we have no intention of sticking with Tk. Qt GUI can/should be pure Qt goodness.
Tcl will likely linger for a while longer but even that is getting pushed into the foreground as just one of several scripting interface possibilities, out of libraries and application infrastructure.
Hello
How brl-cad display 3d .g files in screen. I was searching to implement it to pyqt with opengl. Also checked this repo https://sourceforge.net/p/brlcad/code/HEAD/tree/rt%5E3/trunk/src/QtGUI/ but no tool to show in screen
yeah I also tried to get that QtGUI to compile but don't believe I was able to... my memory on that effort is fuzzy, but I think it boils down to the documentation for that code not being too great, and the makefiles for the whole BRLCAD build not being kept syncronized to allow building that GUI... but I could be wrong, I think it was like a year ago, or more, that I tried.
Did you ever get a chance to commit/upload your Python3 progress? I have a very simple Python GUI to show 3D .g files in, but it is VERY slow... I wonder if your code would give my GUI any reasonable speed-up
@Daniel Rossberg any writeup on how to compile that QT GUI?
make QtGUI
@Nathan McCorkle I'll try to upload today though there is a problem. When _bindings folder is generated, binders opens dll files in the libraries with ctypes. Some of dll's depends each other so setup.py need to see \bin folder otherwise as in my setup , it will return error "no module found". Is it done with os.chdir or any other better way ?
Hello All
My repo is ready for py3 in here( https://github.com/scorp08/python-brlcad). Some small arrangements may be neccessary in ctypesgen side. I created a pull request in olsense's repo. If you install my repo, you may need to apply those changes. Before install you can do neccessary work in .cfg file to arrange path locations of brl-cad and mingw
If there is a stuff to be added, please pull :)
@Daniel Rossberg , @Nathan McCorkle Which repo is more usefull for the GUI : g3d or QtGUI , are they independent from each other ? maybe I will convert to PyQt ,use opengl etc.
Are there a CAD kernel used in BRL-CAD (parasolid etc. ) ? Also are there a step to .g converter or a source code to open step file in database ?
Daniel Rossberg , Nathan McCorkle Which repo is more usefull for the GUI : g3d or QtGUI , are they independent from each other ? maybe I will convert to PyQt ,use opengl etc.
I can't say much about g3d, but, QtGUI can be used as inspiration for the creation of an own Qt based BRL-CAD GUI. They are independent from each other.
Are there a CAD kernel used in BRL-CAD (parasolid etc. ) ? Also are there a step to .g converter or a source code to open step file in database ?
BRL-CAD has its own CAD kernel, which is mainly the librt. There exists even a C++ interface for it.
And, yes there is a step-g converter, which is open source.
Is interface open-source ?
Do we talk about the same software suite? Which content of the BRL-CAD repository is not open source?
Are there a CAD kernel used in BRL-CAD (parasolid etc. ) ? Also are there a step to .g converter or a source code to open step file in database ?
BRL-CAD has its own CAD kernel, which is mainly the librt. There exists even a C++ interface for it.
And, yes there is a step-g converter, which is open source.
I meant the interface for librt
Sure, it is in the BRL-CAD repository, in the rt^3 branch. It's called coreinterface there.
In principle it's the same as the brlcad.dll (SDK download: https://sourceforge.net/projects/brlcad/files/BRL-CAD%20Runtime%20Libraries/7.26.0/, sources are in the main branch misc/win32-msvc/Dll directory (uses the stuff in rt^3 too), see also https://brlcad.org/wiki/BRL-CAD%27s_core_C%2B%2B_interface)
The rt^3 QtGUI with the brlcad.dll as back-end: https://github.com/drossberg/BrlCadQtGUI
Ctypesgen contains an UNCHECKED function in https://github.com/olsonse/ctypesgen/blob/master/ctypesgen/printer_python/preamble/3_2.py which cause callbacks of Cfunctypes to return void. Seems that need to put an __type__.encode() but why in the first place do we need it, do you think ?
can libwdb be a kernel too ? or only librt ?
After using step-g converter , raytrace worked a bit slow in resulting files.So are there any development in converter or is it neccessary to add some stuff ? What do you think ?
@Sean When step-g convert Step Structures to brep structures, does resulting .g contains meshes or nurbs ? Does it contains brl-cad primitives too ?
@scorp08 it imports brep nurbs
It’d be nice to expand support to meshes, but they are rarely seen with real models
@Sean is there a neccessity to modify step-g (increase performance, increase raytrace speed etc) ? is there a project idea?
What kind of method is used raytrace for nurbs ? Are there a possible faster approach ? Maybe need to check articles etc.
Sean is there a neccessity to modify step-g (increase performance, increase raytrace speed etc) ? is there a project idea?
@scorp08 "neccessity"? well that certainly depends on what one's requirements are. it imports ap203 (v1) nurbs models just fine. it doesn't import meshes, doesn't import surface-only model, doesn't handle ap203v2 or ap214 or ap242. those are all features that would be GREAT to have and would make for good project ideas, any of them.
the performance of step-g is typically inconsequential, people would wait hours if they knew it always worked and could trust everything got imported.
converters don't do ray tracing, so do you mean ray tracing of NURBS? that is absolutely a grand project idea.
raytracing nurbs is a super complicated topic, but there is definitely room for improvement in our current implementation. our implementation is based loosely on a 2006 paper on Interactive ray tracing of NURBS. However, we build surface tree's that are unnecessarily deep and it would probably benefit greatly from dynamic surface trees, building them on the fly during ray tracing. it would also benefit greatly from simple memory coherency optimization, e.g., to evaluate bundles of rays at a time instead of individually as nurbs structures are memory-intensive.
@Sean http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.90.7500&rep=rep1&type=pdf this paper ?
Yes, that's the one! We didn't get to the coherent data packing technique they're using, but the general idea of directly evaluating the NURBS surfaces (as opposed to the historic method of subdividing into Bezier or B-Spline patches or polygonal meshes), is essentially the method we're using.
@Sean Thnks, is brlcad 7.24 using it ? I checked the rt_shootray in librt/shoot.c but could not find a connection between that paper ?
Yes it is. You'd have to follow much deeper to actual NURBS logic, which resides in src/librt/primitives/brep
is rt_brep_shot used when shoot to brep ? I thought that theres only one single shoot function which is rt_shootray ?
But, how does rt_shootray know how to ray-trace the primitives? You may have noticed stp->st_meth->ft_shot() in rt_shootray()'s source code. This is a function pointer which points to the primitive specific ray-trace algorithms. Look at it in a debugger.
I would like to divide regions of e.g parasolid file in another CAD software, give names those regions and after convert to .g file via converters, see regions and same names. Is it possible. I tried UG but after converting, got all regions as "all" one single entity in archer
@scorp08 you can think of the rt_*_shot() functions as a basic ray-primitive intersection test which does not typically involve scene traversal, whereas rt_shootray() does
@scorp08 what does "l all" show? Geometry is typically a hierarchy. If you created multiple regions, then they will typically import as multiple regions but then a group is usually still created that combines everything together. The individual regions are still there though.
@Sean Does brlcad has still fastest raytrace kernel ? Can it be powered with NVIDIA OptiX?
@scorp08 that has become a heavily loaded question -- it very much depends what you are comparing, what is valued, and what is supported in a given ray tracing kernel to be able to talk about it's performance. BRL-CAD does have the fastest solid ray tracing with a substantial investment in verification and validation (i.e., it's "more correct" than most with regards to edge case behavior).
there are faster ray tracing kernels for specific types of geometry (e.g., triangle-only ray tracing) or first-hit ray tracing, but they typically don't have verification and validation and if you need solidity, they can be non-starters
We have an experimental OpenCL pipeline that will utilize GPU cores, but it has remained experimental because most real models our main customers ray trace do not come close to fitting on a video card.
It remains an interesting and desirable area of research, particularly for NURBS ray tracing. Our NURBS ray tracing implementation is unoptimized, too, so even basic work there would be a huge benefit (orders of magnitude).
Does brlcad use BSP trees ? or octree ?
@Sean converted a parasolid file containing multiple bodies to stl in nx then convert it to .g with stl-g.exe. but parasolid-stl conversion in nx created one solid body so after stl-g, it is showing only one region as normally
@Sean considering for example two huge (limits up to 14 m) geometries from stl to .g (12 MB size) and one is modeled with primitives (2 MB), is it possible to obtain same rt_shootray performance if shoot to different locations and a lot of times in resulting .g models??
@scorp08 Eh... STL only supports one object per file. So whatever you exported got combined into one entity before it ever got to BRL-CAD.
You should really avoid STL if at all possible. It's a terribly limited and typically lossy format.
Sean considering for example two huge (limits up to 14 m) geometries from stl to .g (12 MB size) and one is modeled with primitives (2 MB), is it possible to obtain same rt_shootray performance if shoot to different locations and a lot of times in resulting .g models??
Primitives will typically out-perform triangles when your mesh density is approximately pixel-sized or smaller. You typically have to tessellate to sub-pixel (1M+ triangles) to get something with curvature equivalence (at least for any reasonable spectral / shading comparison).
@Sean if we compare nurbs(powered with gpu support) vs primitives raytrace, can it be possible to reach to primitive shoot performance ??
It depends. Are the primitives also GPU-accelerated? Does the model fit on a GPU? Are there more primitives and/or Boolean operations than there are NURBS control points? ... :)
@Sean https://brlcad.org/wiki/OpenCL_GPGPU_Brep_Raytracing here is said that there needs to be conversion of object oriented C to strict ANSI C (C99- strict) for opencl . Why strict is neccessary ??
@scorp08 I think that statement is out-of-date and was written well before we had a preliminary pipeline. The conversion that refers to is that the existing library uses a lot of function callbacks, which you can't do on the GPU. The simple workaround was to just call the appropriate OpenCL callback explicitly, I believe. Either way, it wasn't as complex as originally envisioned (or at least, it's all relative).
OH, sorry, I misread -- that's specifically about converting BREP objects to OpenCL. Yes! That must be converted to C. I don't think the "strict" part is actually necessary in a language-sense. I believe it's referring to the source code itself, that you don't have objects in OpenCL, only functions. So if you're going to convert, you need functions to convert.
Still, more than half the code is already C. It's the OpenNURBS portions (which are all C++) that would need to be extracted to be accelerated appropriately.
That's a half-dozen or so functions.
thnks for answers. I had convert parasolid to step then step to .g but some curves (due to complexity ) could not be seen in .g model and shootray was much more slower than the model that I created with primitives. That's why I thught to include a gpu support to see if there are speed ups. I have some basic knowledge about raytracing, nurbs and openCL. Could you recommend a source to study ??
@scorp08 yes primitives will almost always be faster because they use less memory and are really fast to intersect. their downside is modeling time and usability, not performance.
there are massive potential speed ups for nurbs with both coherency optimization (shooting sets of rays instead of individually) as well as gpu or simd optimization. it would be approximately 10x faster each, about 100x faster overall with both. the same however can also be said of the primitives -- the same optimizations would also make them 100x faster.
Last updated: Jan 09 2025 at 00:46 UTC