/usr/include/OTB-5.8/otbVectorDataFileWriter.txx is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbVectorDataFileWriter_txx
#define otbVectorDataFileWriter_txx
#include "otbMacro.h"
#include "otbVectorDataFileWriter.h"
#include "otbVectorDataIOFactory.h"
#include "otbVectorDataAdapter.h"
#include "otbVectorData.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputVectorData>
VectorDataFileWriter<TInputVectorData>
::VectorDataFileWriter() :
m_FileName(""),
m_VectorDataIO(ITK_NULLPTR),
m_UserSpecifiedVectorDataIO(false),
m_FactorySpecifiedVectorDataIO(false)
{
}
/**
* Destructor
*/
template <class TInputVectorData>
VectorDataFileWriter<TInputVectorData>
::~VectorDataFileWriter()
{
}
//---------------------------------------------------------
template <class TInputVectorData>
void
VectorDataFileWriter<TInputVectorData>
::SetInput(const InputVectorDataType *input)
{
// ProcessObject is not const_correct so this cast is required here.
this->ProcessObject::SetNthInput(0,
const_cast<TInputVectorData *>(input));
}
//---------------------------------------------------------
template <class TInputVectorData>
const typename VectorDataFileWriter<TInputVectorData>::InputVectorDataType *
VectorDataFileWriter<TInputVectorData>
::GetInput(void)
{
if (this->GetNumberOfInputs() < 1)
{
return ITK_NULLPTR;
}
return static_cast<TInputVectorData*>
(this->ProcessObject::GetInput(0));
}
//---------------------------------------------------------
template <class TInputVectorData>
const typename VectorDataFileWriter<TInputVectorData>::InputVectorDataType *
VectorDataFileWriter<TInputVectorData>
::GetInput(unsigned int idx)
{
return static_cast<TInputVectorData*> (this->ProcessObject::GetInput(idx));
}
//---------------------------------------------------------
template <class TInputVectorData>
void
VectorDataFileWriter<TInputVectorData>
::Write()
{
const InputVectorDataType * input = this->GetInput();
itkDebugMacro(<< "Writing a vector data file");
// Make sure input is available
if (input == ITK_NULLPTR)
{
itkExceptionMacro(<< "No input to writer!");
}
// Make sure that we can write the file given the name
//
if (m_FileName == "")
{
itkExceptionMacro(<< "No filename was specified");
}
if (m_VectorDataIO.IsNull()) //try creating via factory
{
itkDebugMacro(<< "Attempting factory creation of VectorDataIO for file: "
<< m_FileName);
m_VectorDataIO = VectorDataIOFactory::CreateVectorDataIO(
m_FileName.c_str(),
VectorDataIOFactory::WriteMode);
m_FactorySpecifiedVectorDataIO = true;
}
else
{
if (m_FactorySpecifiedVectorDataIO && !m_VectorDataIO->CanWriteFile(m_FileName.c_str()))
{
itkDebugMacro(<< "VectorDataIO exists but doesn't know how to write file:"
<< m_FileName);
itkDebugMacro(<< "Attempting creation of VectorDataIO with a factory for file:"
<< m_FileName);
m_VectorDataIO = VectorDataIOFactory::CreateVectorDataIO(
m_FileName.c_str(),
VectorDataIOFactory::WriteMode);
m_FactorySpecifiedVectorDataIO = true;
}
}
if (m_VectorDataIO.IsNull())
{
VectorDataFileWriterException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << " Could not create IO object for file "
<< m_FileName.c_str() << std::endl;
msg << " Tried to create one of the following:" << std::endl;
std::list<itk::LightObject::Pointer> allobjects =
itk::ObjectFactoryBase::CreateAllInstance("otbVectorDataIOBase");
for (std::list<LightObject::Pointer>::iterator i = allobjects.begin();
i != allobjects.end(); ++i)
{
VectorDataIOBase* io = dynamic_cast<VectorDataIOBase*>(i->GetPointer());
if(io)
msg << " " << io->GetNameOfClass() << std::endl;
}
msg << " You probably failed to set a file suffix, or" << std::endl;
msg << " set the suffix to an unsupported type." << std::endl;
e.SetDescription(msg.str().c_str());
e.SetLocation(ITK_LOCATION);
throw e;
}
// NOTE: this const_cast<> is due to the lack of const-correctness
// of the ProcessObject.
InputVectorDataType * nonConstVectorData = const_cast<InputVectorDataType *>(input);
// Make sure the data is up-to-date.
if (nonConstVectorData->GetSource())
{
nonConstVectorData->GetSource()->Update();
}
// Notify start event observers
this->InvokeEvent(itk::StartEvent());
// Actually do something
this->GenerateData();
// Notify end event observers
this->InvokeEvent(itk::EndEvent());
// Release upstream data if requested
if (input->ShouldIReleaseData())
{
nonConstVectorData->ReleaseData();
}
}
//---------------------------------------------------------
template <class TInputVectorData>
void
VectorDataFileWriter<TInputVectorData>
::GenerateData(void)
{
const InputVectorDataType * input = this->GetInput();
itkDebugMacro(<< "Writing file: " << m_FileName);
// Setup the vector data IO for writing.
//
m_VectorDataIO->SetFileName(m_FileName.c_str());
typedef VectorDataAdapter<TInputVectorData, VectorData<double, 2> > AdapterType;
typename AdapterType::Pointer adapter = AdapterType::New();
adapter->SetInput(input);
adapter->Update();
m_VectorDataIO->Write(adapter->GetOutput());
}
template <class TInputVectorData>
void
VectorDataFileWriter<TInputVectorData>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "VectorDataFileWriter" << std::endl;
}
} //namespace otb
#endif
|