diff --git a/Data/Input/training/training.dbf b/Data/Input/training/training.dbf new file mode 100755 index 0000000000000000000000000000000000000000..a801689ad76cfb40daf088a0bbe460ca043e4f8c --- /dev/null +++ b/Data/Input/training/training.dbf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88650d26df9784caadaa9684ba37473544b2f131588a6ed155dec6cb3a750caf +size 583257 diff --git a/Data/Input/training/training.prj b/Data/Input/training/training.prj new file mode 100755 index 0000000000000000000000000000000000000000..5adb2a9108a4bd847464a2c506a40c8d199faa69 --- /dev/null +++ b/Data/Input/training/training.prj @@ -0,0 +1 @@ +PROJCS["RGF93_Lambert_93",GEOGCS["GCS_RGF93",DATUM["D_RGF_1993",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",49],PARAMETER["standard_parallel_2",44],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000],UNIT["Meter",1]] \ No newline at end of file diff --git a/Data/Input/training/training.shp b/Data/Input/training/training.shp new file mode 100755 index 0000000000000000000000000000000000000000..730c51d1df89bdbefd3067f484c9cc8f9cfe1bca --- /dev/null +++ b/Data/Input/training/training.shp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1c17dff62d346c046ed85418814db4b19f52fcb14001ae268f3e3468386d265 +size 2454248 diff --git a/Data/Input/training/training.shx b/Data/Input/training/training.shx new file mode 100755 index 0000000000000000000000000000000000000000..af9e2a01dcbb8bb2b12eb27c20a24c2d2e3b2262 --- /dev/null +++ b/Data/Input/training/training.shx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c72e6f244e74a6088669aedd8ef7b6b3df757e981ee76883a2c0b4402d1a3ca5 +size 39972 diff --git a/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py b/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py index 5cb3224bc01e41a3a1df7511dd28f1c5b050f722..5755cf1aec0b2c8a95e23167dab4866b828bec5e 100755 --- a/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py +++ b/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py @@ -83,9 +83,12 @@ def GetApplicationExamplePythonSnippet(app,idx,expand = False, inputpath="",outp paramtype = app.GetParameterType(param) paramrole = app.GetParameterRole(param) if paramtype == ParameterType_ListView: - break # TODO + if app.GetListViewSingleSelectionMode(param): + output += "\t" + appname + ".SetParameterString("+EncloseString(param)+", "+EncloseString(value)+")" + else: + output += "\t" + appname + ".SetParameterStringList("+EncloseString(param)+", "+EncloseString(value)+")" if paramtype == ParameterType_Group: - break # TODO + pass if paramtype == ParameterType_Choice: #app.SetParameterString(param,value) output+= "\t" + appname + ".SetParameterString(" + EncloseString(param) + "," + EncloseString(value) + ")" diff --git a/Documentation/Cookbook/rst/PythonAPI.rst b/Documentation/Cookbook/rst/PythonAPI.rst index 45e25c518c21ca0bf0e9b9d612ab8dbc21595101..cf8d7a98a4e4d7e092ae465a81d280fb8e04ff72 100644 --- a/Documentation/Cookbook/rst/PythonAPI.rst +++ b/Documentation/Cookbook/rst/PythonAPI.rst @@ -389,43 +389,10 @@ happens, this documentation will report the OTB version that fixes the issue. Calling UpdateParameters() ^^^^^^^^^^^^^^^^^^^^^^^^^^ -These wrappers are made as a mirror of the C++ API, so there is a function -``UpdateParameters()``. Its role is to update parameters that depend on others. -It is called at least once at the beginning of ``Execute()``. - -In command line and GUI launchers, this functions gets called each time a -parameter of the application is modified. In Python, this mechanism is not -automated: there are cases where you may have to call it yourself. - -Let's take an example with the application ``PolygonClassStatictics``. In this -application, the choices available in the parameter ``field`` depend on the list -of fields actually present in the vector file ``vec``. If you try to set the -parameters ``vec`` and ``field``, you will get an error: - -.. code-block:: python - - import otbApplication as otb - app = otb.Registry.CreateApplication("PolygonClassStatistics") - app.SetParameterString("vec","../../src/OTB-Data/Input/Classification/variousVectors.sqlite") - app.SetParameterString("field", "label") - -:: - - Traceback (most recent call last): - File "<stdin>", line 1, in <module> - File "/home/gpasero/Projet_OTB/build/OTB/lib/otb/python/otbApplication.py", line 897, in SetParameterString - def SetParameterString(self, *args): return _otbApplication.Application_SetParameterString(self, *args) - RuntimeError: Exception thrown in otbApplication Application_SetParameterString: /home/gpasero/Projet_OTB/src/OTB/Modules/Wrappers/ApplicationEngine/src/otbWrapperListViewParameter.cxx:141: - itk::ERROR: ListViewParameter(0x149da10): Cannot find label - -The error says that the choice ``label`` is not recognized, because ``UpdateParameters()`` -was not called after setting the vector file. The solution is to call it before -setting the ``field`` parameter: - -.. code-block:: python - - app.UpdateParameters() - app.SetParameterString("field", "label") +``UpdateParameters()`` is available to the Python API. But in normal use, it +does not need to be called manually. From OTB 7.0.0 and later, it is called +automatically after each call to ``SetParameter*()`` methods. With previous versions +of OTB you may need to call it after setting a parameter. No metadata in NumPy arrays ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Modules/Adapters/CurlAdapters/src/otbCurlHelper.cxx b/Modules/Adapters/CurlAdapters/src/otbCurlHelper.cxx index fc47583a39d2d3b6e03d5821ee0971b070abf494..6b9a27b731665c595b78dc8b50ac1c29f7794a23 100644 --- a/Modules/Adapters/CurlAdapters/src/otbCurlHelper.cxx +++ b/Modules/Adapters/CurlAdapters/src/otbCurlHelper.cxx @@ -185,7 +185,7 @@ public: } protected: - CurlFileDescriptorResource(){} + CurlFileDescriptorResource(): m_File(nullptr) {} ~CurlFileDescriptorResource() override { @@ -195,9 +195,9 @@ protected: private: FILE * m_File; - // prevent copying and assignment; not implemented - CurlFileDescriptorResource (const CurlFileDescriptorResource &); - CurlFileDescriptorResource & operator= (const CurlFileDescriptorResource &); + // prevent copying and assignment + CurlFileDescriptorResource (const CurlFileDescriptorResource &) = delete; + CurlFileDescriptorResource & operator= (const CurlFileDescriptorResource &) = delete; }; //end of class FileResource #endif // OTB_USE_CURL diff --git a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx index b52f87d6de5a8c4464bb47f768de5d6113b71853..1f0401aeec3586afc10d2964d60c26fc665ef5df 100644 --- a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx +++ b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx @@ -215,8 +215,22 @@ private: // Beware that itemIndex differs from ogr layer field index unsigned int itemIndex = GetSelectedItems("feat")[idx]; std::string fieldName = GetChoiceNames( "feat" )[itemIndex]; + switch ((*it)[fieldName].GetType()) + { + case OFTInteger: + mv[idx] = static_cast<ValueType>((*it)[fieldName].GetValue<int>()); + break; + case OFTInteger64: + mv[idx] = static_cast<ValueType>((*it)[fieldName].GetValue<int>()); + break; + case OFTReal: + mv[idx] = static_cast<ValueType>((*it)[fieldName].GetValue<double>()); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << (*it)[fieldName].GetType() << "."); + } + - mv[idx] = static_cast<ValueType>((*it)[fieldName].GetValue<double>()); } input->PushBack(mv); } @@ -369,7 +383,23 @@ private: ogr::Feature dstFeature(outLayer.GetLayerDefn()); dstFeature.SetFrom( *it , TRUE); dstFeature.SetFID(it->GetFID()); - dstFeature[classfieldname].SetValue<int>(target->GetMeasurementVector(count)[0]); + switch (dstFeature[classfieldname].GetType()) + { + case OFTInteger: + dstFeature[classfieldname].SetValue<int>(target->GetMeasurementVector(count)[0]); + break; + case OFTInteger64: + dstFeature[classfieldname].SetValue<int>(target->GetMeasurementVector(count)[0]); + break; + case OFTReal: + dstFeature[classfieldname].SetValue<double>(target->GetMeasurementVector(count)[0]); + break; + case OFTString: + dstFeature[classfieldname].SetValue<std::string>(std::to_string(target->GetMeasurementVector(count)[0])); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << dstFeature[classfieldname].GetType() << "."); + } if (computeConfidenceMap) dstFeature[confFieldName].SetValue<double>(quality->GetMeasurementVector(count)[0]); if (updateMode) diff --git a/Modules/Applications/AppClassification/include/otbTrainVectorBase.h b/Modules/Applications/AppClassification/include/otbTrainVectorBase.h index bc5c716aef98324bcd14882b451fc2636dbfe9cc..24b731cbd6b09ef5e81bb45388fddbcd43801ca3 100644 --- a/Modules/Applications/AppClassification/include/otbTrainVectorBase.h +++ b/Modules/Applications/AppClassification/include/otbTrainVectorBase.h @@ -65,7 +65,7 @@ public: typedef typename Superclass::SampleType SampleType; typedef typename Superclass::ListSampleType ListSampleType; typedef typename Superclass::TargetListSampleType TargetListSampleType; - + typedef double ValueType; typedef itk::VariableLengthVector <ValueType> MeasurementType; @@ -127,7 +127,10 @@ protected: { m_SelectedCFieldIdx = selectedCFieldIdx; // Handle only one class field name, if several are provided only the first one is used. - m_SelectedCFieldName = selectedCFieldIdx.empty() ? cFieldNames.front() : cFieldNames[selectedCFieldIdx.front()]; + if (selectedCFieldIdx.empty()) + m_SelectedCFieldName.clear(); + else + m_SelectedCFieldName = cFieldNames[selectedCFieldIdx.front()]; } }; @@ -185,12 +188,6 @@ protected: void DoInit() override; void DoUpdateParameters() override; void DoExecute() override; - -private: - /** - * Get the field of the input feature corresponding to the input field - */ - inline TOutputValue GetFeatureField(const ogr::Feature& feature, int field); }; } diff --git a/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx b/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx index c1e4f88f1cf9f428a038da63d99161e26daa9f66..eaaa8bee3189933a532c3c21abbde7a65dc77e87 100644 --- a/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx +++ b/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx @@ -237,23 +237,6 @@ TrainVectorBase<TInputValue, TOutputValue> return measurement; } -// Template specialization for the integer case (i.e.classification), to avoid a cast from double to integer -template <> -inline int -TrainVectorBase<float, int> -::GetFeatureField(const ogr::Feature & feature, int fieldIndex) -{ - return(feature[fieldIndex].GetValue<int>()); -} - -template <class TInputValue, class TOutputValue> -inline TOutputValue -TrainVectorBase<TInputValue, TOutputValue> -::GetFeatureField(const ogr::Feature & feature, int fieldIndex) -{ - return(feature[fieldIndex].GetValue<double>()); -} - template <class TInputValue, class TOutputValue> typename TrainVectorBase<TInputValue, TOutputValue>::SamplesWithLabel TrainVectorBase<TInputValue, TOutputValue> @@ -310,12 +293,45 @@ TrainVectorBase<TInputValue, TOutputValue> MeasurementType mv; mv.SetSize( m_FeaturesInfo.m_NbFeatures ); for( unsigned int idx = 0; idx < m_FeaturesInfo.m_NbFeatures; ++idx ) - mv[idx] = feature[featureFieldIndex[idx]].GetValue<double>(); + { + switch (feature[featureFieldIndex[idx]].GetType()) + { + case OFTInteger: + mv[idx] = static_cast<ValueType>(feature[featureFieldIndex[idx]].GetValue<int>()); + break; + case OFTInteger64: + mv[idx] = static_cast<ValueType>(feature[featureFieldIndex[idx]].GetValue<int>()); + break; + case OFTReal: + mv[idx] = static_cast<ValueType>(feature[featureFieldIndex[idx]].GetValue<double>()); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << feature[featureFieldIndex[idx]].GetType() << "."); + } + } input->PushBack( mv ); if(cFieldIndex>=0 && ogr::Field(feature,cFieldIndex).HasBeenSet()) - target->PushBack(GetFeatureField(feature,cFieldIndex)); + { + switch (feature[cFieldIndex].GetType()) + { + case OFTInteger: + target->PushBack(static_cast<ValueType>(feature[cFieldIndex].GetValue<int>())); + break; + case OFTInteger64: + target->PushBack(static_cast<ValueType>(feature[cFieldIndex].GetValue<int>())); + break; + case OFTReal: + target->PushBack(static_cast<ValueType>(feature[cFieldIndex].GetValue<double>())); + break; + case OFTString: + target->PushBack(static_cast<ValueType>(std::stod(feature[cFieldIndex].GetValue<std::string>()))); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << feature[featureFieldIndex[cFieldIndex]].GetType() << "."); + } + } else target->PushBack( 0. ); diff --git a/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx b/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx index d5ea4307e9ce7b46da59c1a4a9dcbe6f9de16519..78914ed6f878e9788aa854171148345bd06e6f41 100644 --- a/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx +++ b/Modules/Applications/AppDimensionalityReduction/app/otbTrainDimensionalityReduction.cxx @@ -129,7 +129,9 @@ private: otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read); otb::ogr::Layer layer = source->GetLayer(0); ListSampleType::Pointer input = ListSampleType::New(); - const int nbFeatures = GetParameterStringList("feat").size(); + + const auto inputIndexes = GetParameterStringList("feat"); + const int nbFeatures = inputIndexes.size(); input->SetMeasurementVectorSize(nbFeatures); otb::ogr::Layer::const_iterator it = layer.cbegin(); @@ -140,7 +142,20 @@ private: mv.SetSize(nbFeatures); for(int idx=0; idx < nbFeatures; ++idx) { - mv[idx] = (*it)[GetParameterStringList("feat")[idx]].GetValue<double>(); + switch ((*it)[inputIndexes[idx]].GetType()) + { + case OFTInteger: + mv[idx] = static_cast<ValueType>((*it)[inputIndexes[idx]].GetValue<int>()); + break; + case OFTInteger64: + mv[idx] = static_cast<ValueType>((*it)[inputIndexes[idx]].GetValue<int>()); + break; + case OFTReal: + mv[idx] = static_cast<ValueType>((*it)[inputIndexes[idx]].GetValue<double>()); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << (*it)[inputIndexes[idx]].GetType() << "."); + } } input->PushBack(mv); } diff --git a/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx b/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx index 9cf081678667dc329b7db6d4f0a4b6afcc425479..2629ce715998a58b38902703e53d5e85d6889b46 100644 --- a/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx +++ b/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx @@ -221,7 +221,20 @@ private: for(int idx=0; idx < nbFeatures; ++idx) { - mv[idx] = static_cast<float>( (*it)[inputIndexes[idx]].GetValue<double>() ); + switch ((*it)[inputIndexes[idx]].GetType()) + { + case OFTInteger: + mv[idx] = static_cast<ValueType>((*it)[inputIndexes[idx]].GetValue<int>()); + break; + case OFTInteger64: + mv[idx] = static_cast<ValueType>((*it)[inputIndexes[idx]].GetValue<int>()); + break; + case OFTReal: + mv[idx] = static_cast<ValueType>((*it)[inputIndexes[idx]].GetValue<double>()); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << (*it)[inputIndexes[idx]].GetType() << "."); + } } input->PushBack(mv); } @@ -399,7 +412,23 @@ private: for (std::size_t i=0; i<outFields.size(); ++i) { - dstFeature[outFields[i]].SetValue<double>(target->GetMeasurementVector(count)[i]); + switch (dstFeature[outFields[i]].GetType()) + { + case OFTInteger: + dstFeature[outFields[i]].SetValue<int>(target->GetMeasurementVector(count)[0]); + break; + case OFTInteger64: + dstFeature[outFields[i]].SetValue<int>(target->GetMeasurementVector(count)[0]); + break; + case OFTReal: + dstFeature[outFields[i]].SetValue<double>(target->GetMeasurementVector(count)[0]); + break; + case OFTString: + dstFeature[outFields[i]].SetValue<std::string>(std::to_string(target->GetMeasurementVector(count)[0])); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << dstFeature[outFields[i]].GetType() << "."); + } } if (updateMode) { diff --git a/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx b/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx index c826e18469e98ee9fee259b919ad7665da875123..476f7b5710619cc8ba21a12721f723636956398b 100644 --- a/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx +++ b/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx @@ -374,18 +374,7 @@ private: bool CropRegionOfInterest() { FloatVectorImageType::RegionType region; - if ( !HasUserValue("sizex") ) - SetParameterInt( "sizex" , - GetDefaultParameterInt( "sizex" ) ); - if ( !HasUserValue("sizey") ) - SetParameterInt( "sizey" , - GetDefaultParameterInt( "sizey" ) ); - if ( !HasUserValue("startx") ) - SetParameterInt( "startx" , - GetDefaultParameterInt( "startx" ) ); - if ( !HasUserValue("starty") ) - SetParameterInt( "starty" , - GetDefaultParameterInt( "starty" ) ); + region.SetSize(0, GetParameterInt("sizex")); region.SetSize(1, GetParameterInt("sizey")); region.SetIndex(0, GetParameterInt("startx")); diff --git a/Modules/Core/Common/include/otbImageRegionTileMapSplitter.h b/Modules/Core/Common/include/otbImageRegionTileMapSplitter.h index 63767c7acd12477f27151969288ebbcfb384973b..fdcf4e67c1fb37bc614f3beda83ff711b1570bec 100644 --- a/Modules/Core/Common/include/otbImageRegionTileMapSplitter.h +++ b/Modules/Core/Common/include/otbImageRegionTileMapSplitter.h @@ -123,7 +123,7 @@ public: const RegionType& region) override; protected: - ImageRegionTileMapSplitter() : m_AlignStep(256){} + ImageRegionTileMapSplitter() : m_SplitsPerDimension{0}, m_AlignStep(256) {} ~ImageRegionTileMapSplitter() override {} void PrintSelf(std::ostream& os, itk::Indent indent) const override; diff --git a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageBlackmanFunction.h b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageBlackmanFunction.h index 910908443fdc97c419798ce2423adb6b8a98e18f..4bad6a65ef34138eb623b6ea0b3e1310fd104583 100644 --- a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageBlackmanFunction.h +++ b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageBlackmanFunction.h @@ -41,6 +41,7 @@ template<class TInput = double, class TOutput = double> class BlackmanWindowFunction { public: + BlackmanWindowFunction(): m_Radius(1), m_Factor1(CONST_PI), m_Factor2(2.0 * CONST_PI) {} // default radius is 1 at construction void SetRadius(unsigned int radius) { m_Radius = radius; @@ -95,8 +96,7 @@ template<class TInputImage, class TBoundaryCondition = itk::ConstantBoundaryCond double, class TInputInterpolator = double, class TOutputInterpolator = double> class ITK_EXPORT WindowedSincInterpolateImageBlackmanFunction : public WindowedSincInterpolateImageFunctionBase<TInputImage, - typename Function::BlackmanWindowFunction<TInputInterpolator, - TOutputInterpolator>, + typename Function::BlackmanWindowFunction<TInputInterpolator, TOutputInterpolator>, TBoundaryCondition, TCoordRep> { diff --git a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageCosineFunction.h b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageCosineFunction.h index 5f37e59be5177494d82108c153bb6573d6f20940..46a65cc60de9715b6b79840467666e9620f89336 100644 --- a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageCosineFunction.h +++ b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageCosineFunction.h @@ -41,6 +41,7 @@ template<class TInput = double, class TOutput = double> class CosineWindowFunction { public: + CosineWindowFunction(): m_Radius(1), m_Factor(CONST_PI / 2.0) {} // default radius is 1 at construction void SetRadius(unsigned int radius) { m_Radius = radius; @@ -63,9 +64,9 @@ public: return (x == 0.0) ? static_cast<TOutput>(temp) : static_cast<TOutput>(temp * std::sin(px) / px); } private: + unsigned int m_Radius; // Equal to \f$ \frac{\pi}{2 m} \f$ double m_Factor; - unsigned int m_Radius; }; } //namespace Function diff --git a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageGaussianFunction.h b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageGaussianFunction.h index 9d20a68c81157570f581e298fc48fb05072b2e73..b2a6bdc1bc0e18be51b28cce02508d960bfe1e9b 100644 --- a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageGaussianFunction.h +++ b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageGaussianFunction.h @@ -41,6 +41,7 @@ template<class TInput = double, class TOutput = double> class GaussianWindowFunction { public: + GaussianWindowFunction(): m_Radius(1), m_Factor(-2.0 / CONST_PI) {} // default radius is 1 at construction void SetRadius(unsigned int radius) { m_Radius = radius; @@ -63,8 +64,8 @@ public: return (x == 0.0) ? static_cast<TOutput>(temp) : static_cast<TOutput>(temp * std::sin(px) / px); } private: - double m_Factor; unsigned int m_Radius; + double m_Factor; }; } //namespace Function diff --git a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageHammingFunction.h b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageHammingFunction.h index 003bbdd2508a615eea5ab186762d922eec7579ce..2ea6af2790e9608479ea1ac09f7b2731b84506bb 100644 --- a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageHammingFunction.h +++ b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageHammingFunction.h @@ -41,6 +41,7 @@ template<class TInput = double, class TOutput = double> class HammingWindowFunction { public: + HammingWindowFunction(): m_Radius(1), m_Factor(CONST_PI) {} // default radius is 1 at construction void SetRadius(unsigned int radius) { m_Radius = radius; @@ -63,9 +64,9 @@ public: return (x == 0.0) ? static_cast<TOutput>(temp) : static_cast<TOutput>(temp * std::sin(px) / px); } private: + unsigned int m_Radius; // Equal to \f$ \frac{\pi}{m} \f$ double m_Factor; - unsigned int m_Radius; }; } //namespace Function diff --git a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageLanczosFunction.h b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageLanczosFunction.h index bfd9162671520e945d0c28c078a55775677a5d37..8e0e6355aea1385c6b47f84ab7f980576963c4aa 100644 --- a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageLanczosFunction.h +++ b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageLanczosFunction.h @@ -43,6 +43,7 @@ template<class TInput = double, class TOutput = double> class LanczosWindowFunction { public: + LanczosWindowFunction(): m_Radius(1), m_Factor(CONST_PI) {} // default factor is 1 at construction void SetRadius(unsigned int radius) { m_Radius = radius; @@ -74,9 +75,9 @@ public: return (x == 0.0) ? static_cast<TOutput>(temp) : static_cast<TOutput>(temp * std::sin(px) / px); } private: + unsigned int m_Radius; // Equal to \f$ \frac{\pi}{m} \f$ double m_Factor; - unsigned int m_Radius; }; } //namespace Function diff --git a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageWelchFunction.h b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageWelchFunction.h index 5625f2f41188490ce2536de72c88234ceae79743..03fa31a4a3540bc9bed73e21e71ff9862dccc606 100644 --- a/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageWelchFunction.h +++ b/Modules/Core/Interpolation/include/otbWindowedSincInterpolateImageWelchFunction.h @@ -41,6 +41,7 @@ template<class TInput = double, class TOutput = double> class WelchWindowFunction { public: + WelchWindowFunction() : m_Radius(1), m_Factor(1) {} // default radius is 1 at construction void SetRadius(unsigned int radius) { m_Radius = radius; @@ -63,9 +64,9 @@ public: return (x == 0.0) ? static_cast<TOutput>(temp) : static_cast<TOutput>(temp * std::sin(px) / px); } private: + unsigned int m_Radius; // Equal to \f$ \frac{1}{m^2} \f$ double m_Factor; - unsigned int m_Radius; }; } //namespace Function diff --git a/Modules/Core/PointSet/include/otbPointSetExtractROI.hxx b/Modules/Core/PointSet/include/otbPointSetExtractROI.hxx index 8f55da34976475272ff1bbee67bf8f956bc2f1a7..30fe8820c94117163845a4d8d143751c621c6125 100644 --- a/Modules/Core/PointSet/include/otbPointSetExtractROI.hxx +++ b/Modules/Core/PointSet/include/otbPointSetExtractROI.hxx @@ -32,7 +32,7 @@ namespace otb */ template <class TInputPointSet, class TOutputPointSet> PointSetExtractROI<TInputPointSet, TOutputPointSet> -::PointSetExtractROI() +::PointSetExtractROI() : m_StartX(0), m_StartY(0), m_SizeX(0), m_SizeY(0) { } diff --git a/Modules/Filtering/DimensionalityReduction/include/otbEstimateInnerProductPCAImageFilter.hxx b/Modules/Filtering/DimensionalityReduction/include/otbEstimateInnerProductPCAImageFilter.hxx index 24cbb84debf8052f399583c6025488e58f4029a3..7f9d5d39f51012af6e1f83b6261571cb9a467ea1 100644 --- a/Modules/Filtering/DimensionalityReduction/include/otbEstimateInnerProductPCAImageFilter.hxx +++ b/Modules/Filtering/DimensionalityReduction/include/otbEstimateInnerProductPCAImageFilter.hxx @@ -34,9 +34,8 @@ namespace otb */ template <class TInputImage, class TOutputImage> EstimateInnerProductPCAImageFilter<TInputImage, TOutputImage> -::EstimateInnerProductPCAImageFilter() +::EstimateInnerProductPCAImageFilter(): m_NumberOfPrincipalComponentsRequired(1), m_CenterData(true) { - m_NumberOfPrincipalComponentsRequired = 1; } /** diff --git a/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx b/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx index ab3b3e331ca9b90aaa603ad85b03e90b4f64fc13..1498285a882c51ebcc72eb58c2b46b3db987afeb 100644 --- a/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx +++ b/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx @@ -36,6 +36,7 @@ InnerProductPCAImageFilter<TInputImage, TOutputImage> this->SetNthOutput(0, OutputImageType::New()); m_EstimatePCAFilter = EstimatePCAFilterType::New(); m_NormalizePCAFilter = NormalizePCAFilterType::New(); + m_NumberOfPrincipalComponentsRequired = 1; m_CenterData = true; m_GenerateMeanComponent = false; m_MeanFilter = MeanFilterType::New(); diff --git a/Modules/Filtering/Polarimetry/include/otbMultiChannelsPolarimetricSynthesisFilter.hxx b/Modules/Filtering/Polarimetry/include/otbMultiChannelsPolarimetricSynthesisFilter.hxx index 6a0de2726707cd5f9cd7734f3ef18f245317e664..d3e1d6e60a9685044e04bbd321b059cf4f79901c 100644 --- a/Modules/Filtering/Polarimetry/include/otbMultiChannelsPolarimetricSynthesisFilter.hxx +++ b/Modules/Filtering/Polarimetry/include/otbMultiChannelsPolarimetricSynthesisFilter.hxx @@ -36,14 +36,18 @@ namespace otb */ template <class TInputImage, class TOutputImage, class TFunction> MultiChannelsPolarimetricSynthesisFilter<TInputImage, TOutputImage, TFunction> -::MultiChannelsPolarimetricSynthesisFilter() +::MultiChannelsPolarimetricSynthesisFilter(): + m_PsiI(0.0), + m_KhiI(0.0), + m_PsiR(0.0), + m_KhiR(0.0), + m_Gain(1.0), + m_Mode(0), + m_EmissionH(false), + m_EmissionV(false) { this->SetNumberOfRequiredInputs(1); this->InPlaceOff(); - SetEmissionH(false); - SetEmissionV(false); - SetGain(1); - SetMode(0); m_ArchitectureType = PolarimetricData::New(); } diff --git a/Modules/Filtering/Smoothing/include/otbMeanShiftSmoothingImageFilter.h b/Modules/Filtering/Smoothing/include/otbMeanShiftSmoothingImageFilter.h index 606c00e3d678a8fcf98b7fbad52aa722ed082730..ca8e5c5db216468754921f701aa68a8acedc8617 100644 --- a/Modules/Filtering/Smoothing/include/otbMeanShiftSmoothingImageFilter.h +++ b/Modules/Filtering/Smoothing/include/otbMeanShiftSmoothingImageFilter.h @@ -59,10 +59,12 @@ class SpatialRangeJointDomainTransform public: typedef double RealType; - SpatialRangeJointDomainTransform() + SpatialRangeJointDomainTransform(): + m_ImageDimension(0), + m_NumberOfComponentsPerPixel(0), + m_OutputSize(0) { } - // ~SpatialRangeJointDomainTransform() {} typename TOutputJointImage::PixelType operator()(const typename TInputImage::PixelType & inputPixel, const typename TInputImage::IndexType & index) const diff --git a/Modules/IO/IOGDAL/src/otbGDALOverviewsBuilder.cxx b/Modules/IO/IOGDAL/src/otbGDALOverviewsBuilder.cxx index 2ceeb5a2924dab8e85df2eaf420a4c9ab27c8348..fccaddb38eb76b622d580f9d22fb8b9e07bc6b70 100644 --- a/Modules/IO/IOGDAL/src/otbGDALOverviewsBuilder.cxx +++ b/Modules/IO/IOGDAL/src/otbGDALOverviewsBuilder.cxx @@ -155,11 +155,6 @@ GDALOverviewsBuilder if( factor<=1 ) return 0; - assert( minSize>0 ); - - if( minSize<=0 ) - return 0; - assert( !m_GDALDataset.IsNull() ); // unsigned int minSize = static_cast< unsigned int >( pow( factor, n ) ); diff --git a/Modules/IO/ImageIO/include/otbScalarBufferToImageFileWriter.hxx b/Modules/IO/ImageIO/include/otbScalarBufferToImageFileWriter.hxx index df34ef682d94a3d097991b54007b6874aafba2ba..45c633b1fd636d99ad489d919488669d66b86285 100644 --- a/Modules/IO/ImageIO/include/otbScalarBufferToImageFileWriter.hxx +++ b/Modules/IO/ImageIO/include/otbScalarBufferToImageFileWriter.hxx @@ -43,7 +43,7 @@ void ScalarBufferToImageFileWriter<TBufferType, TOutputPixelType>::GenerateData() { // Check image parameters - if( (m_ImageSize[0]==0) || (m_ImageSize[0]==0) ) + if( (m_ImageSize[0]==0) || (m_ImageSize[1]==0) ) { itkExceptionMacro("Invalid output image size, Size can't be null."); } diff --git a/Modules/IO/TestKernel/src/otbTestDriver.cxx b/Modules/IO/TestKernel/src/otbTestDriver.cxx index 930c1910b4ea1311fbb60faa47bbf0e29845e533..8939e2cf1fe9f012edec990eb149939bbe114a15 100644 --- a/Modules/IO/TestKernel/src/otbTestDriver.cxx +++ b/Modules/IO/TestKernel/src/otbTestDriver.cxx @@ -188,9 +188,8 @@ int main(int ac, char* av[]) } // This is a dummy main to be registered as a test for the otbTestMain -int Execute(int argc, char * argv[]) +int Execute(int, char * argv[]) { - argc -= 1; argv += 1; // Create the appropriate itk process itksysProcess * process = itksysProcess_New(); diff --git a/Modules/Learning/Markov/include/otbMarkovRandomFieldFilter.hxx b/Modules/Learning/Markov/include/otbMarkovRandomFieldFilter.hxx index 2b327cafe25714a7825a83c21200583125019fa7..c058234566213edd7551b1517fb81906c73c2b2c 100644 --- a/Modules/Learning/Markov/include/otbMarkovRandomFieldFilter.hxx +++ b/Modules/Learning/Markov/include/otbMarkovRandomFieldFilter.hxx @@ -243,11 +243,6 @@ void MarkovRandomFieldFilter<TInputImage, TClassifiedImage> ::Allocate() { - if (m_NumberOfClasses <= 0) - { - throw itk::ExceptionObject(__FILE__, __LINE__, "NumberOfClasses <= 0.", ITK_LOCATION); - } - //Set the output labelled and allocate the memory LabelledImagePointer outputPtr = this->GetOutput(); diff --git a/Modules/Registration/DisparityMap/include/otbDisparityMapMedianFilter.hxx b/Modules/Registration/DisparityMap/include/otbDisparityMapMedianFilter.hxx index ec3834e950a5037574e066e3517ed45fb0914ed8..a75248d5e61d4740ab872b8103082d42fa2be231 100644 --- a/Modules/Registration/DisparityMap/include/otbDisparityMapMedianFilter.hxx +++ b/Modules/Registration/DisparityMap/include/otbDisparityMapMedianFilter.hxx @@ -260,7 +260,7 @@ DisparityMapMedianFilter< TInputImage, TOutputImage, TMask> InputIt.SetLocation(outputIt.GetIndex()); for (unsigned int i=0; i<InputIt.Size(); i++) { - if (!inputmaskPtr || (inputmaskPtr && MaskInputIt.GetPixel(i) != 0)) + if (!inputmaskPtr || (MaskInputIt.GetPixel(i) != 0)) { p++; pixels.push_back(InputIt.GetPixel(i)); @@ -347,7 +347,7 @@ DisparityMapMedianFilter< TInputImage, TOutputImage, TMask> MaskInputIt.SetLocation(outputIt.GetIndex()); } - if ((!inputmaskPtr || (inputmaskPtr && MaskInputIt.GetCenterPixel() != 0)) && + if ((!inputmaskPtr || (MaskInputIt.GetCenterPixel() != 0)) && std::fabs(InputIt.GetCenterPixel() - MedianIt.Get())>m_IncoherenceThreshold) { outputDisparityMapIt.Set(0.0); //Remove pixel from disparity map// diff --git a/Modules/Registration/DisparityMap/include/otbPixelWiseBlockMatchingImageFilter.hxx b/Modules/Registration/DisparityMap/include/otbPixelWiseBlockMatchingImageFilter.hxx index 2c1ce1af846e8e8088bb08f811299bf794762f73..454a6385f1c86d16a82ad13cb0fff45b0d2ed4cd 100644 --- a/Modules/Registration/DisparityMap/include/otbPixelWiseBlockMatchingImageFilter.hxx +++ b/Modules/Registration/DisparityMap/include/otbPixelWiseBlockMatchingImageFilter.hxx @@ -670,9 +670,9 @@ TOutputDisparityImage,TMaskImage,TBlockMatchingFunctor> ((tmpIndex[1] - this->m_GridIndex[1] + this->m_Step) % this->m_Step == 0)) { // If the mask is present and valid - if(!inLeftMaskPtr || (inLeftMaskPtr && inLeftMaskIt.Get() > 0) ) + if(!inLeftMaskPtr || (inLeftMaskIt.Get() > 0) ) { - if(!inRightMaskPtr || (inRightMaskPtr && inRightMaskIt.Get() > 0) ) + if(!inRightMaskPtr || (inRightMaskIt.Get() > 0) ) { int estimatedMinHDisp = m_MinimumHorizontalDisparity; int estimatedMinVDisp = m_MinimumVerticalDisparity; diff --git a/Modules/Registration/DisparityMap/include/otbSubPixelDisparityImageFilter.hxx b/Modules/Registration/DisparityMap/include/otbSubPixelDisparityImageFilter.hxx index 5a2834ff83fe367750eed2bf522c1a42ecfc5ed4..fdf976a52d326216161d337b5b8f3f560b3d97d5 100644 --- a/Modules/Registration/DisparityMap/include/otbSubPixelDisparityImageFilter.hxx +++ b/Modules/Registration/DisparityMap/include/otbSubPixelDisparityImageFilter.hxx @@ -762,9 +762,9 @@ TDisparityImage,TMaskImage,TBlockMatchingFunctor> inRightMaskIt.SetIndex(curRightPos); } // check that the current positions are not masked - if(!inLeftMaskPtr || (inLeftMaskPtr && inLeftMaskIt.Get() > 0) ) + if(!inLeftMaskPtr || (inLeftMaskIt.Get() > 0) ) { - if(!inRightMaskPtr || (inRightMaskPtr && inRightMaskIt.Get() > 0) ) + if(!inRightMaskPtr || (inRightMaskIt.Get() > 0) ) { RegionType smallRightRegion; smallRightRegion.SetIndex(0,curRightPos[0]-1); @@ -1195,9 +1195,9 @@ TDisparityImage,TMaskImage,TBlockMatchingFunctor> inRightMaskIt.SetIndex(curRightPos); } // check that the current positions are not masked - if(!inLeftMaskPtr || (inLeftMaskPtr && inLeftMaskIt.Get() > 0) ) + if(!inLeftMaskPtr || (inLeftMaskIt.Get() > 0) ) { - if(!inRightMaskPtr || (inRightMaskPtr && inRightMaskIt.Get() > 0) ) + if(!inRightMaskPtr || (inRightMaskIt.Get() > 0) ) { RegionType smallRightRegion; smallRightRegion.SetIndex(0,curRightPos[0]-1); @@ -1696,9 +1696,9 @@ TDisparityImage,TMaskImage,TBlockMatchingFunctor> inRightMaskIt.SetIndex(curRightPos); } // check that the current positions are not masked - if(!inLeftMaskPtr || (inLeftMaskPtr && inLeftMaskIt.Get() > 0) ) + if(!inLeftMaskPtr || (inLeftMaskIt.Get() > 0) ) { - if(!inRightMaskPtr || (inRightMaskPtr && inRightMaskIt.Get() > 0) ) + if(!inRightMaskPtr || (inRightMaskIt.Get() > 0) ) { RegionType smallRightRegion; smallRightRegion.SetIndex(0,curRightPos[0]-1); diff --git a/Modules/Wrappers/SWIG/src/otbApplication.i b/Modules/Wrappers/SWIG/src/otbApplication.i index fbfcdb06a6edf8a272cb0d4b15d5eff2eb1461f2..e509a59d0efd99550be8b19409f82dcd95238fdc 100644 --- a/Modules/Wrappers/SWIG/src/otbApplication.i +++ b/Modules/Wrappers/SWIG/src/otbApplication.i @@ -203,6 +203,35 @@ public: #endif +#if SWIGPYTHON + +// We want all SetParameterXXX functions to call UpdateParameters automaticaly +// so that using it is not required from the Python API +// for more discussion about this see gitlab issue #1842 + +%pythonappend Application::SetParameterInt %{ + self.UpdateParameters() +%} + +%pythonappend Application::SetParameterFloat %{ + self.UpdateParameters() +%} + +%pythonappend Application::SetParameterString %{ + self.UpdateParameters() +%} + +%pythonappend Application::SetParameterStringList %{ + self.UpdateParameters() +%} + +%pythonappend Application::SetParameterOutputImagePixelType %{ + self.UpdateParameters() +%} + +#endif + + class Application: public itkObject { public: @@ -511,7 +540,6 @@ private: void operator =(const Application&); }; - DECLARE_REF_COUNT_CLASS( Application ) diff --git a/Modules/Wrappers/SWIG/test/python/CMakeLists.txt b/Modules/Wrappers/SWIG/test/python/CMakeLists.txt index 154599d1794efe726f31c391ca26e31499735bbd..7b0bd59465dd896e922622afa59427da408eca88 100644 --- a/Modules/Wrappers/SWIG/test/python/CMakeLists.txt +++ b/Modules/Wrappers/SWIG/test/python/CMakeLists.txt @@ -131,7 +131,7 @@ add_test( NAME pyTvNewStyleParameters COMMAND ${TEST_DRIVER} Execute ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonTestDriver.py PythonNewStyleParametersTest - ${OTB_DATA_ROOT}/Input/poupees.tif + ${OTB_DATA_ROOT}/Input/sensor_stereo_left.tif ${TEMP}/pyTvNewStyleParametersTest.tif ${OTB_DATA_ROOT}/Input/apTvUtSmoothingTest_OutXML.xml) @@ -160,3 +160,12 @@ add_test( NAME pyTvParametersDict ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonTestDriver.py PythonParametersDict ${OTB_DATA_ROOT}/Input/poupees.tif) + +add_test( NAME pyTvNoUpdateParameter + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonTestDriver.py + PythonNoUpdateParameter + ${OTB_DATA_ROOT}/Input/poupees.tif + ${OTB_DATA_ROOT}/Input/training/training.shp + ) + diff --git a/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py b/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py index ea6203a0545a537a4f60bc7a556fd69d947b21d6..0320b78f19e40add9ba8cfda4b916c3e89f10a68 100644 --- a/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py +++ b/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py @@ -67,8 +67,8 @@ def test(otb, argv): cm_assert(app.MAP, 'epsg') # 6 - int type 2nd level sub parameters of choice parameter set - app.MAP.EPSG.CODE = 32768 - cm_assert(32768, app.GetParameterInt('map.epsg.code')) + app.MAP.EPSG.CODE = 2154 + cm_assert(2154, app.GetParameterInt('map.epsg.code')) # 7 - another choice with sub parameters set app.MAP = 'utm' diff --git a/Modules/Wrappers/SWIG/test/python/PythonNoUpdateParameter.py b/Modules/Wrappers/SWIG/test/python/PythonNoUpdateParameter.py new file mode 100644 index 0000000000000000000000000000000000000000..8453eb1bb67cf726c9cf73118ec2cff996bfd88a --- /dev/null +++ b/Modules/Wrappers/SWIG/test/python/PythonNoUpdateParameter.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) +# +# This file is part of Orfeo Toolbox +# +# https://www.orfeo-toolbox.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +def test(otb, argv): + """ + The purpose of this test is to check that we don't need UpdateParameter() + from the PythonAPI, especially in the case of ListView parameters + See gitlab issue #1842 + """ + app = otb.Registry.CreateApplication("TrainImagesClassifier") + app.SetParameterStringList("io.il", [argv[1]]) + app.SetParameterStringList("io.vd",[argv[2]]) + app.SetParameterStringList("sample.vfn",["CODE"]) +