[vtkusers] write points and normals to file

Kurt Sansom kayarre at gmail.com
Tue Oct 4 16:44:52 EDT 2016


Hi,
   I have some unstructured data, no triangles, just points and normals.

I am trying to write those to a file in the vtp format using the python
bindings and then load the data in paraview and apply a glyph filter to
view the vectors. but the glyph filter doesn't appear to work eventhough
the data looks alright in the vtp file, what am I missing?

here is the code snippet.

       #write normals
        points = vtk.vtkPoints()
        verts = vtk.vtkCellArray()
        polydata_pts = vtk.vtkPolyData()

        pointNormalsArray = vtk.vtkDoubleArray()
        pointNormalsArray.SetNumberOfComponents(3)

        for i in range(clipSeedIds.GetNumberOfIds()):

            seedId = clipSeedIds.GetId(i)

            locator = vtk.vtkPointLocator()
            locator.SetDataSet(clippedSurface)
            locator.BuildLocator()

            seedPoint = self.Surface.GetPoint(seedId)
            seedPointId = locator.FindClosestPoint(seedPoint)

            planeEstimator = vtkvmtk.vtkvmtkPolyDataNormalPlaneEstimator()
            planeEstimator.SetInputData(clippedSurface)
            planeEstimator.SetOriginPointId(seedPointId)
            planeEstimator.Update()

            plane = vtk.vtkPlane()
            plane.SetOrigin(planeEstimator.GetOrigin())
            plane.SetNormal(planeEstimator.GetNormal())

            #testing the normal vector

            origin_pt = planeEstimator.GetOrigin()
            normal_pt = planeEstimator.GetNormal()

            id = points.InsertNextPoint(origin_pt)
            verts.InsertNextCell(1)
            verts.InsertCellPoint(id)
            pointNormalsArray.InsertNextTuple(normal_pt)



        #Add the points to the polydata container
        polydata_pts.SetPoints(points)
        polydata_pts.SetVerts(verts)

        # Add the normals to the points in the polydata
        #polydata_pts.GetCellData().SetNormals(pointNormalsArray)
        polydata_pts.GetPointData().SetNormals(pointNormalsArray)
        polydata_pts.Modified()


        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetDataModeToAscii()
        writer.SetFileName(os.path.join(
          "/Users/sansomk/caseFiles/ultrasound/cases/DSI003LER/other",
          "pts_out.vtp"))
        writer.SetInputData(polydata_pts)
        writer.Write()


~Kurt

-- 
Kurt Sansom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161004/489bd6b4/attachment.html>


More information about the vtkusers mailing list