[Insight-users] Defining a map of IndexTypes

Karthik Krishnan karthik.krishnan at kitware.com
Wed Oct 28 00:30:52 EDT 2009


Luis:

The comparator can not only be a class (functor), but It can also be a
function pointer with the exact signature that Matt described. In the
latter case, the function pointer type is the third template argument
and the function pointer must be passed in via the constructor.

thx
--
karthik


On Tue, Oct 27, 2009 at 10:10 PM, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> Hi Matthias,
>
> You are mis-constructing the map type.
>
> The code that you need is like the following:
>
> --------------------------------------------------------------------------
> #include "itkImage.h"
>
> template <class TImageType>
> class TEST
> {
> typedef typename    TImageType::IndexType       IndexType;
>
> struct ltstr
> {
>  bool operator()(const IndexType& lhs, const IndexType& rhs) const
>    {
>    //y1 is lower y2
>    if(lhs[1]<rhs[1])return true;
>    //y1==y2 and x1 < x2
>    if((lhs[1]==rhs[1])&&(lhs[0]<rhs[0]))return true;
>    //else
>    return false;
>    }
> };
>
>
> std::map<IndexType, bool, ltstr> recursionPoints;
>
> };
>
> int main()
> {
> return 0;
> }
>
>
>
> Note that the comparator, the third template argument
> of the std::map is actually a class, that has a method
> operator().
>
> More at:
> http://www.sgi.com/tech/stl/Map.html
>
>
>      Regards,
>
>
>             Luis
>
>
> ---------------------------------
> On Tue, Oct 27, 2009 at 12:00 PM, Matthias Dodt
> <matthias.dodt at mdc-berlin.de> wrote:
>> Hi there!
>>
>> I want to store IndexTypes in a map (as keys). I got the following code:
>>          ...
>>
>>           typedef typename    TImageType::IndexType       IndexType;
>>
>>           bool fless(const IndexType& lhs, const IndexType& rhs) const
>>           {
>>             //y1 is lower y2
>>             if(lhs[1]<rhs[1])return true;
>>             //y1==y2 and x1 < x2
>>             if((lhs[1]==rhs[1])&&(lhs[0]<rhs[0]))return true;
>>             //else
>>             return false;
>>           }
>>
>>           typedef bool (*comp_t)( IndexType const &, IndexType const & );
>>
>>           std::map<IndexType, bool, comp_t> recursionPoints(fless);
>>
>> ...
>>
>> Anyway- i get an error saying that fless has no type. I think the problem is
>> that IndexType is a template type...
>>
>> thanks!
>>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list