ctkDICOMIndexerMain.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.commontk.org/LICENSE
  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 <QPushButton>
  17. #include <QTextStream>
  18. // CTK includes
  19. #include <ctkDICOMIndexer.h>
  20. #include <ctkDICOMDatabase.h>
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. #include <fstream>
  25. void print_usage()
  26. {
  27. std::cerr << "Usage:\n";
  28. std::cerr << " 1. ctkDICOMIndexer --add <database.db> <sourceDir> [destDir]\n";
  29. std::cerr << " Adds (or refreshes) sourceDir to the index of the database.\n";
  30. std::cerr << " Creates the database if it is not valid..\n";
  31. std::cerr << " If destDir is provided, images are copied there after import.\n";
  32. std::cerr << " 2. ctkDICOMIndexer --init <database.db> [sqlScript]\n";
  33. std::cerr << " Reinitialize the database. Uses default schema or the provided sqlScript file.\n";
  34. std::cerr << " 3. ctkDICOMIndexer --cleanup <database.db>\n";
  35. std::cerr << " Remove non-existent files from the database.\n";
  36. return;
  37. }
  38. /**
  39. *
  40. */
  41. int main(int argc, char** argv)
  42. {
  43. if (argc < 3)
  44. {
  45. print_usage();
  46. return EXIT_FAILURE;
  47. }
  48. QCoreApplication app(argc, argv);
  49. QTextStream out(stdout);
  50. ctkDICOMIndexer idx;
  51. ctkDICOMDatabase myCTK;
  52. try
  53. {
  54. if (std::string("--add") == argv[1])
  55. {
  56. {
  57. myCTK.openDatabase( argv[2] );
  58. if (argc > 4)
  59. {
  60. idx.addDirectory(myCTK,argv[3],argv[4]);
  61. }
  62. else
  63. {
  64. idx.addDirectory(myCTK,argv[3]);
  65. }
  66. }
  67. }
  68. else if (std::string("--init") == argv[1])
  69. {
  70. myCTK.openDatabase( argv[2] );
  71. if (argc > 2)
  72. {
  73. myCTK.initializeDatabase(argv[2]);
  74. }
  75. else
  76. {
  77. myCTK.initializeDatabase();
  78. }
  79. }
  80. else if (std::string("--cleanup") == argv[1])
  81. {
  82. // TODO
  83. }
  84. else
  85. {
  86. print_usage();
  87. return EXIT_FAILURE;
  88. }
  89. }
  90. catch (std::exception e)
  91. {
  92. std::cerr << "Database error:" << qPrintable(myCTK.lastError());
  93. myCTK.closeDatabase();
  94. return EXIT_FAILURE;
  95. }
  96. return EXIT_SUCCESS;
  97. }