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>
51 ::ImageContainerBySTLMap( Clone<const Domain> aDomain, const Value& aValue)
52 : myDomainPtr( aDomain ), myDefaultValue( aValue )
56 //------------------------------------------------------------------------------
57 template <typename TDomain, typename TValue>
59 DGtal::ImageContainerBySTLMap<TDomain,TValue>
60 ::ImageContainerBySTLMap(const ImageContainerBySTLMap& other)
62 myDomainPtr(other.myDomainPtr), myDefaultValue(other.myDefaultValue)
65 //------------------------------------------------------------------------------
66 template <typename TDomain, typename TValue>
68 DGtal::ImageContainerBySTLMap<TDomain,TValue>&
69 DGtal::ImageContainerBySTLMap<TDomain,TValue>
70 ::operator=(const ImageContainerBySTLMap& other)
74 Parent::operator=(other);
75 myDomainPtr = other.myDomainPtr;
76 myDefaultValue = other.myDefaultValue;
80 //------------------------------------------------------------------------------
81 template <typename TDomain, typename TValue>
83 DGtal::ImageContainerBySTLMap<TDomain,TValue>::~ImageContainerBySTLMap( )
87 //------------------------------------------------------------------------------
88 template <typename TDomain, typename TValue>
90 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Value
91 DGtal::ImageContainerBySTLMap<TDomain,TValue>::operator()(const Point &aPoint) const
93 ASSERT( this->domain().isInside( aPoint ) );
94 ConstIterator it = this->find( aPoint );
95 if ( it == this->end() )
96 return myDefaultValue;
101 //------------------------------------------------------------------------------
102 template <typename TDomain, typename TValue>
105 DGtal::ImageContainerBySTLMap<TDomain,TValue>::setValue(const Point &aPoint, const Value &aValue)
107 ASSERT( this->domain().isInside( aPoint ) );
108 std::pair<typename std::map<Point,Value>::iterator, bool>
109 res = this->insert( std::pair<Point,Value>(aPoint, aValue) );
110 if (res.second == false)
111 res.first->second = aValue;
114 //------------------------------------------------------------------------------
115 template <typename TDomain, typename TValue>
117 const typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Domain&
118 DGtal::ImageContainerBySTLMap<TDomain,TValue>::domain() const
123 //------------------------------------------------------------------------------
124 template <typename TDomain, typename TValue>
126 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::ConstRange
127 DGtal::ImageContainerBySTLMap<TDomain,TValue>::constRange() const
129 return ConstRange( *this );
132 //------------------------------------------------------------------------------
133 template <typename TDomain, typename TValue>
135 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Range
136 DGtal::ImageContainerBySTLMap<TDomain,TValue>::range()
138 return Range( *this );
140 //------------------------------------------------------------------------------
141 template <typename TDomain, typename TValue>
143 typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::OutputIterator
144 DGtal::ImageContainerBySTLMap<TDomain,TValue>::outputIterator()
146 return OutputIterator( *this );
150 //------------------------------------------------------------------------------
151 template <typename TDomain, typename TValue>
154 DGtal::ImageContainerBySTLMap<TDomain,TValue>::isValid() const
159 //------------------------------------------------------------------------------
160 template <typename TDomain, typename TValue>
163 DGtal::ImageContainerBySTLMap<TDomain,TValue>::selfDisplay ( std::ostream & out ) const
165 out << "[Image - STLMap] size=" << this->size() << " valuetype="
166 << sizeof(TValue) << "bytes Domain=" << *myDomainPtr;
169 //------------------------------------------------------------------------------
170 template <typename TDomain, typename TValue>
173 DGtal::ImageContainerBySTLMap<TDomain,TValue>::className() const
175 return "ImageContainerBySTLMap";