ctkVTKChartViewTest1.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 <QSharedPointer>
  17. #include <QTimer>
  18. // CTK includes
  19. #include "ctkVTKChartView.h"
  20. // VTK includes
  21. #include <vtkIntArray.h>
  22. #include <vtkNew.h>
  23. #include <vtkPlotBar.h>
  24. #include <vtkTable.h>
  25. // STD includes
  26. #include <iostream>
  27. // Monthly circulation data
  28. static int data_2008[] = {10822, 10941, 9979, 10370, 9460, 11228, 15093, 12231, 10160, 9816, 9384, 7892};
  29. static int data_2009[] = {9058, 9474, 9979, 9408, 8900, 11569, 14688, 12231, 10294, 9585, 8957, 8590};
  30. static int data_2010[] = {9058, 10941, 9979, 10270, 8900, 11228, 14688, 12231, 10160, 9585, 9384, 8590};
  31. //-----------------------------------------------------------------------------
  32. int ctkVTKChartViewTest1(int argc, char * argv [] )
  33. {
  34. QApplication app(argc, argv);
  35. ctkVTKChartView view(0);
  36. // Create a table with some points in it...
  37. vtkNew<vtkTable> table;
  38. vtkNew<vtkIntArray> arrMonth;
  39. arrMonth->SetName("Month");
  40. table->AddColumn(arrMonth.GetPointer());
  41. vtkNew<vtkIntArray> arr2008;
  42. arr2008->SetName("2008");
  43. table->AddColumn(arr2008.GetPointer());
  44. vtkNew<vtkIntArray> arr2009;
  45. arr2009->SetName("2009");
  46. table->AddColumn(arr2009.GetPointer());
  47. vtkNew<vtkIntArray> arr2010;
  48. arr2010->SetName("2010");
  49. table->AddColumn(arr2010.GetPointer());
  50. table->SetNumberOfRows(12);
  51. for (int i = 0; i < 12; i++)
  52. {
  53. table->SetValue(i,0,i+1);
  54. table->SetValue(i,1,data_2008[i]);
  55. table->SetValue(i,2,data_2009[i]);
  56. table->SetValue(i,3,data_2010[i]);
  57. }
  58. // Add multiple line plots, setting the colors etc
  59. vtkPlotBar* bar = vtkPlotBar::New();
  60. bar->SetInput(table.GetPointer(), 0, 1);
  61. bar->SetColor(0, 255, 0, 255);
  62. view.addPlot(bar);
  63. bar->Delete();
  64. bar = vtkPlotBar::New();
  65. bar->SetInput(table.GetPointer(), 0, 2);
  66. bar->SetColor(255, 0, 0, 255);
  67. view.addPlot(bar);
  68. bar->Delete();
  69. bar = vtkPlotBar::New();
  70. bar->SetInput(table.GetPointer(), 0, 3);
  71. bar->SetColor(0, 0, 255, 255);
  72. view.addPlot(bar);
  73. bar->Delete();
  74. view.show();
  75. QTimer autoExit;
  76. if (argc < 2 || QString(argv[1]) != "-I")
  77. {
  78. QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
  79. autoExit.start(1000);
  80. }
  81. return app.exec();
  82. }