22 #ifndef otbVectorDataFileWriter_hxx
23 #define otbVectorDataFileWriter_hxx
36 template <
class TInputVectorData>
38 : m_FileName(
""), m_VectorDataIO(nullptr), m_UserSpecifiedVectorDataIO(false), m_FactorySpecifiedVectorDataIO(false)
45 template <
class TInputVectorData>
51 template <
class TInputVectorData>
55 this->ProcessObject::SetNthInput(0,
const_cast<TInputVectorData*
>(input));
59 template <
class TInputVectorData>
62 if (this->GetNumberOfInputs() < 1)
67 return static_cast<TInputVectorData*
>(this->ProcessObject::GetInput(0));
71 template <
class TInputVectorData>
74 return static_cast<TInputVectorData*
>(this->ProcessObject::GetInput(idx));
78 template <
class TInputVectorData>
83 itkDebugMacro(<<
"Writing a vector data file");
88 itkExceptionMacro(<<
"No input to writer!");
95 itkExceptionMacro(<<
"No filename was specified");
98 if (m_VectorDataIO.IsNull())
100 itkDebugMacro(<<
"Attempting factory creation of VectorDataIO for file: " << m_FileName);
101 m_VectorDataIO = VectorDataIOFactory::CreateVectorDataIO(m_FileName.c_str(), VectorDataIOFactory::WriteMode);
102 m_FactorySpecifiedVectorDataIO =
true;
106 if (m_FactorySpecifiedVectorDataIO && !m_VectorDataIO->CanWriteFile(m_FileName.c_str()))
108 itkDebugMacro(<<
"VectorDataIO exists but doesn't know how to write file:" << m_FileName);
109 itkDebugMacro(<<
"Attempting creation of VectorDataIO with a factory for file:" << m_FileName);
110 m_VectorDataIO = VectorDataIOFactory::CreateVectorDataIO(m_FileName.c_str(), VectorDataIOFactory::WriteMode);
111 m_FactorySpecifiedVectorDataIO =
true;
115 if (m_VectorDataIO.IsNull())
118 std::ostringstream msg;
119 msg <<
" Could not create IO object for file " << m_FileName << std::endl;
120 msg <<
" Tried to create one of the following:" << std::endl;
121 std::list<itk::LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance(
"otbVectorDataIOBase");
122 for (std::list<LightObject::Pointer>::iterator i = allobjects.begin(); i != allobjects.end(); ++i)
128 msg <<
" You probably failed to set a file suffix, or" << std::endl;
129 msg <<
" set the suffix to an unsupported type." << std::endl;
130 e.SetDescription(msg.str());
131 e.SetLocation(ITK_LOCATION);
140 if (nonConstVectorData->GetSource())
142 nonConstVectorData->GetSource()->Update();
146 this->InvokeEvent(itk::StartEvent());
149 this->GenerateData();
152 this->InvokeEvent(itk::EndEvent());
155 if (input->ShouldIReleaseData())
157 nonConstVectorData->ReleaseData();
162 template <
class TInputVectorData>
167 itkDebugMacro(<<
"Writing file: " << m_FileName);
171 m_VectorDataIO->SetFileName(m_FileName);
174 typename AdapterType::Pointer adapter = AdapterType::New();
175 adapter->SetInput(input);
177 m_VectorDataIO->Write(adapter->GetOutput());
180 template <
class TInputVectorData>
183 Superclass::PrintSelf(os, indent);
184 os << indent <<
"VectorDataFileWriter" << std::endl;