我在VTK中渲染一个网格模型如下:
string mesh_filename = "mesh.ply";
vtkSmartPointer<vtkPLYReader> mesh_reader = read_mesh_ply(mesh_filename);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(mesh_reader->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(640, 480);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
//Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(1, 1, 1);
我正在尝试通过调用来设置相机:
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
renderer->SetActiveCamera(camera);
camera->SetPosition(0, 650, 0);
然后通过调用渲染场景:
renderWindow->Render();
renderWindowInteractor->Start();
问题是,在这个透视投影下,模型没有在这个视角显示。我可以通过调用来获取和设置截锥体的近距和远距值:
double near, far;
camera->GetClippingRange(near, far);
near = 0.001;
far = 1000000;
camera->GetClippingRange(near, far);
但是模型仍然没有显示。我需要更改顶部,底部,左侧和右侧吗?如果是这样,我该怎么做?
编辑:
我已经设置了焦点,视图和相机的位置以及使剪辑范围很大,仍然看不到物体:
camera->SetFocalPoint(0,0,0);
camera->SetViewUp(0,1,0);
camera->SetPosition(0,650,0);
renderer->ResetCameraClippingRange(-10000,100000,-100000,100000,100000,0.0001);