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 ImageContainerBySTLVector.ih
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * @author Guillaume Damiand
21 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
25 * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
26 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
30 * Implementation of inline methods defined in ImageContainerBySTLVector.h
32 * This file is part of the DGtal library.
35 ///////////////////////////////////////////////////////////////////////////////
36 // IMPLEMENTATION of inline methods.
37 ///////////////////////////////////////////////////////////////////////////////
39 //////////////////////////////////////////////////////////////////////////////
41 #include <DGtal/kernel/domains/Linearizer.h>
42 //////////////////////////////////////////////////////////////////////////////
44 //------------------------------------------------------------------------------
45 template <typename Domain, typename T>
47 DGtal::ImageContainerBySTLVector<Domain, T>::
48 ImageContainerBySTLVector(const Domain &aDomain ) :
51 myExtent = (aDomain.upperBound() - aDomain.lowerBound()) + Point::diagonal(1);
52 this->resize( myDomain.size() );
55 //------------------------------------------------------------------------------
56 template <typename Domain, typename T>
58 DGtal::ImageContainerBySTLVector<Domain,T>
59 ::ImageContainerBySTLVector(const ImageContainerBySTLVector& other)
60 : std::vector<T>(other),
61 myDomain(other.myDomain), myExtent(other.myExtent)
64 //------------------------------------------------------------------------------
65 template <typename Domain, typename T>
67 DGtal::ImageContainerBySTLVector<Domain,T>&
68 DGtal::ImageContainerBySTLVector<Domain,T>
69 ::operator=(const ImageContainerBySTLVector& other)
73 std::vector<T>::operator=(other);
74 myDomain = other.myDomain;
75 myExtent = other.myExtent;
81 //------------------------------------------------------------------------------
82 template <typename Domain, typename T>
84 DGtal::ImageContainerBySTLVector<Domain, T>::~ImageContainerBySTLVector( )
89 //------------------------------------------------------------------------------
90 template <typename Domain, typename T>
93 DGtal::ImageContainerBySTLVector<Domain, T>::operator()(const Point &aPoint) const
95 ASSERT(this->domain().isInside(aPoint));
96 return this->operator[](linearized( aPoint ) );
98 //------------------------------------------------------------------------------
99 template <typename Domain, typename T>
102 DGtal::ImageContainerBySTLVector<Domain, T>::setValue(const Point &aPoint, const T &V)
104 ASSERT(this->domain().isInside(aPoint));
105 this->operator[](linearized( aPoint )) = V;
108 //------------------------------------------------------------------------------
109 template <typename Domain, typename T>
111 const typename DGtal::ImageContainerBySTLVector<Domain, T>::Domain&
112 DGtal::ImageContainerBySTLVector<Domain, T>::domain() const
117 //------------------------------------------------------------------------------
118 template <typename Domain, typename T>
120 typename DGtal::ImageContainerBySTLVector<Domain, T>::ConstRange
121 DGtal::ImageContainerBySTLVector<Domain, T>::constRange() const
123 return ConstRange( this->begin(), this->end(), DistanceFunctorFromPoint<Self>(this));
126 //------------------------------------------------------------------------------
127 template <typename Domain, typename T>
129 typename DGtal::ImageContainerBySTLVector<Domain, T>::Range
130 DGtal::ImageContainerBySTLVector<Domain, T>::range()
132 return Range ( this->begin(), this->end(), DistanceFunctorFromPoint<Self>(this) );
134 //------------------------------------------------------------------------------
135 template <typename Domain, typename T>
137 const typename DGtal::ImageContainerBySTLVector<Domain, T>::Vector&
138 DGtal::ImageContainerBySTLVector<Domain, T>::extent() const
143 //------------------------------------------------------------------------------
144 template <typename Domain, typename T>
147 DGtal::ImageContainerBySTLVector<Domain, T>::translateDomain(const Vector& aShift)
149 myDomain = Domain(myDomain.lowerBound()+aShift, myDomain.upperBound()+aShift);
152 //------------------------------------------------------------------------------
153 template <typename TDomain, typename V>
156 DGtal::ImageContainerBySTLVector<TDomain, V>::selfDisplay ( std::ostream & out ) const
158 out << "[Image - STLVector] size=" << this->size() << " valuetype="
159 << sizeof(V) << "bytes Domain=" << myDomain;
162 //------------------------------------------------------------------------------
163 template <typename Domain, typename T>
166 DGtal::ImageContainerBySTLVector<Domain, T>::isValid() const
172 //------------------------------------------------------------------------------
173 template <typename D, typename V>
176 DGtal::ImageContainerBySTLVector<D, V>::className() const
178 return "ImageContainerBySTLVector";
182 ///////////////////////////////////////////////////////////////////////////////
183 // Internals - private :
184 template<typename Domain, typename T>
186 typename DGtal::ImageContainerBySTLVector<Domain, T>::Size
187 DGtal::ImageContainerBySTLVector<Domain, T>::linearized(const Point &aPoint) const
189 return DGtal::Linearizer<Domain, ColMajorStorage>::getIndex( aPoint, myDomain.lowerBound(), myExtent );