[vtkusers] Showing a Line

Bob Palank bob at stlcc.org
Tue May 23 17:25:06 EDT 2006


Given the code below, I see the cylinder, but not the line.
Any idea why ? Shouldn't a line be a visible object like a cylinder?
If not, then does one display a line object using a cylinder with a small
diameter ?
Hopefully there is a simple coding error!
TIA
  Bob

Code follows:
#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkLineSource.h"

int main(int argc, char *argv[])
{
  vtkCylinderSource *cylinder = vtkCylinderSource::New();
  cylinder->SetResolution(18);    // eight circumferential facets.


  vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New();
  cylinderMapper->SetInput(cylinder->GetOutput());


  vtkActor *cylinderActor = vtkActor::New();
  cylinderActor->SetMapper(cylinderMapper);
  cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
  cylinderActor->RotateX(30.0);
  cylinderActor->RotateY(-45.0);

  // =================================================================
  vtkLineSource *lineASource = vtkLineSource::New();
  lineASource->SetPoint1(-12.0,2.0,2.0);
  lineASource->SetPoint2(12.0,4.0,5.0);

  vtkPolyDataMapper *lineAMapper = vtkPolyDataMapper::New();
  lineAMapper->SetInput(lineASource->GetOutput());

  vtkActor *lineASourceActor = vtkActor::New();
  lineASourceActor->GetProperty()->SetColor(0.0, 0.0, 1.0);




  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);


  ren1->AddActor(cylinderActor);
  ren1->AddActor(lineASourceActor);
  ren1->SetBackground(0.1, 0.2, 0.4);
  renWin->SetSize(300, 300);

  // We'll zoom in a little by accessing the camera and invoking a "Zoom"
  // method on it.
  // ren1->GetActiveCamera()->Zoom(1.5);
  renWin->Render();

  // This starts the event loop and as a side effect causes an initial
render.
  iren->Start();

  // Exiting from here, we have to delete all the instances that
  // have been created.
  cylinder->Delete();
  cylinderMapper->Delete();
  cylinderActor->Delete();
  lineASourceActor->Delete();
  lineAMapper->Delete();
  ren1->Delete();
  renWin->Delete();
  iren->Delete();

  return 0;
}




More information about the vtkusers mailing list