marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.05k stars 266 forks source link

vtkLookupTable: Bad table range: [1e+299, -1e+299] while reading a vtu file #419

Closed XushanLu closed 3 years ago

XushanLu commented 3 years ago

Hi @marcomusy,

Here I am again asking for help.

I encountered a strange vtk error while trying to read in a vtu file and then convert that into a mesh object in vedo. Here is the simple reproducible script:

#!/Usr/bin/env python3

import numpy as np
from vedo import TetMesh, show, screenshot, settings, Picture, buildLUT, Box, \
    Plotter, Axes

import time as tm

# Do some settings
settings.useDepthPeeling=False  # Useful to show the axes grid
font_name = 'Theemim'
settings.defaultFont = font_name
settings.multiSamples=8
# settings.useParallelProjection = True # avoid perspective parallax

# Create a TetMesh object form the vtk file
tet_sgi = TetMesh('dyno_output/test_best_cond.vtu')
rec_cond = tet_sgi.tomesh().lineWidth(5).lineColor('w')
# plt.show(msh, cond, rec_cond, axes, size=size, interactive=True, resetcam=0
#          , zoom=1.2)
show(rec_cond, interactive=True)

And here is the data file: test_best_cond.vtu.zip

I think the error was raised when I tried to convert tet_sgi to a mesh object:

rec_cond = tet_sgi.tomesh().lineWidth(5).lineColor('w')

I am not sure what may be causing this and I apologize first if you find my way of doing things strange. I am so used to deal with vtu files and we have a bunch of tools that can be used to generate and manipulate vtu files. Having said that, this can easily be a problem with the vtu file format since this time I manually created the file.

This can also be a vtk bug but I am not sure. I tried to look into the vtk codes but could not really go too far: https://github.com/Kitware/VTK/blob/master/Common/Core/vtkLookupTable.cxx (line 165).

Or, is this something related to vedo?

Thanks very much for your help!

marcomusy commented 3 years ago

Hi - sorry for the late reply, I can read your file as an unstructured grid, are you sure it's a tet mesh?

from vedo import *

# Create a TetMesh object form the vtk file
# tet_sgi = TetMesh('data/test_best_cond.vtu')
tet_sgi = UGrid('data/test_best_cond.vtu')
rec_cond = tet_sgi.tomesh().lineWidth(5).lineColor('w')

show(rec_cond, axes=True, bg='bb')
XushanLu commented 3 years ago

Sorry, I missed your reply!

Well, I now realize that it is not a tetmesh. It is simply just a bunch of nodes connected into triangles. Does that matter?

marcomusy commented 3 years ago

Yep, when you are loading it with TetMesh() it tries to force it to be a tet mesh and this triangulation step seems to be failing (i'm not exactly sure why though)

XushanLu commented 3 years ago

Is there anything in vedo that can deal with just triangulations?

marcomusy commented 3 years ago

Yes there is a tetralize() function, which might turn useful.

XushanLu commented 3 years ago

I finally realized what I was looking for was UGrid instead of TetMesh. Also, that tetralize function does not work because it complains that I am passing in a vtkVolume object. I am happy again with what I am able to plot with vedo. Thanks!