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 ------------------------------
36template <typename Calculus, DGtal::Duality duality>
37DGtal::VectorField<Calculus, duality>::VectorField(ConstAlias<Calculus> _calculus)
38 : myCoordinates((&_calculus)->kFormLength(0, duality), DGtal::Dimension(Calculus::dimensionAmbient)), myCalculus(&_calculus)
43template <typename Calculus, DGtal::Duality duality>
44DGtal::VectorField<Calculus, duality>::VectorField(ConstAlias<Calculus> _calculus, const Coordinates& _coordinates)
45 : myCoordinates(_coordinates), myCalculus(&_calculus)
49template <typename Calculus, DGtal::Duality duality>
50DGtal::VectorField<Calculus, duality>&
51DGtal::VectorField<Calculus, duality>::operator=(const VectorField& _vector_field)
53 myCoordinates = _vector_field.myCoordinates;
54 myCalculus = _vector_field.myCalculus;
58///////////////////////////////////////////////////////////////////////////////
59// Interface - public :
61template <typename Calculus, DGtal::Duality duality>
63DGtal::VectorField<Calculus, duality>::selfDisplay(std::ostream& out) const
65 out << "[" << duality << " vector field (" << myCoordinates.rows() << "x" << myCoordinates.cols() << ")]";
68template <typename Calculus, DGtal::Duality duality>
70DGtal::VectorField<Calculus, duality>::className() const
75template <typename Calculus, DGtal::Duality duality>
77DGtal::VectorField<Calculus, duality>::clear()
79 myCoordinates.clear();
82template <typename Calculus, DGtal::Duality duality>
84DGtal::VectorField<Calculus, duality>::isValid() const
86 return myCalculus != NULL;
89template <typename Calculus, DGtal::Duality duality>
90DGtal::VectorField<Calculus, duality>
91DGtal::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;
109template <typename Calculus, DGtal::Duality duality>
110DGtal::KForm<Calculus, 0, duality>
111DGtal::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);
126template <typename Calculus, DGtal::Duality duality>
127DGtal::KForm<Calculus, 0, duality>
128DGtal::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() );
139template <typename Calculus, DGtal::Duality duality>
140typename DGtal::VectorField<Calculus, duality>::SCell
141DGtal::VectorField<Calculus, duality>::getSCell(const Index& index) const
143 return myCalculus->getSCell(0, duality, index);
146template <typename Calculus, DGtal::Duality duality>
147typename DGtal::VectorField<Calculus, duality>::Index
148DGtal::VectorField<Calculus, duality>::length() const
150 return myCalculus->kFormLength(0, duality);
153template <typename Calculus, DGtal::Duality duality>
154typename DGtal::VectorField<Calculus, duality>::Vector
155DGtal::VectorField<Calculus, duality>::getVector(const Index& index) const
159 for (DGtal::Dimension dim=0; dim<Calculus::dimensionAmbient; dim++)
160 vector[dim] = myCoordinates(index, dim);
165template <typename Calculus, DGtal::Duality duality>
167DGtal::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 //
176template <typename Calculus, DGtal::Duality duality>
178DGtal::operator<<(std::ostream & out, const DGtal::VectorField<Calculus, duality>& object)
180 object.selfDisplay(out);
184template <typename Calculus, DGtal::Duality duality>
185DGtal::VectorField<Calculus, duality>
186DGtal::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);
192template <typename Calculus, DGtal::Duality duality>
193DGtal::VectorField<Calculus, duality>
194DGtal::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);
200template <typename Calculus, DGtal::Duality duality>
201DGtal::VectorField<Calculus, duality>
202DGtal::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);
207template <typename Calculus, DGtal::Duality duality>
208DGtal::VectorField<Calculus, duality>
209DGtal::operator-(const DGtal::VectorField<Calculus, duality>& _vector_field)
211 return DGtal::VectorField<Calculus, duality>(*_vector_field.myCalculus, -_vector_field.myCoordinates);
215///////////////////////////////////////////////////////////////////////////////