diff --git a/Code/IO/otbOGRIOHelper.txx b/Code/IO/otbOGRIOHelper.txx index 894e4f4a2e9405ee98191e7ef4d45fa4f55fbd45..0df90d4a05ceab1a690af25a33a6db0750f94c4c 100644 --- a/Code/IO/otbOGRIOHelper.txx +++ b/Code/IO/otbOGRIOHelper.txx @@ -613,7 +613,7 @@ unsigned int OGRIOHelper<TVectorData> for (typename ChildrenListType::iterator it = children.begin(); it != children.end(); ++it) { DataNodePointerType dataNode = (*it)->Get(); - otbMsgDevMacro(<< "Type of node " << dataNode->GetNodeType() << " id" << dataNode->GetNodeId()); + //otbMsgDevMacro(<< "Type of node " << dataNode->GetNodeType() << " id " << dataNode->GetNodeId()); ++m_Kept; // Get the kwl @@ -621,6 +621,7 @@ unsigned int OGRIOHelper<TVectorData> itk::ExposeMetaData<VectorDataKeywordlist>(dataNode->GetMetaDataDictionary(), MetaDataKey::VectorDataKeywordlistKey, kwl); + // Create the field once if (ogrCurrentLayer != NULL && ogrCurrentLayer->GetFeatureCount() == 0) { @@ -628,11 +629,15 @@ unsigned int OGRIOHelper<TVectorData> // vectordatakeywordlist for (unsigned int fieldIdx = 0; fieldIdx < kwl.GetNumberOfFields(); fieldIdx++) { - if (ogrCurrentLayer->CreateField(kwl.GetNthField(fieldIdx).first) != OGRERR_NONE ) - { - itkExceptionMacro(<< "Failed to create Field "<<kwl.GetNthField(fieldIdx).first->GetNameRef()); - } - } + if ( std::string(kwl.GetNthField(fieldIdx).first->GetNameRef()) != "FID" ) + { + otbMsgDevMacro(<< " CreateField " << kwl.GetNthField(fieldIdx).first); + if (ogrCurrentLayer->CreateField(kwl.GetNthField(fieldIdx).first) != OGRERR_NONE ) + { + itkExceptionMacro(<< "Failed to create Field "<<kwl.GetNthField(fieldIdx).first->GetNameRef()); + } + } + } } switch (dataNode->GetNodeType()) @@ -680,11 +685,16 @@ unsigned int OGRIOHelper<TVectorData> { // Get the key of the Nth OGRFieldRefn const char * key = kwl.GetNthField(i).first->GetNameRef(); + + if (std::string(key) != "FID") + { // Edit the value of the field and add it to the current feature ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str()); + otbMsgDevMacro( << "kwl.GetFieldAsString(key) " << ogrFeature->GetFieldIndex(key) << " " << kwl.GetFieldAsString(key) ) + } } - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->SetGeometry(&ogrPoint); if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE) @@ -738,7 +748,7 @@ unsigned int OGRIOHelper<TVectorData> ogrFeature->SetField(ogrFeature->GetFieldIndex(key) , kwl.GetFieldAsString(key).c_str()); } - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->SetGeometry(&ogrLine); if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE) @@ -851,7 +861,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature * ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPoint); ogrFeature->SetGeometry(ogrMultiPoint); @@ -877,7 +887,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature *ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbMultiLineString); ogrFeature->SetGeometry(ogrMultiLineString); @@ -900,7 +910,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature * ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPolygon); ogrFeature->SetGeometry(ogrMultiPolygon); @@ -924,7 +934,7 @@ unsigned int OGRIOHelper<TVectorData> OGRFeature *ogrFeature; ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); - ogrFeature->SetField("Name", dataNode->GetNodeId()); +// ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->GetDefnRef()->SetGeomType(wkbGeometryCollection); ogrFeature->SetGeometry(ogrCollectionGeometry); diff --git a/Code/IO/otbOGRVectorDataIO.txx b/Code/IO/otbOGRVectorDataIO.txx index 53ad3faddcd383ffec1f5d6c06c47641d3eee1dc..5a9e50d8971fa1aa8871cebe01be76fd864b234b 100644 --- a/Code/IO/otbOGRVectorDataIO.txx +++ b/Code/IO/otbOGRVectorDataIO.txx @@ -282,8 +282,8 @@ void OGRVectorDataIO<TData>::Write(const VectorDataConstPointerType data, char * } chrono.Stop(); - std::cout << "OGRVectorDataIO: file saved in " << chrono.GetMeanTime() << " seconds. (" << layerKept << - " elements)" << std::endl; + otbMsgDevMacro( << "OGRVectorDataIO: file saved in " << chrono.GetMeanTime() << " seconds. (" << layerKept << + " elements)" ); otbMsgDevMacro(<< " OGRVectorDataIO::Write() "); } diff --git a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h index 4d3c17fc968365f4a2c51c7be8ba0a55838dbb29..2027d111d9a22ff1e150ee61c5fd0eeaf89a413a 100644 --- a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h +++ b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h @@ -122,6 +122,13 @@ private: LabeledSampleLocalizationGenerator(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented + std::string GetNextID() + { + std::ostringstream oss; + oss << m_CurrentID++; + return oss.str(); + } + RandomGeneratorType::Pointer m_RandomGenerator; std::string m_ClassKey; @@ -130,6 +137,7 @@ private: double m_InhibitionRadius; unsigned long int m_NbMaxIteration; unsigned int m_NumberOfPositiveSamplesPerPoint; + unsigned int m_CurrentID; }; } // end namespace otb diff --git a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx index 34c30ed40642df81686b3f79ae3f25774a153748..29b6cbc6f2f5fd94834cc2262c58855b95333cda 100644 --- a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx +++ b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx @@ -32,7 +32,8 @@ LabeledSampleLocalizationGenerator<TVectorData> m_RandomLocalizationDensity(.005), m_InhibitionRadius(5.0), m_NbMaxIteration(10000), - m_NumberOfPositiveSamplesPerPoint(50) + m_NumberOfPositiveSamplesPerPoint(50), + m_CurrentID(0) { this->SetNumberOfRequiredInputs(1); this->SetNumberOfRequiredOutputs(1); @@ -210,7 +211,19 @@ LabeledSampleLocalizationGenerator<TVectorData> { if (itVector.Get()->IsPointFeature()) { - this->GetOutput(0)->GetDataTree()->Add(itVector.Get(), document); + // Duplicate input feature + typename DataNodeType::Pointer currentGeometry = DataNodeType::New(); + currentGeometry->SetNodeId(this->GetNextID()); + currentGeometry->SetNodeType(otb::FEATURE_POINT); + currentGeometry->SetPoint(itVector.Get()->GetPoint()); + + std::vector<std::string> fields = itVector.Get()->GetFieldList(); + for (std::vector<std::string>::const_iterator it = fields.begin(); it != fields.end(); ++it) + { + currentGeometry->SetFieldAsString( *it, itVector.Get()->GetFieldAsString(*it) ); + } + + this->GetOutput(0)->GetDataTree()->Add(currentGeometry, document); } ++itVector; } @@ -234,21 +247,21 @@ LabeledSampleLocalizationGenerator<TVectorData> for (typename PointVectorType::const_iterator it = vPoint.begin(); it != vPoint.end(); ++it) { - typename DataNodeType::Pointer CurrentGeometry = DataNodeType::New(); - CurrentGeometry->SetNodeId("FEATURE_POINT"); - CurrentGeometry->SetNodeType(otb::FEATURE_POINT); - CurrentGeometry->SetPoint(*it); - CurrentGeometry->SetFieldAsInt(this->GetClassKey(), this->GetNoClassIdentifier()); - this->GetOutput(0)->GetDataTree()->Add(CurrentGeometry, document); + typename DataNodeType::Pointer currentGeometry = DataNodeType::New(); + currentGeometry->SetNodeId(this->GetNextID()); + currentGeometry->SetNodeType(otb::FEATURE_POINT); + currentGeometry->SetPoint(*it); + currentGeometry->SetFieldAsInt(this->GetClassKey(), this->GetNoClassIdentifier()); + this->GetOutput(0)->GetDataTree()->Add(currentGeometry, document); } for (typename PointVectorType::const_iterator it = pPoint.begin(); it != pPoint.end(); ++it) { - typename DataNodeType::Pointer CurrentGeometry = DataNodeType::New(); - CurrentGeometry->SetNodeId("FEATURE_POINT"); - CurrentGeometry->SetNodeType(otb::FEATURE_POINT); - CurrentGeometry->SetPoint(*it); - CurrentGeometry->SetFieldAsInt(this->GetClassKey(), 1); - this->GetOutput(0)->GetDataTree()->Add(CurrentGeometry, document); + typename DataNodeType::Pointer currentGeometry = DataNodeType::New(); + currentGeometry->SetNodeId(this->GetNextID()); + currentGeometry->SetNodeType(otb::FEATURE_POINT); + currentGeometry->SetPoint(*it); + currentGeometry->SetFieldAsInt(this->GetClassKey(), 1); + this->GetOutput(0)->GetDataTree()->Add(currentGeometry, document); } } ++itVector;