mantidproject / mantid

Main repository for Mantid code
https://www.mantidproject.org
GNU General Public License v3.0
211 stars 124 forks source link

Investigate whether there is a python mesh viewer available #30607

Closed DannyHindson closed 3 years ago

DannyHindson commented 3 years ago

The single crystal instrument scientists at ISIS (WISH, SXD) have indicated that the lack of any screen to view sample mesh shapes in Mantid is a gap. They would like to view the shape to check that the shape and the orientation have been imported into Mantid correctly prior to running absorption correction calculations

We have discussed the fact that using third party CAD tools is an option and may make more sense than Mantid trying to implement its own shape viewer. They have asked whether there is a python based viewer available.

The two mesh formats are: stl and 3mf formats

DannyHindson commented 3 years ago

I've had a related request through that could usefully be investigated at the same time. This one is about whether there is a way of viewing a CSG description of a shape somehow in Mantid or using an external tool. I'd like to look at whether there is a way of exporting the CSG description in a commonly used format to begin with. If the CSG format isn't widely supported we could even look at exporting the shape as a mesh,

There did used to be a way of viewing shapes in Mantid using OpenGL (similar to instrument viewer) but this feature never worked fully and it was disabled in MantidPlot and therefore never made it into Workbench. Speaking to Martyn, it doesn't seem like it's going to be v easy to re-enable this - especially now that we're moving away from OpenGL

RichardWaiteSTFC commented 3 years ago

There seems to be a library PyMesh that can read .stl (and some other formats I hadn't heard of but not .csg) https://pymesh.readthedocs.io/en/latest/basic.html#loading-mesh but it has limited plotting capability. There is another library dedicated just to .stl that might be a better option which plots with matplotlib https://pypi.org/project/numpy-stl/ But no simple scripts - so it looks like we'd need to add a dependency to do this. I don't know whether there is a way to convert a .csg to a .stl (it looks like .csg is not a true mesh format)?

RichardWaiteSTFC commented 3 years ago

Perhaps OpenSCAD can convert csg to stl and vice-versa https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/STL_Import_and_Export

DannyHindson commented 3 years ago

@RichardWaiteSTFC - thanks for looking into this. I hadn't realised there was a format for storing CSG descriptions of shapes. It seems like the .csg format might be OpenSCAD specific so we'll have to take a view on whether this is insufficiently general to use as an export format from Mantid. It might be better (but more work!) to convert the CSG description to a mesh for the purpose of viewing it in a 3rd party tool

DannyHindson commented 3 years ago

Few latest thoughts from me on this ahead of our sprint planning:

DanielMurphy22 commented 3 years ago

As the CSG and .3mf mesh formats aren't yet supported, I'm reopening!

DannyHindson commented 3 years ago

This looks like where the existing "convert to mesh" code lives: Framework\Geometry\src\Rendering\RenderingHelpersOpenGL.cpp