DGtal 1.3.0
Loading...
Searching...
No Matches
ImageContainerBySTLMap.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 ImageContainerBySTLMap.ih
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21 *
22 * @date 2010/06/15
23 *
24 * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
25 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
26 *
27 * @date 2012/02/13
28 *
29 * Implementation of inline methods defined in ImageContainerBySTLMap.h
30 *
31 * This file is part of the DGtal library.
32 */
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38//////////////////////////////////////////////////////////////////////////////
39#include <cstdlib>
40//////////////////////////////////////////////////////////////////////////////
41
42template <typename TDomain, typename TValue>
43const typename TDomain::Dimension DGtal::ImageContainerBySTLMap<TDomain,
44 TValue>::dimension = TDomain::Space::dimension;
45
46//------------------------------------------------------------------------------
47
48template <typename TDomain, typename TValue>
49inline
50DGtal::ImageContainerBySTLMap<TDomain,TValue>::ImageContainerBySTLMap( DGtal::Clone<const TDomain> aDomain, const TValue& aValue): myDomainPtr( aDomain ), myDefaultValue( aValue )
51{
52}
53
54//------------------------------------------------------------------------------
55template <typename TDomain, typename TValue>
56inline
57DGtal::ImageContainerBySTLMap<TDomain,TValue>::ImageContainerBySTLMap(const ImageContainerBySTLMap& other): Parent(other),
58 myDomainPtr(other.myDomainPtr), myDefaultValue(other.myDefaultValue)
59{
60}
61//------------------------------------------------------------------------------
62template <typename TDomain, typename TValue>
63inline
64DGtal::ImageContainerBySTLMap<TDomain,TValue>&
65DGtal::ImageContainerBySTLMap<TDomain,TValue>
66::operator=(const ImageContainerBySTLMap& other)
67{
68 if (this != &other)
69 {
70 Parent::operator=(other);
71 myDomainPtr = other.myDomainPtr;
72 myDefaultValue = other.myDefaultValue;
73 }
74 return *this;
75}
76//------------------------------------------------------------------------------
77template <typename TDomain, typename TValue>
78inline
79DGtal::ImageContainerBySTLMap<TDomain,TValue>::~ImageContainerBySTLMap( )
80{
81}
82
83//------------------------------------------------------------------------------
84template <typename TDomain, typename TValue>
85inline
86typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Value
87DGtal::ImageContainerBySTLMap<TDomain,TValue>::operator()(const Point &aPoint) const
88{
89 ASSERT( this->domain().isInside( aPoint ) );
90 ConstIterator it = this->find( aPoint );
91 if ( it == this->end() )
92 return myDefaultValue;
93 else
94 return it->second;
95}
96
97//------------------------------------------------------------------------------
98template <typename TDomain, typename TValue>
99inline
100void
101DGtal::ImageContainerBySTLMap<TDomain,TValue>::setValue(const Point &aPoint, const Value &aValue)
102{
103 ASSERT( this->domain().isInside( aPoint ) );
104 std::pair<typename std::map<Point,Value>::iterator, bool>
105 res = this->insert( std::pair<Point,Value>(aPoint, aValue) );
106 if (res.second == false)
107 res.first->second = aValue;
108}
109
110//------------------------------------------------------------------------------
111template <typename TDomain, typename TValue>
112inline
113const typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Domain&
114DGtal::ImageContainerBySTLMap<TDomain,TValue>::domain() const
115{
116 return *myDomainPtr;
117}
118
119//------------------------------------------------------------------------------
120template <typename TDomain, typename TValue>
121inline
122typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::ConstRange
123DGtal::ImageContainerBySTLMap<TDomain,TValue>::constRange() const
124{
125 return ConstRange( *this );
126}
127
128//------------------------------------------------------------------------------
129template <typename TDomain, typename TValue>
130inline
131typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Range
132DGtal::ImageContainerBySTLMap<TDomain,TValue>::range()
133{
134 return Range( *this );
135}
136//------------------------------------------------------------------------------
137template <typename TDomain, typename TValue>
138inline
139typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::OutputIterator
140DGtal::ImageContainerBySTLMap<TDomain,TValue>::outputIterator()
141{
142 return OutputIterator( *this );
143}
144
145
146//------------------------------------------------------------------------------
147template <typename TDomain, typename TValue>
148inline
149bool
150DGtal::ImageContainerBySTLMap<TDomain,TValue>::isValid() const
151{
152 return true;
153}
154
155//------------------------------------------------------------------------------
156template <typename TDomain, typename TValue>
157inline
158void
159DGtal::ImageContainerBySTLMap<TDomain,TValue>::selfDisplay ( std::ostream & out ) const
160{
161 out << "[Image - STLMap] size=" << this->size() << " valuetype="
162 << sizeof(TValue) << "bytes Domain=" << *myDomainPtr;
163}
164
165//------------------------------------------------------------------------------
166template <typename TDomain, typename TValue>
167inline
168std::string
169DGtal::ImageContainerBySTLMap<TDomain,TValue>::className() const
170{
171 return "ImageContainerBySTLMap";
172}