diff --git a/Code/OBIA/otbFusionOGRTileFilter.txx b/Code/OBIA/otbFusionOGRTileFilter.txx index 2623cdbd2b2c8573dffc2b98ba53cf7a3dbffb56..16cce76db29448a1f601ecc3e9f0922284c10f7f 100644 --- a/Code/OBIA/otbFusionOGRTileFilter.txx +++ b/Code/OBIA/otbFusionOGRTileFilter.txx @@ -22,6 +22,8 @@ #include "ogrsf_frmts.h" #include <iomanip> +#include "itkTimeProbe.h" + namespace otb { @@ -78,10 +80,16 @@ FusionOGRTileFilter<TImage> unsigned int nbColStream = static_cast<unsigned int>(imageSize[0] / m_StreamSize[0] + 1); //process column + unsigned int nbTransaction = 0; + inputLayer->StartTransaction(); for(unsigned int x=1; x<=nbColStream; x++) { for(unsigned int y=1; y<=nbRowStream; y++) { + /*std::cout<< " column tile number : " << x*y <<std::endl; + itk::TimeProbe chrono; + chrono.Start();*/ + //First compute the intersection between polygons and the streaming line (upper stream) std::vector<FeatureStruct> upperStreamFeatureList; upperStreamFeatureList.clear(); @@ -226,6 +234,11 @@ FusionOGRTileFilter<TImage> inputLayer->DeleteFeature(lower.feat->GetFID()); inputLayer->DeleteFeature(upper.feat->GetFID()); OGRFeature::DestroyFeature( fusionFeature ); + if(++nbTransaction == 65536) + { + inputLayer->CommitTransaction(); + inputLayer->StartTransaction(); + } } } @@ -239,14 +252,24 @@ FusionOGRTileFilter<TImage> OGRFeature::DestroyFeature( lowerStreamFeatureList.at(l).feat ); } + /*chrono.Stop(); + std::cout<< "Column fusion tile took " << chrono.GetTotal() << " sec"<<std::endl;*/ + } //end for x } //end for y + inputLayer->CommitTransaction(); //Process line + nbTransaction = 0; + inputLayer->StartTransaction(); for(unsigned int y=1; y<=nbRowStream; y++) { for(unsigned int x=1; x<=nbColStream; x++) { + /*std::cout<< " line tile number : " << x*y <<std::endl; + itk::TimeProbe chrono; + chrono.Start();*/ + //First compute the intersection between polygons and the streaming line (upper stream) std::vector<FeatureStruct> upperStreamFeatureList; upperStreamFeatureList.clear(); @@ -388,6 +411,11 @@ FusionOGRTileFilter<TImage> inputLayer->DeleteFeature(lower.feat->GetFID()); inputLayer->DeleteFeature(upper.feat->GetFID()); OGRFeature::DestroyFeature( fusionFeature ); + if(++nbTransaction == 65536) + { + inputLayer->CommitTransaction(); + inputLayer->StartTransaction(); + } } } @@ -401,9 +429,13 @@ FusionOGRTileFilter<TImage> OGRFeature::DestroyFeature( lowerStreamFeatureList.at(l).feat ); } + + /*chrono.Stop(); + std::cout<< "line fusion tile took " << chrono.GetTotal() << " sec"<<std::endl;*/ + } //end for x } //end for y - + inputLayer->CommitTransaction(); //Free memory OGRDataSource::DestroyDataSource(inputDataSource); diff --git a/Code/OBIA/otbPersistentImageToOGRDataFilter.h b/Code/OBIA/otbPersistentImageToOGRDataFilter.h index 7e13c6e2372defbaa28a9da3e516300f1cc2c6b0..09528a6153424ff54bdb988505f9c35d66072394 100644 --- a/Code/OBIA/otbPersistentImageToOGRDataFilter.h +++ b/Code/OBIA/otbPersistentImageToOGRDataFilter.h @@ -85,8 +85,12 @@ public: itkSetStringMacro(FileName); itkGetStringMacro(FileName); + /** Set/Get the Field Name of the ogr file in which labels will be written. (default is "DN")*/ itkSetMacro(FieldName, std::string); itkGetMacro(FieldName, std::string); + + /** Get the size of the tile used for streaming. */ + itkGetMacro(StreamSize, SizeType); protected: PersistentImageToOGRDataFilter(); diff --git a/Code/OBIA/otbPersistentImageToOGRDataFilter.txx b/Code/OBIA/otbPersistentImageToOGRDataFilter.txx index cca4197e9f5546b954aa9940fdb6726d9cb33db1..3a348ebe4ed50848d413284bb0385cc1ccabfb50 100644 --- a/Code/OBIA/otbPersistentImageToOGRDataFilter.txx +++ b/Code/OBIA/otbPersistentImageToOGRDataFilter.txx @@ -117,13 +117,7 @@ void PersistentImageToOGRDataFilter<TImage> ::Synthetize() { - typedef FusionOGRTileFilter<InputImageType> FusionFilterType; - typename FusionFilterType::Pointer filter = FusionFilterType::New(); - - filter->SetInput(this->GetInput()); - filter->SetInputFileName(this->m_FileName); - filter->SetStreamSize(this->m_StreamSize); - filter->GenerateData(); + } template<class TImage> @@ -156,10 +150,18 @@ PersistentImageToOGRDataFilter<TImage> ogrDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driverName.c_str()); m_DataSource = ogrDriver->CreateDataSource(this->m_FileName.c_str(), NULL); + + /*char ** options = NULL; + char * opt = "SPATIALITE=YES"; + options = CSLAddString(options, opt ); + m_DataSource = ogrDriver->CreateDataSource(this->m_FileName.c_str(), &options[0]);*/ + m_DataSource->CreateLayer("layer", oSRS ,wkbMultiPolygon, NULL); OGRFieldDefn field(m_FieldName.c_str(),OFTInteger); m_DataSource->GetLayer(0)->CreateField(&field, true); + + //CSLDestroy( options ); } else { @@ -187,6 +189,7 @@ PersistentImageToOGRDataFilter<TImage> unsigned int nbFeatures = poSrcLayer->GetFeatureCount(true); unsigned int i = 0; OGRFeature *poFeature; + poDstLayer->StartTransaction(); while (i<nbFeatures) { OGRFeature *poDstFeature = NULL; @@ -199,12 +202,19 @@ PersistentImageToOGRDataFilter<TImage> poDstFeature->SetFrom( poFeature, TRUE ); poDstLayer->CreateFeature( poDstFeature ); + if (i == nbFeatures-1) + { + poDstLayer->CommitTransaction(); + poDstLayer->StartTransaction(); + } + //free memory OGRFeature::DestroyFeature( poDstFeature ); OGRFeature::DestroyFeature( poFeature ); i++; } + poDstLayer->CommitTransaction(); chrono.Stop(); std::cout<< "write ogr tile took " << chrono.GetTotal() << " sec"<<std::endl; diff --git a/Code/OBIA/otbStreamingVectorizedSegmentationOGR.txx b/Code/OBIA/otbStreamingVectorizedSegmentationOGR.txx index c7265e020c15bbffbdb1b1c9810014808860b1c8..8ba7aa08208174b73b87ea9946d40e63a1cf340b 100644 --- a/Code/OBIA/otbStreamingVectorizedSegmentationOGR.txx +++ b/Code/OBIA/otbStreamingVectorizedSegmentationOGR.txx @@ -159,6 +159,7 @@ PersistentStreamingLabelImageToOGRDataFilter<TImageType, TSegmentationFilter> i++; } m_TileMaxLabel = m_TileMaxLabel + relabelMap.size(); + chrono3.Stop(); std::cout<< "relabel took " << chrono3.GetTotal() << " sec"<<std::endl; return output;