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//-----------------------------------------------------------------------------
42template <typename TSpace>
44DGtal::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//-----------------------------------------------------------------------------
56template <typename TSpace>
58DGtal::SpatialCubicalSubdivision<TSpace>::
59SpatialCubicalSubdivision( 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//-----------------------------------------------------------------------------
75template <typename TSpace>
77DGtal::SpatialCubicalSubdivision<TSpace>::
78SpatialCubicalSubdivision( 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//-----------------------------------------------------------------------------
90template <typename TSpace>
92const typename DGtal::SpatialCubicalSubdivision<TSpace>::Domain &
93DGtal::SpatialCubicalSubdivision<TSpace>::
98//-----------------------------------------------------------------------------
99template <typename TSpace>
101const typename DGtal::SpatialCubicalSubdivision<TSpace>::Domain &
102DGtal::SpatialCubicalSubdivision<TSpace>::
105 return myArray.domain();
108//-----------------------------------------------------------------------------
109template <typename TSpace>
111typename DGtal::SpatialCubicalSubdivision<TSpace>::Point
112DGtal::SpatialCubicalSubdivision<TSpace>::
115 p -= myDomain.lowerBound();
119//-----------------------------------------------------------------------------
120template <typename TSpace>
122typename DGtal::SpatialCubicalSubdivision<TSpace>::Point
123DGtal::SpatialCubicalSubdivision<TSpace>::
124lowest( Point b ) const
127 return b + myDomain.lowerBound();
130//-----------------------------------------------------------------------------
131template <typename TSpace>
133typename DGtal::SpatialCubicalSubdivision<TSpace>::Point
134DGtal::SpatialCubicalSubdivision<TSpace>::
135uppermost( Point b ) const
141//-----------------------------------------------------------------------------
142template <typename TSpace>
145DGtal::SpatialCubicalSubdivision<TSpace>::
146push( const Point& p )
149 Storage* pts = myArray( b );
153 myArray.setValue( b, pts );
158//-----------------------------------------------------------------------------
159template <typename TSpace>
160template <typename PointConstIterator>
163DGtal::SpatialCubicalSubdivision<TSpace>::
164push( PointConstIterator it, PointConstIterator itE )
166 for ( ; it != itE; ++it )
170//-----------------------------------------------------------------------------
171template <typename TSpace>
172template <typename PointPredicate>
175DGtal::SpatialCubicalSubdivision<TSpace>::
176getPoints( 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//-----------------------------------------------------------------------------
191template <typename TSpace>
194DGtal::SpatialCubicalSubdivision<TSpace>::
195getPoints( 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.
218template <typename TSpace>
221DGtal::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.
233template <typename TSpace>
236DGtal::SpatialCubicalSubdivision<TSpace>::isValid() const
243///////////////////////////////////////////////////////////////////////////////
244// Implementation of inline functions //
246template <typename TSpace>
249DGtal::operator<< ( std::ostream & out,
250 const SpatialCubicalSubdivision<TSpace> & object )
252 object.selfDisplay( out );
257///////////////////////////////////////////////////////////////////////////////