FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
RegularCoordinateSlice.hpp
1#ifndef __FIBEROPERATIONS_SLICE_SELECTION
2#define __FIBEROPERATIONS_SLICE_SELECTION
3
4#include <vector/MultiArray.hpp>
5#include <vector/MultiCopy.hpp>
6
7#include <field/MemBase.hpp>
8#include <field/Field.hpp>
9
10#include <eagle/FixedArray.hpp>
11
12#ifdef USE_OPENMP
13#include <omp.h>
14#endif
15
16
17#include "gridopDllApi.h"
18
19namespace Fiber
20{
21
26{
27 int X, Y, Z;
28
29 void setup(int orient);
30
32 {
33 setup(o);
34 }
35
37 index_t y,
38 index_t z) const
39 {
41
42 I[ X ] = x;
43 I[ Y ] = y;
44 I[ Z ] = z;
45
46 return I;
47 }
48
50 {
51 return P[ Z ];
52 }
53
54
66 bool getRectilinearIndex(double CoordinateValue,
68 double&CoordinateIndex);
69
70 bool getRectilinearIndex(double SliceCoordinateValue,
71 const RefPtr<Field>&Coords,
73 double&CoordinateIndex);
74
75
95 const MultiIndex<3>&DataDims,
96 int CornerX, int CornerY,
97 index_t sliceIndex) const
98 {
99// if (sliceIndex < 0) //(mr) unsigned cant be <0
100// return false;
101
102 if (sliceIndex >= DataDims[ Z ] )
103 return false;
104
105 I[ X ] = CornerX*(DataDims[X]-1);
106 I[ Y ] = CornerY*(DataDims[Y]-1);
107 I[ Z ] = sliceIndex;
108
109 return true;
110 }
111
120 getCoordinates(index_t sliceIndex,
121 const MultiIndex<3>&DataDims,
122 const RefPtr<Field>&Coords, const RefPtr<FragmentID>&fid);
123
124
130 template <class Dest, class Source, class Converter>
133 const index_t&SliceNumber,
134 const Converter&C,
135 const MultiIndex<3>&SourceOffset = MIndex(0,0,0) )
136 {
137 MultiIndex<3> Dims = SrcArray.Size();
138
139 index_t DimsX = SrcArray.Size()[X],
140 DimsY = SrcArray.Size()[Y];
141
142 assert( DestArray.Size()[0] >= DimsX );
143 assert( DestArray.Size()[1] >= DimsY );
144
145#ifdef USE_OPENMP
146#pragma omp parallel for
147#endif
148 for(index_t y = 0; y<DimsY; y++)
149 for(index_t x = 0; x<DimsX; x++)
150 {
152 P[X] += x; P[Y] += y; P[Z] += SliceNumber;
153
154 MultiIndex<2> Pdst = MIndex(x,y);
155 C.copy( DestArray[ Pdst ], SrcArray[ P ]);
156 }
157 }
158
159 bool validDestinationSize(const MultiIndex<3>&Dst,
161 const MultiIndex<3>&Src)
162 {
163 // ensure the destination array is large enough to accomodate the data
164 if (Src[X] > Dst[X] ) return false;
165 if (Src[Y] > Dst[Y] ) return false;
166 if (DestSliceNumber >= Dst[Z] ) return false;
167
168 assert( Src[X] <= Dst[X] );
169 assert( Src[Y] <= Dst[Y] );
170 assert( DestSliceNumber < Dst[Z] );
171
172 return true;
173 }
174
184 template <class Dest, class Source, class Converter>
189 const Converter&C)
190 {
191#ifdef VERBOSE
192 printf("extractDataTo3D: src (%dx%dx%d) ==> dst (%dx%dx%d) \n",
193 int(SrcArray .Size()[0]), int(SrcArray .Size()[1]), int(SrcArray .Size()[2]),
194 int(DestArray.Size()[0]), int(DestArray.Size()[1]), int(DestArray.Size()[2]) );
195 fflush(stdout);
196#endif
197 assert( DestArray.count()>0 );
198 assert( SrcArray.count() >0 );
199
200 if (!validDestinationSize(DestArray.Size(),
202 SrcArray.Size()) )
203 {
204 printf("RegularCoordinateSlice::extractDataToOriented3D(): "
205 "Invalid (too small) Destination in slicing src (%dx%dx%d) ==> dst (%dx%dx%d) \n",
206 int(SrcArray .Size()[0]), int(SrcArray .Size()[1]), int(SrcArray .Size()[2]),
207 int(DestArray.Size()[0]), int(DestArray.Size()[1]), int(DestArray.Size()[2]) );
208 fflush(stdout);
209 return false;
210 }
211
212 index_t DimsX = SrcArray.Size()[X],
213 DimsY = SrcArray.Size()[Y];
214
215 // ensure the destination array is large enough to accomodate the data
216 assert( DimsX <= DestArray.Size()[X] );
217 assert( DimsY <= DestArray.Size()[Y] );
218 assert( DestSliceNumber < DestArray.Size()[Z] );
219
220#ifdef USE_OPENMP
221#pragma omp parallel for
222#endif
223 for(index_t y = 0; y<DimsY; y++)
224 for(index_t x = 0; x<DimsX; x++)
225 {
227 P[X] = x; P[Y] = y; P[Z] = SliceNumber;
228
231
232#if 0
233 printf("extractDataTo3D: %dx%dx%d ==> %dx%dx%d\n",
234 int(P[0]), int(P[1]), int(P[2]),
235 int(Pdst[0]), int(Pdst[1]), int(Pdst[2]) ); fflush(stdout);
236#endif
237
238 C.copy( DestArray[ Pdst ], SrcArray[ P ]);
239 }
240 return true;
241 }
242};
243
244
245} // namespace Fiber
246
247#endif // __FIBEROPERATIONS_SLICE_SELECTION
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
index_t getIndex(index_t i, int c) const
Given a major and a minor index, compute the overall index in the dataset according to.
Definition HyperslabParameters.hpp:176
index_t count() const
Return the number of steps which can be traversed through this ElementIterator.
Definition HyperslabParameters.hpp:147
Iterator< component_t > getComponent(int n) const
Get an iterator that operates on the nth component.
Definition vector/Iterator.hpp:1307
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22
Helper class to select a slice from a regular grid.
Definition RegularCoordinateSlice.hpp:26
bool getSliceCornerIndex(MultiIndex< 3 > &I, const MultiIndex< 3 > &DataDims, int CornerX, int CornerY, index_t sliceIndex) const
Given the dimensions of a three-dimensional array, compute the 3D indices of a slice.
Definition RegularCoordinateSlice.hpp:94
bool extractDataToOriented3D(MultiArray< 3, Dest > &DestArray, index_t DestSliceNumber, const MultiArray< 3, Source > &SrcArray, index_t SliceNumber, const Converter &C)
Extract data slice from the source array to the destination array, whereby the destination array must...
Definition RegularCoordinateSlice.hpp:185
void extractData(MultiArray< 2, Dest > &DestArray, const MultiArray< 3, Source > &SrcArray, const index_t &SliceNumber, const Converter &C, const MultiIndex< 3 > &SourceOffset=MIndex(0, 0, 0))
Extract data slice from the source array to a 2D destination array, whereby the destination array mus...
Definition RegularCoordinateSlice.hpp:131