Skip to content
Snippets Groups Projects
Commit 6666c1d1 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

MRG

parents ab5f44e2 df819ec9
No related branches found
No related tags found
No related merge requests found
......@@ -76,10 +76,6 @@ public:
void AddVectorData( VectorDataPointer vData );
void AddNode( TreeNodeType * node );
/** Load a vector data using image reprojection. */
template <typename TImage> void AddVectorData( VectorDataPointer vData, TImage * image );
template <typename TImage> void AddNode( TreeNodeType * node, TImage * image );
void AddPointToGeometry(VertexType& vertex, bool callUpdate = true);
void EndGeometry(void);
void DeleteGeometry(void);
......@@ -127,8 +123,4 @@ private:
}; // end class
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbVectorDataModel.txx"
#endif
#endif
/*=========================================================================
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 __otbVectorDataModel_txx
#define __otbVectorDataModel_txx
#include "otbVectorDataModel.h"
namespace otb
{
template <typename TImage>
void
VectorDataModel::AddVectorData( VectorDataPointer vData, TImage * image )
{
this->EndGeometry();
DataTreeType::Pointer tree = vData->GetDataTree();
TreeNodeType * root = const_cast<TreeNodeType *>(tree->GetRoot());
this->AddNode( root, image );
this->Update();
}
template <typename TImage>
void
VectorDataModel::AddNode( TreeNodeType * node, TImage * image )
{
// From VEctorDataGlComponent
// Render the current node
switch (node->Get()->GetNodeType())
{
case FEATURE_POINT:
{
m_CurrentNodeType = FEATURE_POINT;
typename TImage::IndexType id;
const PointType point = node->Get()->GetPoint();
image->TransformPhysicalPointToIndex(point, id);
VertexType vertex;
vertex[0] = id[0];
vertex[1] = id[1];
this->AddPointToGeometry(vertex, false);
this->EndGeometry();
break;
}
case FEATURE_LINE:
{
m_CurrentNodeType = FEATURE_LINE;
const LineType * line = node->Get()->GetLine();
LineType::VertexListType::ConstIterator vIt = line->GetVertexList()->Begin();
while (vIt != line->GetVertexList()->End())
{
typename TImage::IndexType id;
const PointType point = vIt.Value();
image->TransformPhysicalPointToIndex(point, id);
VertexType vertex;
vertex[0] = id[0];
vertex[1] = id[1];
this->AddPointToGeometry(vertex, false );
}
this->EndGeometry();
break;
}
case FEATURE_POLYGON:
{
m_CurrentNodeType = FEATURE_POLYGON;
const PolygonType * extRing = node->Get()->GetPolygonExteriorRing();
PolygonType::VertexListType::ConstIterator vIt = extRing->GetVertexList()->Begin();
while (vIt != extRing->GetVertexList()->End())
{
typename TImage::IndexType id;
const PointType point = vIt.Value();
image->TransformPhysicalPointToIndex(point, id);
VertexType vertex;
vertex[0] = id[0];
vertex[1] = id[1];
this->AddPointToGeometry(vertex, false);
vIt++;
}
this->EndGeometry();
break;
}
default:
{
// discard
break;
}
}
// Get the children list from the input node
ChildrenListType children = node->GetChildrenList();
// Render each child
ChildrenListType::iterator it = children.begin();
while ( it != children.end() )
{
this->AddNode(*it, image);
++it;
}
}
}
#endif
......@@ -41,6 +41,8 @@
#include "otbVectorDataModel.h"
#include "otbVectorDataActionHandler.h"
#include "otbVectorDataFileReader.h"
#include "otbVectorDataProjectionFilter.h"
int otbVectorDataModelAddVectorDataTest(int argc, char * argv[])
{
......@@ -210,7 +212,26 @@ int otbVectorDataModelAddVectorDataTest(int argc, char * argv[])
VectorDataReaderType::Pointer vdReader = VectorDataReaderType::New();
vdReader->SetFileName(vdataName);
vdReader->Update();
vdModel->AddVectorData(vdReader->GetOutput(), reader->GetOutput());
typedef otb::VectorDataProjectionFilter<VectorDataType,VectorDataType> ProjectionFilterType;
ProjectionFilterType::Pointer vectorDataProjection = ProjectionFilterType::New();
vectorDataProjection->SetInput(vdReader->GetOutput());
ImageType::PointType lNewOrigin;
// polygons are recorded with a 0.5 shift...
lNewOrigin[0] = reader->GetOutput()->GetOrigin()[0]+0.5;
lNewOrigin[1] = reader->GetOutput()->GetOrigin()[1]+0.5;
vectorDataProjection->SetOutputOrigin(lNewOrigin);
vectorDataProjection->SetOutputSpacing(reader->GetOutput()->GetSpacing());
std::string projectionRef;
itk::ExposeMetaData<std::string>(reader->GetOutput()->GetMetaDataDictionary(),
otb::MetaDataKey::ProjectionRefKey, projectionRef );
vectorDataProjection->SetOutputProjectionRef(projectionRef);
vectorDataProjection->SetOutputKeywordList(reader->GetOutput()->GetImageKeywordlist());
vectorDataProjection->Update();
vdModel->AddVectorData(vectorDataProjection->GetOutput());
if (run)
{
......
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