Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkCoreObjectFactoryBase.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 void mitk::CoreObjectFactoryBase::CreateFileExtensions(MultimapType fileExtensionsMap, std::string &fileExtensions)
20 {
21  std::map<std::string, std::string> aMap;
22 
23  // group the extensions by extension-group
24  // e.g. aMap["DICOM files"] = "*.dcm *.DCM *.dc3 *.DC3 *.gdcm"
25  for (MultimapType::iterator it = fileExtensionsMap.begin(); it != fileExtensionsMap.end(); ++it)
26  {
27  std::string aValue = aMap[(*it).second];
28  if (aValue.compare("") != 0)
29  {
30  aValue.append(" ");
31  }
32  aValue.append((*it).first);
33  aMap[(*it).second] = aValue;
34  }
35 
36  // build the "all" entry (it contains all the extensions)
37  // and add it to the string in the first position
38  // e.g. "all (*.dcm *.DCM *.dc3 *.DC3 *.gdcm *.ima *.mhd ... *.vti *.hdr *.nrrd *.nhdr );;"
39  fileExtensions = "known extensions (";
40  std::string lastKey = "";
41  for (MultimapType::iterator it = fileExtensionsMap.begin(); it != fileExtensionsMap.end(); ++it)
42  {
43  std::string aKey = (*it).first;
44 
45  if (aKey.compare(lastKey) != 0)
46  {
47  if (lastKey.compare("") != 0)
48  {
49  fileExtensions.append(" ");
50  }
51  fileExtensions.append(aKey);
52  }
53  lastKey = aKey;
54  }
55  fileExtensions.append(");;all (*);;");
56 
57  // build the entry for each extension-group
58  // e.g. "Sets of 2D slices (*.pic *.pic.gz *.bmp *.png *.dcm *.gdcm *.ima *.tiff);;"
59  for (std::map<std::string, std::string>::iterator it = aMap.begin(); it != aMap.end(); ++it)
60  {
61  // cout << " [" << (*it).first << ", " << (*it).second << "]" << endl;
62  std::string aKey = (*it).first;
63  if (aKey.compare("") != 0)
64  {
65  fileExtensions.append((*it).first);
66  fileExtensions.append(" (");
67  fileExtensions.append((*it).second);
68  fileExtensions.append(");;");
69  }
70  }
71 }
static void CreateFileExtensions(MultimapType fileExtensionsMap, std::string &fileExtensions)
create a string from a map that contains the file extensions
std::multimap< std::string, std::string > MultimapType