[vtkusers] pb displaying vertex and vertices
Matthieu Chabanas
Matthieu.Chabanas at imag.fr
Tue Apr 9 09:06:12 EDT 2002
I have a (stupid) problem to display first a single 3D point, then a set
of points.
I have tried to port the example given in
Examples/DataManipulation/Tcl/BuildUGrid.tcl to c++,
but I can't see anything displayed...
I use vtk4.0 + Qt2.3 + vtkQGL. For this particular example, I have tried
with Visual C++ also, but same results.
Am I missing something completely silly?
Thanks for any help.
Matt
---
//--- A SINGLE POINT:
vtkPoints * vertexPoints = vtkPoints::New();
vertexPoints->SetNumberOfPoints(1);
vertexPoints->InsertPoint(0, 1.0, 1.0, 1.0);
vtkVertex * aVertex = vtkVertex::New();
aVertex->GetPointIds()->SetId(0,0);
vtkUnstructuredGrid * aVertexGrid = vtkUnstructuredGrid::New();
aVertexGrid->Allocate(1, 1);
aVertexGrid->InsertNextCell(aVertex->GetCellType(),
aVertex->GetPointIds());
aVertexGrid->SetPoints(vertexPoints);
vtkDataSetMapper * aVertexMapper = vtkDataSetMapper::New();
aVertexMapper->SetInput(aVertexGrid);
vtkActor * aVertexActor = vtkActor::New();
aVertexActor->SetMapper(aVertexMapper);
aVertexActor->AddPosition(0, 0, 6);
aVertexActor->GetProperty()->SetDiffuseColor(1, 1, 1);
// A SET OF POINTS
vtkPoints * polyVertexPoints = vtkPoints::New();
polyVertexPoints->SetNumberOfPoints(3);
polyVertexPoints->InsertPoint(0, 0, 0, 0);
polyVertexPoints->InsertPoint(1, 1, 0, 0);
polyVertexPoints->InsertPoint(2, 1, 1, 0);
vtkPolyVertex * aPolyVertex = vtkPolyVertex::New();
aPolyVertex->GetPointIds()->SetNumberOfIds(3);
aPolyVertex->GetPointIds()->SetId(0, 0);
aPolyVertex->GetPointIds()->SetId(1, 1);
aPolyVertex->GetPointIds()->SetId(2, 2);
vtkUnstructuredGrid * aPolyVertexGrid = vtkUnstructuredGrid::New();
aPolyVertexGrid->Allocate(1, 1);
aPolyVertexGrid->InsertNextCell( aPolyVertex->GetCellType(),
aPolyVertex->GetPointIds());
aPolyVertexGrid->SetPoints(polyVertexPoints);
vtkDataSetMapper * aPolyVertexMapper = vtkDataSetMapper::New();
aPolyVertexMapper->SetInput(aPolyVertexGrid);
vtkActor * aPolyVertexActor = vtkActor::New();
aPolyVertexActor->SetMapper(aPolyVertexMapper);
aPolyVertexActor->AddPosition(2, 0, 6);
aPolyVertexActor->GetProperty()->SetDiffuseColor(1, 1, 1);
// The usual rendering stuff.
vtkCamera *camera = vtkCamera::New();
camera->SetPosition(0,0,6);
camera->SetFocalPoint(0,0,0);
vtkRenderer *renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renderer->AddActor(aVertexActor);
renderer->AddActor(aPolyVertexActor);
renderer->SetActiveCamera(camera);
renderer->ResetCamera();
renderer->SetBackground(1,1,1);
renWin->SetSize(300,300);
// interact with data
renWin->Render();
iren->Start();
More information about the vtkusers
mailing list