DGtal 1.3.0
Loading...
Searching...
No Matches
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//------------------------------------------------------------------------------
45template <typename Domain, typename T>
46inline
47DGtal::ImageContainerBySTLVector<Domain, T>::
48ImageContainerBySTLVector(const Domain &aDomain ) :
49 myDomain(aDomain)
50{
51 myExtent = (aDomain.upperBound() - aDomain.lowerBound()) + Point::diagonal(1);
52 this->resize( myDomain.size() );
53}
54
55//------------------------------------------------------------------------------
56template <typename Domain, typename T>
57inline
58DGtal::ImageContainerBySTLVector<Domain,T>
59::ImageContainerBySTLVector(const ImageContainerBySTLVector& other)
60 : std::vector<T>(other),
61 myDomain(other.myDomain), myExtent(other.myExtent)
62{
63}
64//------------------------------------------------------------------------------
65template <typename Domain, typename T>
66inline
67DGtal::ImageContainerBySTLVector<Domain,T>&
68DGtal::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//------------------------------------------------------------------------------
82template <typename Domain, typename T>
83inline
84DGtal::ImageContainerBySTLVector<Domain, T>::~ImageContainerBySTLVector( )
85{
86}
87
88
89//------------------------------------------------------------------------------
90template <typename Domain, typename T>
91inline
92T
93DGtal::ImageContainerBySTLVector<Domain, T>::operator()(const Point &aPoint) const
94{
95 ASSERT(this->domain().isInside(aPoint));
96 return this->operator[](linearized( aPoint ) );
97}
98//------------------------------------------------------------------------------
99template <typename Domain, typename T>
100inline
101void
102DGtal::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//------------------------------------------------------------------------------
109template <typename Domain, typename T>
110inline
111const typename DGtal::ImageContainerBySTLVector<Domain, T>::Domain&
112DGtal::ImageContainerBySTLVector<Domain, T>::domain() const
113{
114 return myDomain;
115}
116
117//------------------------------------------------------------------------------
118template <typename Domain, typename T>
119inline
120typename DGtal::ImageContainerBySTLVector<Domain, T>::ConstRange
121DGtal::ImageContainerBySTLVector<Domain, T>::constRange() const
122{
123 return ConstRange( this->begin(), this->end(), DistanceFunctorFromPoint<Self>(this));
124}
125
126//------------------------------------------------------------------------------
127template <typename Domain, typename T>
128inline
129typename DGtal::ImageContainerBySTLVector<Domain, T>::Range
130DGtal::ImageContainerBySTLVector<Domain, T>::range()
131{
132 return Range ( this->begin(), this->end(), DistanceFunctorFromPoint<Self>(this) );
133}
134//------------------------------------------------------------------------------
135template <typename Domain, typename T>
136inline
137const typename DGtal::ImageContainerBySTLVector<Domain, T>::Vector&
138DGtal::ImageContainerBySTLVector<Domain, T>::extent() const
139{
140 return myExtent;
141}
142
143//------------------------------------------------------------------------------
144template <typename Domain, typename T>
145inline
146void
147DGtal::ImageContainerBySTLVector<Domain, T>::translateDomain(const Vector& aShift)
148{
149 myDomain = Domain(myDomain.lowerBound()+aShift, myDomain.upperBound()+aShift);
150}
151
152//------------------------------------------------------------------------------
153template <typename TDomain, typename V>
154inline
155void
156DGtal::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//------------------------------------------------------------------------------
163template <typename Domain, typename T>
164inline
165bool
166DGtal::ImageContainerBySTLVector<Domain, T>::isValid() const
167{
168 return true;
169}
170
171
172//------------------------------------------------------------------------------
173template <typename D, typename V>
174inline
175std::string
176DGtal::ImageContainerBySTLVector<D, V>::className() const
177{
178 return "ImageContainerBySTLVector";
179}
180
181
182///////////////////////////////////////////////////////////////////////////////
183// Internals - private :
184template<typename Domain, typename T>
185inline
186typename DGtal::ImageContainerBySTLVector<Domain, T>::Size
187DGtal::ImageContainerBySTLVector<Domain, T>::linearized(const Point &aPoint) const
188{
189 return DGtal::Linearizer<Domain, ColMajorStorage>::getIndex( aPoint, myDomain.lowerBound(), myExtent );
190}
191
192
193