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 //-----------------------------------------------------------------------------
43 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
45 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::~ParallelStrip()
47 //-----------------------------------------------------------------------------
48 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
50 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::ParallelStrip()
52 //-----------------------------------------------------------------------------
53 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
55 DGtal::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 //-----------------------------------------------------------------------------
67 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
69 DGtal::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 //-----------------------------------------------------------------------------
77 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
79 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>&
80 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::operator=( const ParallelStrip & other )
90 //-----------------------------------------------------------------------------
91 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
93 typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
94 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mu() const
98 //-----------------------------------------------------------------------------
99 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
101 const typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::RealVector&
102 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::normal() const
106 //-----------------------------------------------------------------------------
107 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
109 typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
110 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::nu() const
114 //-----------------------------------------------------------------------------
115 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
117 typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
118 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::width() const
122 //-----------------------------------------------------------------------------
123 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
126 DGtal::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 //-----------------------------------------------------------------------------
135 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
137 typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
138 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::axisWidth() const
140 Dimension i = mainAxis();
141 return std::abs( nu() / myN[ i ] );
143 //-----------------------------------------------------------------------------
144 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
147 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mainDiagonal() const
151 for ( Dimension k = 0; k < Space::dimension; ++k )
153 if ( myN[ k ] < NumberTraits<Scalar>::ZERO )
159 //-----------------------------------------------------------------------------
160 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
162 typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
163 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::diagonalWidth() const
165 return nu() * sqrt( Space::dimension ) / myN.norm1();
167 //-----------------------------------------------------------------------------
168 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
171 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::getBounds( Scalar & aMu, Scalar & mu_plus_nu ) const
174 mu_plus_nu = myMu + myNu;
176 //-----------------------------------------------------------------------------
177 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
180 DGtal::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 //-----------------------------------------------------------------------------
189 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
192 DGtal::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.
208 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
211 DGtal::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.
227 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
230 DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::isValid() const
232 return ( nu() >= NumberTraits<Scalar>::ZERO )
233 && ( normal().norm1() > NumberTraits<Scalar>::ZERO );
238 ///////////////////////////////////////////////////////////////////////////////
239 // Implementation of inline functions //
241 template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
244 DGtal::operator<< ( std::ostream & out,
245 const ParallelStrip<TSpace, muIncluded, muPlusNuIncluded> & object )
247 object.selfDisplay( out );
252 ///////////////////////////////////////////////////////////////////////////////