DGtal  1.4.beta
ImageContainerBySTLVector.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 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
22  *
23  * @date 2010/06/15
24  *
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
27  *
28  * @date 2012/02/16
29  *
30  * Implementation of inline methods defined in ImageContainerBySTLVector.h
31  *
32  * This file is part of the DGtal library.
33  */
34 
35 ///////////////////////////////////////////////////////////////////////////////
36 // IMPLEMENTATION of inline methods.
37 ///////////////////////////////////////////////////////////////////////////////
38 
39 //////////////////////////////////////////////////////////////////////////////
40 #include <cstdlib>
41 #include <DGtal/kernel/domains/Linearizer.h>
42 //////////////////////////////////////////////////////////////////////////////
43 
44 //------------------------------------------------------------------------------
45 template <typename Domain, typename T>
46 inline
47 DGtal::ImageContainerBySTLVector<Domain, T>::
48 ImageContainerBySTLVector(const Domain &aDomain ) :
49  myDomain(aDomain)
50 {
51  myExtent = (aDomain.upperBound() - aDomain.lowerBound()) + Point::diagonal(1);
52  this->resize( myDomain.size() );
53 }
54 
55 //------------------------------------------------------------------------------
56 template <typename Domain, typename T>
57 inline
58 DGtal::ImageContainerBySTLVector<Domain,T>
59 ::ImageContainerBySTLVector(const ImageContainerBySTLVector& other)
60  : std::vector<T>(other),
61  myDomain(other.myDomain), myExtent(other.myExtent)
62 {
63 }
64 //------------------------------------------------------------------------------
65 template <typename Domain, typename T>
66 inline
67 DGtal::ImageContainerBySTLVector<Domain,T>&
68 DGtal::ImageContainerBySTLVector<Domain,T>
69 ::operator=(const ImageContainerBySTLVector& other)
70 {
71  if (this != &other)
72  {
73  std::vector<T>::operator=(other);
74  myDomain = other.myDomain;
75  myExtent = other.myExtent;
76  }
77  return *this;
78 }
79 
80 
81 //------------------------------------------------------------------------------
82 template <typename Domain, typename T>
83 inline
84 DGtal::ImageContainerBySTLVector<Domain, T>::~ImageContainerBySTLVector( )
85 {
86 }
87 
88 
89 //------------------------------------------------------------------------------
90 template <typename Domain, typename T>
91 inline
92 T
93 DGtal::ImageContainerBySTLVector<Domain, T>::operator()(const Point &aPoint) const
94 {
95  ASSERT(this->domain().isInside(aPoint));
96  return this->operator[](linearized( aPoint ) );
97 }
98 //------------------------------------------------------------------------------
99 template <typename Domain, typename T>
100 inline
101 void
102 DGtal::ImageContainerBySTLVector<Domain, T>::setValue(const Point &aPoint, const T &V)
103 {
104  ASSERT(this->domain().isInside(aPoint));
105  this->operator[](linearized( aPoint )) = V;
106 }
107 
108 //------------------------------------------------------------------------------
109 template <typename Domain, typename T>
110 inline
111 const typename DGtal::ImageContainerBySTLVector<Domain, T>::Domain&
112 DGtal::ImageContainerBySTLVector<Domain, T>::domain() const
113 {
114  return myDomain;
115 }
116 
117 //------------------------------------------------------------------------------
118 template <typename Domain, typename T>
119 inline
120 typename DGtal::ImageContainerBySTLVector<Domain, T>::ConstRange
121 DGtal::ImageContainerBySTLVector<Domain, T>::constRange() const
122 {
123  return ConstRange( this->begin(), this->end(), DistanceFunctorFromPoint<Self>(this));
124 }
125 
126 //------------------------------------------------------------------------------
127 template <typename Domain, typename T>
128 inline
129 typename DGtal::ImageContainerBySTLVector<Domain, T>::Range
130 DGtal::ImageContainerBySTLVector<Domain, T>::range()
131 {
132  return Range ( this->begin(), this->end(), DistanceFunctorFromPoint<Self>(this) );
133 }
134 //------------------------------------------------------------------------------
135 template <typename Domain, typename T>
136 inline
137 const typename DGtal::ImageContainerBySTLVector<Domain, T>::Vector&
138 DGtal::ImageContainerBySTLVector<Domain, T>::extent() const
139 {
140  return myExtent;
141 }
142 
143 //------------------------------------------------------------------------------
144 template <typename Domain, typename T>
145 inline
146 void
147 DGtal::ImageContainerBySTLVector<Domain, T>::translateDomain(const Vector& aShift)
148 {
149  myDomain = Domain(myDomain.lowerBound()+aShift, myDomain.upperBound()+aShift);
150 }
151 
152 //------------------------------------------------------------------------------
153 template <typename TDomain, typename V>
154 inline
155 void
156 DGtal::ImageContainerBySTLVector<TDomain, V>::selfDisplay ( std::ostream & out ) const
157 {
158  out << "[Image - STLVector] size=" << this->size() << " valuetype="
159  << sizeof(V) << "bytes Domain=" << myDomain;
160 }
161 
162 //------------------------------------------------------------------------------
163 template <typename Domain, typename T>
164 inline
165 bool
166 DGtal::ImageContainerBySTLVector<Domain, T>::isValid() const
167 {
168  return true;
169 }
170 
171 
172 //------------------------------------------------------------------------------
173 template <typename D, typename V>
174 inline
175 std::string
176 DGtal::ImageContainerBySTLVector<D, V>::className() const
177 {
178  return "ImageContainerBySTLVector";
179 }
180 
181 
182 ///////////////////////////////////////////////////////////////////////////////
183 // Internals - private :
184 template<typename Domain, typename T>
185 inline
186 typename DGtal::ImageContainerBySTLVector<Domain, T>::Size
187 DGtal::ImageContainerBySTLVector<Domain, T>::linearized(const Point &aPoint) const
188 {
189  return DGtal::Linearizer<Domain, ColMajorStorage>::getIndex( aPoint, myDomain.lowerBound(), myExtent );
190 }
191 
192 
193