# Path: pcloudpy/core/utils/vtkhelpers.py
# def actor_from_imagedata(imagedata):
#     actor = vtkImageActor()
#     actor.SetInputData(imagedata)
#     actor.InterpolateOff()
#     return actor
# 
# def actor_from_polydata(PolyData):
#     """
#     Returns the VTK Actor from vtkPolyData Structure
#     """
#     mapper = vtkPolyDataMapper()
#     mapper.SetInputData(PolyData)
#     actor = vtkActor()
#     actor.SetMapper(mapper)
#     #actor.GetProperty().SetPointSize(2)
#     return actor
# 
# Path: pcloudpy/core/io/converters.py
# def numpy_from_polydata(polydata):
#     """
#     Converts vtkPolyData to Numpy Array
# 
#     Parameters
#     ----------
# 
#     polydata: vtkPolyData
#         Input Polydata
# 
#     """
# 
#     nodes_vtk_array = polydata.GetPoints().GetData()
#     nodes_numpy_array = vtk_to_numpy(nodes_vtk_array)
# 
#     if polydata.GetPointData().GetScalars():
#         nodes_numpy_array_colors = vtk_to_numpy(polydata.GetPointData().GetScalars("colors"))
#         return np.c_[nodes_numpy_array, nodes_numpy_array_colors]
#     else:
#         return nodes_numpy_array
# 
# def polydata_from_numpy(coords):
#     """
#     Converts Numpy Array to vtkPolyData
# 
#     Parameters
#     ----------
#     coords: array, shape= [number of points, point features]
#         array containing the point cloud in which each point has three coordinares [x, y, z]
#         and none, one or three values corresponding to colors.
# 
#     Returns:
#     --------
#     PolyData: vtkPolyData
#         concrete dataset represents vertices, lines, polygons, and triangle strips
# 
#     """
# 
#     Npts, Ndim = np.shape(coords)
# 
#     Points = vtkPoints()
#     ntype = get_numpy_array_type(Points.GetDataType())
#     coords_vtk = numpy_to_vtk(np.asarray(coords[:,0:3], order='C',dtype=ntype), deep=1)
#     Points.SetNumberOfPoints(Npts)
#     Points.SetData(coords_vtk)
# 
#     Cells = vtkCellArray()
#     ids = np.arange(0,Npts, dtype=np.int64).reshape(-1,1)
#     IDS = np.concatenate([np.ones(Npts, dtype=np.int64).reshape(-1,1), ids],axis=1)
#     ids_vtk = numpy_to_vtkIdTypeArray(IDS, deep=True)
# 
#     Cells.SetNumberOfCells(Npts)
#     Cells.SetCells(Npts,ids_vtk)
# 
#     if Ndim == 4:
#         color = [128]*len(coords)
#         color = np.c_[color, color, color]
#     elif Ndim == 6:
#         color = coords[:,3:]
#     else:
#         color = [[128, 128, 128]]*len(coords)
# 
#     color_vtk = numpy_to_vtk(
#             np.ascontiguousarray(color, dtype=get_vtk_to_numpy_typemap()[VTK_UNSIGNED_CHAR]),
#             deep=True)
# 
#     color_vtk.SetName("colors")
# 
#     PolyData = vtkPolyData()
#     PolyData.SetPoints(Points)
#     PolyData.SetVerts(Cells)
#     PolyData.GetPointData().SetScalars(color_vtk)
#     return PolyData


from collections import OrderedDict
from vtk import vtkPolyData, vtkImageData
from ..utils.vtkhelpers import actor_from_imagedata, actor_from_polydata
from ..io.converters import numpy_from_polydata, polydata_from_numpy
import copy
import numpy as np
        """
        Gets ImageData
        """
        if self._imagedata:
            return self._imagedata

    def set_imagedata(self, imagedata):
        """
        Sets ImageData
        """
        self._imagedata = imagedata
        self._actor = actor_from_imagedata(self._imagedata)
        self.update_props()

    def _update(self):
        pass

    def update(self):
        self._update()
        self.set_imagedata(self._imagedata)
        self.update_props()

    def clone(self):
        """
        Returns a Clone of an ImageDataBase instance
        """
        imagedata = vtkImageData()
        imagedata.DeepCopy(self._imagedata)
        clone = copy.copy(self)
        clone.set_imagedata(imagedata)

