Orfeo ToolBox  4.2
Orfeo ToolBox is not a black box
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
32 
33 // SAR Sensors
35 
36 #include "itkObjectFactoryBase.h"
37 #include "itkMutexLock.h"
38 #include "itkMutexLockHolder.h"
39 
40 #include <iostream>
41 #include <iterator>
42 #include <vector>
43 
44 namespace otb
45 {
49 {
50  RegisterBuiltInFactories();
51 
52  std::list<ImageMetadataInterfaceBasePointerType> possibleIMI;
53  std::list<itk::LightObject::Pointer> allOpticalObjects =
54  itk::ObjectFactoryBase::CreateAllInstance("OpticalImageMetadataInterface");
55  std::list<itk::LightObject::Pointer> allSarObjects =
56  itk::ObjectFactoryBase::CreateAllInstance("SarImageMetadataInterface");
57  std::list<itk::LightObject::Pointer> allObjects;
58 
59  std::copy(allOpticalObjects.begin(), allOpticalObjects.end(), std::back_inserter(allObjects) );
60  std::copy(allSarObjects.begin(), allSarObjects.end(), std::back_inserter(allObjects) );
61 
62 
63  for (std::list<itk::LightObject::Pointer>::iterator i = allObjects.begin();
64  i != allObjects.end(); ++i)
65  {
66  ImageMetadataInterfaceBase * io = dynamic_cast<ImageMetadataInterfaceBase*>(i->GetPointer());
67  if (io)
68  {
69  possibleIMI.push_back(io);
70  }
71  else
72  {
73  itkGenericExceptionMacro(<< "Error ImageMetadataInterface factory did not return an ImageMetadataInterfaceBase: "
74  << (*i)->GetNameOfClass());
75  }
76  }
77 
78  for (std::list<ImageMetadataInterfaceBasePointerType>::iterator k = possibleIMI.begin();
79  k != possibleIMI.end(); ++k)
80  {
81  (*k)->SetMetaDataDictionary(dict);
82  if ((*k)->CanRead())
83  {
84  return *k;
85  }
86  }
87 
89  defaultIMI->SetMetaDataDictionary(dict);
90  return dynamic_cast<ImageMetadataInterfaceBase*>(static_cast<DefaultImageMetadataInterface*>(defaultIMI));
91 }
92 
93 void
96 {
97  static bool firstTime = true;
98 
99  static itk::SimpleMutexLock mutex;
100  {
101  // This helper class makes sure the Mutex is unlocked
102  // in the event an exception is thrown.
104  if (firstTime)
105  {
106  itk::ObjectFactoryBase::RegisterFactory(IkonosImageMetadataInterfaceFactory::New());
107  itk::ObjectFactoryBase::RegisterFactory(SpotImageMetadataInterfaceFactory::New());
108  itk::ObjectFactoryBase::RegisterFactory(PleiadesImageMetadataInterfaceFactory::New());
109  itk::ObjectFactoryBase::RegisterFactory(Spot6ImageMetadataInterfaceFactory::New());
110  itk::ObjectFactoryBase::RegisterFactory(FormosatImageMetadataInterfaceFactory::New());
111  itk::ObjectFactoryBase::RegisterFactory(QuickBirdImageMetadataInterfaceFactory::New());
112  itk::ObjectFactoryBase::RegisterFactory(WorldView2ImageMetadataInterfaceFactory::New());
113  itk::ObjectFactoryBase::RegisterFactory( TerraSarImageMetadataInterfaceFactory::New() );
114  firstTime = false;
115  }
116  }
117 }
118 
119 } // end namespace otb
Base class for captor metadata reading.
static ImageMetadataInterfaceBasePointerType CreateIMI(const MetaDataDictionaryType &dict)
ImageMetadataInterfaceBase::Pointer ImageMetadataInterfaceBasePointerType
Creation of an "otb" DefaultImageMetadataInterface that gets metadata.