I’m currently working on integrating stereoscopic displays with some software developed using VTK (built heavily off of ParaView and in Qt, as well). I’m pretty new to graphics programming, so I may be missing some obvious details.
I’m having issues with getting the images to actually render when I change camera position. I think this is because my code relies on the images rendering instantaneously, but the rendering is delegated for when the process becomes idle. As such, when I collect my images, they are all the same image since no rendering has occurred yet.
It seems older versions of VTK had vtkMapper::SetGlobalImmediateModeRendering(), which sounds like what I’m looking for. Is there anything similar to use now? Is this a ParaView/Qt Issue and I’m on the wrong track? It is also worth knowing that I’m collecting any where between 30-45 images depending on user desire.
Potential Workarounds I’m looking through
- Generate an animation path and then save an animation of my .pngs, which I can then read in.
- Have multiple renderers (cameras), and then have each yield image data. I worry about this one since that would entail a large amount of renderers being created for the scene.
- Use ParaView’s Simple python module to collect screenshots (which worked in past testing) and then read these .pngs in. I’d rather solve the C++ API issue, though
My code for reference
vtkImageData* ViewHoloDisplay::beginCollectingViews()
{
cout << “Beginning to Collect Views\n”;
cout << “Creating totalAppender\n”;
totalAppender = vtkSmartPointer::New();
totalAppender->SetAppendAxis(1);
cout << “Beginning for loops\n”;
int v_index = 0;
cout << qs_rows << " " << qs_columns << “\n”;
// Collection Loop
for(int currRow = 0; currRow < qs_rows; currRow++)
{
vtkSmartPointer<vtkImageAppend> currAppender = imgAppenders[currRow];
currAppender->SetAppendAxis(0);
for(int currColumn = 0; currColumn < qs_columns; currColumn++)
{
this->setViewIndex(v_index); // Move camera along view plane
activeWindow->Render();
activeRenderer->GetRenderWindow()->Render();
cout << "Phi: " << cameraPhi_active <<"\n";
//activeWindow->WaitForCompletion(); DOES NOT WORK
vtkSmartPointer<vtkWindowToImageFilter> liveWin = vtkSmartPointer<vtkWindowToImageFilter>::New();
liveWin->SetInput(activeWindow);
liveWin->Modified();
liveWin->Update();
vtkImageData* currImg = winToImg->GetOutput();
if(currAppender->GetNumberOfInputs() == qs_columns)
{
currAppender->ReplaceNthInputConnection(currColumn,liveWin->GetOutputPort());
currAppender->Update();
}
else
{
currAppender->AddInputConnection(liveWin->GetOutputPort());
currAppender->Update();
}
// Frame Output check
std::stringstream outName;
outName<<v_index<<".png";
std::string str = outName.str();
const char* outChar = str.c_str();
vtkSmartPointer<vtkPNGWriter> myWriter = vtkSmartPointer<vtkPNGWriter>::New();
myWriter->SetFileName(outChar);
myWriter->SetInputData(liveWin->GetOutput());
myWriter->Write();
v_index++;
} // currCol for
// RowCheck for 1 row
if(currRow == 0)
{
vtkSmartPointer<vtkPNGWriter> myWriter = vtkSmartPointer<vtkPNGWriter>::New();
myWriter->SetFileName("RowCheck.png");
myWriter->SetInputData(currAppender->GetOutput());
myWriter->Write();
}
if(totalAppender->GetNumberOfInputs() == qs_rows)
{
totalAppender->ReplaceNthInputConnection(currRow,currAppender->GetOutputPort());
totalAppender->Update();
}
else
{
totalAppender->AddInputConnection(currAppender->GetOutputPort()); //Builds first row
totalAppender->Update();
}
}// currRow for
this->setViewIndex(v_index);
vtkSmartPointer<vtkPNGWriter> myWriter = vtkSmartPointer<vtkPNGWriter>::New();
myWriter->SetFileName("QuiltCheck.png");
myWriter->SetInputData(totalAppender->GetOutput());
myWriter->Write();
return totalAppender->GetOutput();
}
I’m trying to figure out the code formatting here, sorry!