简体   繁体   中英

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. 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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