[vtkusers] Drawing a single triangle
flymolo at gmail.com
flymolo at gmail.com
Sun Jan 11 18:47:57 EST 2009
After updating the positions, call Grid->Modified(), that should keep it in
sync.
On Jan 11, 2009 2:03pm, Kerry Loux <louxkr at gmail.com> wrote:
> Gerrick,
>
> Thanks for the response. I'm using C++, and created this method to create
a triangle object:
>
> // Create the objects
> Points = vtkPoints::New();
> Array = vtkFloatArray::New();
> Triangle = vtkTriangle::New();
>
> Grid = vtkUnstructuredGrid::New();
> TriangleMapper = vtkDataSetMapper::New();
> aTriangle = vtkActor::New();
>
> // Triangles have three points
> Points->SetNumberOfPoints(3);
>
> // Add some dummy points to the vtkPoints object
>
> Points->InsertPoint(0, 0.0, 0.0, 0.0);
> Points->InsertPoint(1, 0.0, 0.0, 0.0);
> Points->InsertPoint(2, 0.0, 0.0, 0.0);
>
> // Set up the float array
> Array->SetNumberOfComponents(3);
>
> Array->SetNumberOfTuples(3);
> Array->InsertTuple3(0, 1, 1, 1);
> Array->InsertTuple3(1, 2, 2, 2);
> Array->InsertTuple3(2, 3, 3, 3);
>
> // Set up the triangle object
> Triangle->GetPointIds()->SetId(0, 0);
>
> Triangle->GetPointIds()->SetId(1, 1);
> Triangle->GetPointIds()->SetId(2, 2);
>
> // Set up the unstructured grid object
> Grid->Allocate(1, 1);
> Grid->InsertNextCell(Triangle->GetCellType(), Triangle->GetPointIds());
>
> Grid->SetPoints(Points);
> Grid->GetPointData()->SetTCoords(Array);
>
> // Set up the mapper
> TriangleMapper->SetInput(Grid);
>
> // Set up the Actor
> aTriangle->SetMapper(TriangleMapper);
>
>
> aTriangle->GetProperty()->SetColor(1.0, 1.0, 0.0);// Yellow
>
> // Add it to the scene
> Renderer->GetRenderer()->AddActor(aTriangle);
>
> After I create the triangle, I call an update method that does this:
>
>
> Points->SetPoint(0, Node1.X, Node1.Y, Node1.Z);
> Points->SetPoint(1, Node2.X, Node2.Y, Node2.Z);
> Points->SetPoint(2, Node3.X, Node3.Y, Node3.Z);
>
> // Re-render the scene
> Renderer->GetRenderer()->Render();
>
>
> The first time I call this update function, the triangle is displayed
correctly. Subsequent calls, however, do not update the position of the
triangle. I tried changing the update method to include most of the
procedure for creating the object, but I still get no change in the
object's position. Is there something I can do to update the position of
the triangle after it has been created? Do you know why my update function
works the first time but has no effect after the first time it is called?
>
>
> Thanks for your help!
>
> -Kerry
>
> On Wed, Jan 7, 2009 at 9:31 PM, Gerrick Bivins
gbivins at objectreservoir.com> wrote:
>
>
>
>
>
>
> You have to create a data set (vtkPolyData) and add the triangle as a
cell and the points are specified as well.
>
> Look hear for an example:
>
>
http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/Examples/DataManipulation/Python/BuildUGrid.py?root=VTK&content-type=text/plain
>
>
>
>
> Gerrick
>
>
>
>
> On 1/7/09 8:18 PM, "Kerry Loux" louxkr at gmail.com> wrote:
>
>
>
>
>
>
> Hello,
>
>
>
> For my application, I need to display a single triangle in 3-space. The
triangle is not necessarily equilateral. What is the easiest way to create
a triangle object? I considered vtkTriangle and vtkTriangleStrip, but I'm
not clear on how to assign the locations of the vertices. Also, as far as I
can tell the vtkTriangle (and vtkCell) classes don't have any kind of
GetOutput() function. How do you map these classes to an actor? I was
hoping for some kind of primitive shape source, similar to vtkCyliderSource
or vtkSphereSource, but there doesn't seem to be any.
>
>
>
>
> I'm still using the 5.0.4 release.
>
>
>
> Thanks for your advice!
>
>
>
> -Kerry
>
>
>
>
>
> _______________________________________________
>
> This is the private VTK discussion list.
>
> Please keep messages on-topic. Check the 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/20090111/36f61274/attachment.htm>
More information about the vtkusers
mailing list