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 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
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
29 * Implementation of inline methods defined in ImageContainerBySTLMap.h
31 * This file is part of the DGtal library.
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 //////////////////////////////////////////////////////////////////////////////
40 //////////////////////////////////////////////////////////////////////////////
42 template <typename TDomain, typename TValue>
43 const typename TDomain::Dimension DGtal::ImageContainerBySTLMap<TDomain,
44 TValue>::dimension = TDomain::Space::dimension;
46 //------------------------------------------------------------------------------
48 template <typename TDomain, typename TValue>
50 DGtal::ImageContainerBySTLMap<TDomain,TValue>::ImageContainerBySTLMap( DGtal::Clone<const TDomain> aDomain, const TValue& aValue): myDomainPtr( aDomain ), myDefaultValue( aValue )
54 //------------------------------------------------------------------------------
55 template <typename TDomain, typename TValue>
57 DGtal::ImageContainerBySTLMap<TDomain,TValue>::ImageContainerBySTLMap(const ImageContainerBySTLMap& other): Parent(other),
58 myDomainPtr(other.myDomainPtr), myDefaultValue(other.myDefaultValue)
61 //------------------------------------------------------------------------------
62 template <typename TDomain, typename TValue>
64 DGtal::ImageContainerBySTLMap<TDomain,TValue>&
65 DGtal::ImageContainerBySTLMap<TDomain,TValue>
66 ::operator=(const ImageContainerBySTLMap& other)
70 Parent::operator=(other);
71 myDomainPtr = other.myDomainPtr;
72 myDefaultValue = other.myDefaultValue;
76 //------------------------------------------------------------------------------
77 template <typename TDomain, typename TValue>
79 DGtal::ImageContainerBySTLMap<TDomain,TValue>::~ImageContainerBySTLMap( )
83 //------------------------------------------------------------------------------
84 template <typename TDomain, typename TValue>
86 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Value
87 DGtal::ImageContainerBySTLMap<TDomain,TValue>::operator()(const Point &aPoint) const
89 ASSERT( this->domain().isInside( aPoint ) );
90 ConstIterator it = this->find( aPoint );
91 if ( it == this->end() )
92 return myDefaultValue;
97 //------------------------------------------------------------------------------
98 template <typename TDomain, typename TValue>
101 DGtal::ImageContainerBySTLMap<TDomain,TValue>::setValue(const Point &aPoint, const Value &aValue)
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;
110 //------------------------------------------------------------------------------
111 template <typename TDomain, typename TValue>
113 const typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Domain&
114 DGtal::ImageContainerBySTLMap<TDomain,TValue>::domain() const
119 //------------------------------------------------------------------------------
120 template <typename TDomain, typename TValue>
122 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::ConstRange
123 DGtal::ImageContainerBySTLMap<TDomain,TValue>::constRange() const
125 return ConstRange( *this );
128 //------------------------------------------------------------------------------
129 template <typename TDomain, typename TValue>
131 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Range
132 DGtal::ImageContainerBySTLMap<TDomain,TValue>::range()
134 return Range( *this );
136 //------------------------------------------------------------------------------
137 template <typename TDomain, typename TValue>
139 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::OutputIterator
140 DGtal::ImageContainerBySTLMap<TDomain,TValue>::outputIterator()
142 return OutputIterator( *this );
146 //------------------------------------------------------------------------------
147 template <typename TDomain, typename TValue>
150 DGtal::ImageContainerBySTLMap<TDomain,TValue>::isValid() const
155 //------------------------------------------------------------------------------
156 template <typename TDomain, typename TValue>
159 DGtal::ImageContainerBySTLMap<TDomain,TValue>::selfDisplay ( std::ostream & out ) const
161 out << "[Image - STLMap] size=" << this->size() << " valuetype="
162 << sizeof(TValue) << "bytes Domain=" << *myDomainPtr;
165 //------------------------------------------------------------------------------
166 template <typename TDomain, typename TValue>
169 DGtal::ImageContainerBySTLMap<TDomain,TValue>::className() const
171 return "ImageContainerBySTLMap";