[vtkusers] Cannot view lines in camera focal plane
bruno vtk
bruno.itkvtk at gmail.com
Wed Mar 10 09:04:16 EST 2010
Hi everybody,
It has been quite a long time I try to visualize a polygon resulting from
the simple cut of a sphere by a plane. However, using the code below, I
can't see anything with the original camera setup. I guess that I have
problem because my cut is in the camera focal plane but I don't know how to
solve the problem. Do you have any idea to make this code working (I
wouldn't like to change the camera position and focal point) ?
Thanks a lot,
Bruno
#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkPlane.h>
#include <vtkCutter.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkCamera.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
int main(int argc, char **argv)
{
vtkSphereSource *sphere = vtkSphereSource::New();
vtkPlane *plane = vtkPlane::New();
plane->SetOrigin(0., 0., 0.);
plane->SetNormal(0., 0., 1.);
vtkCutter *cutter = vtkCutter::New();
cutter->SetCutFunction(plane);
cutter->SetInput(sphere->GetOutput());
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInput(cutter->GetOutput());
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(1., 0., 0.);
actor->GetProperty()->SetLineWidth(5.);
vtkRenderer *renderer = vtkRenderer::New();
renderer->AddActor(actor);
renderer->GetActiveCamera()->ParallelProjectionOn();
renderer->GetActiveCamera()->SetFocalPoint(0., 0., 0);
renderer->GetActiveCamera()->SetPosition(0., 0., 1.);
renderer->ResetCameraClippingRange(-1., 1., -1., 1., 0, 1);
vtkRenderWindow *renderwindow = vtkRenderWindow::New();
renderwindow->AddRenderer(renderer);
vtkRenderWindowInteractor *interactor =
vtkRenderWindowInteractor::New();
interactor->SetRenderWindow(renderwindow);
interactor->Initialize();
renderwindow->Render();
interactor->Start();
sphere->Delete();
plane->Delete();
cutter->Delete();
mapper->Delete();
actor->Delete();
renderer->Delete();
renderwindow->Delete();
interactor->Delete();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100310/392a72a8/attachment.htm>
More information about the vtkusers
mailing list