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 VectorField.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 VectorField.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::Duality duality>
37 DGtal::VectorField<Calculus, duality>::VectorField(ConstAlias<Calculus> _calculus)
38 : myCoordinates((&_calculus)->kFormLength(0, duality), DGtal::Dimension(Calculus::dimensionAmbient)), myCalculus(&_calculus)
43 template <typename Calculus, DGtal::Duality duality>
44 DGtal::VectorField<Calculus, duality>::VectorField(ConstAlias<Calculus> _calculus, const Coordinates& _coordinates)
45 : myCoordinates(_coordinates), myCalculus(&_calculus)
49 template <typename Calculus, DGtal::Duality duality>
50 DGtal::VectorField<Calculus, duality>&
51 DGtal::VectorField<Calculus, duality>::operator=(const VectorField& _vector_field)
53 myCoordinates = _vector_field.myCoordinates;
54 myCalculus = _vector_field.myCalculus;
58 ///////////////////////////////////////////////////////////////////////////////
59 // Interface - public :
61 template <typename Calculus, DGtal::Duality duality>
63 DGtal::VectorField<Calculus, duality>::selfDisplay(std::ostream& out) const
65 out << "[" << duality << " vector field (" << myCoordinates.rows() << "x" << myCoordinates.cols() << ")]";
68 template <typename Calculus, DGtal::Duality duality>
70 DGtal::VectorField<Calculus, duality>::className() const
75 template <typename Calculus, DGtal::Duality duality>
77 DGtal::VectorField<Calculus, duality>::clear()
79 myCoordinates.clear();
82 template <typename Calculus, DGtal::Duality duality>
84 DGtal::VectorField<Calculus, duality>::isValid() const
86 return myCalculus != NULL;
89 template <typename Calculus, DGtal::Duality duality>
90 DGtal::VectorField<Calculus, duality>
91 DGtal::VectorField<Calculus, duality>::normalized(const typename Calculus::Scalar& epsilon) const
93 VectorField normalized_vector_field(*myCalculus);
95 for (typename Calculus::Index index=0; index<myCalculus->kFormLength(0, duality); index++)
97 Vector vector = getVector(index);
99 const typename Calculus::Scalar& norm = vector.norm();
100 if (norm <= epsilon) continue;
103 normalized_vector_field.setVector(index, vector);
106 return normalized_vector_field;
109 template <typename Calculus, DGtal::Duality duality>
110 DGtal::KForm<Calculus, 0, duality>
111 DGtal::VectorField<Calculus, duality>::intensity(const typename Vector::NormType norm_type) const
113 typedef KForm<Calculus, 0, duality> ZeroForm;
115 ZeroForm zero_form(*myCalculus);
117 for (typename Calculus::Index index=0; index<zero_form.length(); index++)
119 const Vector vector = getVector(index);
120 zero_form.myContainer(index) = vector.norm(norm_type);
126 template <typename Calculus, DGtal::Duality duality>
127 DGtal::KForm<Calculus, 0, duality>
128 DGtal::VectorField<Calculus, duality>::coordAlongDirection(const DGtal::Dimension& dim) const
130 ASSERT( dim < Calculus::dimensionAmbient );
132 typedef KForm<Calculus, 0, duality> ZeroForm;
133 const ZeroForm zero_form(*myCalculus, myCoordinates.col(dim));
134 ASSERT( zero_form.myContainer.rows() == myCoordinates.rows() );
139 template <typename Calculus, DGtal::Duality duality>
140 typename DGtal::VectorField<Calculus, duality>::SCell
141 DGtal::VectorField<Calculus, duality>::getSCell(const Index& index) const
143 return myCalculus->getSCell(0, duality, index);
146 template <typename Calculus, DGtal::Duality duality>
147 typename DGtal::VectorField<Calculus, duality>::Index
148 DGtal::VectorField<Calculus, duality>::length() const
150 return myCalculus->kFormLength(0, duality);
153 template <typename Calculus, DGtal::Duality duality>
154 typename DGtal::VectorField<Calculus, duality>::Vector
155 DGtal::VectorField<Calculus, duality>::getVector(const Index& index) const
159 for (DGtal::Dimension dim=0; dim<Calculus::dimensionAmbient; dim++)
160 vector[dim] = myCoordinates(index, dim);
165 template <typename Calculus, DGtal::Duality duality>
167 DGtal::VectorField<Calculus, duality>::setVector(const Index& index, const Vector& vector)
169 for (DGtal::Dimension dim=0; dim<Calculus::dimensionAmbient; dim++)
170 myCoordinates(index, dim) = vector[dim];
173 ///////////////////////////////////////////////////////////////////////////////
174 // Implementation of inline functions //
176 template <typename Calculus, DGtal::Duality duality>
178 DGtal::operator<<(std::ostream & out, const DGtal::VectorField<Calculus, duality>& object)
180 object.selfDisplay(out);
184 template <typename Calculus, DGtal::Duality duality>
185 DGtal::VectorField<Calculus, duality>
186 DGtal::operator+(const DGtal::VectorField<Calculus, duality>& _vector_field_a, const DGtal::VectorField<Calculus, duality>& _vector_field_b)
188 ASSERT( _vector_field_a.myCalculus == _vector_field_b.myCalculus );
189 return DGtal::VectorField<Calculus, duality>(*_vector_field_a.myCalculus, _vector_field_a.myCoordinates + _vector_field_b.myCoordinates);
192 template <typename Calculus, DGtal::Duality duality>
193 DGtal::VectorField<Calculus, duality>
194 DGtal::operator-(const DGtal::VectorField<Calculus, duality>& _vector_field_a, const DGtal::VectorField<Calculus, duality>& _vector_field_b)
196 ASSERT( _vector_field_a.myCalculus == _vector_field_b.myCalculus );
197 return DGtal::VectorField<Calculus, duality>(*_vector_field_a.myCalculus, _vector_field_a.myCoordinates - _vector_field_b.myCoordinates);
200 template <typename Calculus, DGtal::Duality duality>
201 DGtal::VectorField<Calculus, duality>
202 DGtal::operator*(const typename Calculus::Scalar& _scalar, const DGtal::VectorField<Calculus, duality>& _vector_field)
204 return DGtal::VectorField<Calculus, duality>(*_vector_field.myCalculus, _scalar * _vector_field.myCoordinates);
207 template <typename Calculus, DGtal::Duality duality>
208 DGtal::VectorField<Calculus, duality>
209 DGtal::operator-(const DGtal::VectorField<Calculus, duality>& _vector_field)
211 return DGtal::VectorField<Calculus, duality>(*_vector_field.myCalculus, -_vector_field.myCoordinates);
215 ///////////////////////////////////////////////////////////////////////////////