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 SpatialCubicalSubdivision.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
24 * Implementation of inline methods defined in SpatialCubicalSubdivision.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 //-----------------------------------------------------------------------------
42 template <typename TSpace>
44 DGtal::SpatialCubicalSubdivision<TSpace>::
45 ~SpatialCubicalSubdivision()
47 BinConstRange range = myArray.constRange();
48 for ( typename BinConstRange::ConstIterator it = range.begin(), itE = range.end();
52 if ( ptr ) delete ptr;
55 //-----------------------------------------------------------------------------
56 template <typename TSpace>
58 DGtal::SpatialCubicalSubdivision<TSpace>::
59 SpatialCubicalSubdivision( const SpatialCubicalSubdivision& other )
60 : myDomain( other.myDomain ), mySize( other.mySize ),
61 myArray( other.binDomain() ), myDiag( other.myDiag )
63 BinConstRange range = myArray.constRange();
64 BinConstRange range_src = other.myArray.constRange();
65 for ( typename BinConstRange::ConstIterator it = range.begin(), itE = range.end(),
66 itSrc = other.myArray.constRange();
67 it != itE; ++it, ++itSrc )
69 Storage* ptr = *itSrc;
70 if ( ptr != 0 ) *it = new Storage( *ptr );
74 //-----------------------------------------------------------------------------
75 template <typename TSpace>
77 DGtal::SpatialCubicalSubdivision<TSpace>::
78 SpatialCubicalSubdivision( Point lo, Point up, Coordinate size )
79 : myDomain( lo, up ), mySize( size ), myArray( myDomain )
81 Point dimensions = myDomain.upperBound() - myDomain.lowerBound();
83 // the domain for the bins defines the image domain.
84 myArray = StorageArray( Domain( Point::zero, dimensions ) );
85 // all elements of myArray are initialized with 0.
86 myDiag = myDomain.lowerBound() + Point::diagonal(mySize-1); // used in uppermost
89 //-----------------------------------------------------------------------------
90 template <typename TSpace>
92 const typename DGtal::SpatialCubicalSubdivision<TSpace>::Domain &
93 DGtal::SpatialCubicalSubdivision<TSpace>::
98 //-----------------------------------------------------------------------------
99 template <typename TSpace>
101 const typename DGtal::SpatialCubicalSubdivision<TSpace>::Domain &
102 DGtal::SpatialCubicalSubdivision<TSpace>::
105 return myArray.domain();
108 //-----------------------------------------------------------------------------
109 template <typename TSpace>
111 typename DGtal::SpatialCubicalSubdivision<TSpace>::Point
112 DGtal::SpatialCubicalSubdivision<TSpace>::
115 p -= myDomain.lowerBound();
119 //-----------------------------------------------------------------------------
120 template <typename TSpace>
122 typename DGtal::SpatialCubicalSubdivision<TSpace>::Point
123 DGtal::SpatialCubicalSubdivision<TSpace>::
124 lowest( Point b ) const
127 return b + myDomain.lowerBound();
130 //-----------------------------------------------------------------------------
131 template <typename TSpace>
133 typename DGtal::SpatialCubicalSubdivision<TSpace>::Point
134 DGtal::SpatialCubicalSubdivision<TSpace>::
135 uppermost( Point b ) const
141 //-----------------------------------------------------------------------------
142 template <typename TSpace>
145 DGtal::SpatialCubicalSubdivision<TSpace>::
146 push( const Point& p )
149 Storage* pts = myArray( b );
153 myArray.setValue( b, pts );
158 //-----------------------------------------------------------------------------
159 template <typename TSpace>
160 template <typename PointConstIterator>
163 DGtal::SpatialCubicalSubdivision<TSpace>::
164 push( PointConstIterator it, PointConstIterator itE )
166 for ( ; it != itE; ++it )
170 //-----------------------------------------------------------------------------
171 template <typename TSpace>
172 template <typename PointPredicate>
175 DGtal::SpatialCubicalSubdivision<TSpace>::
176 getPoints( std::vector<Point> & pts,
177 Point bin_lo, Point bin_up, const PointPredicate & pred ) const
179 Domain local( bin_lo.sup( binDomain().lowerBound() ),
180 bin_up.inf( binDomain().upperBound() ) );
181 for ( typename Domain::ConstIterator it = local.begin(), itE = local.end(); it != itE; ++it )
183 const Storage* storage = myArray( *it );
185 for ( typename Storage::const_iterator its = storage->begin(), itsE = storage->end();
187 if ( pred( *its ) ) pts.push_back( *its );
190 //-----------------------------------------------------------------------------
191 template <typename TSpace>
194 DGtal::SpatialCubicalSubdivision<TSpace>::
195 getPoints( std::vector<Point> & pts,
196 Point bin_lo, Point bin_up ) const
198 Domain local( bin_lo.sup( binDomain().lowerBound() ),
199 bin_up.inf( binDomain().upperBound() ) );
200 for ( typename Domain::ConstIterator it = local.begin(), itE = local.end(); it != itE; ++it )
202 const Storage* storage = myArray( *it );
204 for ( typename Storage::const_iterator its = storage->begin(), itsE = storage->end();
206 pts.push_back( *its );
211 ///////////////////////////////////////////////////////////////////////////////
212 // Interface - public :
215 * Writes/Displays the object on an output stream.
216 * @param out the output stream where the object is written.
218 template <typename TSpace>
221 DGtal::SpatialCubicalSubdivision<TSpace>::selfDisplay ( std::ostream & out ) const
223 out << "[SpatialCubicalSubdivision domain=" << domain()
224 << " binDomain=" << binDomain()
225 << " binSize=" << mySize
230 * Checks the validity/consistency of the object.
231 * @return 'true' if the object is valid, 'false' otherwise.
233 template <typename TSpace>
236 DGtal::SpatialCubicalSubdivision<TSpace>::isValid() const
243 ///////////////////////////////////////////////////////////////////////////////
244 // Implementation of inline functions //
246 template <typename TSpace>
249 DGtal::operator<< ( std::ostream & out,
250 const SpatialCubicalSubdivision<TSpace> & object )
252 object.selfDisplay( out );
257 ///////////////////////////////////////////////////////////////////////////////