DGtal 1.3.0
Loading...
Searching...
No Matches
ImageLinearCellEmbedder.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 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
21 *
22 * @date 2012/02/14
23 *
24 * Implementation of inline methods defined in ImageLinearCellEmbedder.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32
33//self include
34#include "DGtal/images/ImageLinearCellEmbedder.h"
35
36
37///////////////////////////////////////////////////////////////////////////////
38// IMPLEMENTATION of inline methods.
39///////////////////////////////////////////////////////////////////////////////
40
41///////////////////////////////////////////////////////////////////////////////
42// ----------------------- Standard services ------------------------------
43
44//-----------------------------------------------------------------------------
45template < typename TKSpace, typename TImage, typename TEmbedder >
46inline
47DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
48~ImageLinearCellEmbedder()
49{}
50//-----------------------------------------------------------------------------
51template < typename TKSpace, typename TImage, typename TEmbedder >
52inline
53DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
54ImageLinearCellEmbedder()
55 : myPtrK( 0 ), myPtrImage( 0 ), myPtrEmbedder( 0 )
56{}
57//-----------------------------------------------------------------------------
58template < typename TKSpace, typename TImage, typename TEmbedder >
59inline
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 )
66{}
67//-----------------------------------------------------------------------------
68template < typename TKSpace, typename TImage, typename TEmbedder >
69inline
70DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder> &
71DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
72operator=( const ImageLinearCellEmbedder & other )
73{
74 if ( this != &other )
75 {
76 myPtrK = other.myPtrK;
77 myPtrImage = other.myPtrImage;
78 myPtrEmbedder = other.myPtrEmbedder;
79 myIsoValue = other.myIsoValue;
80 }
81 return *this;
82}
83//-----------------------------------------------------------------------------
84template < typename TKSpace, typename TImage, typename TEmbedder >
85inline
86void
87DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
88init( ConstAlias<KSpace> K, ConstAlias<Image> f, ConstAlias<Embedder> e,
89 double iso_value )
90{
91 myPtrK = &K;
92 myPtrImage = &f;
93 myPtrEmbedder = &e;
94 myIsoValue = iso_value;
95}
96//-----------------------------------------------------------------------------
97template < typename TKSpace, typename TImage, typename TEmbedder >
98inline
99typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
100DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
101embed( const Point & p ) const
102{
103 ASSERT( myPtrEmbedder != 0 );
104 return myPtrEmbedder->embed( p );
105}
106//-----------------------------------------------------------------------------
107template < typename TKSpace, typename TImage, typename TEmbedder >
108inline
109typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
110DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
111embedCell( const Cell & cell ) const
112{
113 return this->operator()( cell );
114}
115//-----------------------------------------------------------------------------
116template < typename TKSpace, typename TImage, typename TEmbedder >
117inline
118typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
119DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
120operator()( const Cell & cell ) const
121{
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 );
129 qit != 0; ++qit )
130 { // cell is closed along this dimension.
131 // estimate coordinate by interpolation, looking for f(...)=0.
132 Dimension k = *qit;
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 );
138 }
139 return x1;
140}
141//-----------------------------------------------------------------------------
142template < typename TKSpace, typename TImage, typename TEmbedder >
143inline
144typename DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::RealPoint
145DGtal::ImageLinearCellEmbedder<TKSpace, TImage, 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 ImageValue y1 = (*myPtrImage)( p1 );
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 ImageValue y2 = (*myPtrImage)( p2 );
161 x1[ k ] -= ( NumberTraits<ImageValue>::castToDouble( y1 ) - myIsoValue )
162 * ( x2[ k ] - x1[ k ] )
163 / NumberTraits<ImageValue>::castToDouble( y2 - y1 );
164 }
165 return x1;
166}
167
168
169///////////////////////////////////////////////////////////////////////////////
170// Interface - public :
171
172/**
173 * Writes/Displays the object on an output stream.
174 * @param out the output stream where the object is written.
175 */
176template < typename TKSpace, typename TImage, typename TEmbedder >
177inline
178void
179DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
180selfDisplay ( std::ostream & out ) const
181{
182 out << "[ImageLinearCellEmbedder]";
183}
184
185/**
186 * Checks the validity/consistency of the object.
187 * @return 'true' if the object is valid, 'false' otherwise.
188 */
189template < typename TKSpace, typename TImage, typename TEmbedder >
190inline
191bool
192DGtal::ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder>::
193isValid() const
194{
195 return ( myPtrK != 0 ) && ( myPtrImage != 0 ) && ( myPtrEmbedder != 0 );
196}
197
198
199
200///////////////////////////////////////////////////////////////////////////////
201// Implementation of inline functions //
202
203template < typename TKSpace, typename TImage, typename TEmbedder >
204inline
205std::ostream&
206DGtal::operator<< ( std::ostream & out,
207 const ImageLinearCellEmbedder<TKSpace, TImage, TEmbedder> & object )
208{
209 object.selfDisplay( out );
210 return out;
211}
212
213// //
214///////////////////////////////////////////////////////////////////////////////
215
216