[vtkusers] Coloring HedgeHog vectors

Philip Cook p.cook at cs.ucl.ac.uk
Sat Aug 24 08:06:02 EDT 2002


On Saturday 24 August 2002 11:37, vtkusers-request at public.kitware.com wrote:
> I am using vtkHedgehog to visualize vector data from a
> structured grid data set. I would like the color of the
> vector line to be scaled to the length of the vector, and
> not a particular scalar component of the vector. How do I pull this
> off?  Various combinations of inputs to the vtkHedgehog or the
> polydatamapper have given solid colors, but not a color
> scale.
>
> Jess Neri

I'm not sure if you want each line to have multiple colours (I don't know how 
to do that). 

If you want to colour each line with one colour that is determined by its 
vector magnitude, you can use vtkGlyph3D. This class will place an oriented 
glyph (in our case a line, but it can be any polygonal shape) at each point 
in an input dataset. You can scale and colour by vector, normal, or scalar 
values. 

	// make a line for our glyph
	vtkLineSource *line = vtkLineSource::New();
	
	line->SetPoint1(0.0f, 0.0f, 0.0f);
	line->SetPoint2(1.0f, 0.0f, 0.0f);

	line->Update();

 	vtkGlyph3D *glyph = vtkGlyph3D::New();

	// Set vectors for points in structured points
	// vectors should be a vtkDataArray containing the vectors for each point
	spoints->GetPointData()->SetVectors(vectors);

	// Tell the glyph what we want to use as input
	glyph->SetInput(spoints);

	// Tell the glyph what shape we want placed at each point of input
 	glyph->SetSource(line->GetOutput());

	// Tell the glyph to orient all source objects
	glyph->OrientOn();

	//Tell the glyph to orient by vector
  	glyph->SetVectorModeToUseVector();
	
 	 // Tell the glyph to scale by vector
	 // can alternatively call ScalingOff() to make all lines the same length 
  	glyph->SetScaleModeToScaleByVector();

	  // And also to colour by vector
 	 glyph->SetColorModeToColorByVector();

	  // Make sure all those orders took effect
 	 glyph->Update();

	// Now make an LUT
  	vtkLookupTable *lut = vtkLookupTable::New();
        lut->SetHueRange(0.667, 0.0);

  	// map to graphics library
  	vtkPolyDataMapper *map = vtkPolyDataMapper::New();
	map->SetInput(glyph->GetOutput());

	// minScalar, maxScalar should correspond to min and max vector magnitude in
	// input vector data
 	map->SetScalarRange(minScalar, maxScalar);
  	lut->SetRange(minScalar, maxScalar);
  	map->SetLookupTable(lut);

  	// actor coordinates geometry, properties, transformation
  	vtkActor *aGlyph = vtkActor::New();
  	aGlyph->SetMapper(map);
  
And so on.


Phil



More information about the vtkusers mailing list