2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file ImplicitFunctionDiff1LinearCellEmbedder.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
24 * Implementation of inline methods defined in ImplicitFunctionDiff1LinearCellEmbedder.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 //-----------------------------------------------------------------------------
42 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
44 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
45 ~ImplicitFunctionDiff1LinearCellEmbedder()
47 //-----------------------------------------------------------------------------
48 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
50 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
51 ImplicitFunctionDiff1LinearCellEmbedder()
52 : myPtrK( 0 ), myPtrFct( 0 ), myPtrEmbedder( 0 )
54 //-----------------------------------------------------------------------------
55 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
57 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
58 ImplicitFunctionDiff1LinearCellEmbedder( const ImplicitFunctionDiff1LinearCellEmbedder & other )
59 : myPtrK( other.myPtrK ),
60 myPtrFct( other.myPtrFct ),
61 myPtrEmbedder( other.myPtrEmbedder )
63 //-----------------------------------------------------------------------------
64 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
66 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder> &
67 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
68 operator=( const ImplicitFunctionDiff1LinearCellEmbedder & other )
72 myPtrK = other.myPtrK;
73 myPtrFct = other.myPtrFct;
74 myPtrEmbedder = other.myPtrEmbedder;
78 //-----------------------------------------------------------------------------
79 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
82 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
83 init( ConstAlias<KSpace> K, ConstAlias<ImplicitFunctionDiff1> f, ConstAlias<Embedder> e )
89 //-----------------------------------------------------------------------------
90 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
92 typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::GradientMap
93 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
96 return GradientMap( *this );
98 //-----------------------------------------------------------------------------
99 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
101 typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
102 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
103 embed( const Point & p ) const
105 ASSERT( myPtrEmbedder != 0 );
106 return myPtrEmbedder->embed( p );
108 //-----------------------------------------------------------------------------
109 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
111 typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
112 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
113 embedCell( const Cell & cell ) const
115 return this->operator()( cell );
117 //-----------------------------------------------------------------------------
118 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
120 typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
121 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
122 operator()( const Cell & cell ) const
124 ASSERT( this->isValid() );
125 // embed first the spel related to the cell.
126 Point p1( myPtrK->uCoords( cell ) );
127 RealPoint x1( embed( p1 ) );
128 ImplicitFctValue y1 = (*myPtrFct)( x1 );
129 for ( typename KSpace::DirIterator qit = myPtrK->uOrthDirs( cell );
131 { // cell is closed along this dimension.
132 // estimate coordinate by interpolation, looking for f(...)=0.
134 Point p2( p1 ); --p2[ k ];
135 RealPoint x2( embed( p2 ) );
136 ImplicitFctValue y2 = (*myPtrFct)( x2 );
137 x1[ k ] -= y1 * ( x2[ k ] - x1[ k ] ) / ( y2 - y1 );
141 //-----------------------------------------------------------------------------
142 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
144 typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
145 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
146 embedSCell( const SCell & scell ) const
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 ImplicitFctValue y1 = (*myPtrFct)( x1 );
153 for ( typename KSpace::DirIterator qit = myPtrK->sOrthDirs( scell );
155 { // cell is closed along this dimension.
156 // estimate coordinate by interpolation, looking for f(...)=0.
158 Point p2( p1 ); --p2[ k ];
159 RealPoint x2( embed( p2 ) );
160 ImplicitFctValue y2 = (*myPtrFct)( x2 );
161 x1[ k ] -= y1 * ( x2[ k ] - x1[ k ] ) / ( y2 - y1 );
165 //-----------------------------------------------------------------------------
166 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
169 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
170 embed( const Point & p, RealPoint & x, RealVector & grad ) const
173 grad = myPtrFct->gradient( x );
175 //-----------------------------------------------------------------------------
176 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
179 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
180 embedCell( const Cell & cell, RealPoint & x, RealVector & grad ) const
182 x = embedCell( cell );
183 grad = myPtrFct->gradient( x );
185 //-----------------------------------------------------------------------------
186 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
189 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
190 embedSCell( const SCell & scell, RealPoint & x, RealVector & grad ) const
192 x = embedSCell( scell );
193 grad = myPtrFct->gradient( x );
198 ///////////////////////////////////////////////////////////////////////////////
199 // Interface - public :
202 * Writes/Displays the object on an output stream.
203 * @param out the output stream where the object is written.
205 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
208 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
209 selfDisplay ( std::ostream & out ) const
211 out << "[ImplicitFunctionDiff1LinearCellEmbedder]";
215 * Checks the validity/consistency of the object.
216 * @return 'true' if the object is valid, 'false' otherwise.
218 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
221 DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
224 return ( myPtrK != 0 ) && ( myPtrFct != 0 ) && ( myPtrEmbedder != 0 );
229 ///////////////////////////////////////////////////////////////////////////////
230 // Implementation of inline functions //
232 template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
235 DGtal::operator<< ( std::ostream & out,
236 const ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder> & object )
238 object.selfDisplay( out );
243 ///////////////////////////////////////////////////////////////////////////////