DGtal 1.4.0
Loading...
Searching...
No Matches
ImplicitFunctionLinearCellEmbedder.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 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
21 *
22 * @date 2012/02/14
23 *
24 * Implementation of inline methods defined in ImplicitFunctionLinearCellEmbedder.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 TImplicitFunction, typename TEmbedder >
43inline
44DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
45~ImplicitFunctionLinearCellEmbedder()
46{}
47//-----------------------------------------------------------------------------
48template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
49inline
50DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
51ImplicitFunctionLinearCellEmbedder()
52 : myPtrK( 0 ), myPtrFct( 0 ), myPtrEmbedder( 0 )
53{}
54//-----------------------------------------------------------------------------
55template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
56inline
57DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
58ImplicitFunctionLinearCellEmbedder( const ImplicitFunctionLinearCellEmbedder & other )
59 : myPtrK( other.myPtrK ),
60 myPtrFct( other.myPtrFct ),
61 myPtrEmbedder( other.myPtrEmbedder )
62{}
63//-----------------------------------------------------------------------------
64template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
65inline
66DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder> &
67DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
68operator=( const ImplicitFunctionLinearCellEmbedder & 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 TImplicitFunction, typename TEmbedder >
80inline
81void
82DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
83init( ConstAlias<KSpace> K, ConstAlias<ImplicitFunction> f, ConstAlias<Embedder> e )
84{
85 myPtrK = &K;
86 myPtrFct = &f;
87 myPtrEmbedder = &e;
88}
89//-----------------------------------------------------------------------------
90template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
91inline
92typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
93DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
94embed( const Point & p ) const
95{
96 ASSERT( myPtrEmbedder != 0 );
97 return myPtrEmbedder->embed( p );
98}
99//-----------------------------------------------------------------------------
100template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
101inline
102typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
103DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
104embedCell( const Cell & cell ) const
105{
106 return this->operator()( cell );
107}
108//-----------------------------------------------------------------------------
109template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
110inline
111typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
112DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
113operator()( const Cell & cell ) const
114{
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 );
121 qit != 0; ++qit )
122 { // cell is closed along this dimension.
123 // estimate coordinate by interpolation, looking for f(...)=0.
124 Dimension k = *qit;
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 );
129 }
130 return x1;
131}
132//-----------------------------------------------------------------------------
133template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
134inline
135typename DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::RealPoint
136DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
137embedSCell( const SCell & scell ) const
138{
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 );
145 qit != 0; ++qit )
146 { // cell is closed along this dimension.
147 // estimate coordinate by interpolation, looking for f(...)=0.
148 Dimension k = *qit;
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 );
153 }
154 return x1;
155}
156
157
158///////////////////////////////////////////////////////////////////////////////
159// Interface - public :
160
161/**
162 * Writes/Displays the object on an output stream.
163 * @param out the output stream where the object is written.
164 */
165template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
166inline
167void
168DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
169selfDisplay ( std::ostream & out ) const
170{
171 out << "[ImplicitFunctionLinearCellEmbedder]";
172}
173
174/**
175 * Checks the validity/consistency of the object.
176 * @return 'true' if the object is valid, 'false' otherwise.
177 */
178template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
179inline
180bool
181DGtal::ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder>::
182isValid() const
183{
184 return ( myPtrK != 0 ) && ( myPtrFct != 0 ) && ( myPtrEmbedder != 0 );
185}
186
187
188
189///////////////////////////////////////////////////////////////////////////////
190// Implementation of inline functions //
191
192template < typename TKSpace, typename TImplicitFunction, typename TEmbedder >
193inline
194std::ostream&
195DGtal::operator<< ( std::ostream & out,
196 const ImplicitFunctionLinearCellEmbedder<TKSpace, TImplicitFunction, TEmbedder> & object )
197{
198 object.selfDisplay( out );
199 return out;
200}
201
202// //
203///////////////////////////////////////////////////////////////////////////////
204
205