ctkDICOMIndexer.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 // Qt includes
00022 #include <QApplication>
00023 #include <QPushButton>
00024 #include <QTextStream>
00025 
00026 // CTK includes
00027 #include <ctkDICOMIndexer.h>
00028 #include <ctkDICOM.h>
00029 
00030 // STD includes
00031 #include <cstdlib>
00032 #include <iostream>
00033 #include <fstream>
00034 
00035 void print_usage()
00036 {
00037   std::cerr << "Usage:\n";
00038   std::cerr << "  1. ctkDICOMIndexer --add <database.db> <sourceDir> [destDir]\n";
00039   std::cerr << "     Adds (or refreshes) sourceDir to the index of the database.\n";
00040   std::cerr << "     Creates the database if it is not valid..\n";
00041   std::cerr << "     If destDir is provided, images are copied there after import.\n";
00042   std::cerr << "  2. ctkDICOMIndexer --init <database.db> [sqlScript]\n";
00043   std::cerr << "     Reinitialize the database. Uses default schema or the provided sqlScript file.\n";
00044   std::cerr << "  3. ctkDICOMIndexer --cleanup <database.db>\n";
00045   std::cerr << "     Remove non-existent files from the database.\n";
00046   return;
00047 }
00048 
00049 
00053 int main(int argc, char** argv)
00054 {
00055 
00056   if (argc < 3)
00057   {
00058     print_usage();
00059     return EXIT_FAILURE;
00060   }
00061 
00062   QApplication app(argc, argv);
00063   QTextStream out(stdout);
00064 
00065   ctkDICOMIndexer idx;
00066   ctkDICOM myCTK;
00067 
00068 
00069   try
00070   {
00071     if (std::string("--add") == argv[1])
00072     {
00073       {
00074         myCTK.openDatabase( argv[2] );
00075         if (argc > 4)
00076         {
00077           idx.addDirectory(myCTK.database(),argv[3],argv[4]);
00078         }
00079         else
00080         {
00081           idx.addDirectory(myCTK.database(),argv[3]);
00082         }
00083       }
00084     }
00085     else if (std::string("--init") == argv[1])
00086     {
00087       myCTK.openDatabase( argv[2] );
00088       if (argc > 2)
00089       {
00090         myCTK.initializeDatabase(argv[2]);
00091       }
00092       else
00093       {
00094         myCTK.initializeDatabase();
00095       }
00096     }
00097     else if (std::string("--cleanup") == argv[1])
00098     {
00099       // TODO
00100     }
00101     else
00102     {
00103       print_usage();
00104       return EXIT_FAILURE;
00105     }
00106   }
00107   catch (std::exception e)
00108   {
00109     std::cerr << "Database error:" << qPrintable(myCTK.GetLastError());
00110     myCTK.closeDatabase();
00111     return EXIT_FAILURE;
00112   }
00113   return EXIT_SUCCESS;
00114 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1