Boost logo

Boost Users :

Subject: Re: [Boost-users] question about multi_array use
From: Alle Meije Wink (a.m.wink_at_[hidden])
Date: 2009-08-10 08:30:48


> On Sat, Aug 8, 2009 at 4:51 PM, Alle Meije Wink<a.m.wink_at_[hidden]> wrote:
>
>>> You could always just wrap up each of the possible dimensions in a
>>> struct that can handle the (de)serialization and everything too,
>>> perhaps use crtp to put identical functionality in a non-virtual base
>>> class.
>
>> Overmind, I guess compared to what I had in mind (define the data container
>> of the image [template?] class as a multi_array with a dimensionality given
>> as a size_t parameter), the CRTP struct you are talking about specifies all
>> of the possible types. Is that correct?
>>
>> If I understand it correctly then this does what I want, but does that mean
>> that in the worst-case scenario, I have to write out the functionality for
>> all different dimensionalities? If the parameterised template class idea is
>> possible, that would save some typing!
>
> I could see using fusion (mostly the "apply" construct) would make it
> generic to any number of dimensions. Boost.Fusion is amazing for such
> work, think MPL, but it works at runtime too.
>

I like the look of boost::Fusion in terms of advanced generic C++
programming, but in terms of finding a concise description of my image
template class / class / data type, this may be overshooting the aim a
bit. Plus I will need to read up on template metaprogramming!

Coming back to the original idea: my images are stored as files which
have a (on-disc 1-dimensional) sequence of intensities, and a header
containing a number dims (dimensionality) and an array dim[8] (maximum
of 8 dimensions).

The problem that images can have different (but all built-in) data types
can be circumvented with template programming, which is great compared
to the old C-style casting to double.

But talking about C-style, dealing with dimensions was possible in a
fast way (in terms of both coding and runnning) with malloc and pointers
(to pointers (to pointers)).

Previously this is how I used to implement operations on images: casting
everything to double, using pointers to get to image elements.

I was hoping that by using templates to abstract from element type, and
multi_array to cover different dimensionalities, it would be possible
code image operations only once, for all types and dimensionalities.

 From what I understand, the curious recursion way matches most closely
what I was looking for (and is still as close to generic programming as
possible?). The scopira narray class
http://www.scopira.org/api/narray_8h-source.html seems to do something
similar.

If there is another way to do this then I'm still very interested!

Thanks,
Alle Meije


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net