Skip to content
Snippets Groups Projects
Commit 38c6ac02 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH : add possibility to load vector data in VectorDataMoadel

parent 9390433c
No related branches found
No related tags found
No related merge requests found
......@@ -294,6 +294,7 @@ VectorDataGlComponent<TVectorData>
// Render each child
for (typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it)
{
this->Render(*it, extent, space2ScreenTransform);
}
}
......
......@@ -44,7 +44,6 @@ void VectorDataModel::Update(void)
void VectorDataModel::AddPointToGeometry(VertexType& vertex)
{
std::cout<<"AddPointToGeometry"<<std::endl;
VertexType newPoint;
newPoint[0] = m_Origin[0] + vertex[0] / m_Spacing[0];
newPoint[1] = m_Origin[1] + vertex[1] / m_Spacing[1];
......@@ -57,7 +56,6 @@ void VectorDataModel::AddPointToGeometry(VertexType& vertex)
if (m_CurrentNodeType == FEATURE_POINT)
{
std::cout<<"Creating and adding new point"<<std::endl;
otbMsgDevMacro(<< "VectorDataModel::AddPointToGeometry: Creating and adding new point");
if (m_CurrentGeometry.IsNull())
{
......@@ -76,7 +74,6 @@ void VectorDataModel::AddPointToGeometry(VertexType& vertex)
}
else if (m_CurrentNodeType == FEATURE_POLYGON)
{
std::cout<<"Creating and adding new FEATURE_POLYGON"<<std::endl;
if (m_CurrentGeometry.IsNull())
{
otbMsgDevMacro(<< "VectorDataModel::AddPointToGeometry: Creating new polygon");
......@@ -236,4 +233,87 @@ void VectorDataModel::SetSelectedGeometry(int n)
m_SelectedGeometry = GetNthDataNode(n);
}
void
VectorDataModel::AddVectorData( VectorDataPointer vData )
{
this->EndGeometry();
DataTreeType::Pointer tree = vData->GetDataTree();
TreeNodeType * root = const_cast<TreeNodeType *>(tree->GetRoot());
this->AddNode( root );
}
void
VectorDataModel::AddNode( TreeNodeType * node )
{
// From VEctorDataGlComponent
// Render the current node
switch (node->Get()->GetNodeType())
{
case FEATURE_POINT:
{
m_CurrentNodeType = FEATURE_POINT;
PointType point = node->Get()->GetPoint();
VertexType vertex;
vertex[0] = point[0];
vertex[1] = point[1];
this->AddPointToGeometry(vertex);
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())
{
PointType point = vIt.Value();
VertexType vertex;
vertex[0] = point[0];
vertex[1] = point[1];
this->AddPointToGeometry(vertex);
}
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())
{
PointType point = vIt.Value();
VertexType vertex;
vertex[0] = point[0];
vertex[1] = point[1];
this->AddPointToGeometry(vertex);
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);
++it;
}
}
}
......@@ -45,7 +45,11 @@ public:
typedef itk::SmartPointer<const Self> ConstPointer;
typedef otb::VectorData<double, 2> VectorDataType;
typedef VectorDataType::Pointer VectorDataPointer;
typedef VectorDataType::DataNodeType DataNodeType;
typedef VectorDataType::DataTreeType DataTreeType;
typedef DataTreeType::TreeNodeType TreeNodeType;
typedef TreeNodeType::ChildrenListType ChildrenListType;
typedef VectorDataType::PointType PointType;
typedef VectorDataType::SpacingType SpacingType;
typedef VectorDataType::PolygonType PolygonType;
......@@ -67,6 +71,14 @@ public:
/** Return a pointer to the vector data */
itkGetObjectMacro(VectorData, VectorDataType);
/** Load a vector data. */
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);
void EndGeometry(void);
......@@ -94,8 +106,8 @@ private:
VectorDataModel(const Self &);
void operator =(const Self&);
VectorDataType::Pointer m_VectorData;
NodeType m_CurrentNodeType;
VectorDataPointer m_VectorData;
NodeType m_CurrentNodeType;
/** Node where the next geometry should be attached */
DataNodeType::Pointer m_CurrentRootNode;
......@@ -115,4 +127,8 @@ private:
}; // end class
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbVectorDataModel.txx"
#endif
#endif
......@@ -355,6 +355,13 @@ ${LARGEINPUTDATA}/QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS
)
ENDIF(OTB_DATA_USE_LARGEINPUT)
ADD_TEST(vrTvVectorDataModelAddVectorDataTest ${VISUREFAC_TESTS1}
otbVectorDataModelAddVectorDataTest
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
200 500 200 0
${INPUTDATA}/Capitole-Shadows.shp
)
# Testing srcs
SET(Visualization_SRCS1
otbVisualizationTests1.cxx
......@@ -404,6 +411,7 @@ otbSplittedWidgetManagerNew.cxx
otbVerticalAsymptoteCurveNew.cxx
otbVectorDataModelNew.cxx
otbVectorDataModelTest.cxx
otbVectorDataModelAddVectorDataTest.cxx
)
OTB_ADD_EXECUTABLE(otbVisualizationTests1 "${Visualization_SRCS1}" "OTBVisualization;OTBIO;OTBTesting")
......
......@@ -71,4 +71,5 @@ void RegisterTests()
REGISTER_TEST(otbVerticalAsymptoteCurveNew);
REGISTER_TEST(otbVectorDataModelNew);
REGISTER_TEST(otbVectorDataModelTest);
REGISTER_TEST(otbVectorDataModelAddVectorDataTest);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment