Skip to content

Commit

Permalink
fix clone() after warp() call in #929
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Sep 13, 2023
1 parent 78d4be2 commit 4d88c42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
19 changes: 14 additions & 5 deletions vedo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ def ncells(self):
def points(self, pts=None, transformed=True):
"""
Set/Get the vertex coordinates of a mesh or point cloud.
Keyword `pts` can also be a list of indices to be retrieved.
Set `transformed=False` to ignore any previous transformation applied to the mesh.
"""
Expand All @@ -1060,22 +1061,30 @@ def points(self, pts=None, transformed=True):
return utils.vtk2numpy(vpts.GetData())
return np.array([], dtype=np.float32)

else: ### setter
else:

if len(pts) == 3 and len(pts[0]) != 3:
# assume plist is in the format [all_x, all_y, all_z]
pts = np.stack((pts[0], pts[1], pts[2]), axis=1)
pts = np.asarray(pts, dtype=np.float32)

if pts.ndim == 1:
### getter by point index ###################
indices = pts.astype(int)
vpts = self.polydata(transformed).GetPoints()
arr = utils.vtk2numpy(vpts.GetData())
return arr[indices] ###########

### setter ####################################
if pts.shape[1] == 2:
pts = np.c_[pts, np.zeros(pts.shape[0], dtype=np.float32)]
vpts = self.inputdata().GetPoints()
arr = utils.numpy2vtk(pts, dtype=np.float32)

vpts = self._data.GetPoints()
vpts.SetData(arr)
vpts.Modified()
# reset mesh to identity matrix position/rotation:
self.PokeMatrix(vtk.vtkMatrix4x4())
self.point_locator = None
self.cell_locator = None
self.transform = None
return self


Expand Down
11 changes: 9 additions & 2 deletions vedo/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,15 @@ def clone(self, deep=True, transformed=False):

if not transformed:
if self.transform:
# already has a transform which can be non linear, so use that
cloned.SetUserTransform(self.transform)
# already has a so use that
try:
cloned.SetUserTransform(self.transform)
except TypeError: # transform which can be non linear
cloned.SetOrigin(self.GetOrigin())
cloned.SetScale(self.GetScale())
cloned.SetOrientation(self.GetOrientation())
cloned.SetPosition(self.GetPosition())

else:
# assign the same transformation to the copy
cloned.SetOrigin(self.GetOrigin())
Expand Down

0 comments on commit 4d88c42

Please sign in to comment.