19 #ifndef __otbVectorDataFileWriter_txx
20 #define __otbVectorDataFileWriter_txx
33 template <
class TInputVectorData>
38 m_UserSpecifiedVectorDataIO(false)
44 template <
class TInputVectorData>
51 template <
class TInputVectorData>
57 this->ProcessObject::SetNthInput(0,
58 const_cast<TInputVectorData *>(input));
62 template <
class TInputVectorData>
67 if (this->GetNumberOfInputs() < 1)
72 return static_cast<TInputVectorData*
>
73 (this->ProcessObject::GetInput(0));
77 template <
class TInputVectorData>
82 return static_cast<TInputVectorData*
> (this->ProcessObject::GetInput(idx));
86 template <
class TInputVectorData>
93 itkDebugMacro(<<
"Writing a vector data file");
98 itkExceptionMacro(<<
"No input to writer!");
103 if (m_FileName ==
"")
105 itkExceptionMacro(<<
"No filename was specified");
108 if (m_VectorDataIO.IsNull())
110 itkDebugMacro(<<
"Attempting factory creation of VectorDataIO for file: "
115 m_FactorySpecifiedVectorDataIO =
true;
119 if (m_FactorySpecifiedVectorDataIO && !m_VectorDataIO->CanWriteFile(m_FileName.c_str()))
121 itkDebugMacro(<<
"VectorDataIO exists but doesn't know how to write file:"
123 itkDebugMacro(<<
"Attempting creation of VectorDataIO with a factory for file:"
128 m_FactorySpecifiedVectorDataIO =
true;
132 if (m_VectorDataIO.IsNull())
135 std::ostringstream msg;
136 msg <<
" Could not create IO object for file "
137 << m_FileName.c_str() << std::endl;
138 msg <<
" Tried to create one of the following:" << std::endl;
139 std::list<itk::LightObject::Pointer> allobjects =
141 for (std::list<LightObject::Pointer>::iterator i = allobjects.begin();
142 i != allobjects.end(); ++i)
147 msg <<
" You probably failed to set a file suffix, or" << std::endl;
148 msg <<
" set the suffix to an unsupported type." << std::endl;
159 if (nonConstVectorData->GetSource())
161 nonConstVectorData->GetSource()->Update();
168 this->GenerateData();
174 if (input->ShouldIReleaseData())
176 nonConstVectorData->ReleaseData();
181 template <
class TInputVectorData>
188 itkDebugMacro(<<
"Writing file: " << m_FileName);
192 m_VectorDataIO->SetFileName(m_FileName.c_str());
195 typename AdapterType::Pointer adapter = AdapterType::New();
196 adapter->SetInput(input);
198 m_VectorDataIO->Write(adapter->GetOutput());
202 template <
class TInputVectorData>
207 Superclass::PrintSelf(os, indent);
208 os << indent <<
"VectorDataFileWriter" << std::endl;