[vtkusers] RE: Solid 2D shapes

Goodwin Lawlor goodwin.lawlor at ucd.ie
Wed May 26 11:26:04 EDT 2004


Hi Jan-Jaap,

Replace: polydata->SetLines(rect);

With: polydata->SetPolys(rect);

And delete the final: rect->InsertCellPoint(0);

and it should work. Note your polygon must be convex.

Hth,

Goodwin



Date: Wed, 26 May 2004 10:35:40 +0200
From: Jan-Jaap van der Heijden <Jan-Jaap.vanderHeijden at phoenixbv.com>
Subject: [vtkusers] Solid 2D shapes
To: vtkusers <vtkusers at vtk.org>
Message-ID:
	<20040526103540.7a4f0346.Jan-Jaap.vanderHeijden at phoenixbv.com>
Content-Type: text/plain; charset=US-ASCII


Hello all,

Say I want to draw a solid, 2D box in a window.
A wireframe goes like this:


  // define coordinates, and scalar values at these coordinates
  vtkPoints *pts = vtkPoints::New();
  pts->GetData()->SetName(arrayname);
  pts->InsertPoint(0, 0.2,0.2,0);
  pts->InsertPoint(1, 0.8,0.2,0);
  pts->InsertPoint(2, 0.8,0.6,0);
  pts->InsertPoint(3, 0.2,0.6,0);

  vtkDoubleArray *scalars = vtkDoubleArray::New();
  scalars->SetNumberOfTuples(4);
  scalars->InsertValue(0,0);
  scalars->InsertValue(1,1);
  scalars->InsertValue(2,2);
  scalars->InsertValue(3,1);

  // define connectivity
  vtkCellArray *rect = vtkCellArray::New();
  rect->InsertNextCell(5);
  rect->InsertCellPoint(0);
  rect->InsertCellPoint(1);
  rect->InsertCellPoint(2);
  rect->InsertCellPoint(3);
  rect->InsertCellPoint(0);

  // Create the dataset
  vtkCoordinate *coords = vtkCoordinate::New();
  coords->SetCoordinateSystemToNormalizedViewport();

  vtkPolyData *polydata = vtkPolyData::New();
  polydata->SetPoints(pts);
  polydata->SetLines(rect);
  polydata->GetPointData()->SetScalars(scalars);

  vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();
  mapper->SetInput(polydata);
  mapper->SetScalarRange(0,2);
  mapper->SetLookupTable(lut);

  // Create an actor.
  vtkActor2D *actor = vtkActor2D::New();
  actor->SetMapper(mapper);
  ren->AddActor2D(actor);


This gives a wireframe box.
How do I make it solid? There's no equivalent of
vtkProperty::SetRepresentationToSurface() in vtkProperty2D

Thanks in advance,
Jan-Jaap





More information about the vtkusers mailing list