ctkVTKObjectEventsObserverTest1.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Qt includes
  2. #include <QApplication>
  3. #include <QDebug>
  4. #include <QList>
  5. #include <QTimer>
  6. // CTKVTK includes
  7. #include "ctkVTKObjectEventsObserver.h"
  8. // STD includes
  9. #include <cstdlib>
  10. #include <iostream>
  11. // VTK includes
  12. #include <vtkCallbackCommand.h>
  13. #include <vtkCommand.h>
  14. #include <vtkObject.h>
  15. #include <vtkSmartPointer.h>
  16. #include <vtkTimerLog.h>
  17. int ctkVTKObjectEventsObserverTest1( int argc, char * argv [] )
  18. {
  19. QApplication app(argc, argv);
  20. int objects = 1000;
  21. int events = 100;
  22. vtkObject* obj = vtkObject::New();
  23. QObject* topObject = new QObject(0);
  24. ctkVTKObjectEventsObserver* observer = new ctkVTKObjectEventsObserver(topObject);
  25. for (int i = 0; i < objects; ++i)
  26. {
  27. QTimer* slotObject = new QTimer(topObject);
  28. observer->addConnection(obj, vtkCommand::ModifiedEvent,
  29. slotObject, SLOT(stop()));
  30. }
  31. vtkSmartPointer<vtkTimerLog> timerLog =
  32. vtkSmartPointer<vtkTimerLog>::New();
  33. timerLog->StartTimer();
  34. for (int i = 0; i < events; ++i)
  35. {
  36. obj->Modified();
  37. }
  38. timerLog->StopTimer();
  39. double t1 = timerLog->GetElapsedTime();
  40. qDebug() << events << "events listened by" << objects << "objects (ctkVTKConnection): " << t1 << "seconds";
  41. obj->Delete();
  42. delete topObject;
  43. return EXIT_SUCCESS;
  44. }