I am using dash_vtk to render geological data and i would like to export it (as a .dxf or .obj for example).
Can someone give some hints about how to do it ?
Moreover, I would like to display infos on hovering of points, is that possible at the moment and how ?
Here is an example of what I render with dash_vtk :
VTK does not have a dxf reader/writer built in but we do support .obj file. On the server side you should be able to use vtkOBJWriter to generate your file from your mesh. Then I’m not exactly sure how to send it to the client via dash but I’m sure someone might be able to give you some pointers.
The hovering part is now supported (since 0.0.9). You just have to declare what you want to monitor on your view with pickingModes=['hover', 'click', 'select'] (for you just hover should do it) and then monitor hoverInfo/clickInfo/selectInfo based on what you are listening to. From there we have several examples available below using that information:
Thank you for answering !
I was just working on the vtkOBJWriter, and I wondered , how can I get a vtkPolyData from a dash_vtk.PolyData.
The following code doesn’t work :
But my thinking is that you must be getting those points/polys/elevation from somewhere?
If they are coming from VTK, you might already have your polydata. In which case, you would not need to deconstruct and reconstruct it for your use case. You can even use to_mesh helper with the dash-vtk/mesh object directly…
Actually, I am constructing those points and polys with a delaunay triangulation : get the points from a database then I use spicy.spatial Delaunay to get the polys.
I tried your solution :
nb_points = int(len(points) / 3)
vtk_points = vtk.vtkPoints()
for i in range(nb_points):
vtk_points.InsertNextPoint(float(points[i*3]), float(points[i*3+1]), float(points[i*3+2]))
vtk_polydata = vtk.vtkPolyData()
vtk_polydata.SetPoints(vtk_points)
but the coordinates of the points were converted to ints for no reason.
So I ended up writing directly in a file and it worked :
vtk_polys = f.vtk_polys(polys)
nb_points = int(len(points) / 3)
nb_polys = int(len(vtk_polys) / 3)
print(nb_polys)
with open(filepath, 'w') as file:
for i in range(nb_points):
file.write("v %.4f %.4f %.4f\n" % (float(points[i*3]), float(points[i*3+1]), float(points[i*3+2])))
for i in range(nb_polys):
file.write("f %d %d %d\n" % (int(vtk_polys[i*3] + 1), int(vtk_polys[i*3+1] + 1), int(vtk_polys[i*3+2] + 1)))
file.close()
The vtk_polys function is used to remove all the “3” in polys : [3, x0, y0, z0, 3, x1, y1, z1 ...] → [x0, y0, z0, x1, y1, z1 ...]
For the hover : it works just fine with the Sebastian’s solution !
Thank you everyone for your time and precious help !
I have a 3D FEM mesh with some values associated with the elements (“damage_data”). When hoovering, I’m trying to show these values using "pickingModes=[‘hover’]. Is this possible ?. Code: