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//////////////////////////////////////////////////////////////////////////////
42template <typename TDomain, typename TValue>
43const typename TDomain::Dimension DGtal::ImageContainerBySTLMap<TDomain,
44 TValue>::dimension = TDomain::Space::dimension;
46//------------------------------------------------------------------------------
48template <typename TDomain, typename TValue>
50DGtal::ImageContainerBySTLMap<TDomain,TValue>::ImageContainerBySTLMap( DGtal::Clone<const TDomain> aDomain, const TValue& aValue): myDomainPtr( aDomain ), myDefaultValue( aValue )
54//------------------------------------------------------------------------------
55template <typename TDomain, typename TValue>
57DGtal::ImageContainerBySTLMap<TDomain,TValue>::ImageContainerBySTLMap(const ImageContainerBySTLMap& other): Parent(other),
58 myDomainPtr(other.myDomainPtr), myDefaultValue(other.myDefaultValue)
61//------------------------------------------------------------------------------
62template <typename TDomain, typename TValue>
64DGtal::ImageContainerBySTLMap<TDomain,TValue>&
65DGtal::ImageContainerBySTLMap<TDomain,TValue>
66::operator=(const ImageContainerBySTLMap& other)
70 Parent::operator=(other);
71 myDomainPtr = other.myDomainPtr;
72 myDefaultValue = other.myDefaultValue;
76//------------------------------------------------------------------------------
77template <typename TDomain, typename TValue>
79DGtal::ImageContainerBySTLMap<TDomain,TValue>::~ImageContainerBySTLMap( )
83//------------------------------------------------------------------------------
84template <typename TDomain, typename TValue>
86typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Value
87DGtal::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//------------------------------------------------------------------------------
98template <typename TDomain, typename TValue>
101DGtal::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//------------------------------------------------------------------------------
111template <typename TDomain, typename TValue>
113const typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Domain&
114DGtal::ImageContainerBySTLMap<TDomain,TValue>::domain() const
119//------------------------------------------------------------------------------
120template <typename TDomain, typename TValue>
122typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::ConstRange
123DGtal::ImageContainerBySTLMap<TDomain,TValue>::constRange() const
125 return ConstRange( *this );
128//------------------------------------------------------------------------------
129template <typename TDomain, typename TValue>
131typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::Range
132DGtal::ImageContainerBySTLMap<TDomain,TValue>::range()
134 return Range( *this );
136//------------------------------------------------------------------------------
137template <typename TDomain, typename TValue>
139typename DGtal::ImageContainerBySTLMap<TDomain,TValue>::OutputIterator
140DGtal::ImageContainerBySTLMap<TDomain,TValue>::outputIterator()
142 return OutputIterator( *this );
146//------------------------------------------------------------------------------
147template <typename TDomain, typename TValue>
150DGtal::ImageContainerBySTLMap<TDomain,TValue>::isValid() const
155//------------------------------------------------------------------------------
156template <typename TDomain, typename TValue>
159DGtal::ImageContainerBySTLMap<TDomain,TValue>::selfDisplay ( std::ostream & out ) const
161 out << "[Image - STLMap] size=" << this->size() << " valuetype="
162 << sizeof(TValue) << "bytes Domain=" << *myDomainPtr;
165//------------------------------------------------------------------------------
166template <typename TDomain, typename TValue>
169DGtal::ImageContainerBySTLMap<TDomain,TValue>::className() const
171 return "ImageContainerBySTLMap";