Commit 39a8995b authored by Arnaud Jaen's avatar Arnaud Jaen

ENH: Speed up the writing of sqlite files for streaming segmentation.

parent 1d1bf98a
......@@ -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);
......
......@@ -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();
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment