def vertex_normal (dataset) : "Returns the vertex normal of each point in a dataset." if not dataset : raise RuntimeError, 'Need a dataset to compute vertex_normal' ds = dataset.NewInstance() ds.UnRegister(None) ds.CopyStructure(dataset.VTKObject) filter = vtk.vtkPolyDataNormals() filter.SetInputData(ds) filter.ComputeCellNormalsOff() filter.ComputePointNormalsOn() filter.SetFeatureAngle(180) filter.SplittingOff() filter.ConsistencyOff() filter.AutoOrientNormalsOff() filter.FlipNormalsOff() filter.NonManifoldTraversalOff() filter.Update() varray = filter.GetOutput().GetPointData().GetNormals() ans = dataset_adapter.vtkDataArrayToVTKArray(varray, dataset) # The association information has been lost over the vtk filter # we must reconstruct it otherwise lower pipeline will be broken. ans.Association = dataset_adapter.ArrayAssociation.POINT return ans
def calculer_surface_moyenne(surface_1, surface_2, precision=1e-6, pas_initial=10): """fonction qui calcule une surface moyenne par la methode des spheres inscrites extension de la methode des cercles inscrits """ # conversion en polydata et fusion des blocs surface_1 = convertir_surface_en_polydata(surface_1) surface_2 = convertir_surface_en_polydata(surface_2) #calcul du vecteur Normals normals = vtk.vtkPolyDataNormals() normals.SetInput(surface_1) normals.Update() surface_1_modif = normals.GetOutput() # derafinement de la surface_1 #derafiner = vtk.vtkCleanPolyData() #derafiner.SetInput(surface_1_modif) #derafiner.SetToleranceIsAbsolute(1) #derafiner.SetAbsoluteTolerance(1) #derafiner.Update() #surface_1_modif = derafiner.GetOutput() # calcul de la surface moyenne surface_moyenne = trouver_centres_spheres_inscrites(surface_1_modif, surface_2, precision = precision, pas_initial = pas_initial) normals = vtk.vtkPolyDataNormals() normals.SetInput(surface_moyenne) normals.ConsistencyOn() normals.Update() surface_moyenne = normals.GetOutput() coords = numpy_support.vtk_to_numpy(surface_moyenne.GetPoints().GetData()) normals = numpy_support.vtk_to_numpy(surface_moyenne.GetPointData().GetArray('Normals')) inf = coords - normals * 1e3 sup = coords + normals * 1e3 source = vtk.vtkLineSource() source.SetPoint1(inf[0]) source.SetPoint2(sup[0]) # return source.GetOutput() return surface_moyenne