I am trying to project some points of mesh using some function. I have access the point and cell data from polydata. From that I get projected point. Now I want to replace those points with projected points. Is there any way to update points in mayavi or vtk?
To get polydata from .ply file
from plyfile import PlyData,PlyElement
import numpy as np
import time
from mayavi import mlab
from tvtk.api import tvtk
plydata = PlyData.read(ply_file)
points = plydata.elements[0].data
# Get X,Y,Z coordinates from .ply file
x,y,z = [],[],[]
for i in points:
x.append(i[0])
y.append(i[1])
z.append(i[2])
s = [0.1]*len(x)
mesh = mlab.pipeline.delaunay2d(pts)
surf = mlab.pipeline.surface(mesh,color=(1,1,1))
actor = surf.actor.actors[0]
polydata = tvtk.to_vtk(actor.mapper.input)
projecting points:
for i in range(polydata.GetNumberOfCells()):
pts = polydata.GetCell(i).GetPoints()
np_pts = np.array([pts.GetPoint(i) for i in range(pts.GetNumberOfPoints())])
projected_point1,projected_point2,projected_point3 = project_points(point1,point2,point3)
Now for saving I tried following line in above for loop:
polydata_return.GetCell(i).GetPoints() = np.array([projected_point1,projected_point2,projected_point3])
but got error as follows: SyntaxError: can't assign to function call
Is there any way to replace/edit present points with projected points. Thanks in advance.
UPDATE : To generate mesh :
from mayavi import mlab
from tvtk.api import tvtk
import numpy as np
from plyfile import PlyData,PlyElement
x = [random.randint(0,250) for i in range(250)]
y = [random.randint(0,250) for i in range(250)]
z = [random.randint(0,5) for i in range(250)]
s = [0.1]*len(x)
pts = mlab.points3d(x, y, z,s)
mesh = mlab.pipeline.delaunay2d(pts)
surf = mlab.pipeline.surface(mesh,color=(1,1,1))
After generating above mesh I want to map a texture to mesh using following image and then I have to flattened the mesh using some transformation, so mesh will get flattened along with a texture. I doing this for dewrapping image to remove distortion in image. texture image
For projecting image I use following code:
image_file = texture_image_path
if image_file.split('.')[-1] == 'png':
img = tvtk.PNGReader()
elif image_file.split('.')[-1] == 'jpg':
img = tvtk.JPEGReader()
img.file_name=image_file
texture = tvtk.Texture(input_connection=img.output_port, interpolate=0)
surf.actor.enable_texture = True
surf.actor.tcoord_generator_mode = 'plane'
surf.actor.actor.texture = texture
mlab.show()