#include "vtkFitsReader.h" #include "vtkPolyDataMapper.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include VTK_MODULE_INIT(vtkInteractionStyle); void CallbackFunction(vtkObject *caller, long unsigned int vtkNotUsed(eventId), void *vtkNotUsed(clientData), void *vtkNotUsed(callData)) { vtkRenderer *renderer = static_cast(caller); double timeInSeconds = renderer->GetLastRenderTimeInSeconds(); double fps = double(1.0) / timeInSeconds; } int main(int argc, char *argv[]) { //Reading data and prepairing it in implicit form //..... // isosurface vtkMarchingCubes *shellE = vtkMarchingCubes::New(); shellE->SetInputData(implicit->GetOutput()); shellE->ComputeNormalsOn(); shellE->SetValue(0, 3 * fitsReader->GetRMS()); shellE->Update(); std::cout << "Cells number " << shellE->GetOutput()->GetNumberOfCells() << std::endl; vtkPolyDataMapper *shellM = vtkPolyDataMapper::New(); shellM->SetInputConnection(shellE->GetOutputPort()); shellM->ScalarVisibilityOff(); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(shellM); renderer->AddActor(actor); vtkRenderWindow *renderWindow = vtkRenderWindow::New(); renderWindow->AddRenderer(renderer); renderWindow->SetSize(1600, 1600); vtkRenderWindowInteractor *renderWindowInteractor = vtkRenderWindowInteractor::New(); renderWindowInteractor->SetRenderWindow(renderWindow); vtkSmartPointer style = vtkSmartPointer::New(); // like // paraview renderWindowInteractor->SetInteractorStyle(style); vtkSmartPointer callback = vtkSmartPointer::New(); callback->SetCallback(CallbackFunction); renderer->AddObserver(vtkCommand::EndEvent, callback); renderer->SetBackground(.3, .6, .3); // Background color green double bounds[6]; shellE->GetOutput()->GetBounds(bounds); renderer->ResetCamera(); auto cam = renderer->GetActiveCamera(); double pos[3]; double time = 0; int endCount = 120; for (int i = 0; i < endCount; i++) { double max[3] = {bounds[1] + vtkMath::Random(0, 10), bounds[3] + vtkMath::Random(0, 10), bounds[5] + vtkMath::Random(0, 10)}; double min[3] = {bounds[0] + vtkMath::Random(0, 10), bounds[2] + vtkMath::Random(0, 10), bounds[4] + vtkMath::Random(0, 10)}; renderer->ResetCamera(min[0], max[0], min[1], max[1], min[2], max[2]); renderWindow->Render(); double sec = renderer->GetLastRenderTimeInSeconds(); time += sec; std::cout << "seconds " << sec << std::endl; } std::cout << "Total FPS: " << double(endCount) / time << std::endl; vtkSmartPointer clock = vtkSmartPointer::New(); clock->StartTimer(); for (int i = 0; i < endCount; i++) { double max[3] = {bounds[1] + vtkMath::Random(0, 10), bounds[3] + vtkMath::Random(0, 10), bounds[5] + vtkMath::Random(0, 10)}; double min[3] = {bounds[0] + vtkMath::Random(0, 10), bounds[2] + vtkMath::Random(0, 10), bounds[4] + vtkMath::Random(0, 10)}; renderer->ResetCamera(min[0], max[0], min[1], max[1], min[2], max[2]); renderWindow->Render(); } clock->StopTimer(); double frameRate = (double)endCount / clock->GetElapsedTime(); std::cout << "AVERAGE FRAME RATE: " << frameRate << " fps" << std::endl; renderWindowInteractor->Start(); }