Line segments not coloured correctly with data read in from VTU files
See original GitHub issueHi @marcomusy,
Another VTU-related problem. I was trying to plot line segments with different colors used to denote different lithology units as revealed from drilling. The original data was prepared into vtu files with segments as cells. The following picture was originally plotted using PyVista:
Not something I am satisfied with but at least it is able to show segments with different colors. I then tried to plot something similar using vedo and here’s what I got:
As you can see, the segments are not properly colored as expected although the colorbar was showing correctly. Any ideas on how to get the expected picture plotted? Thanks very much!
Here are all the data needed to plot the picture: vedo_issue.zip
The following code was used to plot the figure:
from vedo import *
import numpy as np
settings.defaultFont = 'Theemim'
settings.multiSamples=8
# Plot the two drillholes
l2400_vtu = 'L2400E.vtu'
l3200_vtu = 'L3200E.vtu'
l2400 = UGrid(l2400_vtu).tomesh().lineWidth(20).lc('w')
l3200 = UGrid(l3200_vtu).tomesh().lineWidth(20)
# Lookup table for drillhole lithology
lut_table = [
# Value, color, alpha, category
(1., 'gray', 1, 'Overburden'),
(2., 'bronw', 1, 'Fault'),
(3., 'red', 1, 'Fault (graphite)'),
(4., 'green', 1, 'Basement'),
]
lut = buildLUT(lut_table)
l2400.cmap(lut, 'Lithology', on='cells')
l3200.cmap(lut, 'Lithology', on='cells')
l2400.addScalarBar3D(
categories=lut_table,
title="Lithology",
labelSize=2,
pos=(606500, 6371000, -50),
sx=40,
sy=1200,
)
# l3200.addScalarBar3D(
# categories=lut_table,
# title="Lithology",
# labelSize=2,
# pos=(606500, 6371500, -50),
# )
# Create a UGrid object from surface_input.vtu file
igen = 20
vtu_file = 'test_knots_igen=' + '{:03d}'.format(igen) + '.vtu'
ug_cell = UGrid(vtu_file)
ug_node = ug_cell.clone()
# Get the mesh objects for both cells and nodes
mesh_cell = ug_cell.tomesh().lineWidth(5).lineColor('blue').alpha(0.5)
mesh_cell.cmap("coolwarm", 'names001', on='cells')
mesh_cell.addScalarBar3D(
title='Cell conductivity (S/m)',
titleXOffset=-2.5,
labelSize=1.5,
pos=(603550, 6371500, -50),
sx=30,
sy=1200,
)
mesh_node = ug_node.tomesh()
# We need to build a look up table for our color bar, and now it supports
# using category names as labels instead of the numerical values
# This was implemented upon my request
lut_table = [
# Value, color, alpha, category
(1.2, 'cyan', 1, r'\pm200'),
(2.2, 'red', 1, '\pm200'),
(3.2, 'dodgerblue', 1, '\pm400'),
(4.2, 'purple', 1, '\pm500'),
(5.2, 'green', 1, '\pm150'),
]
lut = buildLUT(lut_table)
# Adde color maps to both nodes and cells
mesh_node.cmap(lut, 'nodeGroup', on='points')
mesh_node.pointSize(25)
# Options for axes
group = mesh_node + mesh_cell
axes = Axes(group,
xtitle='Easting (m)',
ytitle='Northing (m)',
ztitle='Elevation (m)',
xTitlePosition=0.55,
xLabelSize=0.018,
yTitlePosition=0.65,
yLabelRotation=-90,
yLabelSize=0.018,
# yLabelOffset=-1.5,
# yTitleOffset=-1.12,
yTitleRotation=180,
axesLineWidth=4,
xrange=mesh_cell.xbounds(),
yrange=mesh_cell.ybounds(),
# yzShift=1,
zxGrid=True,
)
# manually move the Z axis back in place
for a in axes.unpack():
# print(a.name)
if ("zAxis" in a.name or "zM" in a.name or "zN" in a.name
or "zxGrid" in a.name or "zTipCone" in a.name or 'ztitle' in a.name):
yb = group.ybounds()
a.shift(0, (yb[1]-yb[0]), 0)
mesh_node.addScalarBar3D(
categories=lut_table,
title='Search volumes (m)',
titleRotation=180,
titleXOffset=-4,
labelSize=2,
labelOffset=1.5,
labelRotation=-90,
pos=(606000, 6371000, -50),
sx=40,
sy=1200,
)
# put scalarbar vertical and shift it up a bit
mesh_node.scalarbar.rotateZ(90, locally=True).shift(-1200, -1000, 0)
# mesh_node.scalarbar.shift(-1000, -500, 0)
# Also rotate the scalarbar showing cell conductivity
mesh_cell.scalarbar.rotateX(90, locally=True).rotateY(-45, locally=True).rotateZ(-15, locally=True)
plt = Plotter()
plt.camera.SetPosition( [602592.516, 6368179.979, 2912.739] )
plt.camera.SetFocalPoint( [604701.971, 6370768.195, -30.009] )
plt.camera.SetViewUp( [0.472, 0.466, 0.748] )
plt.camera.SetDistance( 4450.667 )
plt.camera.SetClippingRange( [2453.388, 6975.564] )
# Define the window size in pixels
# size = [3940, 2160]
size = [2560, 1600]
# plt.show(mesh_node, mesh_cell, axes, l2400, l3200, size=size, zoom=1.2,
# interactive=False)
plt.show(mesh_node, mesh_cell, axes, l2400, l3200, size=size,
interactive=True)
# filename = 'surface_input_no_point_size.png'
filename = 'surface_input.png'
screenshot(filename)
from wand import image
with image.Image(filename=filename) as imag:
imag.trim(color=None, fuzz=0)
imag.save(filename=filename)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Cool,
Yes. Sadly VTK starting from version 8.2 suffers of artifacts when plotting lines and transparent objects. Shrinking a bit the triangles is probably helping with that…
The program for the above rendering is this:
Ah, yes! That should be a cmap thing. Tried it and it surely works. Thanks!