support for point cloud
This commit is contained in:
parent
744e3bb50b
commit
575da581a9
|
@ -41,13 +41,12 @@ class VTK: # capitals needed/preferred?
|
||||||
"""
|
"""
|
||||||
Create an unstructured grid (mesh).
|
Create an unstructured grid (mesh).
|
||||||
|
|
||||||
connectivity: 1 based at the moment
|
connectivity: 0 based at the moment, shape Ncell x N nodes
|
||||||
cell_type: TRIANGLE, 'QUAD', 'TETRA','HEXAHEDRON'
|
cell_type: TRIANGLE, 'QUAD', 'TETRA','HEXAHEDRON'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
vtk_nodes = vtk.vtkPoints()
|
vtk_nodes = vtk.vtkPoints()
|
||||||
vtk_nodes.SetData(nps.numpy_to_vtk(nodes))
|
vtk_nodes.SetData(nps.numpy_to_vtk(nodes))
|
||||||
|
|
||||||
cells = vtk.vtkCellArray()
|
cells = vtk.vtkCellArray()
|
||||||
cells.SetNumberOfCells(connectivity.shape[0])
|
cells.SetNumberOfCells(connectivity.shape[0])
|
||||||
T = np.concatenate((np.ones((connectivity.shape[0],1),dtype=np.int64)*connectivity.shape[1],
|
T = np.concatenate((np.ones((connectivity.shape[0],1),dtype=np.int64)*connectivity.shape[1],
|
||||||
|
@ -62,8 +61,21 @@ class VTK: # capitals needed/preferred?
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_points(nodes,connectivity,cell_type):
|
def from_polyData(points):
|
||||||
pass
|
vtk_points= vtk.vtkPoints()
|
||||||
|
vtk_points.SetData(nps.numpy_to_vtk(points))
|
||||||
|
|
||||||
|
vertices = vtk.vtkCellArray()
|
||||||
|
vertices.SetNumberOfCells(points.shape[0])
|
||||||
|
T = np.concatenate((np.ones((points.shape[0],1),dtype=np.int64),
|
||||||
|
np.arange(points.shape[0],dtype=np.int64).reshape(-1,1)),axis=1).ravel()
|
||||||
|
vertices.SetCells(points.shape[0],nps.numpy_to_vtk(T, deep=True, array_type=vtk.VTK_ID_TYPE))
|
||||||
|
|
||||||
|
geom = vtk.vtkPolyData()
|
||||||
|
geom.SetPoints(vtk_points)
|
||||||
|
geom.SetVerts(vertices)
|
||||||
|
|
||||||
|
return VTK(geom)
|
||||||
|
|
||||||
|
|
||||||
def write(self,fname): #ToDo: Discuss how to handle consistently filename extensions
|
def write(self,fname): #ToDo: Discuss how to handle consistently filename extensions
|
||||||
|
@ -95,7 +107,7 @@ class VTK: # capitals needed/preferred?
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""ASCII representation of the VTK data."""
|
"""ASCII representation of the VTK data."""
|
||||||
writer = vtk.vtkDataSetWriter()
|
writer = vtk.vtkDataSetWriter()
|
||||||
writer.SetHeader('DAMASK.VTK v{}'.format(version))
|
writer.SetHeader('# DAMASK.VTK v{}'.format(version))
|
||||||
writer.WriteToOutputStringOn()
|
writer.WriteToOutputStringOn()
|
||||||
writer.SetInputData(self.geom)
|
writer.SetInputData(self.geom)
|
||||||
writer.Write()
|
writer.Write()
|
||||||
|
|
|
@ -975,11 +975,11 @@ class Result:
|
||||||
datasets_in = {}
|
datasets_in = {}
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
with h5py.File(self.fname,'r') as f:
|
with h5py.File(self.fname,'r') as f:
|
||||||
for arg,label in datasets.items():
|
for arg,label in datasets.items():
|
||||||
loc = f[group+'/'+label]
|
loc = f[group+'/'+label]
|
||||||
datasets_in[arg]={'data' :loc[()],
|
datasets_in[arg]={'data' :loc[()],
|
||||||
'label':label,
|
'label':label,
|
||||||
'meta': {k:v.decode() for k,v in loc.attrs.items()}}
|
'meta': {k:v.decode() for k,v in loc.attrs.items()}}
|
||||||
lock.release()
|
lock.release()
|
||||||
r = func(**datasets_in,**args)
|
r = func(**datasets_in,**args)
|
||||||
return [group,r]
|
return [group,r]
|
||||||
|
@ -1042,26 +1042,15 @@ class Result:
|
||||||
|
|
||||||
if self.structured:
|
if self.structured:
|
||||||
v = VTK.from_rectilinearGrid(self.grid+1,self.size,self.origin)
|
v = VTK.from_rectilinearGrid(self.grid+1,self.size,self.origin)
|
||||||
vtk_geom = v.geom
|
|
||||||
else:
|
else:
|
||||||
with h5py.File(self.fname,'r') as f:
|
with h5py.File(self.fname,'r') as f:
|
||||||
v = VTK.from_unstructuredGrid(f['/geometry/x_n'][()],
|
v = VTK.from_unstructuredGrid(f['/geometry/x_n'][()],
|
||||||
f['/geometry/T_c'][()]-1,
|
f['/geometry/T_c'][()]-1,
|
||||||
f['/geometry/T_c'].attrs['VTK_TYPE'].decode())
|
f['/geometry/T_c'].attrs['VTK_TYPE'].decode())
|
||||||
vtk_geom = v.geom
|
|
||||||
|
|
||||||
elif mode.lower()=='point':
|
elif mode.lower()=='point':
|
||||||
Points = vtk.vtkPoints()
|
v = VTK.from_polyData(self.cell_coordinates())
|
||||||
Vertices = vtk.vtkCellArray()
|
|
||||||
for c in self.cell_coordinates():
|
|
||||||
pointID = Points.InsertNextPoint(c)
|
|
||||||
Vertices.InsertNextCell(1)
|
|
||||||
Vertices.InsertCellPoint(pointID)
|
|
||||||
|
|
||||||
vtk_geom = vtk.vtkPolyData()
|
vtk_geom = v.geom
|
||||||
vtk_geom.SetPoints(Points)
|
|
||||||
vtk_geom.SetVerts(Vertices)
|
|
||||||
vtk_geom.Modified()
|
|
||||||
|
|
||||||
N_digits = int(np.floor(np.log10(int(self.increments[-1][3:]))))+1
|
N_digits = int(np.floor(np.log10(int(self.increments[-1][3:]))))+1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue