def DeformSurface(self):
        # interpolate and sample the displacement norms over the surface
        rbf = vtkvmtkcontrib.vtkvmtkRBFInterpolation2()
        rbf.SetSource(self.SourceSpheres)
        rbf.SetRBFTypeToBiharmonic()
        rbf.ComputeCoefficients()
        sampler = vtkvmtkcontrib.vtkvmtkPolyDataSampleFunction()
        sampler.SetInput(self.Surface)
        sampler.SetImplicitFunction(rbf)
        sampler.SetSampleArrayName("DisplacementNorms")
        sampler.Update()

        sampArray = sampler.GetOutput().GetPointData().GetArray("DisplacementNorms")

        ##Clamp the negative values to 0 and the positive values to one in a weight array
        calculator = vtk.vtkArrayCalculator()
        calculator.SetInput(sampler.GetOutput())
        calculator.AddScalarArrayName("DisplacementNorms")
        calculator.SetFunction("if( DisplacementNorms > 0 , iHat, jHat)")
        calculator.SetResultArrayName("Weights")
        calculator.SetResultArrayType(vtk.VTK_FLOAT)
        calculator.Update()

        # Create the transform
        thinPlateSplineTransform = vtk.vtkThinPlateSplineTransform()
        thinPlateSplineTransform.SetBasisToR()
        thinPlateSplineTransform.SetSourceLandmarks(self.SourcePoints)
        thinPlateSplineTransform.SetTargetLandmarks(self.TargetPoints)

        transform = vtk.vtkTransform()
        transform.Identity()
        transform2 = vtk.vtkTransform()
        transform2.Identity()

        # Apply weighted transform
        transformFilter = vtk.vtkWeightedTransformFilter()
        transformFilter.SetInput(calculator.GetOutput())
        transformFilter.SetNumberOfTransforms(3)
        transformFilter.SetWeightArray("Weights")
        transformFilter.SetTransform(thinPlateSplineTransform, 0)
        transformFilter.SetTransform(transform, 1)
        transformFilter.SetTransform(transform2, 2)
        transformFilter.Update()

        normalsFilter = vtk.vtkPolyDataNormals()
        normalsFilter.SetInput(transformFilter.GetOutput())
        normalsFilter.Update()

        # FIXME: the normal filter apparently introduced some holes in some meshes (wtf?). This filter cleans the mesh
        cleanFilter = vtk.vtkCleanPolyData()
        cleanFilter.SetInput(normalsFilter.GetOutput())
        cleanFilter.Update()

        self.DeformedSurface = cleanFilter.GetOutput()
 def ComputeArray(self):
     rbf = vtkvmtkcontrib.vtkvmtkRBFInterpolation2()
     rbf.SetSource(self.Spheres)
     if self.RBFType == "thinplatespline":
         rbf.SetRBFTypeToThinPlateSpline()
     elif self.RBFType == "biharmonic":
         rbf.SetRBFTypeToBiharmonic()
     elif self.RBFType == "triharmonic":
         rbf.SetRBFTypeToTriharmonic()
     rbf.ComputeCoefficients()
     sampler = vtkvmtkcontrib.vtkvmtkPolyDataSampleFunction()
     sampler.SetInput(self.Surface)
     sampler.SetImplicitFunction(rbf)
     sampler.SetSampleArrayName(self.ResolutionArrayName)
     sampler.Update()
     return sampler.GetOutput()
Esempio n. 3
0
 def ComputeArray(self):
     rbf = vtkvmtkcontrib.vtkvmtkRBFInterpolation2()
     rbf.SetSource(self.Spheres)
     if self.RBFType == "thinplatespline":
         rbf.SetRBFTypeToThinPlateSpline()
     elif self.RBFType == "biharmonic":
         rbf.SetRBFTypeToBiharmonic()
     elif self.RBFType == "triharmonic":
         rbf.SetRBFTypeToTriharmonic()
     rbf.ComputeCoefficients()
     sampler = vtkvmtkcontrib.vtkvmtkPolyDataSampleFunction()
     sampler.SetInput(self.Surface)
     sampler.SetImplicitFunction(rbf)
     sampler.SetSampleArrayName(self.ResolutionArrayName)
     sampler.Update()
     return sampler.GetOutput()