ctkVTKObjectEventsObserverTest1.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QDebug>
  17. #include <QList>
  18. #include <QTimer>
  19. // CTKVTK includes
  20. #include "ctkVTKObjectEventsObserver.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. // VTK includes
  25. #include <vtkCallbackCommand.h>
  26. #include <vtkCommand.h>
  27. #include <vtkObject.h>
  28. #include <vtkSmartPointer.h>
  29. #include <vtkTimerLog.h>
  30. int ctkVTKObjectEventsObserverTest1( int argc, char * argv [] )
  31. {
  32. QApplication app(argc, argv);
  33. int objects = 1000;
  34. int events = 100;
  35. vtkObject* obj = vtkObject::New();
  36. QObject* topObject = new QObject(0);
  37. ctkVTKObjectEventsObserver* observer = new ctkVTKObjectEventsObserver(topObject);
  38. for (int i = 0; i < objects; ++i)
  39. {
  40. QTimer* slotObject = new QTimer(topObject);
  41. observer->addConnection(obj, vtkCommand::ModifiedEvent,
  42. slotObject, SLOT(stop()));
  43. }
  44. vtkSmartPointer<vtkTimerLog> timerLog =
  45. vtkSmartPointer<vtkTimerLog>::New();
  46. timerLog->StartTimer();
  47. for (int i = 0; i < events; ++i)
  48. {
  49. obj->Modified();
  50. }
  51. timerLog->StopTimer();
  52. double t1 = timerLog->GetElapsedTime();
  53. qDebug() << events << "events listened by" << objects << "objects (ctkVTKConnection): " << t1 << "seconds";
  54. obj->Delete();
  55. delete topObject;
  56. return EXIT_SUCCESS;
  57. }