[vtkusers] Observer/Progress problem ?!

de Boer Ingo I.deBoer at polytec.de
Mon Aug 11 03:59:22 EDT 2003


Hi,
 
I am using the vtkSurfaceReconstructionFilter with about 130000
to 250000 points. This takes quite some time. I want to show
some kind of progress bar or stdout or whatsoever which shows 
the current point number, so the user knows how long he has to
wait...

The following sample shows the number of points (of course),
but then only:

start progress
progress: 1.000000
end progress

Why is that ? How do I get some kind of counter progress ?

greets 
 Ingo

############################################################

///////////////////////////////////////////
void StartProgress(void *arg)
{
 fprintf(stdout, "start progress\n");
}

///////////////////////////////////////////
void EndProgress(void *arg)
{
 fprintf(stdout, "end progress\n");
}

///////////////////////////////////////////
void UpdateProgress(void *arg)
{
 vtkProcessObject* process = reinterpret_cast<vtkProcessObject*>(arg);
 fprintf(stdout, "progress: %f\r", process->GetProgress());
}

///////////////////////////////////////////
int main( int argc, char *argv[] )
{
 // Read some 3d points.
 FILE *datei = fopen(argv[1],"rt");

 vtkPolyData *data = vtkPolyData::New();
 vtkPoints *points = vtkPoints::New();

 int iCounter = 0;
 while (!feof(datei))
 {
   fprintf(stdout,"reading points: %i\r", iCounter);
   float x, y, z;
   fscanf(datei,"%f %f %f\n", &x, &y, &z);
   points->InsertPoint(iCounter++, x, y, z);
 }
 data->SetPoints(points);
 fclose(datei);
 fprintf(stdout,"\n\n");

 // Construct the surface and create isosurface
 vtkSurfaceReconstructionFilter *surf = vtkSurfaceReconstructionFilter::New();
 surf->SetInput(data);

 surf->SetStartMethod(StartProgress, static_cast<void*>(surf));
 surf->SetEndMethod(EndProgress, static_cast<void*>(surf));
 surf->SetProgressMethod(UpdateProgress, static_cast<void*>(surf));

 vtkContourFilter *cf = vtkContourFilter::New();
 cf->SetInput((vtkDataSet*)surf->GetOutput());
 cf->SetValue(0, 0.0);

 vtkReverseSense *reverse = vtkReverseSense::New();
 reverse->SetInput(cf->GetOutput());
 reverse->ReverseCellsOn();
 reverse->ReverseNormalsOn();

 vtkPolyDataMapper *map = vtkPolyDataMapper::New();
 map->SetInput(reverse->GetOutput());

 map->ScalarVisibilityOff();

 vtkActor *surfaceActor = vtkActor::New();
 surfaceActor->SetMapper(map);

 // The usual rendering stuff.
 vtkCamera *camera = vtkCamera::New();
 vtkRenderer *renderer = vtkRenderer::New();
 vtkRenderWindow *renWin = vtkRenderWindow::New();
 renWin->AddRenderer(renderer);

 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
 iren->SetRenderWindow(renWin);

 renderer->AddActor(surfaceActor);
 renderer->SetActiveCamera(camera);
 
 renWin->SetSize(300,300);

 // interact with data
 renWin->Render();
 iren->Start();

 // Clean up
 [snip]
 
 return 0;
}





More information about the vtkusers mailing list