ProgressReport
VTKExamples/Cxx/Developers/ProgressReport
Description¶
This example demonstrates how to get the progress of a filter. This requires that the filter is updating its progress in a sensible way. A sample filter is provided which loops through the input points and updates its progress along the way.
Code¶
ProgressReport.cxx
#include <vtkSmartPointer.h> #include <vtkPoints.h> #include <vtkPolyData.h> #include <vtkSphereSource.h> #include <vtkCallbackCommand.h> #include <vtkCommand.h> #include "vtkTestProgressReportFilter.h" void ProgressFunction(vtkObject* caller, long unsigned int eventId, void* clientData, void* callData); int main(int, char *[]) { vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); sphereSource->Update(); vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New(); progressCallback->SetCallback(ProgressFunction); vtkSmartPointer<vtkTestProgressReportFilter> testFilter = vtkSmartPointer<vtkTestProgressReportFilter>::New(); testFilter->SetInputConnection(sphereSource->GetOutputPort()); testFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback); testFilter->Update(); return EXIT_SUCCESS; } void ProgressFunction ( vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* vtkNotUsed(clientData), void* vtkNotUsed(callData) ) { vtkTestProgressReportFilter* testFilter = static_cast<vtkTestProgressReportFilter*>(caller); std::cout << "Progress: " << testFilter->GetProgress() << std::endl; }
vtkTestProgressReportFilter.h
#ifndef __vtkTestProgressReportFilter_h #define __vtkTestProgressReportFilter_h #include <vtkPolyDataAlgorithm.h> class vtkTestProgressReportFilter : public vtkPolyDataAlgorithm { public: static vtkTestProgressReportFilter *New(); vtkTypeMacro(vtkTestProgressReportFilter,vtkAlgorithm); protected: vtkTestProgressReportFilter(){} ~vtkTestProgressReportFilter() VTK_OVERRIDE {} int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) VTK_OVERRIDE; private: vtkTestProgressReportFilter(const vtkTestProgressReportFilter&) VTK_DELETE_FUNCTION; void operator=(const vtkTestProgressReportFilter&) VTK_DELETE_FUNCTION; }; #endif
vtkTestProgressReportFilter.cxx
#include "vtkTestProgressReportFilter.h" #include <vtkObjectFactory.h> #include <vtkStreamingDemandDrivenPipeline.h> #include <vtkInformationVector.h> #include <vtkInformation.h> #include <vtkDataObject.h> #include <vtkSmartPointer.h> vtkStandardNewMacro(vtkTestProgressReportFilter); int vtkTestProgressReportFilter::RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector) { // Get the info objects vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); vtkInformation *outInfo = outputVector->GetInformationObject(0); // Get the input and ouptut vtkPolyData *input = vtkPolyData::SafeDownCast( inInfo->Get(vtkDataObject::DATA_OBJECT())); vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT())); for(vtkIdType i = 0; i < input->GetNumberOfPoints(); i++) { this->UpdateProgress(static_cast<double>(i)/input->GetNumberOfPoints()); } output->ShallowCopy(input); return 1; }
CMakeLists.txt¶
cmake_minimum_required(VERSION 2.8) PROJECT(ProgressReport) find_package(VTK REQUIRED) include(${VTK_USE_FILE}) add_executable(ProgressReport MACOSX_BUNDLE ProgressReport.cxx vtkTestProgressReportFilter.cxx) target_link_libraries(ProgressReport ${VTK_LIBRARIES})
Download and Build ProgressReport¶
Click here to download ProgressReport and its CMakeLists.txt file. Once the tarball ProgressReport.tar has been downloaded and extracted,
cd ProgressReport/build
If VTK is installed:
cmake ..
If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..
Build the project:
make
and run it:
./ProgressReport
WINDOWS USERS PLEASE NOTE: Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.