[vtkusers] How to make 2D Glyphs

Elvis Dowson elvis.dowson at mac.com
Sat Oct 4 04:24:06 EDT 2008


Hi,
         I figured out why it wasn't working. I didn't specify the  
point data for drawing the glyphs at.

You know, these things are not really described anywhere, neither in  
the VTK Book nor in the documentation. If you look at some of the  
tests or examples, you can see somethings, but you really have no  
information documented on the minimum number of things that you need  
to set-up, in order to get it (vtkGlyph2D) to work. Comments,  
anyone? :-)

Best regards,

Elvis Dowson


Working code fragment

	// Prototype: 2D Glyph Source
	// ----------------------------
	#ifdef PROTOTYPE_2D_GLYPH_SOURCE
	{
		// Declare object instance variables
		vtkPolyData*		glyphPolyData	= NULL;
		vtkPoints*			glyphPoints		= NULL;
		vtkGlyphSource2D*	glyphSource		= NULL;
		vtkGlyph2D*			glyphDiamond	= NULL;
		vtkActor2D*			glyphActor		= NULL;
		
		// Generate points for glyphs
		glyphPolyData	= vtkPolyData::New();
		glyphPoints	= vtkPoints::New();
		glyphPolyData->SetPoints(glyphPoints);
		glyphPoints->InsertNextPoint(50,50,0);
		glyphPoints->InsertNextPoint(100,100,0);
		glyphPoints->InsertNextPoint(200,100,0);
		
		// Generate 2D Glyph: Diamond
		glyphSource = vtkGlyphSource2D::New();
		glyphSource->SetGlyphTypeToDiamond();
		glyphSource->SetScale(20);
		glyphSource->SetCenter(0,0,0);
		glyphSource->FilledOff();
		glyphSource->CrossOn();
		
		glyphDiamond = vtkGlyph2D::New();
		glyphDiamond->SetInput(glyphPolyData);
		glyphDiamond->SetSource(glyphSource->GetOutput());
		glyphDiamond->ScalingOff();
		glyphDiamond->OrientOn();
		glyphDiamond->SetVectorModeToUseVector();
		glyphDiamond->SetColorModeToColorByVector();
		
		// Rendering objects.
		vtkPolyDataMapper2D* mapperGlyph = NULL;
		mapperGlyph = vtkPolyDataMapper2D::New();
		mapperGlyph->SetInputConnection(glyphDiamond->GetOutputPort());
		mapperGlyph->SetScalarRange(50, 180);
		
		// Add actor to renderer
		glyphActor = vtkActor2D::New();
		glyphActor->SetMapper(mapperGlyph);
		
		// Add Actor to renderer
		ren->AddActor2D(glyphActor);		
	}
	#endif




On Oct 4, 2008, at 11:22 AM, Elvis Dowson wrote:

> Hi,
>         I am trying to make a 2D Glyph, but nothing gets displayed  
> in the following code:
>
> 	// Prototype: 2D Glyph Source
> 	// ----------------------------
> 	#ifdef PROTOTYPE_2D_GLYPH_SOURCE
> 	{
> 		// Declare object instance variables
> 		vtkGlyphSource2D*	glyphSource	= NULL;
> 		vtkGlyph2D*		glyphDiamond	= NULL;
> 		vtkActor2D*		glyphActor	= NULL;
> 		
> 		// Generate 2D Glyph: Diamond
> 		glyphSource = vtkGlyphSource2D::New();
> 		glyphSource->SetGlyphTypeToDiamond();
> 		glyphSource->SetScale(0.2);
> 		glyphSource->FilledOff();
> 		
> 		glyphDiamond = vtkGlyph2D::New();
> 		glyphDiamond->SetSource(glyphSource->GetOutput());
> 		glyphDiamond->ScalingOff();
> 		glyphDiamond->OrientOn();
> 		glyphDiamond->SetVectorModeToUseVector();
> 		glyphDiamond->SetColorModeToColorByVector();
> 		
> 		// Rendering objects.
> 		vtkPolyDataMapper2D* mapperGlyph = NULL;
> 		mapperGlyph = vtkPolyDataMapper2D::New();
> 		mapperGlyph->SetInputConnection(glyphDiamond->GetOutputPort());
> 		mapperGlyph->SetScalarRange(50, 180);
> 		
> 		// Add actor to renderer
> 		glyphActor = vtkActor2D::New();
> 		glyphActor->SetMapper(mapperGlyph);
> 		
> 		// Add Actor to renderer
> 		ren->AddActor2D(glyphActor);		
> 	}
> 	#endif
>
> Best regards,
>
> Elvis Dowson

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081004/653662ef/attachment.htm>


More information about the vtkusers mailing list