[vtkusers] Glyph coloring

David Gobbi david.gobbi at gmail.com
Thu Nov 25 22:22:50 EST 2010


It should be possible to modify the scalars the same way as the points:

points->SetPoint(idx, point);
colors->SetTupleValue(idx, color);
glypher->Modified();

The vtkCellArray isn't necessary (but somehow polydata with no cells goes
against my sense of aesthetics).

  David

On Thu, Nov 25, 2010 at 7:07 PM, Gib Bogle <g.bogle at auckland.ac.nz> wrote:

> It turns out there was a difference between what I was doing and the wiki
> example code, one of those seemingly insignificant details that are actually
> important.
>
> I had
>  glypher->SetScaleFactor(1.0);
> and the wiki code has
>  glypher->ScalingOff();
> With that change it works (although I don't know why).
>
> I have a final (I hope!) question.  I now want to selectively change the
> color of glyphs.  I know how to change the position of the point indexed by
> idx:
>  points->SetPoint(idx,x,y,z);
>  glypher->Modified();
>
> Presumably something very similar is needed to change the color of this
> glyph, but I don't know how to access the array that holds the colors, which
> was initialized with:
>  input->GetPointData()->SetScalars(colors);
>
> Can someone help me over this last hurdle?
>
>
>
> On 26/11/2010 12:42 p.m., Gib Bogle wrote:
>
>> I've been trying to follow David Gobbi's suggestion about coloring the
>> glyphs
>> that I am now using to render my squares with. The hints he provided were
>> not
>> enough for me to get it working, so I hunted around and found the wiki
>> example
>> http://www.itk.org/Wiki/VTK/Examples/Cxx/Visualization/ColorGlyphs
>> This works fine, so I thought I could just follow the same path. It
>> doesn't work
>> for me, and I'm guessing that it's because I'm using a vtkPolyData that
>> contains
>> both vtkPoints and vtkCellArray. David advised me to use
>> input->GetPointData()->AddArray(...)
>> but I couldn't see how to implement this. My code is shown below. What am
>> I
>> missing? (This code doesn't display the squares at all, unless I comment
>> out
>> input->GetPointData()->SetScalars(colors).)
>> I apologize for the ignorance I'm displaying - I don't understand why it's
>> necessary to use the vtkCellArray, for example.
>>
>> points = vtkSmartPointer<vtkPoints>::New();
>> vtkSmartPointer<vtkCellArray> dummycells =
>> vtkSmartPointer<vtkCellArray>::New();
>> points->SetNumberOfPoints(npos); // number of squares
>> dummycells->InsertNextCell(npos);
>> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
>> colors->SetName("colors");
>> colors->SetNumberOfComponents(3);
>> unsigned char g[3] = {0,255,0};
>> for (int ipos=0; ipos<npos; ipos++) {
>> points->SetPoint(ipos, x, y, z);
>> dummycells->InsertCellPoint(ipos);
>> colors->InsertNextTupleValue(g);
>> }
>> input = vtkSmartPointer<vtkPolyData>::New();
>> input->SetPoints(points);
>> input->SetVerts(dummycells);
>> input->GetPointData()->SetScalars(colors);
>> glypher = vtkSmartPointer<vtkGlyph3D>::New();
>> glypher->SetInput(input);
>> glypher->SetSource(polygonPolyData);
>> glypher->SetScaleFactor(1.0);
>> glypher->SetColorModeToColorByScalar();
>> // glypher->SetInputArrayToProcess(3, 0, 0, 0, "colors");
>> glypher->Update();
>> squareMapper = vtkPolyDataMapper::New();
>> squareMapper->SetInputConnection(glypher->GetOutputPort());
>> glactor = vtkActor::New();
>> glactor->SetMapper(squareMapper);
>> glactor->GetProperty()->SetAmbient(0.5);
>> glactor->GetProperty()->SetDiffuse(0.2);
>> glactor->GetProperty()->SetSpecular(0.5);
>> ren->AddActor(glactor);
>> _______________________________________________
>> 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
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101125/d049a9d6/attachment.htm>


More information about the vtkusers mailing list