diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 7fc63854f6..960535e42b 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -1,63 +1,63 @@ set(MITK_DEFAULT_SUBPROJECTS MITK-Examples) #----------------------------------------------------------------------------- # Set-up example plugins #----------------------------------------------------------------------------- if(MITK_USE_BLUEBERRY) # Specify which plug-ins belong to this project macro(GetMyTargetLibraries all_target_libraries varname) set(re_ctkplugin_mitk "^org_mitk_example_[a-zA-Z0-9_]+$") set(_tmp_list) list(APPEND _tmp_list ${all_target_libraries}) ctkMacroListFilter(_tmp_list re_ctkplugin_mitk OUTPUT_VARIABLE ${varname}) endmacro() set(MITK_EXAMPLE_PLUGIN_TARGETS ) foreach(mitk_example_plugin ${MITK_EXAMPLE_PLUGINS}) ctkFunctionExtractOptionNameAndValue(${mitk_example_plugin} plugin_name plugin_value) string(REPLACE "." "_" _plugin_target ${plugin_name}) list(APPEND MITK_EXAMPLE_PLUGIN_TARGETS ${_plugin_target}) mark_as_advanced(${${_plugin_target}_option_name}) endforeach() endif() #----------------------------------------------------------------------------- # Add example executables #----------------------------------------------------------------------------- set(MITK_DIR ${PROJECT_BINARY_DIR}) set(MITK_EXPORTS_FILE_INCLUDED 1) set(_example_dirs + Dump MbiLog QtFreeRender Tutorial # Overlays# depends on MitkQtWidgetsExt.. ) # some examples depend on Qt 5 if (MITK_USE_Qt5) list(APPEND _example_dirs QuickRender ) elseif (MITK_USE_Qt4) list(APPEND _example_dirs QtAppExample - mitkdump - mitkdumpdir + DumpDir ) endif() if(MITK_USE_BLUEBERRY) list(APPEND _example_dirs BlueBerryExampleLauncher ) endif() foreach(_example_dir ${_example_dirs}) add_subdirectory(${_example_dir}) endforeach() diff --git a/Examples/Dump/CMakeLists.txt b/Examples/Dump/CMakeLists.txt new file mode 100644 index 0000000000..1e43f130f0 --- /dev/null +++ b/Examples/Dump/CMakeLists.txt @@ -0,0 +1,4 @@ +project(Dump) +find_package(MITK REQUIRED) + +mitk_create_executable(DEPENDS MitkDICOMReader WARNINGS_AS_ERRORS) \ No newline at end of file diff --git a/Examples/mitkdump/files.cmake b/Examples/Dump/files.cmake similarity index 100% rename from Examples/mitkdump/files.cmake rename to Examples/Dump/files.cmake diff --git a/Examples/mitkdump/mitkdump.cpp b/Examples/Dump/mitkdump.cpp similarity index 97% rename from Examples/mitkdump/mitkdump.cpp rename to Examples/Dump/mitkdump.cpp index 34a10db93a..94b7d1f99b 100644 --- a/Examples/mitkdump/mitkdump.cpp +++ b/Examples/Dump/mitkdump.cpp @@ -1,287 +1,287 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ /** \file mitkdump.cpp \brief Commandline application to see what DICOMFileReaderSelector would produce from a set of files. Usage: \verbatim mitkdump [-v] file1 [... fileN] -v output more details on commandline fileN DICOM file \endverbatim The application will ask a DICOMFileReaderSelector to analyze the files given as file1 .. fileN. Once the reader with the least number of files is selected, this result is printed to commandline. If the "-v" flag is used (as a first parameter), the output will contain details about filenames, which can make the output considerably harder to read. Output is also written to a log file of name "%gt;datetime-stamp%lt;_dir_>directory-name<.mitkdump */ #include "mitkDICOMFileReaderSelector.h" #include "mitkDICOMReaderConfigurator.h" #include "mitkDICOMImageFrameInfo.h" using mitk::DICOMTag; std::string buildDateString() { std::time_t rawtime; std::tm* timeinfo; char buffer [80]; std::time(&rawtime); timeinfo = std::localtime(&rawtime); std::strftime(buffer,80,"%Y%m%d-%H%M%S",timeinfo); return std::string(buffer); } void gen_random(char *s, const int len) { static const char alphanum[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (int i = 0; i < len; ++i) { s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; } s[len] = 0; } std::string gen_random(const int len) { if (len > 0 && len < 100) { char retval[100]; gen_random(retval, len); return std::string(retval); } else { return std::string(""); } } std::string removeUnsafeChars(const std::string& str) { std::string retval; for(std::string::const_iterator it = str.begin(); it != str.end(); ++it) { const char& c = *it; if ( (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '.') || (c == '-') || (c == '_') ) { retval += c; } } return retval; } std::string extractDirString(const std::string& dirString) { std::string wholeprefix = dirString.substr(0, dirString.find_last_of("/\\")); std::string lastDirectoryPart = wholeprefix.substr(wholeprefix.find_last_of("/\\")+1); std::string cleanLastDirectoryPart = removeUnsafeChars(lastDirectoryPart); if (!cleanLastDirectoryPart.empty()) { return cleanLastDirectoryPart; } else { std::stringstream emptydirname; emptydirname << "noname_" << gen_random(6); return emptydirname.str(); } } int main(int argc, char* argv[]) { bool fileDetails(false); bool loadimage(false); int firstFileIndex = 1; // see if we got the '-v' flag to output file details if (argc > 1 && std::string(argv[firstFileIndex]) == "-v") { fileDetails = true; ++firstFileIndex; } // see if we got the '-l' flag if (argc > 1 && std::string(argv[firstFileIndex]) == "-l") { loadimage = true; ++firstFileIndex; } // analyze files from argv mitk::StringList inputFiles; for (int a = firstFileIndex; a < argc; ++a) { inputFiles.push_back( std::string(argv[a]) ); } if (inputFiles.empty()) { MITK_INFO << "0 input files given, exiting..."; return EXIT_SUCCESS; } mitk::DICOMFileReaderSelector::Pointer configSelector = mitk::DICOMFileReaderSelector::New(); configSelector->LoadBuiltIn3DConfigs(); // a set of compiled in ressources with standard configurations that work well configSelector->SetInputFiles( inputFiles ); mitk::DICOMFileReader::Pointer reader = configSelector->GetFirstReaderWithMinimumNumberOfOutputImages(); if (reader.IsNull()) { MITK_ERROR << "Could not configure any DICOM reader.. Exiting..."; return EXIT_FAILURE; } // output best reader result MITK_INFO << "---- Best reader configuration '" << reader->GetConfigurationLabel() << "' with " << reader->GetNumberOfOutputs() << " outputs"; if (fileDetails) { reader->PrintOutputs(std::cout, fileDetails); } // construct the name of a log file std::string datestring = buildDateString();; std::string dirString = extractDirString(argv[firstFileIndex]); std::string logfilename = datestring + "_dir_" + dirString + ".mitkdump"; MITK_INFO << "Logfile " << logfilename; // write output to file for later analysis std::ofstream fs; fs.open(logfilename.c_str()); fs << "---- " << dirString << ": Best reader configuration '" << reader->GetConfigurationLabel() << "' with " << reader->GetNumberOfOutputs() << " outputs" << std::endl; reader->PrintOutputs( fs, true); // always verbose in log file fs.close(); // serialize, deserialize, analyze again, verify result! mitk::DICOMReaderConfigurator::Pointer serializer = mitk::DICOMReaderConfigurator::New(); std::string readerSerialization = serializer->CreateConfigStringFromReader(reader.GetPointer()); bool outputError(false); for (unsigned int outputIndex = 0; outputIndex < reader->GetNumberOfOutputs(); ++outputIndex) { const mitk::DICOMImageBlockDescriptor& outputDescriptor = reader->GetOutput(outputIndex); mitk::StringList filenamesOfThisGroup; const mitk::DICOMImageFrameList& frames = outputDescriptor.GetImageFrameList(); for (mitk::DICOMImageFrameList::const_iterator fIter = frames.begin(); fIter != frames.end(); ++fIter) { filenamesOfThisGroup.push_back( (*fIter)->Filename ); } mitk::DICOMReaderConfigurator::Pointer readerConfigurator = mitk::DICOMReaderConfigurator::New(); mitk::DICOMFileReader::Pointer dicomReader = readerConfigurator->CreateFromUTF8ConfigString( readerSerialization ); dicomReader->SetInputFiles( filenamesOfThisGroup ); dicomReader->AnalyzeInputFiles(); if (dicomReader->GetNumberOfOutputs() != 1) { MITK_ERROR << "****** Re-analyzing files of output group " << outputIndex << " yields " << dicomReader->GetNumberOfOutputs() << " groups"; outputError = true; for (mitk::DICOMImageFrameList::const_iterator fIter = frames.begin(); fIter != frames.end(); ++fIter) { MITK_INFO << "filename group " << outputIndex << ": " << (*fIter)->Filename; } } else { MITK_INFO << "Re-analyzing files of output group " << outputIndex << " yields " << dicomReader->GetNumberOfOutputs() << " groups"; } } if (outputError) { std::stringstream es; es << "Original reader configuration: " << std::endl; reader->PrintConfiguration(es); es << std::endl; mitk::DICOMReaderConfigurator::Pointer readerConfigurator = mitk::DICOMReaderConfigurator::New(); mitk::DICOMFileReader::Pointer dicomReader = readerConfigurator->CreateFromUTF8ConfigString( readerSerialization ); es << "New reader configuration: " << std::endl; dicomReader->PrintConfiguration(es); es << std::endl; es << "Original XML: \n" << readerSerialization << std::endl; std::string newSerialization = serializer->CreateConfigStringFromReader(dicomReader.GetPointer()); es << "New XML: \n" << newSerialization << std::endl; MITK_ERROR << es.str(); } if (loadimage) { MITK_INFO << "Loading..."; reader->LoadImages(); mitk::Image::Pointer image = reader->GetOutput(0).GetMitkImage(); MITK_INFO << "---- Output image:"; - mitk::Geometry3D::Pointer geo3D = image->GetGeometry(); + mitk::BaseGeometry::Pointer geo3D = image->GetGeometry(); if (geo3D.IsNotNull()) { mitk::SlicedGeometry3D::Pointer sg = dynamic_cast(geo3D.GetPointer()); if (sg.IsNotNull()) { unsigned int nos = sg->GetSlices(); - mitk::Geometry2D::Pointer first = sg->GetGeometry2D(0); - mitk::Geometry2D::Pointer last = sg->GetGeometry2D(nos-1); + mitk::PlaneGeometry::ConstPointer first = sg->GetPlaneGeometry(0); + mitk::PlaneGeometry::ConstPointer last = sg->GetPlaneGeometry(nos-1); mitk::Point3D firstOrigin = first->GetOrigin(); mitk::Point3D lastOrigin = last->GetOrigin(); MITK_INFO << "Geometry says: First slice at " << firstOrigin << ", last slice at " << lastOrigin; mitk::StringLookupTableProperty::Pointer sliceLocations = dynamic_cast( image->GetProperty("dicom.image.0020.1041").GetPointer() ); if (sliceLocations.IsNotNull()) { std::string firstSliceLocation = sliceLocations->GetValue().GetTableValue(0); std::string lastSliceLocation = sliceLocations->GetValue().GetTableValue(nos-1); MITK_INFO << "Image properties says: first slice location at " << firstSliceLocation << ", last slice location at " << lastSliceLocation; } mitk::StringLookupTableProperty::Pointer instanceNumbers = dynamic_cast( image->GetProperty("dicom.image.0020.0013").GetPointer() ); if (instanceNumbers.IsNotNull()) { std::string firstInstanceNumber = instanceNumbers->GetValue().GetTableValue(0); std::string lastInstanceNumber = instanceNumbers->GetValue().GetTableValue(nos-1); MITK_INFO << "Image properties says: first instance number at " << firstInstanceNumber << ", last instance number at " << lastInstanceNumber; } } } MITK_INFO << "---- End of output"; } // if we got so far, everything is fine return EXIT_SUCCESS; } diff --git a/Examples/DumpDir/CMakeLists.txt b/Examples/DumpDir/CMakeLists.txt new file mode 100644 index 0000000000..046da707bb --- /dev/null +++ b/Examples/DumpDir/CMakeLists.txt @@ -0,0 +1,6 @@ +project(DumpDir) +find_package(MITK REQUIRED) + +if(TARGET MitkDump) + mitk_create_executable(PACKAGE_DEPENDS Qt4|QtCore WARNINGS_AS_ERRORS) +endif() \ No newline at end of file diff --git a/Examples/mitkdumpdir/files.cmake b/Examples/DumpDir/files.cmake similarity index 100% rename from Examples/mitkdumpdir/files.cmake rename to Examples/DumpDir/files.cmake diff --git a/Examples/mitkdumpdir/mitkdumpdir.cpp b/Examples/DumpDir/mitkdumpdir.cpp similarity index 93% rename from Examples/mitkdumpdir/mitkdumpdir.cpp rename to Examples/DumpDir/mitkdumpdir.cpp index fbf3be0871..08b4d40f22 100644 --- a/Examples/mitkdumpdir/mitkdumpdir.cpp +++ b/Examples/DumpDir/mitkdumpdir.cpp @@ -1,127 +1,127 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ /** \file mitkdumpdir.cpp - \brief Commandline application that calls the mitkdump application on multiple directories. + \brief Commandline application that calls the MitkDump application on multiple directories. Usage: \verbatim - mitkdumpdir [-v] dir1 [... dirN] + MitkDumpDir [-v] dir1 [... dirN] -v output more details on commandline dirN directory names \endverbatim The application will traverse each directory for sub-directories. For each leaf-directory (i.e. directories without sub-directories), the mitkdump application will be called, given all files from the leaf directory. If the "-v" flag is used, it will be passed to the mitkdump application, which can create considerably more output. */ #include bool printEachOutput(false); bool processLeafNode(const QString& dirname, const QString& executablename) { qDebug() << "Processing " << qPrintable(dirname); QFileInfoList fileinfos = QDir( dirname ).entryInfoList( QDir::Files | QDir::Readable ); QStringList filenames; foreach(QFileInfo info, fileinfos) { filenames << info.absoluteFilePath(); } QProcess mitkdump; mitkdump.start(executablename, filenames); if (!mitkdump.waitForStarted()) return false; if (!mitkdump.waitForFinished()) return false; if (printEachOutput) { QString output(mitkdump.readAll()); qDebug() << output; } return true; } void processLeafNodes(const QString& rootDir, const QString& executablename) { QDirIterator dirIter(rootDir, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable, QDirIterator::Subdirectories); while (dirIter.hasNext()) { dirIter.next(); if ( QDir( dirIter.fileInfo().absoluteFilePath() ).entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable ).empty() ) { processLeafNodes( dirIter.filePath(), executablename ); } } if ( QDir( rootDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable ).empty() ) { - bool successful = processLeafNode( rootDir, executablename ); + processLeafNode( rootDir, executablename ); } } int main(int argc, char* argv[]) { QCoreApplication a(argc,argv); int firstDirIndex = 1; // see if we got the '-v' flag to output file details if (argc > 1 && std::string(argv[firstDirIndex]) == "-v") { printEachOutput = true; ++firstDirIndex; } - QString executablename( QCoreApplication::applicationDirPath() + QDir::separator() + "mitkdump" ); + QString executablename( QCoreApplication::applicationDirPath() + QDir::separator() + "MitkDump" ); #ifdef WIN32 executablename += ".exe"; #endif // analyze dirs from argv QStringList inputDirs; for (int a = firstDirIndex; a < argc; ++a) { inputDirs << argv[a]; } foreach(QString dirname, inputDirs) { processLeafNodes(dirname, executablename); } // if we got so far, everything is fine return EXIT_SUCCESS; } diff --git a/Examples/mitkdump/CMakeLists.txt b/Examples/mitkdump/CMakeLists.txt deleted file mode 100644 index f28419c500..0000000000 --- a/Examples/mitkdump/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -project(mitkdump) -find_package(MITK REQUIRED) - -mitk_check_module_dependencies(MODULES DICOMReader MISSING_DEPENDENCIES_VAR _missing_deps) -if(_missing_deps) - message(STATUS "mitkdump application won't be built. Missing: ${_missing_deps}") -else(_missing_deps) - mitk_create_executable(mitkdump DEPENDS DICOMReader WARNINGS_AS_ERRORS) -endif() diff --git a/Examples/mitkdumpdir/CMakeLists.txt b/Examples/mitkdumpdir/CMakeLists.txt deleted file mode 100644 index 9cf86752b5..0000000000 --- a/Examples/mitkdumpdir/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -project(mitkdumpdir) -find_package(MITK REQUIRED) - -mitk_check_module_dependencies(MODULES Qmitk MISSING_DEPENDENCIES_VAR _missing_deps) -if(_missing_deps) - message(STATUS "mitkdumpdir application won't be built. Missing: ${_missing_deps}") -else(_missing_deps) - - mitk_create_executable(mitkdumpdir DEPENDS Qmitk WARNINGS_AS_ERRORS) - -endif()