DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageLinearCellEmbedder.ih
1 
30 
31 #include <cstdlib>
32 
33 //self include
34 #include "DGtal/images/ImageLinearCellEmbedder.h"
35 
36 
38 // IMPLEMENTATION of inline methods.
40 
42 // ----------------------- Standard services ------------------------------
43 
44 //-----------------------------------------------------------------------------
45 template < typename TKSpace, typename TImage, typename TEmbedder >
46 inline
49 {}
50 //-----------------------------------------------------------------------------
51 template < typename TKSpace, typename TImage, typename TEmbedder >
52 inline
55  : myPtrK( 0 ), myPtrImage( 0 ), myPtrEmbedder( 0 )
56 {}
57 //-----------------------------------------------------------------------------
58 template < typename TKSpace, typename TImage, typename TEmbedder >
59 inline
62  : myPtrK( other.myPtrK ),
63  myPtrImage( other.myPtrImage ),
64  myPtrEmbedder( other.myPtrEmbedder ),
65  myIsoValue( other.myIsoValue )
66 {}
67 //-----------------------------------------------------------------------------
68 template < typename TKSpace, typename TImage, typename TEmbedder >
69 inline
73 {
74  if ( this != &other )
75  {
76  myPtrK = other.myPtrK;
77  myPtrImage = other.myPtrImage;
78  myPtrEmbedder = other.myPtrEmbedder;
79  myIsoValue = other.myIsoValue;
80  }
81  return *this;
82 }
83 //-----------------------------------------------------------------------------
84 template < typename TKSpace, typename TImage, typename TEmbedder >
85 inline
86 void
88 init( const KSpace & K, const Image & f, const Embedder & e,
89  ImageValue iso_value )
90 {
91  myPtrK = &K;
92  myPtrImage = &f;
93  myPtrEmbedder = &e;
94  myIsoValue = iso_value;
95 }
96 //-----------------------------------------------------------------------------
97 template < typename TKSpace, typename TImage, typename TEmbedder >
98 inline
101 embed( const Point & p ) const
102 {
103  ASSERT( myPtrEmbedder != 0 );
104  return myPtrEmbedder->embed( p );
105 }
106 //-----------------------------------------------------------------------------
107 template < typename TKSpace, typename TImage, typename TEmbedder >
108 inline
111 embedCell( const Cell & cell ) const
112 {
113  return this->operator()( cell );
114 }
115 //-----------------------------------------------------------------------------
116 template < typename TKSpace, typename TImage, typename TEmbedder >
117 inline
120 operator()( const Cell & cell ) const
121 {
122  ASSERT( this->isValid() );
123  // embed first the spel related to the cell.
124  Point p1( myPtrK->uCoords( cell ) );
125  RealPoint x1( embed( p1 ) );
126  ImageValue y1 = (*myPtrImage)( p1 );
127  for ( typename KSpace::DirIterator qit = myPtrK->uOrthDirs( cell );
128  qit != 0; ++qit )
129  { // cell is closed along this dimension.
130  // estimate coordinate by interpolation, looking for f(...)=0.
131  Dimension k = *qit;
132  Point p2( p1 ); --p2[ k ];
133  RealPoint x2( embed( p2 ) );
134  ImageValue y2 = (*myPtrImage)( p2 );
135  x1[ k ] -= NumberTraits<ImageValue>::castToDouble( y1 - myIsoValue )
136  * ( x2[ k ] - x1[ k ] )
138  }
139  return x1;
140 }
141 //-----------------------------------------------------------------------------
142 template < typename TKSpace, typename TImage, typename TEmbedder >
143 inline
146 embedSCell( const SCell & scell ) const
147 {
148  ASSERT( this->isValid() );
149  // embed first the spel related to the cell.
150  Point p1( myPtrK->sCoords( scell ) );
151  RealPoint x1( embed( p1 ) );
152  ImageValue y1 = (*myPtrImage)( p1 );
153  for ( typename KSpace::DirIterator qit = myPtrK->sOrthDirs( scell );
154  qit != 0; ++qit )
155  { // cell is closed along this dimension.
156  // estimate coordinate by interpolation, looking for f(...)=0.
157  Dimension k = *qit;
158  Point p2( p1 ); --p2[ k ];
159  RealPoint x2( embed( p2 ) );
160  ImageValue y2 = (*myPtrImage)( p2 );
161  x1[ k ] -= NumberTraits<ImageValue>::castToDouble( y1 - myIsoValue )
162  * ( x2[ k ] - x1[ k ] )
164  }
165  return x1;
166 }
167 
168 
170 // Interface - public :
171 
176 template < typename TKSpace, typename TImage, typename TEmbedder >
177 inline
178 void
180 selfDisplay ( std::ostream & out ) const
181 {
182  out << "[ImageLinearCellEmbedder]";
183 }
184 
189 template < typename TKSpace, typename TImage, typename TEmbedder >
190 inline
191 bool
193 isValid() const
194 {
195  return ( myPtrK != 0 ) && ( myPtrImage != 0 ) && ( myPtrEmbedder != 0 );
196 }
197 
198 
199 
201 // Implementation of inline functions //
202 
203 template < typename TKSpace, typename TImage, typename TEmbedder >
204 inline
205 std::ostream&
206 DGtal::operator<< ( std::ostream & out,
208 {
209  object.selfDisplay( out );
210  return out;
211 }
212 
213 // //
215 
216