[vtkusers] Assigning color to a point cloud

Thales Luis Rodrigues Sabino tluisrs at gmail.com
Mon Feb 29 07:23:00 EST 2016


Try colors.InsertNextTupleValue([red, green, blue])

I'm not sure about the python signature of the method, I load colors in my
c++ code like this:

auto colors = vtkSmartPointer<vtkUnsignedCharArray>::New();

  colors->SetNumberOfComponents(3);


    for(vtkIdType iIndex = 0; iIndex < numberOfPoints; ++iIndex)

    {

        unsigned char color[3] =

        {

            m_CloudData->at(iIndex).r,

            m_CloudData->at(iIndex).g,

            m_CloudData->at(iIndex).b

        };

        colors->InsertNextTupleValue(color);

    }


    auto polyData = vtkSmartPointer<vtkPolyData>::New();

    polyData->SetPoints(points);

    polyData->SetVerts(vertices);

    polyData->GetCellData()->SetScalars(colors);




On Mon, Feb 29, 2016 at 7:14 AM, Olivier Rodenberg <orodenberg at gmail.com>
wrote:

> 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
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Thales Luis Rodrigues Sabino

PhD Student at PGMC-UFJF <http://www.ufjf.br/pgmc/>
Lattes <http://lattes.cnpq.br/0601030410417146> | LinkedIn
<https://br.linkedin.com/in/tluisrs> | ResearchGate
<https://www.researchgate.net/profile/Thales_Luis_Sabino>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160229/34392b7a/attachment.html>


More information about the vtkusers mailing list