[vtkusers] Assigning color to a point cloud

Olivier Rodenberg orodenberg at gmail.com
Mon Feb 29 05:14:16 EST 2016


Hi all,

I am trying to load a point cloud in paraview using a programmable source. I am able to load the points but when assigning a color to each point I get the error message: ‘AttributeError: 'vtkCommonCorePython.vtkUnsignedCharArray' object has no attribute 'InsertNExtTuple3'. Next is the code I am using:

from paraview import vtk
import psycopg2

def connectDBMS():
    conn = psycopg2.connect("host='localhost' dbname='thesis' user='postgres' password='ww'")
    cur = conn.cursor() 
    cur.execute('SELECT x , y , z , red, green, blue FROM pointcloud;')                                                    
    return  cur.fetchall()

def DBMSToGeom(pointcloud): 
    # Create the points
    points = vtk.vtkPoints()

    # create output
    pdo  = self.GetPolyDataOutput()

    # create color attribute
    colors = vtk.vtkUnsignedCharArray();
    colors.SetNumberOfComponents(3);
    colors.SetName("Color");

    # loop over the octants in the database
    for  x , y , z , red, green, blue in pointcloud:

        # create the points
        points.InsertNextPoint(float(x), float(y), float(z))

        # create the colors
        colors.InsertNExtTuple3(int(red), int(green), int(blue));

    pdo.SetPoints(points)
    pdo.GetPointData().AddArray(colors)
    del colors

if (__name__ == "__main__"):
    DBMSToGeom(connectDBMS())

Does anyone know what I am doing wrong?

Thanks in advance,

Olivier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160229/8c242222/attachment.html>


More information about the vtkusers mailing list