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//-----------------------------------------------------------------------------
42template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
44DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
45~ImplicitFunctionLinearCellEmbedder()
47//-----------------------------------------------------------------------------
48template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
50DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
51ImplicitFunctionLinearCellEmbedder()
52 : myPtrK( 0 ), myPtrFct( 0 ), myPtrEmbedder( 0 )
54//-----------------------------------------------------------------------------
55template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
57DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
58ImplicitFunctionLinearCellEmbedder( const ImplicitFunctionLinearCellEmbedder & other )
59 : myPtrK( other.myPtrK ),
60 myPtrFct( other.myPtrFct ),
61 myPtrEmbedder( other.myPtrEmbedder )
63//-----------------------------------------------------------------------------
64template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
66DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder> &
67DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
68operator=( const ImplicitFunctionLinearCellEmbedder & other )
72 myPtrK = other.myPtrK;
73 myPtrFct = other.myPtrFct;
74 myPtrEmbedder = other.myPtrEmbedder;
78//-----------------------------------------------------------------------------
79template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
82DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
83init( ConstAlias<KSpace> K, ConstAlias<ImplicitFunction> f, ConstAlias<Embedder> e )
89//-----------------------------------------------------------------------------
90template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
92typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
93DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
94embed( const Point & p ) const
96 ASSERT( myPtrEmbedder != 0 );
97 return myPtrEmbedder->embed( p );
99//-----------------------------------------------------------------------------
100template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
102typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
103DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
104embedCell( const Cell & cell ) const
106 return this->operator()( cell );
108//-----------------------------------------------------------------------------
109template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
111typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
112DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
113operator()( 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//-----------------------------------------------------------------------------
133template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
135typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
136DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
137embedSCell( 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.
165template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
168DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
169selfDisplay ( 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.
178template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
181DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
184 return ( myPtrK != 0 ) && ( myPtrFct != 0 ) && ( myPtrEmbedder != 0 );
189///////////////////////////////////////////////////////////////////////////////
190// Implementation of inline functions //
192template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
195DGtal::operator<< ( std::ostream & out,
196 const ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder> & object )
198 object.selfDisplay( out );
203///////////////////////////////////////////////////////////////////////////////