# Path: pcloudpy/core/utils/vtkhelpers.py
# def actor_from_imagedata(imagedata):
#     actor = vtkImageActor()
#     actor.SetInputData(imagedata)
#     actor.InterpolateOff()
#     return actor
# 
# def actor_from_polydata(PolyData):
#     """
#     Returns the VTK Actor from vtkPolyData Structure
#     """
#     mapper = vtkPolyDataMapper()
#     mapper.SetInputData(PolyData)
#     actor = vtkActor()
#     actor.SetMapper(mapper)
#     #actor.GetProperty().SetPointSize(2)
#     return actor
# 
# Path: pcloudpy/core/io/converters.py
# def numpy_from_polydata(polydata):
#     """
#     Converts vtkPolyData to Numpy Array
# 
#     Parameters
#     ----------
# 
#     polydata: vtkPolyData
#         Input Polydata
# 
#     """
# 
#     nodes_vtk_array = polydata.GetPoints().GetData()
#     nodes_numpy_array = vtk_to_numpy(nodes_vtk_array)
# 
#     if polydata.GetPointData().GetScalars():
#         nodes_numpy_array_colors = vtk_to_numpy(polydata.GetPointData().GetScalars("colors"))
#         return np.c_[nodes_numpy_array, nodes_numpy_array_colors]
#     else:
#         return nodes_numpy_array
# 
# def polydata_from_numpy(coords):
#     """
#     Converts Numpy Array to vtkPolyData
# 
#     Parameters
#     ----------
#     coords: array, shape= [number of points, point features]
#         array containing the point cloud in which each point has three coordinares [x, y, z]
#         and none, one or three values corresponding to colors.
# 
#     Returns:
#     --------
#     PolyData: vtkPolyData
#         concrete dataset represents vertices, lines, polygons, and triangle strips
# 
#     """
# 
#     Npts, Ndim = np.shape(coords)
# 
#     Points = vtkPoints()
#     ntype = get_numpy_array_type(Points.GetDataType())
#     coords_vtk = numpy_to_vtk(np.asarray(coords[:,0:3], order='C',dtype=ntype), deep=1)
#     Points.SetNumberOfPoints(Npts)
#     Points.SetData(coords_vtk)
# 
#     Cells = vtkCellArray()
#     ids = np.arange(0,Npts, dtype=np.int64).reshape(-1,1)
#     IDS = np.concatenate([np.ones(Npts, dtype=np.int64).reshape(-1,1), ids],axis=1)
#     ids_vtk = numpy_to_vtkIdTypeArray(IDS, deep=True)
# 
#     Cells.SetNumberOfCells(Npts)
#     Cells.SetCells(Npts,ids_vtk)
# 
#     if Ndim == 4:
#         color = [128]*len(coords)
#         color = np.c_[color, color, color]
#     elif Ndim == 6:
#         color = coords[:,3:]
#     else:
#         color = [[128, 128, 128]]*len(coords)
# 
#     color_vtk = numpy_to_vtk(
#             np.ascontiguousarray(color, dtype=get_vtk_to_numpy_typemap()[VTK_UNSIGNED_CHAR]),
#             deep=True)
# 
#     color_vtk.SetName("colors")
# 
#     PolyData = vtkPolyData()
#     PolyData.SetPoints(Points)
#     PolyData.SetVerts(Cells)
#     PolyData.GetPointData().SetScalars(color_vtk)
#     return PolyData


# Path: pcloudpy/core/io/base.py
from collections import OrderedDict
from vtk import vtkPolyData, vtkImageData
from ..utils.vtkhelpers import actor_from_imagedata, actor_from_polydata
from ..io.converters import numpy_from_polydata, polydata_from_numpy
import copy
import numpy as np

        """
        Gets ImageData
        """
        if self._imagedata:
            return self._imagedata

    def set_imagedata(self, imagedata):
        """
        Sets ImageData
        """
        self._imagedata = imagedata
        self._actor = actor_from_imagedata(self._imagedata)
        self.update_props()

    def _update(self):
        pass

    def update(self):
        self._update()
        self.set_imagedata(self._imagedata)
        self.update_props()

    def clone(self):
        """
        Returns a Clone of an ImageDataBase instance
        """
        imagedata = vtkImageData()
        imagedata.DeepCopy(self._imagedata)
        clone = copy.copy(self)
        clone.set_imagedata(imagedata)

        clone.set_actor(actor_from_imagedata(self._imagedata))