DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RegularPointEmbedder.ih
1 
30 
31 #include <cstdlib>
32 #include <cmath>
33 #include "DGtal/kernel/NumberTraits.h"
35 
37 // IMPLEMENTATION of inline methods.
39 
41 // ----------------------- Standard services ------------------------------
42 
43 //-----------------------------------------------------------------------------
44 template <typename TSpace>
45 inline
47 {
48 }
49 //-----------------------------------------------------------------------------
50 template <typename TSpace>
51 inline
53 {}
54 //-----------------------------------------------------------------------------
55 template <typename TSpace>
56 inline
60 {
61  if ( this != &other )
62  {
63  myGridSteps = other.myGridSteps;
64  }
65  return *this;
66 }
67 //-----------------------------------------------------------------------------
68 template <typename TSpace>
69 inline
70 void
72 ::init( typename RealVector::Component gridStep )
73 {
74  myGridSteps = RealVector::diagonal( gridStep );
75 }
76 //-----------------------------------------------------------------------------
77 template <typename TSpace>
78 inline
79 void
81 ::init( const RealVector & aGridSteps )
82 {
83  myGridSteps = aGridSteps;
84 }
85 //-----------------------------------------------------------------------------
86 template <typename TSpace>
87 inline
90 ::floor( const RealPoint & p ) const
91 {
92  Point aPoint;
93  for ( Dimension i = 0; i < Space::dimension; ++i )
94  aPoint[ i ] = (Integer) ::floor( p[ i ] / myGridSteps[ i ] );
95  return aPoint;
96 }
97 //-----------------------------------------------------------------------------
98 template <typename TSpace>
99 inline
102 ::ceil( const RealPoint & p ) const
103 {
104  Point aPoint;
105  for ( Dimension i = 0; i < Space::dimension; ++i )
106  aPoint[ i ] = (Integer) ::ceil( p[ i ] / myGridSteps[ i ] );
107  return aPoint;
108 }
109 //-----------------------------------------------------------------------------
110 template <typename TSpace>
111 inline
114 ::round( const RealPoint & p ) const
115 {
116  Point aPoint;
117  for ( Dimension i = 0; i < Space::dimension; ++i )
118  aPoint[ i ] = (Integer) ::round( p[ i ] / myGridSteps[ i ] );
119  return aPoint;
120 }
121 //-----------------------------------------------------------------------------
122 template <typename TSpace>
123 inline
126 ::embed( const Point & p ) const
127 {
128  return this->operator()( p );
129 }
130 //-----------------------------------------------------------------------------
131 template <typename TSpace>
132 inline
135 ::operator()( const Point & p ) const
136 {
137  RealPoint aRealPoint;
138  for ( Dimension i = 0; i < Space::dimension; ++i )
139  aRealPoint[ i ] = NumberTraits<Integer>::castToDouble( p[ i ] )
140  * myGridSteps[ i ];
141  return aRealPoint;
142 }
143 //-----------------------------------------------------------------------------
144 template <typename TSpace>
145 inline
148 ::gridSteps() const
149 {
150  return myGridSteps;
151 }
152 
153 
155 // Interface - public :
156 
161 template <typename TSpace>
162 inline
163 void
165 {
166  out << "[RegularPointEmbedder]";
167 }
168 
173 template <typename TSpace>
174 inline
175 bool
177 {
178  return true;
179 }
180 
181 
182 
184 // Implementation of inline functions //
185 
186 template <typename TSpace>
187 inline
188 std::ostream&
189 DGtal::operator<< ( std::ostream & out,
190  const RegularPointEmbedder<TSpace> & object )
191 {
192  object.selfDisplay( out );
193  return out;
194 }
195 
196 // //
198 
199