2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file LinearOperator.ih
19 * @author Pierre Gueth (\c pierre.gueth@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in LinearOperator.h
26 * This file is part of the DGtal library.
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
33///////////////////////////////////////////////////////////////////////////////
34// ----------------------- Standard services ------------------------------
36template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
37DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::LinearOperator(ConstAlias<Calculus> _calculus)
38 : myContainer((&_calculus)->kFormLength(order_out, duality_out), (&_calculus)->kFormLength(order_in, duality_in)), myCalculus(&_calculus)
43template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
44DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::LinearOperator(ConstAlias<Calculus> _calculus, const Container& _container)
45 : myContainer(_container), myCalculus(&_calculus)
47 ASSERT( myCalculus->kFormLength(order_out, duality_out) == myContainer.rows() );
48 ASSERT( myCalculus->kFormLength(order_in, duality_in) == myContainer.cols() );
51template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
52DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>&
53DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::operator=(const LinearOperator& _operator)
55 myContainer = _operator.myContainer;
56 myCalculus = _operator.myCalculus;
60///////////////////////////////////////////////////////////////////////////////
61// Interface - public :
63template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
65DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::clear()
70template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
72DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::selfDisplay(std::ostream& os) const
75 os << duality_in << " " << order_in << "-form => " << duality_out << " " << order_out << "-form";
77 os << "(" << myContainer.cols() << " => " << myContainer.rows() << ")";
81template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
82DGtal::LinearOperator<Calculus, order_out, duality_out, order_in, duality_in>
83DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::transpose() const
85 return TransposedLinearOperator(*myCalculus, myContainer.transpose());
88template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
90DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::isValid() const
92 return myCalculus != NULL;
95///////////////////////////////////////////////////////////////////////////////
96// Implementation of inline functions //
98template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
100DGtal::operator<<(std::ostream& out, const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& object)
102 object.selfDisplay(out);
106template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
107DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
108DGtal::operator+(const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& linear_operator_a, const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& linear_operator_b)
110 ASSERT( linear_operator_a.myCalculus == linear_operator_b.myCalculus );
111 typedef DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out> OutputOperator;
112 return OutputOperator(*linear_operator_a.myCalculus, linear_operator_a.myContainer + linear_operator_b.myContainer);
115template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
116DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
117DGtal::operator-(const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& linear_operator_a, const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& linear_operator_b)
119 ASSERT( linear_operator_a.myCalculus == linear_operator_b.myCalculus );
120 typedef DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out> OutputOperator;
121 return OutputOperator(*linear_operator_a.myCalculus, linear_operator_a.myContainer - linear_operator_b.myContainer);
124template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
125DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
126DGtal::operator*(const typename Calculus::Scalar& scalar, const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& linear_operator)
128 typedef DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out> OutputOperator;
129 return OutputOperator(*linear_operator.myCalculus, scalar * linear_operator.myContainer);
132template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
133DGtal::KForm<Calculus, order_out, duality_out>
134DGtal::operator*(const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& linear_operator, const DGtal::KForm<Calculus, order_in, duality_in>& input_form)
136 ASSERT( linear_operator.myCalculus == input_form.myCalculus );
137 return DGtal::KForm<Calculus, order_out, duality_out>(*linear_operator.myCalculus, linear_operator.myContainer * input_form.myContainer);
140template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_fold, DGtal::Duality duality_fold, DGtal::Order order_out, DGtal::Duality duality_out>
141DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
142DGtal::operator*(const DGtal::LinearOperator<Calculus, order_fold, duality_fold, order_out, duality_out>& operator_left, const DGtal::LinearOperator<Calculus, order_in, duality_in, order_fold, duality_fold>& operator_right)
144 ASSERT( operator_right.myCalculus == operator_right.myCalculus );
145 typedef DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out> OutputOperator;
146 return OutputOperator(*operator_left.myCalculus, operator_left.myContainer * operator_right.myContainer);
149template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
150DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
151DGtal::operator-(const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& linear_operator)
153 typedef DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out> OutputOperator;
154 return OutputOperator(*linear_operator.myCalculus, -linear_operator.myContainer);
158///////////////////////////////////////////////////////////////////////////////