[vtkusers] Representing Points in 3D

Christof Mueller mueller at cg.nrcan.gc.ca
Thu Apr 4 18:20:31 EST 2002


Thanks for all the 'input'.

Here is what finally worked for me, maybe a bit clumsy ...
Thought it might serve as an example to somebody else:

 vtkPoints *polyVertexPoints=vtkPoints::New();
  polyVertexPoints->SetNumberOfPoints(MAXPOINTS);
 vtkPolyVertex *aPolyVertex=vtkPolyVertex::New();
  aPolyVertex->GetPointIds()->SetNumberOfIds(MAXPOINTS);
 vtkUnstructuredGrid *aPolyVertexGrid=vtkUnstructuredGrid::New();
  aPolyVertexGrid->Allocate(1,1);
 vtkDataSetMapper *aPolyVertexMapper=vtkDataSetMapper::New();
    vtkGlyph3D *cloud = vtkGlyph3D::New();
    vtkPolyDataMapper *cloudMapper = vtkPolyDataMapper::New();
 vtkSphereSource *sphere=vtkSphereSource::New();
  sphere->SetRadius(5.0);
 vtkActor *srcActor = vtkActor::New();
 i=0;
 while(fscanf(srcfp,"%f%f%f",&x,&y,&z)!=EOF){
   polyVertexPoints->InsertPoint(i,x,y,z);
   aPolyVertex->GetPointIds()->SetId(i,i);
   i++;
 }


aPolyVertexGrid->InsertNextCell(aPolyVertex->GetCellType(),aPolyVertex->GetPointIds());

   aPolyVertexGrid->SetPoints(polyVertexPoints);
   aPolyVertexMapper->SetInput(aPolyVertexGrid);
   cloud->SetScaleModeToDataScalingOff();
   cloud->SetInput(aPolyVertexMapper->GetInput());
   cloud->SetSource(sphere->GetOutput());
   cloudMapper->SetInput(cloud->GetOutput());
   srcActor->SetMapper(cloudMapper);
   srcActor->AddPosition(0,0,6);
   srcActor->GetProperty()->SetDiffuseColor(1.0,0.0,0.5);
 ren1->AddActor(srcActor);


Christof



Roland Schwarz wrote:

> Hi Christof,
>
> Points are best represented by a vtkPolyData object that has exacatly one
> cell of type VTK_VERTEX. This Vertex Cell is simply a list of Id's that are
> indices to your data.
>
> You should read about writing a reader class. I recommend to derive from
> class vtkPolyDataSource then.
> I.e.:
> class VTK_IO_EXPORT vtkMyReader : public vtkPolyDataSource
> {
> .... your class definitions
> }
>
> This reader will become the starting point of your pipeline. You will then
> connect this reader to a mapper and so  on.
>
> Tip.: Have a look on the available reader classes in the library to see how
> it is done.
>
> Roland
>
> ----- Original Message -----
> From: "Christof Mueller" <mueller at cg.nrcan.gc.ca>
> To: <vtkusers at public.kitware.com>
> Sent: Thursday, April 04, 2002 12:49 AM
> Subject: [vtkusers] Representing Points in 3D
>
> > I've been trying to represent a number of points in space, but without
> > success:
> >
> > I tried to use vtkAssembly to represent each point by a sphere:
> >
> >  vtkAssembly *actors=vtkAssembly::New();
> >  vtkSphereSource *sphere=vtkSphereSource::New();
> >  vtkActor *srcactor = vtkActor::New();
> >  vtkPolyDataMapper *spheremapper = vtkPolyDataMapper::New();
> >
> >   while(fscanf(srcfp,"%f %f %f",&x,&y,&z)!=EOF){
> >           sphere->SetCenter(x,y,z);
> >           sphere->SetRadius(3.0);
> >           spheremapper->SetInput(sphere->GetOutput());
> >           srcactor->SetMapper(spheremapper);
> >           actors->AddPart(srcactor);
> >
> >  }
> >  ren1->AddActor(actors);
> >
> > The result shows only the last srcactor.
> >
> > I assume that I would have to represent each point by it's own actor.
> > There must be a simpler way to do this ...
> >
> > Any suggestions ? Even a completely different approach would be fine,
> > since I belive that mine is probably not very smart ...
> >
> > Cheers,
> >
> >                 Christof
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq>
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/vtkusers
> >




More information about the vtkusers mailing list