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//-----------------------------------------------------------------------------
45template < typename TKSpace, typename TImage, typename TEmbedder >
47DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
48~ImageLinearCellEmbedder()
50//-----------------------------------------------------------------------------
51template < typename TKSpace, typename TImage, typename TEmbedder >
53DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
54ImageLinearCellEmbedder()
55 : myPtrK( 0 ), myPtrImage( 0 ), myPtrEmbedder( 0 )
57//-----------------------------------------------------------------------------
58template < typename TKSpace, typename TImage, typename TEmbedder >
60DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
61ImageLinearCellEmbedder( const ImageLinearCellEmbedder & other )
62 : myPtrK( other.myPtrK ),
63 myPtrImage( other.myPtrImage ),
64 myPtrEmbedder( other.myPtrEmbedder ),
65 myIsoValue( other.myIsoValue )
67//-----------------------------------------------------------------------------
68template < typename TKSpace, typename TImage, typename TEmbedder >
70DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder> &
71DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
72operator=( const ImageLinearCellEmbedder & other )
76 myPtrK = other.myPtrK;
77 myPtrImage = other.myPtrImage;
78 myPtrEmbedder = other.myPtrEmbedder;
79 myIsoValue = other.myIsoValue;
83//-----------------------------------------------------------------------------
84template < typename TKSpace, typename TImage, typename TEmbedder >
87DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
88init( ConstAlias<KSpace> K, ConstAlias<Image> f, ConstAlias<Embedder> e,
94 myIsoValue = iso_value;
96//-----------------------------------------------------------------------------
97template < typename TKSpace, typename TImage, typename TEmbedder >
99typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
100DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
101embed( const Point & p ) const
103 ASSERT( myPtrEmbedder != 0 );
104 return myPtrEmbedder->embed( p );
106//-----------------------------------------------------------------------------
107template < typename TKSpace, typename TImage, typename TEmbedder >
109typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
110DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
111embedCell( const Cell & cell ) const
113 return this->operator()( cell );
115//-----------------------------------------------------------------------------
116template < typename TKSpace, typename TImage, typename TEmbedder >
118typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
119DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
120operator()( 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//-----------------------------------------------------------------------------
142template < typename TKSpace, typename TImage, typename TEmbedder >
144typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
145DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
146embedSCell( 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.
176template < typename TKSpace, typename TImage, typename TEmbedder >
179DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
180selfDisplay ( 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.
189template < typename TKSpace, typename TImage, typename TEmbedder >
192DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
195 return ( myPtrK != 0 ) && ( myPtrImage != 0 ) && ( myPtrEmbedder != 0 );
200///////////////////////////////////////////////////////////////////////////////
201// Implementation of inline functions //
203template < typename TKSpace, typename TImage, typename TEmbedder >
206DGtal::operator<< ( std::ostream & out,
207 const ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder> & object )
209 object.selfDisplay( out );
214///////////////////////////////////////////////////////////////////////////////