SliceSelection.hpp

00001 #ifndef __FIBEROPERATIONS_SLICE_SELECTION
00002 #define __FIBEROPERATIONS_SLICE_SELECTION
00003 
00004 #include <vector/MultiArray.hpp>
00005 #include <vector/MultiCopy.hpp>
00006 
00007 namespace Fiber
00008 {
00009 
00010 struct  SliceSelection
00011 {
00012         int     X, Y, Z;
00013 
00014         void setup(int orient)
00015         {
00016                 switch( orient % 3 )
00017                 {
00018                 default:
00019                 case 2:  X = 0; Y = 1; Z = 2; break;
00020                 case 0:  X = 1; Y = 2; Z = 0; break;
00021                 case 1:  X = 2; Y = 0; Z = 1; break;
00022                 }
00023         }
00024 
00025 
00026         SliceSelection(int o = 0)
00027         {
00028                 setup(o);
00029         }
00030 };
00031 
00032 
00038 template <class Dest, class Source, class Converter>
00039 void    ExtractSlice2D(MultiArray<2, Dest>&DestArray, const MultiArray<3, Source>&SrcArray, 
00040                        const SliceSelection&O, const index_t&SliceNumber,
00041                        const Converter&C)
00042 {
00043 index_t DimsX = SrcArray.Size()[O.X],
00044         DimsY = SrcArray.Size()[O.Y]; 
00045 
00046         assert( DestArray.Size()[0] >= DimsX );
00047         assert( DestArray.Size()[1] >= DimsY );
00048 
00049         for(index_t y = 0; y<DimsY; y++)
00050         for(index_t x = 0; x<DimsX; x++)
00051         {
00052         MultiIndex<3> P;
00053                 P[O.X] = x; P[O.Y] = y; P[O.Z] = SliceNumber;
00054 
00055         MultiIndex<2> Pdst = MIndex(x,y);
00056 
00057                 C.copy( DestArray[ Pdst ], SrcArray[ P ]);
00058         }
00059 }
00060 
00061 template <class Dest, class Source, class Converter>
00062 void    ExtractSlice2D(MultiArray<2, Dest>&DestArray, const MultiArray<3, Source>&SrcArray, 
00063                        const MultiIndex<3>&SourceOffset,
00064                        const SliceSelection&O, const index_t&SliceNumber,
00065                        const Converter&C)
00066 {
00067 MultiIndex<3> Dims = SrcArray.Size();
00068 
00069         for(index_t y = 0; y<Dims[O.Y]; y++)
00070         for(index_t x = 0; x<Dims[O.X]; x++)
00071         {
00072         MultiIndex<3> P = SourceOffset;
00073                 P[O.X] += x; P[O.Y] += y; P[O.Z] += SliceNumber;
00074 
00075         MultiIndex<2> Pdst = MIndex(x,y);
00076 
00077                 C.copy( DestArray[ Pdst ], SrcArray[ P ]);
00078         } 
00079 }
00080 
00081 
00082 } // namespace Fiber
00083 
00084 #endif // __FIBEROPERATIONS_SLICE_SELECTION