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//-----------------------------------------------------------------------------
42template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
44DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
45~ImplicitFunctionDiff1LinearCellEmbedder()
47//-----------------------------------------------------------------------------
48template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
50DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
51ImplicitFunctionDiff1LinearCellEmbedder()
52 : myPtrK( 0 ), myPtrFct( 0 ), myPtrEmbedder( 0 )
54//-----------------------------------------------------------------------------
55template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
57DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
58ImplicitFunctionDiff1LinearCellEmbedder( const ImplicitFunctionDiff1LinearCellEmbedder & other )
59 : myPtrK( other.myPtrK ),
60 myPtrFct( other.myPtrFct ),
61 myPtrEmbedder( other.myPtrEmbedder )
63//-----------------------------------------------------------------------------
64template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
66DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder> &
67DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
68operator=( const ImplicitFunctionDiff1LinearCellEmbedder & other )
72 myPtrK = other.myPtrK;
73 myPtrFct = other.myPtrFct;
74 myPtrEmbedder = other.myPtrEmbedder;
78//-----------------------------------------------------------------------------
79template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
82DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
83init( ConstAlias<KSpace> K, ConstAlias<ImplicitFunctionDiff1> f, ConstAlias<Embedder> e )
89//-----------------------------------------------------------------------------
90template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
92typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::GradientMap
93DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
96 return GradientMap( *this );
98//-----------------------------------------------------------------------------
99template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
101typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
102DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
103embed( const Point & p ) const
105 ASSERT( myPtrEmbedder != 0 );
106 return myPtrEmbedder->embed( p );
108//-----------------------------------------------------------------------------
109template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
111typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
112DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
113embedCell( const Cell & cell ) const
115 return this->operator()( cell );
117//-----------------------------------------------------------------------------
118template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
120typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
121DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
122operator()( 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//-----------------------------------------------------------------------------
142template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
144typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
145DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
146embedSCell( 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//-----------------------------------------------------------------------------
166template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
169DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
170embed( const Point & p, RealPoint & x, RealVector & grad ) const
173 grad = myPtrFct->gradient( x );
175//-----------------------------------------------------------------------------
176template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
179DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
180embedCell( const Cell & cell, RealPoint & x, RealVector & grad ) const
182 x = embedCell( cell );
183 grad = myPtrFct->gradient( x );
185//-----------------------------------------------------------------------------
186template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
189DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
190embedSCell( 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.
205template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
208DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
209selfDisplay ( 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.
218template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
221DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
224 return ( myPtrK != 0 ) && ( myPtrFct != 0 ) && ( myPtrEmbedder != 0 );
229///////////////////////////////////////////////////////////////////////////////
230// Implementation of inline functions //
232template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
235DGtal::operator<< ( std::ostream & out,
236 const ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder> & object )
238 object.selfDisplay( out );
243///////////////////////////////////////////////////////////////////////////////