22 #ifndef otbVectorDataFileReader_hxx
23 #define otbVectorDataFileReader_hxx
31 #include "itksys/SystemTools.hxx"
40 template <
class TOutputVectorData>
48 template <
class TOutputVectorData>
58 template <
class TOutputVectorData>
62 if (!itksys::SystemTools::FileExists(this->m_FileName))
65 std::ostringstream msg;
66 msg <<
"The file doesn't exist. " << std::endl <<
"Filename = " << this->m_FileName << std::endl;
67 e.SetDescription(msg.str());
77 if (itksys::SystemTools::FileExists(this->m_FileName,
true) ==
true)
79 std::ifstream readTester;
80 readTester.open(this->m_FileName);
81 if (readTester.fail())
84 std::ostringstream msg;
85 msg <<
"The file couldn't be opened for reading. " << std::endl <<
"Filename: " << this->m_FileName << std::endl;
94 template <
class TOutputVectorData>
97 itkDebugMacro(
"setting VectorDataIO to " << vectorDataIO);
98 if (this->m_VectorDataIO != vectorDataIO)
100 this->m_VectorDataIO = vectorDataIO;
103 m_UserSpecifiedVectorDataIO =
true;
106 template <
class TOutputVectorData>
109 typename TOutputVectorData::Pointer output = this->GetOutput();
111 itkDebugMacro(<<
"Reading file for GenerateOutputInformation()" << m_FileName);
115 if (m_FileName ==
"")
125 m_ExceptionMessage =
"";
126 this->TestFileExistenceAndReadability();
128 catch (itk::ExceptionObject& err)
130 m_ExceptionMessage = err.GetDescription();
133 if (m_UserSpecifiedVectorDataIO ==
false)
138 if (m_VectorDataIO.IsNull())
140 std::ostringstream msg;
141 msg <<
" Could not create IO object for file " << m_FileName << std::endl;
142 if (m_ExceptionMessage.size())
144 msg << m_ExceptionMessage;
148 msg <<
" Tried to create one of the following:" << std::endl;
149 std::list<itk::LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance(
"otbVectorDataIOBase");
150 for (std::list<itk::LightObject::Pointer>::iterator i = allobjects.begin(); i != allobjects.end(); ++i)
155 msg <<
" You probably failed to set a file suffix, or" << std::endl;
156 msg <<
" set the suffix to an unsupported type." << std::endl;
163 m_VectorDataIO->SetFileName(m_FileName);
166 output->SetMetaDataDictionary(m_VectorDataIO->GetMetaDataDictionary());
167 this->SetMetaDataDictionary(m_VectorDataIO->GetMetaDataDictionary());
170 template <
class TOutputVectorData>
174 typename TOutputVectorData::Pointer output = this->GetOutput();
176 itkDebugMacro(<<
"VectorDataFileReader::GenerateData() \n");
182 m_ExceptionMessage =
"";
183 this->TestFileExistenceAndReadability();
185 catch (itk::ExceptionObject& err)
187 m_ExceptionMessage = err.GetDescription();
190 m_VectorDataIO->SetFileName(m_FileName);
196 typename AdapterType::InputVectorDataType::Pointer input = AdapterType::InputVectorDataType::New();
198 m_VectorDataIO->Read(input);
200 typename AdapterType::Pointer adapter = AdapterType::New();
201 adapter->SetInput(input);
202 adapter->GraftOutput(output);
204 this->GraftOutput(adapter->GetOutput());
209 template <
class TOutputVectorData>
212 Superclass::PrintSelf(os, indent);
216 os << indent <<
"VectorDataIO: \n";
217 m_VectorDataIO->Print(os, indent.GetNextIndent());
221 os << indent <<
"m_VectorDataIO: (null)"
225 os << indent <<
"UserSpecifiedVectorDataIO flag: " << m_UserSpecifiedVectorDataIO <<
"\n";
226 os << indent <<
"m_FileName: " << m_FileName <<
"\n";