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 ------------------------------
36 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
37 DGtal::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)
43 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
44 DGtal::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() );
51 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
52 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>&
53 DGtal::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 :
63 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
65 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::clear()
70 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
72 DGtal::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() << ")";
81 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
82 DGtal::LinearOperator<Calculus, order_out, duality_out, order_in, duality_in>
83 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::transpose() const
85 return TransposedLinearOperator(*myCalculus, myContainer.transpose());
88 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
90 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>::isValid() const
92 return myCalculus != NULL;
95 ///////////////////////////////////////////////////////////////////////////////
96 // Implementation of inline functions //
98 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
100 DGtal::operator<<(std::ostream& out, const DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>& object)
102 object.selfDisplay(out);
106 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
107 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
108 DGtal::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);
115 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
116 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
117 DGtal::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);
124 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
125 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
126 DGtal::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);
132 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
133 DGtal::KForm<Calculus, order_out, duality_out>
134 DGtal::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);
140 template <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>
141 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
142 DGtal::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);
149 template <typename Calculus, DGtal::Order order_in, DGtal::Duality duality_in, DGtal::Order order_out, DGtal::Duality duality_out>
150 DGtal::LinearOperator<Calculus, order_in, duality_in, order_out, duality_out>
151 DGtal::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 ///////////////////////////////////////////////////////////////////////////////