DGtal 1.3.0
Loading...
Searching...
No Matches
ParallelStrip.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 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
21 *
22 * @date 2013/09/26
23 *
24 * Implementation of inline methods defined in ParallelStrip.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32#include <cmath>
33//////////////////////////////////////////////////////////////////////////////
34
35///////////////////////////////////////////////////////////////////////////////
36// IMPLEMENTATION of inline methods.
37///////////////////////////////////////////////////////////////////////////////
38
39///////////////////////////////////////////////////////////////////////////////
40// ----------------------- Standard services ------------------------------
41
42//-----------------------------------------------------------------------------
43template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
44inline
45DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::~ParallelStrip()
46{}
47//-----------------------------------------------------------------------------
48template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
49inline
50DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::ParallelStrip()
51{}
52//-----------------------------------------------------------------------------
53template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
54inline
55DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::ParallelStrip
56( Scalar aMu, const RealVector & N, Scalar aNu )
57 : myMu( aMu ), myN( N ), myNu( aNu )
58{
59 Scalar l = myN.norm();
60 if ( l != 1.0 ) {
61 myMu /= l;
62 myN /= l;
63 myNu /= l;
64 }
65}
66//-----------------------------------------------------------------------------
67template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
68inline
69DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::ParallelStrip
70( const ParallelStrip& other )
71 : myMu( other.myMu ), myN( other.myN ), myNu( other.myNu )
72{
73 ASSERT( myNu != NumberTraits<Scalar>::ZERO );
74 ASSERT( myN.norm1() != NumberTraits<Scalar>::ZERO );
75}
76//-----------------------------------------------------------------------------
77template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
78inline
79DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>&
80DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::operator=( const ParallelStrip & other )
81{
82 if ( this != &other )
83 {
84 myMu = other.myMu;
85 myN = other.myN;
86 myNu = other.myNu;
87 }
88 return *this;
89}
90//-----------------------------------------------------------------------------
91template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
92inline
93typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
94DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mu() const
95{
96 return myMu;
97}
98//-----------------------------------------------------------------------------
99template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
100inline
101const typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::RealVector&
102DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::normal() const
103{
104 return myN;
105}
106//-----------------------------------------------------------------------------
107template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
108inline
109typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
110DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::nu() const
111{
112 return myNu;
113}
114//-----------------------------------------------------------------------------
115template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
116inline
117typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
118DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::width() const
119{
120 return nu();
121}
122//-----------------------------------------------------------------------------
123template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
124inline
125DGtal::Dimension
126DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mainAxis() const
127{
128 Dimension i = 0;
129 for ( Dimension k = 1; k < Space::dimension; ++k )
130 if ( std::abs( myN[ k ] ) > std::abs( myN[ i ] ) )
131 i = k;
132 return i;
133}
134//-----------------------------------------------------------------------------
135template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
136inline
137typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
138DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::axisWidth() const
139{
140 Dimension i = mainAxis();
141 return std::abs( nu() / myN[ i ] );
142}
143//-----------------------------------------------------------------------------
144template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
145inline
146DGtal::Dimension
147DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::mainDiagonal() const
148{
149 Dimension d = 0;
150 Dimension i = 1;
151 for ( Dimension k = 0; k < Space::dimension; ++k )
152 {
153 if ( myN[ k ] < NumberTraits<Scalar>::ZERO )
154 d += i;
155 i <<= 1;
156 }
157 return d;
158}
159//-----------------------------------------------------------------------------
160template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
161inline
162typename DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::Scalar
163DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::diagonalWidth() const
164{
165 return nu() * sqrt( Space::dimension ) / myN.norm1();
166}
167//-----------------------------------------------------------------------------
168template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
169inline
170void
171DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::getBounds( Scalar & aMu, Scalar & mu_plus_nu ) const
172{
173 aMu = myMu;
174 mu_plus_nu = myMu + myNu;
175}
176//-----------------------------------------------------------------------------
177template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
178inline
179bool
180DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::operator()( const Point & p ) const
181{
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() ) );
187}
188//-----------------------------------------------------------------------------
189template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
190inline
191bool
192DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::operator()( const RealPoint & p ) const
193{
194 Scalar s = myN.dot( p );
195 return ( muIncluded ? ( mu() <= s ) : ( mu() < s ) )
196 && ( muPlusNuIncluded ? ( s <= mu() + nu() ) : ( s < mu() + nu() ) );
197}
198
199
200
201///////////////////////////////////////////////////////////////////////////////
202// Interface - public :
203
204/**
205 * Writes/Displays the object on an output stream.
206 * @param out the output stream where the object is written.
207 */
208template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
209inline
210void
211DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::selfDisplay ( std::ostream & out ) const
212{
213 out << "[ParallelStrip " << mu()
214 << ( muIncluded ? " <= " : " < " )
215 << "( " << myN[ 0 ];
216 for ( Dimension i = 1; i < Space::dimension; ++i )
217 out << ", " << myN[ i ];
218 out << " ).X"
219 << ( muPlusNuIncluded ? " <= " : " < " )
220 << (mu()+nu()) << "]";
221}
222
223/**
224 * Checks the validity/consistency of the object.
225 * @return 'true' if the object is valid, 'false' otherwise.
226 */
227template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
228inline
229bool
230DGtal::ParallelStrip<TSpace, muIncluded, muPlusNuIncluded>::isValid() const
231{
232 return ( nu() >= NumberTraits<Scalar>::ZERO )
233 && ( normal().norm1() > NumberTraits<Scalar>::ZERO );
234}
235
236
237
238///////////////////////////////////////////////////////////////////////////////
239// Implementation of inline functions //
240
241template <typename TSpace, bool muIncluded, bool muPlusNuIncluded>
242inline
243std::ostream&
244DGtal::operator<< ( std::ostream & out,
245 const ParallelStrip<TSpace, muIncluded, muPlusNuIncluded> & object )
246{
247 object.selfDisplay( out );
248 return out;
249}
250
251// //
252///////////////////////////////////////////////////////////////////////////////