DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DGtal/shapes/Shapes.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
44 template <typename TDomain>
45 inline
47 {
48 }
49 
50 
60 template <typename TDomain>
61 template <typename TDigitalSet>
62 inline
63 void
65 ( TDigitalSet & aSet,
66  const Point & aCenter,
67  UnsignedInteger aRadius )
68 {
69  Point v1( aCenter.diagonal( aRadius ) );
70  Point p1( aCenter );
71  Point p2( p1 );
72  p1 -= v1;
73  p2 += v1;
74  const Domain & domain = aSet.domain();
75  typedef DGtal::HyperRectDomain<Space> LocalSpace;
76  LocalSpace ballDomain( p1, p2 );
77  for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
78  it != ballDomain.end();
79  ++it )
80  {
81  if ( domain.isInside( *it )
82  && ( (*it - aCenter ).norm1() <= aRadius ) )
83  aSet.erase( *it );
84  }
85 }
95 template <typename TDomain>
96 template <typename TDigitalSet>
97 inline
98 void
100 ( TDigitalSet & aSet,
101  const Point & aCenter,
102  UnsignedInteger aRadius )
103 {
104  Point v1( aCenter.diagonal( aRadius ) );
105  Point p1( aCenter );
106  Point p2( p1 );
107  p1 -= v1;
108  p2 += v1;
109  const Domain & domain = aSet.domain();
110  typedef DGtal::HyperRectDomain<Space> LocalSpace;
111  LocalSpace ballDomain( p1, p2 );
112  for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
113  it != ballDomain.end();
114  ++it )
115  {
116  if ( domain.isInside( *it )
117  && ( (*it - aCenter ).norm1() <= aRadius ) )
118  aSet.insert( *it );
119  }
120 }
121 
122 
132 template <typename TDomain>
133 template <typename TDigitalSet>
134 inline
135 void
137 ( TDigitalSet & aSet,
138  const Point & aCenter,
139  UnsignedInteger aRadius )
140 {
141  Point v1( aCenter.diagonal( aRadius ) );
142  Point p1( aCenter );
143  Point p2( p1 );
144  p1 -= v1;
145  p2 += v1;
146  const Domain & domain = aSet.domain();
147  typedef DGtal::HyperRectDomain<Space> LocalSpace;
148  LocalSpace ballDomain( p1, p2 );
149  for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
150  it != ballDomain.end();
151  ++it )
152  {
153  if ( domain.isInside( *it )
154  && ( (*it - aCenter ).norm() <= aRadius ) )
155  aSet.erase( *it );
156  }
157 }
158 
159 
169 template <typename TDomain>
170 template <typename TDigitalSet>
171 inline
172 void
174 ( TDigitalSet & aSet,
175  const Point & aCenter,
176  UnsignedInteger aRadius )
177 {
178  Point v1( aCenter.diagonal( aRadius ) );
179  Point p1( aCenter );
180  Point p2( p1 );
181  p1 -= v1;
182  p2 += v1;
183  const Domain & domain = aSet.domain();
184  typedef DGtal::HyperRectDomain<Space> LocalSpace;
185  LocalSpace ballDomain( p1, p2 );
186  for ( typename LocalSpace::ConstIterator it = ballDomain.begin();
187  it != ballDomain.end();
188  ++it )
189  {
190  if ( domain.isInside( *it )
191  && ( (*it - aCenter ).norm() <= aRadius ) )
192  aSet.insert( *it );
193  }
194 }
195 
196 template <typename TDomain>
197 template <typename TDigitalSet, typename ShapeFunctor>
198 void
200  const ShapeFunctor & aFunctor)
201 {
202  typedef DGtal::HyperRectDomain<Space> LocalSpace;
203 
204  BOOST_CONCEPT_ASSERT((CDigitalBoundedShape<ShapeFunctor>));
205  BOOST_CONCEPT_ASSERT((CDigitalOrientedShape<ShapeFunctor>));
206 
207 
208  Point pLow = aFunctor.getLowerBound();
209  Point pUpp = aFunctor.getUpperBound();
210 
211  LocalSpace implicitDomain( pLow, pUpp );
212  for ( typename LocalSpace::ConstIterator it = implicitDomain.begin();
213  it != implicitDomain.end();
214  ++it )
215  {
216  if ( aFunctor.orientation( *it ) == INSIDE)
217  aSet.insert( *it );
218  }
219 }
220 
221 
222 template <typename TDomain>
223 template <typename TDigitalSet, typename ShapeFunctor>
224 void
226  const ShapeFunctor & aFunctor,
227  const double h)
228 {
229 
230  BOOST_CONCEPT_ASSERT((CEuclideanBoundedShape<ShapeFunctor>));
231  BOOST_CONCEPT_ASSERT((CEuclideanOrientedShape<ShapeFunctor>));
232 
233  RealPoint pLow = aFunctor.getLowerBound();
234  RealPoint pUpp = aFunctor.getUpperBound();
236  dig.attach( aFunctor ); // attaches the shape.
237  dig.init( pLow, pUpp, h);
238 
239  // Creates a set from the digitizer.
240  Shapes<Domain>::digitalShaper( aSet, dig );
241 }
242 
243 template <typename TDomain>
244 template <typename DigitalSet, typename PointPredicate>
245 void
247 ( DigitalSet & aSet,
248  const PointPredicate & aPP )
249 {
250 
251  BOOST_CONCEPT_ASSERT(( CDigitalSet< DigitalSet > ));
252  BOOST_CONCEPT_ASSERT(( CPointPredicate< PointPredicate > ));
253  BOOST_STATIC_ASSERT
255  BOOST_STATIC_ASSERT
257 
258  typedef typename Domain::ConstIterator ConstIterator;
259  for ( ConstIterator it = aSet.domain().begin(),
260  it_end = aSet.domain().end(); it != it_end; ++it )
261  if ( aPP( *it ) ) aSet.insert( *it );
262 }
263 
264 
265 
266 
268 // Interface - public :
269 
274 template <typename TDomain>
275 inline
276 void
277 DGtal::Shapes<TDomain>::selfDisplay ( std::ostream & out ) const
278 {
279  out << "[Shapes]";
280 }
281 
286 template <typename TDomain>
287 inline
288 bool
290 {
291  return true;
292 }
293 
294 
295 
297 // Implementation of inline functions //
298 
299 template <typename TDomain>
300 inline
301 std::ostream&
302 DGtal::operator<< ( std::ostream & out,
303  const Shapes<TDomain> & object )
304 {
305  object.selfDisplay( out );
306  return out;
307 }
308 
309 // //
311 
312