DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Lattice.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
44 template <typename TSpace>
45 inline
46 typename TSpace::Dimension
48 {
49  return myN;
50 }
51 
55 template <typename TSpace>
56 inline
57 typename TSpace::Dimension
59 {
60  return myM;
61 }
62 
64 // Interface - public :
65 
70 template <typename TSpace>
71 inline
72 void
73 DGtal::Lattice<TSpace>::selfDisplay ( std::ostream & out ) const
74 {
75  out << "[Lattice n=" << myN << " m=" << myM << "]";
76 }
77 
82 template <typename TSpace>
83 inline
84 bool
86 {
87  return true;
88 }
89 
91 // Standard services - public :
92 
96 template <typename TSpace>
97 inline
99 {
100  if ( myX0 != 0 ) delete[] myX0;
101  if ( myV != 0 ) delete[] myV;
102 }
103 
104 
108 template <typename TSpace>
109 inline
111  : myN( 0 ), myM( 0 ), myX0( 0 ), myV( 0 )
112 {
113 }
114 
119 template <typename TSpace>
121  : myN( other.myN ), myM( other.myM ), myX0( 0 ), myV( 0 )
122 {
123  if ( ( myN == 0 ) || ( myM == 0 ) ) return;
124  myX0 = new double[ myM ];
125  myV = new double[ myM * myN ];
126  for ( Dimension j = 0; j < myM; j++ )
127  myX0[ j ] = other.myX0[ j ];
128  for ( Dimension i = 0; i < myN; i++ )
129  {
130  for ( Dimension j = 0; j < myM; j++ )
131  myV[ m*i + j ] = other.myV[ m*i + j ];
132  }
133 }
134 
140 template <typename TSpace>
141 inline
144 {
145  if ( this != &other )
146  {
147  if ( ( other.myM != myM ) || ( other.myN != myN ) )
148  {
149  if ( myX0 != 0 ) delete[] myX0;
150  if ( myV != 0 ) delete[] myV;
151  myN = other.myN;
152  myM = other.myM;
153  if ( ( myN == 0 ) || ( myM == 0 ) )
154  {
155  myX0 =0;
156  myV = 0;
157  }
158  else
159  {
160  myX0 = new double[ myM ];
161  myV = new double[ myM * myN ];
162  }
163  }
164  for ( Dimension j = 0; j < myM; j++ )
165  myX0[ j ] = other.myX0[ j ];
166  for ( Dimension i = 0; i < myN; i++ )
167  {
168  for ( Dimension j = 0; j < myM; j++ )
169  myV[ m*i + j ] = other.myV[ m*i + j ];
170  }
171  }
172  return *this;
173 }
174 
183 template <typename TSpace>
184 inline
185 void
187 {
188  ASSERT( aN > 0 );
189  ASSERT( aM > 0 );
190  if ( ( aM != myM ) || ( aN != myN ) )
191  {
192  myN = aN;
193  myM = aM;
194  if ( myX0 != 0 ) delete[] myX0;
195  if ( myV != 0 ) delete[] myV;
196  myX0 = new double[ aM ];
197  myV = new double[ aM*aN ];
198  }
199  for ( Dimension j = 0; j < aM; j++ )
200  myX0[ j ] = 0.0;
201  for ( Dimension i = 0; i < aN; i++ )
202  {
203  for ( Dimension j = 0; j < aM; j++ )
204  myV[ aM*i + j ] = ( j == ( i % aM ) ) ? dh : 0.0;
205  }
206 }
207 
208 template <typename TSpace>
209 inline
210 void
212 {
213  if ( myX0 != 0 ) delete[] myX0;
214  if ( myV != 0 ) delete[] myV;
215  myX0 = 0;
216  myV = 0;
217  myN = 0;
218  myM = 0;
219 }
220 
225 template <typename TSpace>
226 inline
227 void
229 {
230  for ( Dimension j = 0; j < myM; j++ )
231  myX0[ j ] = x[ j ];
232 }
233 
234 
240 template <typename TSpace>
241 inline
242 void
244 {
245  double* off_v = myV + myM*i;
246  for ( Dimension j = 0; j < myM; j++ )
247  off_v[ j ] = v[ j ];
248 }
249 
250 
257 template <typename TSpace>
258 inline
259 void
260 DGtal::Lattice<TSpace>::immerse( const Integer* p, double* x ) const
261 {
262  for ( Dimension j = 0; j < myM; j++ )
263  x[ j ] = myX0[ j ];
264 
265  double* off_v = myV;
266  for ( Dimension i = 0; i < myN; i++ )
267  {
268  Integer pi = p[ i ];
269  for ( Dimension j = 0; j < myM; j++ )
270  {
271  x[ j ] += (*off_v) * pi;
272  ++off_v;
273  }
274  }
275 }
276 
283 template <typename TSpace>
284 inline
285 void
286 DGtal::Lattice<TSpace>::immerse( const Point & p, double* x ) const
287 {
288  for ( Dimension j = 0; j < myM; j++ )
289  x[ j ] = myX0[ j ];
290 
291  double* off_v = myV;
292  for ( Dimension i = 0; i < myN; i++ )
293  {
294  Integer pi = p[ i ];
295  for ( Dimension j = 0; j < myM; j++ )
296  {
297  x[ j ] += (*off_v) * pi;
298  ++off_v;
299  }
300  }
301 }
302 
309 template <typename TSpace>
310 inline
311 void
312 DGtal::Lattice<TSpace>::immerse( const Integer* p, float* x ) const
313 {
314  for ( Dimension j = 0; j < myM; j++ )
315  x[ j ] = (float) myX0[ j ];
316 
317  double* off_v = myV;
318  for ( Dimension i = 0; i < myN; i++ )
319  {
320  Integer pi = p[ i ];
321  for ( Dimension j = 0; j < myM; j++ )
322  {
323  x[ j ] += (float) ((*off_v) * pi);
324  ++off_v;
325  }
326  }
327 }
328 
335 template <typename TSpace>
336 inline
337 void
338 DGtal::Lattice<TSpace>::immerse( const Point & p, float* x ) const
339 {
340  for ( Dimension j = 0; j < myM; j++ )
341  x[ j ] = (float) myX0[ j ];
342 
343  double* off_v = myV;
344  for ( Dimension i = 0; i < myN; i++ )
345  {
346  Integer pi = p[ i ];
347  for ( Dimension j = 0; j < myM; j++ )
348  {
349  x[ j ] += (float) ((*off_v) * pi);
350  ++off_v;
351  }
352  }
353 }
354 
355 
357 // Implementation of inline functions //
358 
359 template <typename TSpace>
360 inline
361 std::ostream&
362 DGtal::operator<< ( std::ostream & out,
363  const Lattice<TSpace> & object )
364 {
365  object.selfDisplay( out );
366  return out;
367 }
368 
369 // //
371 
372