Commit 06939888 authored by Julien Osman's avatar Julien Osman
Browse files

Merge branch '2160-SarSensorModel-burst' into 'develop'

Implements Deburst algorithms

See merge request !823
parents 52c83621 5e55bfcd
Pipeline #8143 passed with stages
in 19 minutes and 44 seconds
......@@ -15,3 +15,6 @@ AcquisitionStartTime 2011-04-18T18:03:27.915976Z
AcquisitionStopTime 2011-04-18T18:03:29.380925Z
SAR <SARParam>
SARCalib <SARCalib>
GCP <GCPParam>
{"Projection": "",
[]}
\ No newline at end of file
......@@ -19,7 +19,4 @@
#
project(OTBBoostAdapters)
set(OTBBoostAdapters_LIBRARIES OTBBoostAdapters)
otb_module_impl()
/*
* Copyright (C) 2005-2020 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.
*/
#ifndef ossimDateTime_h
#define ossimDateTime_h
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/config.hpp>
#include "otbOperatorUtilities.h"
// boost::posix_time::time_duration doesn't have a sufficient precision to
// store things such an azimuth time interval, and yet, this IS a duration.
// Hence this new class injected into boost namespace to emulate a duration
// with precision behind the microsecond.
namespace boost { namespace posix_time {
class precise_duration;
double ratio_(precise_duration const& lhs, precise_duration const& rhs);
class precise_duration
: private boostAdapter::addable<precise_duration>
, private boostAdapter::substractable<precise_duration>
, private boostAdapter::streamable<precise_duration>
, private boostAdapter::multipliable2<precise_duration, double>
, private boostAdapter::dividable<precise_duration, double>
, private boostAdapter::equality_comparable<precise_duration>
, private boostAdapter::less_than_comparable<precise_duration>
, private boostAdapter::addable<ptime, precise_duration>
, private boostAdapter::substractable<ptime, precise_duration>
{
public:
typedef double scalar_type;
/**@name Construction/destruction
*/
//@{
/** Initialization constructor.
*/
precise_duration() {} // = default;
explicit precise_duration(double usec_frac)
: m_usec_frac(usec_frac) {}
precise_duration(time_duration const& d)
: m_usec_frac(d.total_microseconds()) {}
//@}
double total_seconds() const {
return total_microseconds() / 1000000.;
}
double total_microseconds() const {
return m_usec_frac;
}
bool is_negative() const { return total_microseconds() < 0.0; }
precise_duration invert_sign() { return precise_duration(- total_seconds()); }
std::ostream & display(std::ostream & os) const { return os << m_usec_frac; }
std::istream & read (std::istream & is) { return is >> m_usec_frac; }
protected:
/**@name Operations
*/
//@{
void add(precise_duration const& rhs) { m_usec_frac += rhs.total_microseconds(); }
void sub(precise_duration const& rhs) { m_usec_frac -= rhs.total_microseconds(); }
void mult(scalar_type coeff) { m_usec_frac *= coeff; }
void div(scalar_type coeff) { assert(coeff && "Cannot divide by 0"); m_usec_frac /= coeff; }
friend precise_duration& operator+=(precise_duration & u, precise_duration const& v) {
u.add(v);
return u;
}
friend ptime& operator+=(ptime & u, precise_duration const& v) {
const time_duration d = microseconds(static_cast<int> (floor(v.total_microseconds()+0.5)));
u += d;
return u;
}
friend precise_duration& operator-=(precise_duration & u, precise_duration const& v) {
u.sub(v);
return u;
}
friend ptime& operator-=(ptime & u, precise_duration const& v) {
const time_duration d = microseconds(static_cast<int>( floor(v.total_microseconds()+0.5)));
u -= d;
return u;
}
template <typename U, typename V> static U diff(V const& lhs, V const& rhs) {
U const res(lhs.total_microseconds() - rhs.total_microseconds());
return res;
}
friend precise_duration& operator*=(precise_duration & u, scalar_type const& v) {
u.mult(v);
return u;
}
friend precise_duration& operator/=(precise_duration & u, scalar_type const& v) {
u.div(v);
return u;
}
friend bool operator<(precise_duration const& lhs, precise_duration const& rhs) {
return lhs.total_microseconds() < rhs.total_microseconds();
}
friend bool operator==(precise_duration const& lhs, precise_duration const& rhs) {
return lhs.total_microseconds() == rhs.total_microseconds();
}
public:
friend scalar_type ratio_(precise_duration const& lhs, precise_duration const& rhs)
{ return lhs.total_microseconds() / rhs.total_microseconds(); }
//@}
private:
double m_usec_frac;
};
time_duration abs(time_duration d);
}
} // boost::time namespaces
namespace otb
{
namespace MetaData
{
using TimeType = boost::posix_time::ptime;
using DurationType = boost::posix_time::precise_duration;
}
}
#endif
/*
* Copyright (C) 2005-2020 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.
*/
#ifndef otbOperatorUtilities_h
#define otbOperatorUtilities_h
#include <iostream>
namespace boostAdapter {
// Uses Barton-Nackman trick to help implement operator on classes
// Strongly inspired by boost.operators interface
//TODO: imported from ossim plugins, but can we use boost instead ?
#define DEFINE_OPERATORS(name, compound, op) \
template <typename T> struct name ## 1 \
{ \
friend T operator op(T lhs, T const& rhs) { \
lhs compound rhs; \
return lhs; \
} \
}; \
template <typename T, typename U> struct name ## 2 \
{ \
friend T operator op(T lhs, U const& rhs) { \
lhs compound rhs; \
return lhs; \
} \
friend T operator op(U const& lhs, T rhs) { \
rhs compound lhs; \
return rhs; \
} \
}; \
template <typename T, typename U=void> struct name : name ## 2<T,U> {}; \
template <typename T> struct name<T,void> : name ## 1<T> {};
template <typename U, typename V> struct substractable_asym
{
friend U operator-(V const& lhs, V const& rhs) {
return V::template diff<U,V>(lhs, rhs);
}
};
DEFINE_OPERATORS(addable, +=, +);
DEFINE_OPERATORS(substractable, -=, -);
DEFINE_OPERATORS(multipliable, *=, *);
#undef DEFINE_OPERATORS
template <typename T, typename R> struct dividable {
typedef R scalar_type;
friend T operator/(T lhs, scalar_type const& rhs) {
lhs /= rhs;
return lhs;
}
friend scalar_type operator/(T const& lhs, T const& rhs) {
return ratio_(lhs, rhs);
}
};
template <typename T> struct streamable {
friend std::ostream & operator<<(std::ostream & os, const T & v)
{ return v.display(os); }
friend std::istream & operator>>(std::istream & is, T & v)
{ return v.read(is); }
};
template <typename T> struct less_than_comparable {
friend bool operator>(T const& lhs, T const& rhs) {
return rhs < lhs;
}
friend bool operator>=(T const& lhs, T const& rhs) {
return !(lhs < rhs);
}
friend bool operator<=(T const& lhs, T const& rhs) {
return !(rhs < lhs);
}
};
template <typename T> struct equality_comparable {
friend bool operator!=(T const& lhs, T const& rhs) {
return !(rhs == lhs);
}
};
}// namespace boostAdapter
#endif // otbOperatorUtilities_h
......@@ -21,7 +21,6 @@
set(DOCUMENTATION "Adapters for the Boost library.")
otb_module(OTBBoostAdapters
ENABLE_SHARED
DEPENDS
OTBBoost
DESCRIPTION
......
#
# Copyright (C) 2005-2020 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.
#
set(OTBBoostAdapters_SRC
otbDateTime.cxx
)
add_library(OTBBoostAdapters ${OTBBoostAdapters_SRC})
target_link_libraries(OTBBoostAdapters
${OTBBoost_LIBRARIES}
)
otb_module_target(OTBBoostAdapters)
......@@ -137,15 +137,13 @@ private:
}*/
// Coniguration for fusion filter
fusionFilter->SetSLCImageKeyWorList(in->GetImageKeywordlist());
fusionFilter->SetSLCImageMetadata(in->GetImageMetadata());
// Get Invalid pixel Key (from Image 0)
FloatVectorImageType::Pointer Im0 = inList->GetNthElement(0);
Im0->UpdateOutputInformation();
auto const& kwl = Im0->GetImageKeywordlist();
const bool inputWithInvalidPixels = kwl.HasKey("support_data.invalid_pixels") && kwl.GetMetadataByKey("support_data.invalid_pixels") == "yes";
auto const & imd = Im0->GetImageMetadata();
const bool inputWithInvalidPixels = imd.Has("invalid_pixels") && imd["invalid_pixels"] == "yes";
fusionFilter->getDeburstLinesAndSamples(lines, samples, burst_index, inputWithInvalidPixels);
......
......@@ -109,20 +109,19 @@ private:
FloatVectorImageType* in = GetParameterImage("in");
// Set the filer input
m_DeburstFilter = DeburstFilterType::New();
m_DeburstFilter->SetInput(in);
auto deburstFilter = DeburstFilterType::New();
deburstFilter->SetInput(in);
if (IsParameterEnabled("onlyvalidsamples"))
{
m_DeburstFilter->SetOnlyValidSample(true);
deburstFilter->SetOnlyValidSample(true);
}
// Set the output image
SetParameterOutputImage("out", m_DeburstFilter->GetOutput());
SetParameterOutputImage("out", deburstFilter->GetOutput());
RegisterPipeline();
}
DeburstFilterType::Pointer m_DeburstFilter;
};
}
}
......
/*
* Copyright (C) 2005-2020 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.
*/
#ifndef otbDateTime_h
#define otbDateTime_h
// Use nanosecond precision in boost dates and durations
#define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/config.hpp>
#include <boost/operators.hpp>
namespace otb
{
namespace MetaData
{
namespace details
{
// division by a scalar and ratio
template <typename T, typename R> struct dividable
{
typedef R scalar_type;
friend T operator/(T lhs, scalar_type const& rhs)
{
lhs /= rhs;
return lhs;
}
friend scalar_type operator/(T const& lhs, T const& rhs)
{
return ratio_(lhs, rhs);
}
};
template <typename U, typename V> struct substractable_asym
{
friend U operator-(V const& lhs, V const& rhs)
{
return V::template diff<U,V>(lhs, rhs);
}
};
template <typename T> struct streamable
{
friend std::ostream & operator<<(std::ostream & os, const T & v)
{
return v.Display(os);
}
friend std::istream & operator>>(std::istream & is, T & v)
{
return v.Read(is);
}
};
} // namespace details
class Duration;
class TimePoint : private details::streamable<TimePoint>,
private details::substractable_asym<Duration, TimePoint>,
private boost::equality_comparable<TimePoint>,
private boost::less_than_comparable<TimePoint>
{
public:
//friend class Duration;
TimePoint() = default;
std::ostream & Display(std::ostream & os) const { return os << m_Time; }
std::istream & Read (std::istream & is) { return is >> m_Time; }
template <typename U, typename V> static U diff(V const& lhs, V const& rhs)
{
U const res(lhs.m_Time - rhs.m_Time);
return res;
}
friend bool operator < (TimePoint const& lhs, TimePoint const& rhs)
{
return lhs.m_Time < rhs.m_Time;
}
friend bool operator == (TimePoint const& lhs, TimePoint const& rhs)
{
return lhs.m_Time == rhs.m_Time;
}
public:
boost::posix_time::ptime m_Time;
};
using TimeType = TimePoint;
double ratio_(Duration const& lhs, Duration const& rhs);
class Duration : private details::streamable<Duration>,
private boost::addable<Duration>,
private boost::subtractable<Duration>,
private boost::multipliable2<Duration, double>,
private details::dividable<Duration, double>,
private boost::equality_comparable<Duration>,
private boost::less_than_comparable<Duration>,
private boost::addable<TimeType, Duration>,
private boost::subtractable<TimeType, Duration>
{
public:
using InternalDurationType = boost::posix_time::time_duration;
Duration() = default;
Duration(InternalDurationType const& d): m_Duration(d) {}
static Duration Seconds(double d)
{
return Duration(boost::posix_time::nanoseconds(static_cast<long long>(std::round(d * 1e9))));
}
static Duration Nanoseconds(double d)
{
return Duration(boost::posix_time::nanoseconds(static_cast<long long>(std::round(d))));
}
Duration(double d): m_Duration(boost::posix_time::nanoseconds(static_cast<long long>(std::round(d)))) {}
double TotalNanoseconds() const
{
return m_Duration.total_nanoseconds();
}
double TotalSeconds() const
{
return m_Duration.total_nanoseconds() * 1e9;
}
friend Duration& operator+=(Duration & u, Duration const& v)
{
u.m_Duration += v.m_Duration;
return u;
}
friend Duration& operator-=(Duration & u, Duration const& v)
{
u.m_Duration -= v.m_Duration;
return u;
}
friend Duration& operator*=(Duration & u, double v)
{
u.m_Duration = boost::posix_time::nanoseconds(static_cast<long long>(std::round(
u.m_Duration.total_nanoseconds() * v)));
return u;
}
friend Duration& operator/=(Duration & u, double v)
{
u.m_Duration = boost::posix_time::nanoseconds(static_cast<long long>(std::round(
u.m_Duration.total_nanoseconds() / v)));
return u;
}
friend bool operator < (Duration const& lhs, Duration const& rhs)
{
return lhs.m_Duration < rhs.m_Duration;
}
friend bool operator == (Duration const& lhs, Duration const& rhs)
{
return lhs.m_Duration == rhs.m_Duration;
}
friend TimeType& operator+=(TimeType & u, Duration const& v)
{
u.m_Time += v.m_Duration;
return u;
}
friend TimeType& operator-=(TimeType & u, Duration const& v)
{
u.m_Time -= v.m_Duration;
return u;
}
std::ostream & Display(std::ostream & os) const { return os << m_Duration; }
std::istream & Read (std::istream & is) { return is >> m_Duration; }
friend Duration Abs(Duration d);
private:
InternalDurationType m_Duration;
};
Duration Abs(Duration d);
using DurationType = Duration;
DurationType seconds(double);
TimeType ReadFormattedDate(const std::string & dateStr, const std::string & format = "%Y-%m-%dT%H:%M:%S%F");
}
}
#endif
......@@ -72,6 +72,13 @@ public:
*/
bool FetchRPC(ImageMetadata & imd);