Medical Imaging Interaction Toolkit  2018.4.99-67d34b5d
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 void mitk::CoreObjectFactoryBase::CreateFileExtensions(MultimapType fileExtensionsMap, std::string &fileExtensions)
16 {
17  std::map<std::string, std::string> aMap;
18 
19  // group the extensions by extension-group
20  // e.g. aMap["DICOM files"] = "*.dcm *.DCM *.dc3 *.DC3 *.gdcm"
21  for (auto it = fileExtensionsMap.begin(); it != fileExtensionsMap.end(); ++it)
22  {
23  std::string aValue = aMap[(*it).second];
24  if (aValue.compare("") != 0)
25  {
26  aValue.append(" ");
27  }
28  aValue.append((*it).first);
29  aMap[(*it).second] = aValue;
30  }
31 
32  // build the "all" entry (it contains all the extensions)
33  // and add it to the string in the first position
34  // e.g. "all (*.dcm *.DCM *.dc3 *.DC3 *.gdcm *.ima *.mhd ... *.vti *.hdr *.nrrd *.nhdr );;"
35  fileExtensions = "known extensions (";
36  std::string lastKey = "";
37  for (auto it = fileExtensionsMap.begin(); it != fileExtensionsMap.end(); ++it)
38  {
39  std::string aKey = (*it).first;
40 
41  if (aKey.compare(lastKey) != 0)
42  {
43  if (lastKey.compare("") != 0)
44  {
45  fileExtensions.append(" ");
46  }
47  fileExtensions.append(aKey);
48  }
49  lastKey = aKey;
50  }
51  fileExtensions.append(");;all (*);;");
52 
53  // build the entry for each extension-group
54  // e.g. "Sets of 2D slices (*.pic *.pic.gz *.bmp *.png *.dcm *.gdcm *.ima *.tiff);;"
55  for (auto it = aMap.begin(); it != aMap.end(); ++it)
56  {
57  // cout << " [" << (*it).first << ", " << (*it).second << "]" << endl;
58  std::string aKey = (*it).first;
59  if (aKey.compare("") != 0)
60  {
61  fileExtensions.append((*it).first);
62  fileExtensions.append(" (");
63  fileExtensions.append((*it).second);
64  fileExtensions.append(");;");
65  }
66  }
67 }
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