简体   繁体   English

VTK:旋转3D模型并捕获其深度图

[英]VTK: rotate a 3D model and capture its depth map

Currently, based on the VTK ZBuffer example, I iteratively rotate the 3D model and capture each time the depth map. 目前,基于VTK ZBuffer示例,我迭代旋转3D模型并在每次深度图捕获。 The issue is that although the model rotates the output images contain all the first depth map. 问题是,尽管模型旋转,但输出图像仍包含所有第一深度图。

int main(int argc, char *argv[]){

...variable declaration/initialization

//read off file
offReader->SetFileName(argv[1]);
offReader->Update(); 

int step = 30; std::string out;
for (int i = 0; i < 3; i++) { 
    mapper->NewInstance();
    actor->NewInstance();
    renWin->NewInstance();
    renderer->NewInstance();

    mapper->SetInputData(polyData);
    actor->SetMapper(mapper);

    out = std::to_string(i);

    actor->RotateZ(step*i);

    renWin->AddRenderer(renderer);

    renderer->AddActor(actor);
    renderer->SetBackground(1, 1, 1);
    renWin->Render(); 

    // Create Depth Map
    filter->NewInstance();
    scale->NewInstance();
    imageWriter->NewInstance();

    filter->SetInput(renWin);
    filter->SetMagnification(3);
    filter->SetInputBufferTypeToZBuffer();        //Extract z buffer value
    filter->Update();

    scale->SetOutputScalarTypeToUnsignedChar();     
    scale->SetInputConnection(filter->GetOutputPort());     
    scale->SetShift(0);
    scale->SetScale(-255);
    scale->Update();

    std::string out1 = out + "_depth.bmp";
    std::cout << " " << out1 << std::endl;

    // Write surface map as a .bmp image
    imageWriter->SetFileName(out1.c_str());
    imageWriter->SetInputConnection(scale->GetOutputPort());
    imageWriter->Update();
    imageWriter->Write();

    filter->RemoveAllInputs();
    scale->RemoveAllInputs();
    imageWriter->RemoveAllInputs();
    renderer->RemoveActor(actor);
    renWin->RemoveRenderer(renderer); 

    .... remaining script

} 

The output depth maps are all identical . 输出的深度图都是相同的 0_depth.bmp, 1_depth.bmp & 2_depth.bmp 0_depth.bmp,1_depth.bmp和2_depth.bmp

Has anyone encountered the same issue? 有没有人遇到过同样的问题? If yes, what could be a potential solution. 如果是,那可能是一个潜在的解决方案。

Problem solved by introducing a function within the rotation took place. 通过在旋转中引入函数来解决问题。 Apparently it was a matter of a variable content update issue, that could be solved in a more straight forward way. 显然,这是一个可变的内容更新问题,可以通过更直接的方式解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM