[Insight-developers] Image as an OrientedImage Progress

Steve M. Robbins steve at sumost.ca
Fri Oct 10 04:01:36 EDT 2008


On Mon, Sep 22, 2008 at 12:50:08PM -0400, Rupert Brooks wrote:

> What could work, could be something like
> template<class TPixel, unsigned int VImageDimension = 2, unsigned int
> VSpaceDimension=VImageDimension>
> class itk::Image< TPixel, VImageDimension, VSpaceDimension >
> 
> Sadly, i dont think the default argument for a template parameter can
> be another template parameter, although i didnt try this.

I just tried and it works on my system (Linux/GCC 4).  In fact, this is
part of the C++ standard working draft [1, section 14.2, page 279]:

  13 The scope of a template-parameter extends from its point of
     declaration until the end of its template. In particular, a
     template-parameter can be used in the declaration of subsequent
     template-parameters and their default arguments.
  
     [ Example:
      
       template < class T , T * p , class U = T > class X { /* ... */ };


Here's a simple test program to demonstrate.

#include <iostream>

template <class TPixel, 
	  unsigned int VImageDimension=2, 
	  unsigned int VSpaceDimension=VImageDimension>
class Image
{
public:
    unsigned int getImageDimension() const { return VImageDimension; }
    unsigned int getSpaceDimension() const { return VSpaceDimension; }
    void printSelf() 
    {
	std::cout << "Image dimension: " << getImageDimension()
		  << ", space dimension: " << getSpaceDimension()
		  << "\n";
    }

};

int main( int ac, char* av[] )
{
    Image<short> image1;
    image1.printSelf();

    Image<short,9> image2;
    image2.printSelf();

    Image<short,7,2> image3;
    image3.printSelf();

    return 0;
}


As a test, I have started adding VSpaceDimension to Image, ImageBase,
ImageHelper, ImageRegion, etc.  It ends up touching a lot of classes,
so I'm not done yet.  What do you all think of this approach?

-Steve


[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20081010/10b7b611/attachment.pgp>


More information about the Insight-developers mailing list