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 ParallelStrip.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
24 * Implementation of inline methods defined in ParallelStrip.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
33//////////////////////////////////////////////////////////////////////////////
35///////////////////////////////////////////////////////////////////////////////
36// IMPLEMENTATION of inline methods.
37///////////////////////////////////////////////////////////////////////////////
39///////////////////////////////////////////////////////////////////////////////
40// ----------------------- Standard services ------------------------------
42//-----------------------------------------------------------------------------
43template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
45DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::~ParallelStrip()
47//-----------------------------------------------------------------------------
48template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
50DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::ParallelStrip()
52//-----------------------------------------------------------------------------
53template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
55DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::ParallelStrip
56( Scalar aMu, const RealVector & N, Scalar aNu )
57 : myMu( aMu ), myN( N ), myNu( aNu )
59 Scalar l = myN.norm();
66//-----------------------------------------------------------------------------
67template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
69DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::ParallelStrip
70( const ParallelStrip& other )
71 : myMu( other.myMu ), myN( other.myN ), myNu( other.myNu )
73 ASSERT( myNu != NumberTraits<Scalar>::ZERO );
74 ASSERT( myN.norm1() != NumberTraits<Scalar>::ZERO );
76//-----------------------------------------------------------------------------
77template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
79DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>&
80DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::operator=( const ParallelStrip & other )
90//-----------------------------------------------------------------------------
91template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
93typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
94DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mu() const
98//-----------------------------------------------------------------------------
99template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
101const typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::RealVector&
102DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::normal() const
106//-----------------------------------------------------------------------------
107template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
109typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
110DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::nu() const
114//-----------------------------------------------------------------------------
115template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
117typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
118DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::width() const
122//-----------------------------------------------------------------------------
123template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
126DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mainAxis() const
129 for ( Dimension k = 1; k < Space::dimension; ++k )
130 if ( std::abs( myN[ k ] ) > std::abs( myN[ i ] ) )
134//-----------------------------------------------------------------------------
135template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
137typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
138DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::axisWidth() const
140 Dimension i = mainAxis();
141 return std::abs( nu() / myN[ i ] );
143//-----------------------------------------------------------------------------
144template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
147DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mainDiagonal() const
151 for ( Dimension k = 0; k < Space::dimension; ++k )
153 if ( myN[ k ] < NumberTraits<Scalar>::ZERO )
159//-----------------------------------------------------------------------------
160template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
162typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
163DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::diagonalWidth() const
165 return nu() * sqrt( Space::dimension ) / myN.norm1();
167//-----------------------------------------------------------------------------
168template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
171DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::getBounds( Scalar & aMu, Scalar & mu_plus_nu ) const
174 mu_plus_nu = myMu + myNu;
176//-----------------------------------------------------------------------------
177template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
180DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::operator()( const Point & p ) const
182 Scalar s = NumberTraits<Scalar>::ZERO;
183 for ( Dimension i = 0; i < Space::dimension; ++i )
184 s += myN[ i ] * NumberTraits<typename Point::Coordinate>::castToDouble( p[ i ] );
185 return ( muIncluded ? ( mu() <= s ) : ( mu() < s ) )
186 && ( muPlusNuIncluded ? ( s <= mu() + nu() ) : ( s < mu() + nu() ) );
188//-----------------------------------------------------------------------------
189template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
192DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::operator()( const RealPoint & p ) const
194 Scalar s = myN.dot( p );
195 return ( muIncluded ? ( mu() <= s ) : ( mu() < s ) )
196 && ( muPlusNuIncluded ? ( s <= mu() + nu() ) : ( s < mu() + nu() ) );
201///////////////////////////////////////////////////////////////////////////////
202// Interface - public :
205 * Writes/Displays the object on an output stream.
206 * @param out the output stream where the object is written.
208template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
211DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::selfDisplay ( std::ostream & out ) const
213 out << "[ParallelStrip " << mu()
214 << ( muIncluded ? " <= " : " < " )
216 for ( Dimension i = 1; i < Space::dimension; ++i )
217 out << ", " << myN[ i ];
219 << ( muPlusNuIncluded ? " <= " : " < " )
220 << (mu()+nu()) << "]";
224 * Checks the validity/consistency of the object.
225 * @return 'true' if the object is valid, 'false' otherwise.
227template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
230DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::isValid() const
232 return ( nu() >= NumberTraits<Scalar>::ZERO )
233 && ( normal().norm1() > NumberTraits<Scalar>::ZERO );
238///////////////////////////////////////////////////////////////////////////////
239// Implementation of inline functions //
241template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
244DGtal::operator<< ( std::ostream & out,
245 const ParallelStrip<TSpace, muIncluded, muPlusNuIncluded> & object )
247 object.selfDisplay( out );
252///////////////////////////////////////////////////////////////////////////////