DGtal 1.4.0
Loading...
Searching...
No Matches
ImplicitFunctionDiff1LinearCellEmbedder.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
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
21 *
22 * @date 2012/02/14
23 *
24 * Implementation of inline methods defined in ImplicitFunctionDiff1LinearCellEmbedder.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
40
41//-----------------------------------------------------------------------------
42template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
43inline
44DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
45~ImplicitFunctionDiff1LinearCellEmbedder()
46{}
47//-----------------------------------------------------------------------------
48template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
49inline
50DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
51ImplicitFunctionDiff1LinearCellEmbedder()
52 : myPtrK( 0 ), myPtrFct( 0 ), myPtrEmbedder( 0 )
53{}
54//-----------------------------------------------------------------------------
55template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
56inline
57DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
58ImplicitFunctionDiff1LinearCellEmbedder( const ImplicitFunctionDiff1LinearCellEmbedder & other )
59 : myPtrK( other.myPtrK ),
60 myPtrFct( other.myPtrFct ),
61 myPtrEmbedder( other.myPtrEmbedder )
62{}
63//-----------------------------------------------------------------------------
64template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
65inline
66DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder> &
67DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
68operator=( const ImplicitFunctionDiff1LinearCellEmbedder & other )
69{
70 if ( this != &other )
71 {
72 myPtrK = other.myPtrK;
73 myPtrFct = other.myPtrFct;
74 myPtrEmbedder = other.myPtrEmbedder;
75 }
76 return *this;
77}
78//-----------------------------------------------------------------------------
79template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
80inline
81void
82DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
83init( ConstAlias<KSpace> K, ConstAlias<ImplicitFunctionDiff1> f, ConstAlias<Embedder> e )
84{
85 myPtrK = &K;
86 myPtrFct = &f;
87 myPtrEmbedder = &e;
88}
89//-----------------------------------------------------------------------------
90template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
91inline
92typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::GradientMap
93DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
94gradientMap() const
95{
96 return GradientMap( *this );
97}
98//-----------------------------------------------------------------------------
99template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
100inline
101typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
102DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
103embed( const Point & p ) const
104{
105 ASSERT( myPtrEmbedder != 0 );
106 return myPtrEmbedder->embed( p );
107}
108//-----------------------------------------------------------------------------
109template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
110inline
111typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
112DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
113embedCell( const Cell & cell ) const
114{
115 return this->operator()( cell );
116}
117//-----------------------------------------------------------------------------
118template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
119inline
120typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
121DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
122operator()( const Cell & cell ) const
123{
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 );
130 qit != 0; ++qit )
131 { // cell is closed along this dimension.
132 // estimate coordinate by interpolation, looking for f(...)=0.
133 Dimension k = *qit;
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 );
138 }
139 return x1;
140}
141//-----------------------------------------------------------------------------
142template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
143inline
144typename DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::RealPoint
145DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
146embedSCell( const SCell & scell ) const
147{
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 );
154 qit != 0; ++qit )
155 { // cell is closed along this dimension.
156 // estimate coordinate by interpolation, looking for f(...)=0.
157 Dimension k = *qit;
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 );
162 }
163 return x1;
164}
165//-----------------------------------------------------------------------------
166template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
167inline
168void
169DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
170embed( const Point & p, RealPoint & x, RealVector & grad ) const
171{
172 x = embed( p );
173 grad = myPtrFct->gradient( x );
174}
175//-----------------------------------------------------------------------------
176template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
177inline
178void
179DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
180embedCell( const Cell & cell, RealPoint & x, RealVector & grad ) const
181{
182 x = embedCell( cell );
183 grad = myPtrFct->gradient( x );
184}
185//-----------------------------------------------------------------------------
186template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
187inline
188void
189DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
190embedSCell( const SCell & scell, RealPoint & x, RealVector & grad ) const
191{
192 x = embedSCell( scell );
193 grad = myPtrFct->gradient( x );
194}
195
196
197
198///////////////////////////////////////////////////////////////////////////////
199// Interface - public :
200
201/**
202 * Writes/Displays the object on an output stream.
203 * @param out the output stream where the object is written.
204 */
205template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
206inline
207void
208DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
209selfDisplay ( std::ostream & out ) const
210{
211 out << "[ImplicitFunctionDiff1LinearCellEmbedder]";
212}
213
214/**
215 * Checks the validity/consistency of the object.
216 * @return 'true' if the object is valid, 'false' otherwise.
217 */
218template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
219inline
220bool
221DGtal::ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder>::
222isValid() const
223{
224 return ( myPtrK != 0 ) && ( myPtrFct != 0 ) && ( myPtrEmbedder != 0 );
225}
226
227
228
229///////////////////////////////////////////////////////////////////////////////
230// Implementation of inline functions //
231
232template < typename TKSpace, typename TImplicitFunctionDiff1, typename TEmbedder >
233inline
234std::ostream&
235DGtal::operator<< ( std::ostream & out,
236 const ImplicitFunctionDiff1LinearCellEmbedder<TKSpace, TImplicitFunctionDiff1, TEmbedder> & object )
237{
238 object.selfDisplay( out );
239 return out;
240}
241
242// //
243///////////////////////////////////////////////////////////////////////////////
244
245