[vtkusers] try to abort rendering. althought vtkRenderWindow->Render() comes back, rendering continues until everything is completely rendered

Tracy Hu tracy.hu at yahoo.com
Wed Apr 29 18:59:26 EDT 2009


I try to abort a lengthy rendering before it finishs. 
I first measured the time it takes to finish rendering everything. 

start = time(NULL);
renWindow->Render();
end = time(NULL);
cout <<"time spent for rendering: " <<difftime(end, start)<<endl;

it was 19 seconds.

then I tried to kill the rendering process before it finish by doing this: 
Once render window showed up, I clicked it. renWindow->Render() came back,
 and rendering took 3 seconds. 

but after that, render window was still not responsive. Only after about 
16 seconds, the complete images show up in window and window became 
responsive after that. 

It looks to me that although vtk already kill the rendering process, 
Windows still try to finish rendering everything. That might explain why
 the window remained not
 responsive until everything finished rendering.

Does anybody knows the true reason? and how could I kill the rendering 
process and immediately get back the interaction with the window?

Thank you very much

Tracy

the code is as following:
======================================
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredPointsReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkColorTransferFunction.h"
#include "vtkCamera.h"
#include "vtkStructuredPoints.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkCommand.h"
#include "time.h"

class InteractionCallBack : public vtkCommand {

public:

  static InteractionCallBack* New()
 {
    return new InteractionCallBack;
  }

  virtual void Execute(vtkObject* caller, unsigned long, void* data) {
    vtkRenderWindow* renWin = vtkRenderWindow::SafeDownCast(caller);
    if (renWin->GetEventPending()) {
      renWin->SetAbortRender(1);
    }
  }

};

int main( int argc, char *argv[] )
{
    vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
        reader->SetFileName("D:\\Simulations\\ironProt.vtk");
        reader->Update();

    vtkPiecewiseFunction *opacity = vtkPiecewiseFunction::New();
        opacity->AddSegment(0, 0.0, 255, 0.5);
    
    vtkVolumeProperty *volumeProperty =
 vtkVolumeProperty::New();
        volumeProperty->SetScalarOpacity(opacity);
        volumeProperty->SetInterpolationTypeToLinear();
        volumeProperty->ShadeOn();

    vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
    vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
        volumeMapper->SetInput(reader->GetOutput());
        volumeMapper->SetVolumeRayCastFunction(compositeFunction);
        volumeMapper->SetSampleDistance(0.01);

    vtkVolume *volume = vtkVolume::New();
        volume->SetMapper(volumeMapper);
       
 volume->SetProperty(volumeProperty);
    
    vtkRenderer *renderer = vtkRenderer::New();
        renderer->SetBackground(1.0, 1.0, 1.0);
        renderer->AddVolume(volume);
        renderer->ResetCamera();
    vtkRenderWindow *renWindow = vtkRenderWindow::New();
        renWindow->SetSize(400,400);
        renWindow->SetPosition(600, 400);
        renWindow->AddRenderer(renderer);
    vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
        interactor->SetRenderWindow(renWindow);
    vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
   
     interactor->SetInteractorStyle(style);

    InteractionCallBack* icb = InteractionCallBack::New();
    renWindow->AddObserver(vtkCommand::AbortCheckEvent, icb);
    
    time_t start, end;
    start = time(NULL);

    renWindow->Render();

    end = time(NULL);
    cout <<"time spent for rendering: " <<difftime(end, start)<<endl;

    interactor->Start();

    renderer->Delete();
    renWindow->Delete();
    interactor->Delete();
    reader->Delete();
    opacity->Delete();
    volumeProperty->Delete();
    compositeFunction->Delete();
   
 volumeMapper->Delete();
    volume->Delete();

    return 0;

}




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090429/9c09a871/attachment.htm>


More information about the vtkusers mailing list