[Insight-developers] PixelTraits for Vector

Brad King brad.king@kitware.com
Fri, 4 Jan 2002 17:00:12 -0500 (EST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

---1463811583-1208684618-1010181359=:29963
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <Pine.LNX.4.21.0201041656031.29963@darkstar.kitware.com>

Hello, all:

I have experimented a bit with MSVC in an effort to solve Lydia's problem
with the PixelTraits for a Vector pixel type.  There is a solution that
does not require all possible specializations of itk::Vector to have pixel
traits defined.  A standalone example demonstrating the solution is
attached.  It is valid C++, and works on all of our supported compilers.  
It does not use partial specialization. The interface to the PixelTraits
class for a particular pixel type will remain unchanged if this solution
is used in ITK.  It is also easy to add new templated pixel types without
much trouble.

Thoughts?
-Brad

---1463811583-1208684618-1010181359=:29963
Content-Type: exts="c/x-unknown; name="traits1.cxx"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.21.0201041700120.29963@darkstar.kitware.com>
Content-Description: 
Content-Disposition: attachment; filename="traits1.cxx"

I2luY2x1ZGUgPGlvc3RyZWFtPgoKLy8gRHVtbXkgVmVjdG9yIGNsYXNzIGZv
ciB1c2UgaW4gZXhhbXBsZS4KdGVtcGxhdGUgPHR5cGVuYW1lIFRFbGVtZW50
LCB1bnNpZ25lZCBpbnQgVkxlbmd0aD4Kc3RydWN0IFZlY3Rvcgp7CiAgdHlw
ZWRlZiBURWxlbWVudCBFbGVtZW50OwogIGVudW0geyBMZW5ndGggPSBWTGVu
Z3RoIH07CiAgVmVjdG9yKGNvbnN0IFRFbGVtZW50Jikge30KfTsKCi8vIER1
bW15IE1hdHJpeCBjbGFzcyBmb3IgdXNlIGluIGV4YW1wbGUuCnRlbXBsYXRl
IDx0eXBlbmFtZSBURWxlbWVudCwgdW5zaWduZWQgaW50IFZIZWlnaHQsIHVu
c2lnbmVkIGludCBWV2lkdGg+CnN0cnVjdCBNY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