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 ImageLinearCellEmbedder.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 ImageLinearCellEmbedder.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
34 #include "DGtal/images/ImageLinearCellEmbedder.h"
37 ///////////////////////////////////////////////////////////////////////////////
38 // IMPLEMENTATION of inline methods.
39 ///////////////////////////////////////////////////////////////////////////////
41 ///////////////////////////////////////////////////////////////////////////////
42 // ----------------------- Standard services ------------------------------
44 //-----------------------------------------------------------------------------
45 template < typename TKSpace, typename TImage, typename TEmbedder >
47 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
48 ~ImageLinearCellEmbedder()
50 //-----------------------------------------------------------------------------
51 template < typename TKSpace, typename TImage, typename TEmbedder >
53 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
54 ImageLinearCellEmbedder()
55 : myPtrK( 0 ), myPtrImage( 0 ), myPtrEmbedder( 0 )
57 //-----------------------------------------------------------------------------
58 template < typename TKSpace, typename TImage, typename TEmbedder >
60 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
61 ImageLinearCellEmbedder( const ImageLinearCellEmbedder & other )
62 : myPtrK( other.myPtrK ),
63 myPtrImage( other.myPtrImage ),
64 myPtrEmbedder( other.myPtrEmbedder ),
65 myIsoValue( other.myIsoValue )
67 //-----------------------------------------------------------------------------
68 template < typename TKSpace, typename TImage, typename TEmbedder >
70 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder> &
71 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
72 operator=( const ImageLinearCellEmbedder & other )
76 myPtrK = other.myPtrK;
77 myPtrImage = other.myPtrImage;
78 myPtrEmbedder = other.myPtrEmbedder;
79 myIsoValue = other.myIsoValue;
83 //-----------------------------------------------------------------------------
84 template < typename TKSpace, typename TImage, typename TEmbedder >
87 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
88 init( ConstAlias<KSpace> K, ConstAlias<Image> f, ConstAlias<Embedder> e,
94 myIsoValue = iso_value;
96 //-----------------------------------------------------------------------------
97 template < typename TKSpace, typename TImage, typename TEmbedder >
99 typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
100 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
101 embed( const Point & p ) const
103 ASSERT( myPtrEmbedder != 0 );
104 return myPtrEmbedder->embed( p );
106 //-----------------------------------------------------------------------------
107 template < typename TKSpace, typename TImage, typename TEmbedder >
109 typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
110 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
111 embedCell( const Cell & cell ) const
113 return this->operator()( cell );
115 //-----------------------------------------------------------------------------
116 template < typename TKSpace, typename TImage, typename TEmbedder >
118 typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
119 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
120 operator()( const Cell & cell ) const
122 ASSERT( this->isValid() );
123 // embed first the spel related to the cell.
124 Point p1( myPtrK->uCoords( cell ) );
125 RealPoint x1( embed( p1 ) );
126 ImageValue y1 = (*myPtrImage)( p1 );
127 double v1 = NumberTraits<ImageValue>::castToDouble( y1 );
128 for ( typename KSpace::DirIterator qit = myPtrK->uOrthDirs( cell );
130 { // cell is closed along this dimension.
131 // estimate coordinate by interpolation, looking for f(...)=0.
133 Point p2( p1 ); --p2[ k ];
134 RealPoint x2( embed( p2 ) );
135 ImageValue y2 = (*myPtrImage)( p2 );
136 double v2 = NumberTraits<ImageValue>::castToDouble( y2 );
137 x1[ k ] -= ( v1 - myIsoValue ) * ( x2[ k ] - x1[ k ] ) / ( v2 - v1 );
141 //-----------------------------------------------------------------------------
142 template < typename TKSpace, typename TImage, typename TEmbedder >
144 typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
145 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
146 embedSCell( 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 ImageValue y1 = (*myPtrImage)( p1 );
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 ImageValue y2 = (*myPtrImage)( p2 );
161 x1[ k ] -= ( NumberTraits<ImageValue>::castToDouble( y1 ) - myIsoValue )
162 * ( x2[ k ] - x1[ k ] )
163 / NumberTraits<ImageValue>::castToDouble( y2 - y1 );
169 ///////////////////////////////////////////////////////////////////////////////
170 // Interface - public :
173 * Writes/Displays the object on an output stream.
174 * @param out the output stream where the object is written.
176 template < typename TKSpace, typename TImage, typename TEmbedder >
179 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
180 selfDisplay ( std::ostream & out ) const
182 out << "[ImageLinearCellEmbedder]";
186 * Checks the validity/consistency of the object.
187 * @return 'true' if the object is valid, 'false' otherwise.
189 template < typename TKSpace, typename TImage, typename TEmbedder >
192 DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
195 return ( myPtrK != 0 ) && ( myPtrImage != 0 ) && ( myPtrEmbedder != 0 );
200 ///////////////////////////////////////////////////////////////////////////////
201 // Implementation of inline functions //
203 template < typename TKSpace, typename TImage, typename TEmbedder >
206 DGtal::operator<< ( std::ostream & out,
207 const ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder> & object )
209 object.selfDisplay( out );
214 ///////////////////////////////////////////////////////////////////////////////