Commit bb4296c5 authored by Jordi Inglada's avatar Jordi Inglada

ENH: rename exluded features to excluded fields

parent f5f2db61
......@@ -215,10 +215,10 @@ private:
std::vector<std::string> cFieldNames = GetChoiceNames("field");
std::string fieldName = cFieldNames[selectedCFieldIdx.front()];
std::vector<std::string> excludedFeatures =
GetExcludedFeatures( GetChoiceNames( "exclude" ),
GetSelectedItems( "exclude" ));
for(const auto& ef : excludedFeatures)
std::vector<std::string> excludedFields =
GetExcludedFields( GetChoiceNames( "exclude" ),
GetSelectedItems( "exclude" ));
for(const auto& ef : excludedFields)
otbAppLogINFO("Excluding feature " << ef << '\n');
int seed = std::time(nullptr);
......@@ -232,7 +232,7 @@ private:
filter->SetOutputSamples(output);
filter->SetClassFieldName(fieldName);
filter->SetLabel(this->GetParameterInt("label"));
filter->SetExcludedFeatures(excludedFeatures);
filter->SetExcludedFields(excludedFields);
filter->SetSeed(seed);
switch (this->GetParameterInt("strategy"))
{
......@@ -264,8 +264,8 @@ private:
}
std::vector<std::string> GetExcludedFeatures(const std::vector<std::string>& fieldNames,
const std::vector<int>& selectedIdx)
std::vector<std::string> GetExcludedFields(const std::vector<std::string>& fieldNames,
const std::vector<int>& selectedIdx)
{
auto nbFeatures = static_cast<unsigned int>(selectedIdx.size());
std::vector<std::string> result( nbFeatures );
......
......@@ -91,13 +91,13 @@ public:
}
itkSetMacro(NumberOfSamples, int);
itkGetMacro(NumberOfSamples, int);
void SetExcludedFeatures(const std::vector<std::string>& ef)
void SetExcludedFields(const std::vector<std::string>& ef)
{
m_ExcludedFeatures = ef;
m_ExcludedFields = ef;
}
std::vector<std::string> GetExcludedFeatures() const
std::vector<std::string> GetExcludedFields() const
{
return m_ExcludedFeatures;
return m_ExcludedFields;
}
itkSetMacro(StdFactor, double);
itkGetMacro(StdFactor, double);
......@@ -127,16 +127,16 @@ protected:
SampleVectorType extractSamples(const ogr::DataSource::Pointer vectors,
size_t layerName,
const std::string& classField, const int label,
const std::vector<std::string>& excludedFeatures = {});
const std::vector<std::string>& excludedFields = {});
void sampleToOGRFeatures(const ogr::DataSource::Pointer& vectors,
ogr::DataSource* output,
const SampleVectorType& samples,
const size_t layerName,
const std::string& classField, int label,
const std::vector<std::string>& excludedFeatures = {});
const std::vector<std::string>& excludedFields = {});
std::set<size_t> getExcludedFeaturesIds(const std::vector<std::string>& excludedFeatures,
std::set<size_t> getExcludedFieldsIds(const std::vector<std::string>& excludedFields,
const ogr::Layer& inputLayer);
bool isNumericField(const ogr::Feature& feature, const int idx);
......@@ -149,7 +149,7 @@ private:
std::string m_ClassFieldName;
size_t m_Layer;
int m_Label;
std::vector<std::string> m_ExcludedFeatures;
std::vector<std::string> m_ExcludedFields;
Strategy m_Strategy;
int m_NumberOfSamples;
double m_StdFactor;
......
......@@ -84,7 +84,7 @@ SampleAugmentationFilter
auto inSamples = this->extractSamples(inputDS, m_Layer,
m_ClassFieldName,
m_Label,
m_ExcludedFeatures);
m_ExcludedFields);
SampleVectorType newSamples;
switch (m_Strategy)
{
......@@ -114,7 +114,7 @@ SampleAugmentationFilter
this->sampleToOGRFeatures(inputDS, outputDS, newSamples, m_Layer,
m_ClassFieldName,
m_Label,
m_ExcludedFeatures);
m_ExcludedFields);
// this->SetNthOutput(0,outputDS);
......@@ -128,7 +128,7 @@ SampleAugmentationFilter
::extractSamples(const ogr::DataSource::Pointer vectors,
size_t layerName,
const std::string& classField, const int label,
const std::vector<std::string>& excludedFeatures)
const std::vector<std::string>& excludedFields)
{
ogr::Layer layer = vectors->GetLayer(layerName);
ogr::Feature feature = layer.ogr().GetNextFeature();
......@@ -144,9 +144,10 @@ SampleAugmentationFilter
}
auto numberOfFields = feature.ogr().GetFieldCount();
auto excludedIds = this->getExcludedFeaturesIds(excludedFeatures, layer);
auto excludedIds = this->getExcludedFieldsIds(excludedFields, layer);
SampleVectorType samples;
bool goesOn{feature.addr() != 0};
int sampleCount{0};
while( goesOn )
{
// Retrieve all the features for each field in the ogr layer.
......@@ -161,10 +162,12 @@ SampleAugmentationFilter
mv.push_back(feature.ogr().GetFieldAsDouble(idx));
}
samples.push_back(mv);
++sampleCount;
}
feature = layer.ogr().GetNextFeature();
goesOn = feature.addr() != 0;
}
std::cout << "Read " << sampleCount << "samples\n";
return samples;
}
......@@ -175,11 +178,11 @@ SampleAugmentationFilter
const SampleAugmentationFilter::SampleVectorType& samples,
const size_t layerName,
const std::string& classField, int label,
const std::vector<std::string>& excludedFeatures)
const std::vector<std::string>& excludedFields)
{
auto inputLayer = vectors->GetLayer(layerName);
auto excludedIds = this->getExcludedFeaturesIds(excludedFeatures, inputLayer);
auto excludedIds = this->getExcludedFieldsIds(excludedFields, inputLayer);
OGRSpatialReference * oSRS = nullptr;
if (inputLayer.GetSpatialRef())
......@@ -217,25 +220,25 @@ SampleAugmentationFilter
}
}
std::set<size_t>
SampleAugmentationFilter
::getExcludedFeaturesIds(const std::vector<std::string>& excludedFeatures,
const ogr::Layer& inputLayer)
{
auto feature = *(inputLayer).begin();
std::set<size_t> excludedIds;
if( excludedFeatures.size() != 0)
{
for(const auto& fieldName : excludedFeatures)
{
auto idx = feature.ogr().GetFieldIndex( fieldName.c_str() );
excludedIds.insert(idx);
}
}
return excludedIds;
}
std::set<size_t>
SampleAugmentationFilter
::getExcludedFieldsIds(const std::vector<std::string>& excludedFields,
const ogr::Layer& inputLayer)
{
auto feature = *(inputLayer).begin();
std::set<size_t> excludedIds;
if( excludedFields.size() != 0)
{
for(const auto& fieldName : excludedFields)
{
auto idx = feature.ogr().GetFieldIndex( fieldName.c_str() );
excludedIds.insert(idx);
}
}
return excludedIds;
}
bool
bool
SampleAugmentationFilter
::isNumericField(const ogr::Feature& feature,
const int idx)
......
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