Skip to content
Snippets Groups Projects
Commit b1ed8927 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: move ProcessNode up and unmix input/output types

parent 17b1e009
No related branches found
No related tags found
No related merge requests found
......@@ -56,6 +56,29 @@ public:
typedef typename TInputVectorData::ConstPointer InputVectorDataPointer;
typedef typename TOutputVectorData::Pointer OutputVectorDataPointer;
typedef typename InputVectorDataType::DataNodeType InputDataNodeType;
typedef typename OutputVectorDataType::DataNodeType OutputDataNodeType;
typedef typename InputVectorDataType::DataTreeType::TreeNodeType InputInternalTreeNodeType;
typedef typename OutputVectorDataType::DataTreeType::TreeNodeType OutputInternalTreeNodeType;
typedef typename InputDataNodeType::PointType InputPointType;
typedef typename InputDataNodeType::LineType InputLineType;
typedef typename InputDataNodeType::PolygonType InputPolygonType;
typedef typename InputDataNodeType::PolygonListType InputPolygonListType;
typedef typename InputLineType::Pointer InputLinePointerType;
typedef typename InputPolygonType::Pointer InputPolygonPointerType;
typedef typename InputPolygonListType::Pointer InputPolygonListPointerType;
typedef typename OutputDataNodeType::PointType OutputPointType;
typedef typename OutputDataNodeType::LineType OutputLineType;
typedef typename OutputDataNodeType::PolygonType OutputPolygonType;
typedef typename OutputDataNodeType::PolygonListType OutputPolygonListType;
typedef typename OutputLineType::Pointer OutputLinePointerType;
typedef typename OutputPolygonType::Pointer OutputPolygonPointerType;
typedef typename OutputPolygonListType::Pointer OutputPolygonListPointerType;
typedef itk::DataObject::Pointer DataObjectPointer;
virtual void SetInput(const InputVectorDataType *input);
......@@ -66,6 +89,27 @@ protected:
VectorDataToVectorDataFilter();
/** Destructor */
virtual ~VectorDataToVectorDataFilter() {}
virtual OutputPointType ProcessPoint(InputPointType point) const
{
itkExceptionMacro( << "Subclass should reimplement this method");
}
virtual OutputLinePointerType ProcessLine(InputLinePointerType line) const
{
itkExceptionMacro( << "Subclass should reimplement this method");
}
virtual OutputPolygonPointerType ProcessPolygon(InputPolygonPointerType polygon) const
{
itkExceptionMacro( << "Subclass should reimplement this method");
}
virtual OutputPolygonListPointerType ProcessPolygonList(InputPolygonListPointerType polygonList) const
{
itkExceptionMacro( << "Subclass should reimplement this method");
}
/** Go through the vector data tree and process the nodes */
void ProcessNode(InputInternalTreeNodeType * source, OutputInternalTreeNodeType * destination) const;
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
......
......@@ -20,6 +20,7 @@
#include "otbVectorDataToVectorDataFilter.h"
#include "itkProgressReporter.h"
#include "otbDataNode.h"
namespace otb
{
......@@ -58,6 +59,118 @@ VectorDataToVectorDataFilter<TInputVectorData, TOutputVectorData>
(this->itk::ProcessObject::GetInput(0));
}
template <class TInputVectorData, class TOutputVectorData>
void
VectorDataToVectorDataFilter<TInputVectorData, TOutputVectorData>
::ProcessNode(InputInternalTreeNodeType * source, OutputInternalTreeNodeType * destination) const
{
// Get the children list from the input node
typedef typename InputInternalTreeNodeType::ChildrenListType InputChildrenListType;
InputChildrenListType children = source->GetChildrenList();
// For each child
typename InputChildrenListType::const_iterator it = children.begin();
while (it != children.end())
{
typename OutputInternalTreeNodeType::Pointer newContainer;
typedef typename InputVectorDataType::DataNodePointerType InputDataNodePointerType;
typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
// Copy input DataNode info
InputDataNodePointerType dataNode = (*it)->Get();
OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
newDataNode->SetNodeType(dataNode->GetNodeType());
newDataNode->SetNodeId(dataNode->GetNodeId());
newDataNode->SetMetaDataDictionary(dataNode->GetMetaDataDictionary());
switch (dataNode->GetNodeType())
{
case ROOT:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case DOCUMENT:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FOLDER:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_POINT:
{
newDataNode->SetPoint(this->ProcessPoint(dataNode->GetPoint()));
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
break;
}
case FEATURE_LINE:
{
newDataNode->SetLine(this->ProcessLine(dataNode->GetLine()));
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
break;
}
case FEATURE_POLYGON:
{
newDataNode->SetPolygonExteriorRing(this->ProcessPolygon(dataNode->GetPolygonExteriorRing()));
newDataNode->SetPolygonInteriorRings(this->ProcessPolygonList(dataNode->GetPolygonInteriorRings()));
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
break;
}
case FEATURE_MULTIPOINT:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_MULTILINE:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_MULTIPOLYGON:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_COLLECTION:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
}
++it;
}
}
/**
* PrintSelf Method
*/
......
......@@ -86,28 +86,29 @@ public:
typedef itk::Vector<double, 2> SpacingType;
typedef itk::Point<double, 2> OriginType;
typedef typename InputVectorDataType::DataNodePointerType InputDataNodePointerType;
typedef typename OutputVectorDataType::DataNodeType OutputDataNodeType;
typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
typedef typename OutputVectorDataType::DataTreePointerType OutputDataTreePointerType;
typedef typename InputVectorDataType::DataNodeType InputDataNodeType;
typedef typename InputVectorDataType::DataTreeType::TreeNodeType InputInternalTreeNodeType;
typedef typename OutputVectorDataType::DataTreeType::TreeNodeType OutputInternalTreeNodeType;
typedef typename InputInternalTreeNodeType::ChildrenListType InputChildrenListType;
typedef typename OutputDataNodeType::PointType PointType;
typedef typename InputDataNodeType::PointType InputPointType;
typedef typename InputDataNodeType::LineType InputLineType;
typedef typename InputDataNodeType::PolygonType InputPolygonType;
typedef typename InputDataNodeType::PolygonListType InputPolygonListType;
typedef typename OutputDataNodeType::LineType LineType;
typedef typename OutputDataNodeType::LineConstPointerType LineConstPointerType;
typedef typename OutputDataNodeType::LinePointerType LinePointerType;
typedef typename InputLineType::Pointer InputLinePointerType;
typedef typename InputPolygonType::Pointer InputPolygonPointerType;
typedef typename InputPolygonListType::Pointer InputPolygonListPointerType;
typedef typename OutputDataNodeType::PolygonType PolygonType;
typedef typename OutputDataNodeType::PolygonConstPointerType PolygonConstPointerType;
typedef typename OutputDataNodeType::PolygonPointerType PolygonPointerType;
typedef typename OutputDataNodeType::PointType OutputPointType;
typedef typename OutputDataNodeType::LineType OutputLineType;
typedef typename OutputDataNodeType::PolygonType OutputPolygonType;
typedef typename OutputDataNodeType::PolygonListType OutputPolygonListType;
typedef typename OutputDataNodeType::PolygonListType PolygonListType;
typedef typename OutputDataNodeType::PolygonListConstPointerType PolygonListConstPointerType;
typedef typename OutputDataNodeType::PolygonListPointerType PolygonListPointerType;
typedef typename OutputLineType::Pointer OutputLinePointerType;
typedef typename OutputPolygonType::Pointer OutputPolygonPointerType;
typedef typename OutputPolygonListType::Pointer OutputPolygonListPointerType;
/** Method for creation through the object factory. */
itkNewMacro(Self);
......@@ -178,18 +179,16 @@ protected:
VectorDataProjectionFilter();
virtual ~VectorDataProjectionFilter() {}
PointType ProcessPoint(PointType point) const;
LinePointerType ProcessLine(LinePointerType line) const;
PolygonPointerType ProcessPolygon(PolygonPointerType polygon) const;
PolygonListPointerType ProcessPolygonList(PolygonListPointerType polygonList) const;
virtual OutputPointType ProcessPoint(InputPointType point) const;
virtual OutputLinePointerType ProcessLine(InputLinePointerType line) const;
virtual OutputPolygonPointerType ProcessPolygon(InputPolygonPointerType polygon) const;
virtual OutputPolygonListPointerType ProcessPolygonList(InputPolygonListPointerType polygonList) const;
void InstanciateTransform(void);
void GenerateOutputInformation(void);
void GenerateData(void);
void ProcessNode(InputInternalTreeNodeType * source, OutputInternalTreeNodeType * destination) const;
private:
VectorDataProjectionFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
......
......@@ -22,7 +22,6 @@
#include "itkProgressReporter.h"
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
#include "otbDataNode.h"
#include "itkTimeProbe.h"
namespace otb
......@@ -178,9 +177,9 @@ VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
* Convert point
*/
template <class TInputVectorData, class TOutputVectorData>
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::PointType
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::OutputPointType
VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
::ProcessPoint(PointType pointCoord) const
::ProcessPoint(InputPointType pointCoord) const
{
itk::Point<double, 2> point;
......@@ -192,20 +191,20 @@ VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
* Convert line
*/
template <class TInputVectorData, class TOutputVectorData>
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::LinePointerType
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::OutputLinePointerType
VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
::ProcessLine(LinePointerType line) const
::ProcessLine(InputLinePointerType line) const
{
typedef typename LineType::VertexListType::ConstPointer VertexListConstPointerType;
typedef typename LineType::VertexListConstIteratorType VertexListConstIteratorType;
typedef typename InputLineType::VertexListType::ConstPointer VertexListConstPointerType;
typedef typename InputLineType::VertexListConstIteratorType VertexListConstIteratorType;
VertexListConstPointerType vertexList = line->GetVertexList();
VertexListConstIteratorType it = vertexList->Begin();
typename LineType::Pointer newLine = LineType::New();
typename OutputLineType::Pointer newLine = OutputLineType::New();
while (it != vertexList->End())
{
itk::Point<double, 2> point;
itk::ContinuousIndex<double, 2> index;
typename LineType::VertexType pointCoord = it.Value();
typename InputLineType::VertexType pointCoord = it.Value();
point = m_Transform->TransformPoint(pointCoord);
index[0] = point[0];
index[1] = point[1];
......@@ -221,20 +220,20 @@ VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
* Convert polygon
*/
template <class TInputVectorData, class TOutputVectorData>
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::PolygonPointerType
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::OutputPolygonPointerType
VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
::ProcessPolygon(PolygonPointerType polygon) const
::ProcessPolygon(InputPolygonPointerType polygon) const
{
typedef typename PolygonType::VertexListType::ConstPointer VertexListConstPointerType;
typedef typename PolygonType::VertexListConstIteratorType VertexListConstIteratorType;
typedef typename InputPolygonType::VertexListType::ConstPointer VertexListConstPointerType;
typedef typename InputPolygonType::VertexListConstIteratorType VertexListConstIteratorType;
VertexListConstPointerType vertexList = polygon->GetVertexList();
VertexListConstIteratorType it = vertexList->Begin();
typename PolygonType::Pointer newPolygon = PolygonType::New();
typename OutputPolygonType::Pointer newPolygon = OutputPolygonType::New();
while (it != vertexList->End())
{
itk::Point<double, 2> point;
itk::ContinuousIndex<double, 2> index;
typename PolygonType::VertexType pointCoord = it.Value();
typename InputPolygonType::VertexType pointCoord = it.Value();
point = m_Transform->TransformPoint(pointCoord);
index[0] = point[0];
index[1] = point[1];
......@@ -248,13 +247,13 @@ VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
* Convert polygon list
*/
template <class TInputVectorData, class TOutputVectorData>
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::PolygonListPointerType
typename VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>::OutputPolygonListPointerType
VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
::ProcessPolygonList(PolygonListPointerType polygonList) const
::ProcessPolygonList(InputPolygonListPointerType polygonList) const
{
PolygonListPointerType newPolygonList = PolygonListType::New();
for (typename PolygonListType::ConstIterator it = polygonList->Begin();
OutputPolygonListPointerType newPolygonList = OutputPolygonListType::New();
for (typename InputPolygonListType::ConstIterator it = polygonList->Begin();
it != polygonList->End(); ++it)
{
newPolygonList->PushBack(this->ProcessPolygon(it.Get()));
......@@ -342,12 +341,14 @@ VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
//Instanciate the transform
this->InstanciateTransform();
typedef typename OutputVectorDataType::DataTreePointerType OutputDataTreePointerType;
OutputDataTreePointerType tree = outputPtr->GetDataTree();
// Get the input tree root
InputInternalTreeNodeType * inputRoot = const_cast<InputInternalTreeNodeType *>(inputPtr->GetDataTree()->GetRoot());
// Create the output tree root
typedef typename OutputVectorDataType::DataNodePointerType OutputDataNodePointerType;
OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
newDataNode->SetNodeType(inputRoot->Get()->GetNodeType());
newDataNode->SetNodeId(inputRoot->Get()->GetNodeId());
......@@ -358,121 +359,11 @@ VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
// Start recursive processing
itk::TimeProbe chrono;
chrono.Start();
ProcessNode(inputRoot, outputRoot);
this->ProcessNode(inputRoot, outputRoot);
chrono.Stop();
otbMsgDevMacro(<< "VectoDataProjectionFilter: features Processed in " << chrono.GetMeanTime() << " seconds.");
}
template <class TInputVectorData, class TOutputVectorData>
void
VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
::ProcessNode(InputInternalTreeNodeType * source, OutputInternalTreeNodeType * destination) const
{
// Get the children list from the input node
InputChildrenListType children = source->GetChildrenList();
// For each child
typename InputChildrenListType::const_iterator it = children.begin();
while (it != children.end())
//for(typename InputChildrenListType::iterator it = children.begin(); it!=children.end(); ++it)
{
typename OutputInternalTreeNodeType::Pointer newContainer;
// Copy input DataNode info
InputDataNodePointerType dataNode = (*it)->Get();
OutputDataNodePointerType newDataNode = OutputDataNodeType::New();
newDataNode->SetNodeType(dataNode->GetNodeType());
newDataNode->SetNodeId(dataNode->GetNodeId());
newDataNode->SetMetaDataDictionary(dataNode->GetMetaDataDictionary());
switch (dataNode->GetNodeType())
{
case ROOT:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case DOCUMENT:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FOLDER:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_POINT:
{
newDataNode->SetPoint(this->ProcessPoint(dataNode->GetPoint()));
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
break;
}
case FEATURE_LINE:
{
newDataNode->SetLine(this->ProcessLine(dataNode->GetLine()));
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
break;
}
case FEATURE_POLYGON:
{
newDataNode->SetPolygonExteriorRing(this->ProcessPolygon(dataNode->GetPolygonExteriorRing()));
newDataNode->SetPolygonInteriorRings(this->ProcessPolygonList(dataNode->GetPolygonInteriorRings()));
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
break;
}
case FEATURE_MULTIPOINT:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_MULTILINE:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_MULTIPOLYGON:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
case FEATURE_COLLECTION:
{
newContainer = OutputInternalTreeNodeType::New();
newContainer->Set(newDataNode);
destination->AddChild(newContainer);
ProcessNode((*it), newContainer);
break;
}
}
++it;
}
}
} // end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment