[vtkusers] WG: Fwd: Re: Glyph coloring by vector magnitud
Sebastian Gatzka
sebastian.gatzka at stud.tu-darmstadt.de
Wed Mar 10 05:03:24 EST 2010
Hello again.
I had a quick look into the example
There were different things "wrong"
* There had to be some vector components you set to the points.
* The code you commented with "//create anything you want here, we
will use a cube for the demo" is crucial to the glyph.
It desribes how the glyh will look like. If you set a cube the
glyp tip will look like a cube.
If you set a sphere the glyph tip will look like a sphere. So an
arrow is the choice here.
So now there a three arrows displayed at the three points.
But they are not colored. *The transformation from color information
(having three components) to scalar informations (having one component)
the coloring can be done with is not known to me.*
Hope you have an answere to that. The current example code looks like
this - I haven't updated the wiki page yet, because it's not coloring so
far - only displaying the glyphs.
#include <vtkSmartPointer.h>
#include <vtkPointData.h>
// #include <vtkCubeSource.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkGlyph3D.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkUnsignedCharArray.h>
#include <vtkArrowSource.h>
int exampleColorGlyphs()
{
//create points
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(0,0,0);
points->InsertNextPoint(1,0,0);
points->InsertNextPoint(2,0,0);
//create vector components
vtkSmartPointer<vtkUnsignedCharArray> vectors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
vectors->SetName("Vectors");
vectors->SetNumberOfComponents(3);
vectors->InsertNextTuple3(1,1,0);
vectors->InsertNextTuple3(0,1,0);
vectors->InsertNextTuple3(0,0,1);
//setup scales
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetName("colors");
colors->SetNumberOfComponents(3);
unsigned char r[3] = {255,0,0};
unsigned char g[3] = {0,255,0};
unsigned char b[3] = {0,0,255};
colors->InsertNextTupleValue(r);
colors->InsertNextTupleValue(g);
colors->InsertNextTupleValue(b);
//combine into a polydata
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
//polydata->GetPointData()->SetScalars(colors);
polydata->GetPointData()->SetVectors(vectors);
vtkSmartPointer<vtkArrowSource> arrow =
vtkSmartPointer<vtkArrowSource>::New();
vtkSmartPointer<vtkGlyph3D> glyph3D =
vtkSmartPointer<vtkGlyph3D>::New();
glyph3D->SetColorModeToColorByScalar();
glyph3D->SetSourceConnection(arrow->GetOutputPort());
glyph3D->SetInput(polydata);
glyph3D->Update();
//Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(glyph3D->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
//Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
//Add the actor to the scene
renderer->AddActor(actor);
renderer->SetBackground(1,1,1); // Background color white
//Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}
Am 05.03.2010 21:55, schrieb David Doria:
> On Fri, Mar 5, 2010 at 3:35 PM, Sebastian Gatzka
> <sebastian.gatzka at stud.tu-darmstadt.de
> <mailto:sebastian.gatzka at stud.tu-darmstadt.de>> wrote:
>
> Obviously there was nothing wrong.
>
> When we moved on from this “constructed” example to the real
> application we are working with everything went fine.
>
> All Vectors are scales and colored now!
>
>
> Do you think you could fix this example?
>
> http://www.vtk.org/Wiki/VTK/Examples/Visualization/ColorGlyphs
>
> Thanks,
>
> David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100310/878d3810/attachment.htm>
More information about the vtkusers
mailing list