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