我在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);
答案 0 :(得分:4)
摄像机的位置由焦点,位置和向上矢量定义。要查看模型,您希望焦点靠近模型,以便相机查看它。如果其他一切正常,相机可能只是指向错误的方向。
您可以使用vtkCamera
方法SetFocalPoint
的重载来设置相机焦点。
您可能还想尝试使用vtkRenderer
方法ResetCamera()
来修改相机以查看所有可见的演员。