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/>.
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 KForm.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, DGtal::Duality duality>
37 DGtal::KForm<Calculus, order, duality>
38 DGtal::KForm<Calculus, order, duality>::ones(ConstAlias<Calculus> _calculus)
40 KForm<Calculus, order, duality> kform(_calculus);
41 kform.myContainer.fill(1);
45 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
46 DGtal::KForm<Calculus, order, duality>
47 DGtal::KForm<Calculus, order, duality>::zeros(ConstAlias<Calculus> _calculus)
49 KForm<Calculus, order, duality> kform(_calculus);
53 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
54 DGtal::KForm<Calculus, order, duality>
55 DGtal::KForm<Calculus, order, duality>::dirac(ConstAlias<Calculus> _calculus, const typename Calculus::Cell& _cell)
57 KForm<Calculus, order, duality> kform(_calculus);
58 kform.myContainer( _calculus->getCellIndex(_cell) ) = 1;
62 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
63 DGtal::KForm<Calculus, order, duality>::KForm(ConstAlias<Calculus> _calculus)
64 : myContainer((&_calculus)->kFormLength(order, duality)), myCalculus(&_calculus)
69 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
70 DGtal::KForm<Calculus, order, duality>::KForm(ConstAlias<Calculus> _calculus, const Container& _container)
71 : myContainer(_container), myCalculus(&_calculus)
73 ASSERT( myCalculus->kFormLength(order, duality) == myContainer.rows() );
76 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
77 DGtal::KForm<Calculus, order, duality>&
78 DGtal::KForm<Calculus, order, duality>::operator=(const KForm& _form)
80 myContainer = _form.myContainer;
81 myCalculus = _form.myCalculus;
85 ///////////////////////////////////////////////////////////////////////////////
86 // Interface - public :
88 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
90 DGtal::KForm<Calculus, order, duality>::selfDisplay(std::ostream& out) const
92 out << "[" << duality << " " << order << "-form (" << myContainer.rows() << ")]";
95 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
97 DGtal::KForm<Calculus, order, duality>::className() const
102 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
103 typename DGtal::KForm<Calculus, order, duality>::SCell
104 DGtal::KForm<Calculus, order, duality>::getSCell(const typename DGtal::KForm<Calculus, order, duality>::Index& index) const
106 return myCalculus->getSCell(order, duality, index);
109 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
110 typename DGtal::KForm<Calculus, order, duality>::Index
111 DGtal::KForm<Calculus, order, duality>::length() const
113 return myCalculus->kFormLength(order, duality);
116 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
118 DGtal::KForm<Calculus, order, duality>::clear()
120 myContainer.setZero();
123 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
125 DGtal::KForm<Calculus, order, duality>::isValid() const
127 return myCalculus != NULL;
130 ///////////////////////////////////////////////////////////////////////////////
131 // Implementation of inline functions //
133 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
135 DGtal::operator<<(std::ostream& out, const DGtal::KForm<Calculus, order, duality>& object)
137 object.selfDisplay(out);
141 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
142 DGtal::KForm<Calculus, order, duality>
143 DGtal::operator+(const DGtal::KForm<Calculus, order, duality>& form_a, const DGtal::KForm<Calculus, order, duality>& form_b)
145 ASSERT( form_a.myCalculus == form_b.myCalculus );
146 return DGtal::KForm<Calculus, order, duality>(*form_a.myCalculus, form_a.myContainer + form_b.myContainer);
149 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
150 DGtal::KForm<Calculus, order, duality>
151 DGtal::operator-(const DGtal::KForm<Calculus, order, duality>& form_a, const DGtal::KForm<Calculus, order, duality>& form_b)
153 ASSERT( form_a.myCalculus == form_b.myCalculus );
154 return DGtal::KForm<Calculus, order, duality>(*form_a.myCalculus, form_a.myContainer - form_b.myContainer);
157 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
158 DGtal::KForm<Calculus, order, duality>
159 DGtal::operator*(const typename Calculus::Scalar& scalar, const DGtal::KForm<Calculus, order, duality>& form)
161 return DGtal::KForm<Calculus, order, duality>(*form.myCalculus, scalar * form.myContainer);
164 template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
165 DGtal::KForm<Calculus, order, duality>
166 DGtal::operator-(const DGtal::KForm<Calculus, order, duality>& form)
168 return DGtal::KForm<Calculus, order, duality>(*form.myCalculus, -form.myContainer);
173 ///////////////////////////////////////////////////////////////////////////////