DGtal 1.3.0
Loading...
Searching...
No Matches
KForm.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
18 * @file KForm.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
21 *
22 * @date 2014/03/26
23 *
24 * Implementation of inline methods defined in KForm.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
32
33///////////////////////////////////////////////////////////////////////////////
34// ----------------------- Standard services ------------------------------
35
36template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
37DGtal::KForm<Calculus, order, duality>
38DGtal::KForm<Calculus, order, duality>::ones(ConstAlias<Calculus> _calculus)
39{
40 KForm<Calculus, order, duality> kform(_calculus);
41 kform.myContainer.fill(1);
42 return kform;
43}
44
45template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
46DGtal::KForm<Calculus, order, duality>
47DGtal::KForm<Calculus, order, duality>::zeros(ConstAlias<Calculus> _calculus)
48{
49 KForm<Calculus, order, duality> kform(_calculus);
50 return kform;
51}
52
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)
56{
57 KForm<Calculus, order, duality> kform(_calculus);
58 kform.myContainer( _calculus->getCellIndex(_cell) ) = 1;
59 return kform;
60}
61
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)
65{
66 clear();
67}
68
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)
72{
73 ASSERT( myCalculus->kFormLength(order, duality) == myContainer.rows() );
74}
75
76template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
77DGtal::KForm<Calculus, order, duality>&
78DGtal::KForm<Calculus, order, duality>::operator=(const KForm& _form)
79{
80 myContainer = _form.myContainer;
81 myCalculus = _form.myCalculus;
82 return *this;
83}
84
85///////////////////////////////////////////////////////////////////////////////
86// Interface - public :
87
88template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
89void
90DGtal::KForm<Calculus, order, duality>::selfDisplay(std::ostream& out) const
91{
92 out << "[" << duality << " " << order << "-form (" << myContainer.rows() << ")]";
93}
94
95template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
96std::string
97DGtal::KForm<Calculus, order, duality>::className() const
98{
99 return "KForm";
100}
101
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
105{
106 return myCalculus->getSCell(order, duality, index);
107}
108
109template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
110typename DGtal::KForm<Calculus, order, duality>::Index
111DGtal::KForm<Calculus, order, duality>::length() const
112{
113 return myCalculus->kFormLength(order, duality);
114}
115
116template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
117void
118DGtal::KForm<Calculus, order, duality>::clear()
119{
120 myContainer.clear();
121}
122
123template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
124bool
125DGtal::KForm<Calculus, order, duality>::isValid() const
126{
127 return myCalculus != NULL;
128}
129
130///////////////////////////////////////////////////////////////////////////////
131// Implementation of inline functions //
132
133template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
134std::ostream&
135DGtal::operator<<(std::ostream& out, const DGtal::KForm<Calculus, order, duality>& object)
136{
137 object.selfDisplay(out);
138 return out;
139}
140
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)
144{
145 ASSERT( form_a.myCalculus == form_b.myCalculus );
146 return DGtal::KForm<Calculus, order, duality>(*form_a.myCalculus, form_a.myContainer + form_b.myContainer);
147}
148
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)
152{
153 ASSERT( form_a.myCalculus == form_b.myCalculus );
154 return DGtal::KForm<Calculus, order, duality>(*form_a.myCalculus, form_a.myContainer - form_b.myContainer);
155}
156
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)
160{
161 return DGtal::KForm<Calculus, order, duality>(*form.myCalculus, scalar * form.myContainer);
162}
163
164template <typename Calculus, DGtal::Order order, DGtal::Duality duality>
165DGtal::KForm<Calculus, order, duality>
166DGtal::operator-(const DGtal::KForm<Calculus, order, duality>& form)
167{
168 return DGtal::KForm<Calculus, order, duality>(*form.myCalculus, -form.myContainer);
169}
170
171
172// //
173///////////////////////////////////////////////////////////////////////////////