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 ImplicitFunctionLinearCellEmbedder.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 ImplicitFunctionLinearCellEmbedder.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 TImplicitFunction, typename TEmbedder >
44 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
45 ~ImplicitFunctionLinearCellEmbedder()
47 //-----------------------------------------------------------------------------
48 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
50 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
51 ImplicitFunctionLinearCellEmbedder()
52 : myPtrK( 0 ), myPtrFct( 0 ), myPtrEmbedder( 0 )
54 //-----------------------------------------------------------------------------
55 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
57 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
58 ImplicitFunctionLinearCellEmbedder( const ImplicitFunctionLinearCellEmbedder & other )
59 : myPtrK( other.myPtrK ),
60 myPtrFct( other.myPtrFct ),
61 myPtrEmbedder( other.myPtrEmbedder )
63 //-----------------------------------------------------------------------------
64 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
66 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder> &
67 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
68 operator=( const ImplicitFunctionLinearCellEmbedder & other )
72 myPtrK = other.myPtrK;
73 myPtrFct = other.myPtrFct;
74 myPtrEmbedder = other.myPtrEmbedder;
78 //-----------------------------------------------------------------------------
79 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
82 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
83 init( ConstAlias<KSpace> K, ConstAlias<ImplicitFunction> f, ConstAlias<Embedder> e )
89 //-----------------------------------------------------------------------------
90 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
92 typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
93 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
94 embed( const Point & p ) const
96 ASSERT( myPtrEmbedder != 0 );
97 return myPtrEmbedder->embed( p );
99 //-----------------------------------------------------------------------------
100 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
102 typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
103 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
104 embedCell( const Cell & cell ) const
106 return this->operator()( cell );
108 //-----------------------------------------------------------------------------
109 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
111 typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
112 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
113 operator()( const Cell & cell ) const
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 );
122 { // cell is closed along this dimension.
123 // estimate coordinate by interpolation, looking for f(...)=0.
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 );
132 //-----------------------------------------------------------------------------
133 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
135 typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
136 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
137 embedSCell( const SCell & scell ) const
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 );
146 { // cell is closed along this dimension.
147 // estimate coordinate by interpolation, looking for f(...)=0.
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 );
158 ///////////////////////////////////////////////////////////////////////////////
159 // Interface - public :
162 * Writes/Displays the object on an output stream.
163 * @param out the output stream where the object is written.
165 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
168 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
169 selfDisplay ( std::ostream & out ) const
171 out << "[ImplicitFunctionLinearCellEmbedder]";
175 * Checks the validity/consistency of the object.
176 * @return 'true' if the object is valid, 'false' otherwise.
178 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
181 DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
184 return ( myPtrK != 0 ) && ( myPtrFct != 0 ) && ( myPtrEmbedder != 0 );
189 ///////////////////////////////////////////////////////////////////////////////
190 // Implementation of inline functions //
192 template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
195 DGtal::operator<< ( std::ostream & out,
196 const ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder> & object )
198 object.selfDisplay( out );
203 ///////////////////////////////////////////////////////////////////////////////