Difference between revisions of "VTK/Examples/Cxx/Developers/ProgressReport"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(vtkTestProgressReportFilter.cxx)
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/ProgressReport ProgressReport] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples we...")
 
Line 1: Line 1:
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.
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/Developers/ProgressReport ProgressReport] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
 
 
==ProgressReport.cxx==
 
<source lang="cpp">
 
#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;
 
}
 
</source>
 
 
 
==vtkTestProgressReportFilter.h==
 
<source lang="cpp">
 
#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
 
</source>
 
 
 
==vtkTestProgressReportFilter.cxx==
 
<source lang="cpp">
 
#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;
 
}
 
</source>
 
 
 
{{VTKCMakeListsMultiple|{{SUBPAGENAME}}|vtkTestProgressReportFilter}}
 
 
 
[[Category:VTKNoVizRequired]]
 

Latest revision as of 17:03, 12 April 2019

See ProgressReport on the new VTKExamples website.