DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImplicitFunctionLinearCellEmbedder.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
41 //-----------------------------------------------------------------------------
42 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
43 inline
46 {}
47 //-----------------------------------------------------------------------------
48 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
49 inline
52  : myPtrK( 0 ), myPtrFct( 0 ), myPtrEmbedder( 0 )
53 {}
54 //-----------------------------------------------------------------------------
55 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
56 inline
59  : myPtrK( other.myPtrK ),
60  myPtrFct( other.myPtrFct ),
61  myPtrEmbedder( other.myPtrEmbedder )
62 {}
63 //-----------------------------------------------------------------------------
64 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
65 inline
69 {
70  if ( this != &other )
71  {
72  myPtrK = other.myPtrK;
73  myPtrFct = other.myPtrFct;
74  myPtrEmbedder = other.myPtrEmbedder;
75  }
76  return *this;
77 }
78 //-----------------------------------------------------------------------------
79 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
80 inline
81 void
83 init( const KSpace & K, const ImplicitFunction & f, const Embedder & e )
84 {
85  myPtrK = &K;
86  myPtrFct = &f;
87  myPtrEmbedder = &e;
88 }
89 //-----------------------------------------------------------------------------
90 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
91 inline
94 embed( const Point & p ) const
95 {
96  ASSERT( myPtrEmbedder != 0 );
97  return myPtrEmbedder->embed( p );
98 }
99 //-----------------------------------------------------------------------------
100 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
101 inline
104 embedCell( const Cell & cell ) const
105 {
106  return this->operator()( cell );
107 }
108 //-----------------------------------------------------------------------------
109 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
110 inline
113 operator()( const Cell & cell ) const
114 {
115  ASSERT( this->isValid() );
116  // embed first the spel related to the cell.
117  Point p1( myPtrK->uCoords( cell ) );
118  RealPoint x1( embed( p1 ) );
119  ImplicitFctValue y1 = (*myPtrFct)( x1 );
120  for ( typename KSpace::DirIterator qit = myPtrK->uOrthDirs( cell );
121  qit != 0; ++qit )
122  { // cell is closed along this dimension.
123  // estimate coordinate by interpolation, looking for f(...)=0.
124  Dimension k = *qit;
125  Point p2( p1 ); --p2[ k ];
126  RealPoint x2( embed( p2 ) );
127  ImplicitFctValue y2 = (*myPtrFct)( x2 );
128  x1[ k ] -= y1 * ( x2[ k ] - x1[ k ] ) / ( y2 - y1 );
129  }
130  return x1;
131 }
132 //-----------------------------------------------------------------------------
133 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
134 inline
137 embedSCell( const SCell & scell ) const
138 {
139  ASSERT( this->isValid() );
140  // embed first the spel related to the cell.
141  Point p1( myPtrK->sCoords( scell ) );
142  RealPoint x1( embed( p1 ) );
143  ImplicitFctValue y1 = (*myPtrFct)( x1 );
144  for ( typename KSpace::DirIterator qit = myPtrK->sOrthDirs( scell );
145  qit != 0; ++qit )
146  { // cell is closed along this dimension.
147  // estimate coordinate by interpolation, looking for f(...)=0.
148  Dimension k = *qit;
149  Point p2( p1 ); --p2[ k ];
150  RealPoint x2( embed( p2 ) );
151  ImplicitFctValue y2 = (*myPtrFct)( x2 );
152  x1[ k ] -= y1 * ( x2[ k ] - x1[ k ] ) / ( y2 - y1 );
153  }
154  return x1;
155 }
156 
157 
159 // Interface - public :
160 
165 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
166 inline
167 void
169 selfDisplay ( std::ostream & out ) const
170 {
171  out << "[ImplicitFunctionLinearCellEmbedder]";
172 }
173 
178 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
179 inline
180 bool
182 isValid() const
183 {
184  return ( myPtrK != 0 ) && ( myPtrFct != 0 ) && ( myPtrEmbedder != 0 );
185 }
186 
187 
188 
190 // Implementation of inline functions //
191 
192 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
193 inline
194 std::ostream&
195 DGtal::operator<< ( std::ostream & out,
197 {
198  object.selfDisplay( out );
199  return out;
200 }
201 
202 // //
204 
205