我是VTK的新手。我试图在我的macbook上运行下面的代码,但窗口无法弹出。好像它意外退出了。有人能告诉我什么原因???
TIA
int main(int argc, const char * argv[]) {
//cylinder
vtkSphereSource *sphere = vtkSphereSource::New();
sphere->SetPhiResolution(16);
sphere->SetThetaResolution(16);
//Shrink
vtkShrinkFilter *shrink = vtkShrinkFilter::New();
shrink->SetInputConnection(sphere->GetOutputPort());
shrink->SetShrinkFactor(0.9);
//Elevation Filter
vtkElevationFilter *colorIt = vtkElevationFilter::New();
colorIt->SetInputConnection(shrink->GetOutputPort());
colorIt->SetLowPoint(0,0,-0.5);
colorIt->SetHighPoint(0,0,0.5);
vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
sphereMapper->SetInputConnection(colorIt->GetOutputPort());
vtkActor *sphereActor = vtkActor::New();
sphereActor->SetMapper(sphereMapper);
vtkRenderer *ren1 = vtkRenderer::New();
ren1->AddActor(sphereActor);
ren1->SetBackground(0.1,0.2,0.4);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
renWin->SetSize(300,300);
renWin->Render();
shrink->SetInputConnection(colorIt->GetOutputPort());
renWin->Render();
return 0;
}
答案 0 :(得分:0)
最后两行的目的是什么?
shrink->SetInputConnection(colorIt->GetOutputPort());
renWin->Render();
这会创建过滤器的循环连接:sphere-> shrink-> colorIt-> ....(mapper,actor) - >再次缩小。你想把它缩小两次吗?然后,使用更高的收缩系数更简单。或者你想要两个不同的领域?比你必须为它们创建两个单独的对象。
此外,vtkShrinkFilter的输出是vtkUnstructuredGrid,而不是vtkPolyData,因此您必须使用vtkDataSetMapper而不是vtkPolyDataMapper。我执行此更改时您的代码适用于我,并删除第二个shrink-> SetInputConnection行。