Exemplo n.º 1
0
 def mesh(self):
     if 'vtkInterface' in sys.modules:
         return vtki.MeshfromVF(self.v, self.f)
     else:
         raise Exception(
             'Cannot generate mesh without vtkInterface.  Run:\n' +
             'pip install vtkInterface')
Exemplo n.º 2
0
 def mesh(self):
     """ the surface mesh """
     if vtkenabled:
         return vtki.MeshfromVF(self.v, self.f)
     else:
         raise Exception('Cannot generate mesh without vtkInterface.\n' +
                         'Run: pip install vtkInterface')
Exemplo n.º 3
0
    def RemovePoints(self, remove_mask, mode='all', keepscalars=True):
        """
        Rebuild a mesh by removing points that are true in "remove_mask"

        Parameters
        ----------
        remove_mask : np.ndarray
            Points that are True will be removed.

        mode : str, optional
            When 'all', only faces containing all points flagged for removal
            will be removed.  Default 'all'

        keepscalars : bool, optional
            When True, point and cell scalars will be passed on to the new
            mesh.

        Returns
        -------
        mesh : vtkInterface.PolyData
            Mesh without the points flagged for removal.

        """
        # Extract points and faces from mesh
        v = self.points
        f = self.GetNumpyFaces()

        if remove_mask.size != v.shape[0]:
            raise Exception('"remove_mask" size is not the same as the ' +
                            'number of points in the mesh')

        vmask = remove_mask.take(f)
        if mode == 'all':
            fmask = np.logical_not(vmask).all(1)
        else:
            fmask = np.logical_not(vmask).any(1)

        # Regenerate face and point arrays
        uni = np.unique(f.compress(fmask, 0), return_inverse=True)
        v = v.take(uni[0], 0)
        f = np.reshape(uni[1], (fmask.sum(), 3))

        newmesh = vtkInterface.MeshfromVF(v, f, False)
        ridx = uni[0]

        # Add scalars back to mesh if requested
        if keepscalars:
            # Point data
            narr = self.GetPointData().GetNumberOfArrays()
            for i in range(narr):
                # Extract original array
                vtkarr = self.GetPointData().GetArray(i)

                # Rearrange the indices and add this to the new polydata
                adata = vtk_to_numpy(vtkarr)[ridx]
                newmesh.AddPointScalars(adata, vtkarr.GetName())

            # Cell data
            narr = self.GetCellData().GetNumberOfArrays()
            for i in range(narr):
                # Extract original array
                vtkarr = self.GetCellData().GetArray(i)
                adata = vtk_to_numpy(vtkarr)[fmask]
                newmesh.AddCellScalars(adata, vtkarr.GetName())

        # Return vtk surface and reverse indexing array
        return newmesh, ridx