Skip to content

Commit

Permalink
Merge pull request #1022 from JeffreyWardman/enable-using-copy-library
Browse files Browse the repository at this point in the history
allow mesh classes to handle copy.deepcopy
  • Loading branch information
marcomusy authored Jan 18, 2024
2 parents f9be5d9 + 47477cf commit 1457c5b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions vedo/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,12 @@ def polydata(self, **kwargs):
c="y")
return self.dataset

def __copy__(self):
return self.clone(deep=False)

def __deepcopy__(self, memo):
return self.clone(deep=memo)

def copy(self, deep=True):
"""Return a copy of the object. Alias of `clone()`."""
return self.clone(deep=deep)
Expand All @@ -846,7 +852,7 @@ def clone(self, deep=True):
![](https://vedo.embl.es/images/basic/mirror.png)
"""
poly = vtk.vtkPolyData()
if deep:
if deep or isinstance(deep, dict): # if a memo object is passed this checks as True
poly.DeepCopy(self.dataset)
else:
poly.ShallowCopy(self.dataset)
Expand All @@ -856,19 +862,18 @@ def clone(self, deep=True):
else:
cloned = Points(poly)

# new_instance = self.__class__
# print("******* cloning", new_instance.__name__)
# cloned = new_instance(poly)

cloned.transform = self.transform.clone()

cloned.copy_properties_from(self)

cloned.name = str(self.name)
cloned.filename = str(self.filename)
cloned.info = dict(self.info)

cloned.pipeline = utils.OperationNode("clone", parents=[self], shape="diamond", c="#edede9")

if isinstance(deep, dict):
deep[id(self)] = cloned

return cloned

def compute_normals_with_pca(self, n=20, orientation_point=None, invert=False):
Expand Down

0 comments on commit 1457c5b

Please sign in to comment.