Orfeo Toolbox  4.0
otbImageMetadataInterfaceFactory.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 
19 
21 
23 
24 // Optical sensors
31 
32 // SAR Sensors
34 
35 #include "itkObjectFactoryBase.h"
36 #include "itkMutexLock.h"
37 #include "itkMutexLockHolder.h"
38 
39 #include <iostream>
40 #include <iterator>
41 #include <vector>
42 
43 namespace otb
44 {
48 {
49  RegisterBuiltInFactories();
50 
51  std::list<ImageMetadataInterfaceBasePointerType> possibleIMI;
52  std::list<itk::LightObject::Pointer> allOpticalObjects =
53  itk::ObjectFactoryBase::CreateAllInstance("OpticalImageMetadataInterface");
54  std::list<itk::LightObject::Pointer> allSarObjects =
55  itk::ObjectFactoryBase::CreateAllInstance("SarImageMetadataInterface");
56  std::list<itk::LightObject::Pointer> allObjects;
57 
58  std::copy(allOpticalObjects.begin(), allOpticalObjects.end(), std::back_inserter(allObjects) );
59  std::copy(allSarObjects.begin(), allSarObjects.end(), std::back_inserter(allObjects) );
60 
61 
62  for (std::list<itk::LightObject::Pointer>::iterator i = allObjects.begin();
63  i != allObjects.end(); ++i)
64  {
65  ImageMetadataInterfaceBase * io = dynamic_cast<ImageMetadataInterfaceBase*>(i->GetPointer());
66  if (io)
67  {
68  possibleIMI.push_back(io);
69  }
70  else
71  {
72  itkGenericExceptionMacro(<< "Error ImageMetadataInterface factory did not return an ImageMetadataInterfaceBase: "
73  << (*i)->GetNameOfClass());
74  }
75  }
76 
77  for (std::list<ImageMetadataInterfaceBasePointerType>::iterator k = possibleIMI.begin();
78  k != possibleIMI.end(); ++k)
79  {
80  (*k)->SetMetaDataDictionary(dict);
81  if ((*k)->CanRead())
82  {
83  return *k;
84  }
85  }
86 
88  defaultIMI->SetMetaDataDictionary(dict);
89  return dynamic_cast<ImageMetadataInterfaceBase*>(static_cast<DefaultImageMetadataInterface*>(defaultIMI));
90 }
91 
92 void
95 {
96  static bool firstTime = true;
97 
98  static itk::SimpleMutexLock mutex;
99  {
100  // This helper class makes sure the Mutex is unlocked
101  // in the event an exception is thrown.
103  if (firstTime)
104  {
112  firstTime = false;
113  }
114  }
115 }
116 
117 } // end namespace otb

Generated at Sat Mar 8 2014 15:59:08 for Orfeo Toolbox with doxygen 1.8.3.1