[OpendTect_Developers] Array slicing to avoid data duplication

Raman Singh raman.singh at dgbes.com
Mon Jun 6 13:08:24 CEST 2011


Dear fellow developers,

Sometimes we find ourselves in situations where we unnecessarily end up 
copying data from one object to another only because we need that data 
in an object of a particular class. For example, if you have an 
attribute cube in memory in the form of an Array3D and you need to pass 
a slice of this cube (viz. Inline, Crossline or Z slice) to a function, 
it would be a pity if we have to allocate a fresh Array2D and copy the 
relevant data from the original Array3D to this newly allocated Array2D.

In OpendTect we handle these situations with array slicing. You can 
create an Array#DSlice, give it an ArrayND of a higher dimension, set 
the slicing parameters and get going. The new Array#DSlice will work as 
an Array#D adapter without any duplication of data. The following 
example should make it clear:

Let us say you load an attribute volume (1000 inlines, 1000 crosslines, 
1000 samples) into an Array3D:

Array3DImpl<float> cube3d( 1000, 1000, 1000 );
loadData( cube3d );

Now say we want a Z-slice at index 200:

Array2DSlice<float> arr2d( cube3d );
arr2d.setDimMap( 0, 0 );   // Map dimension 0 in srr2d to dimension 0 in 
cube3d
arr2d.setDimMap( 1, 1 );
arr2d.setPos( 2, 200 );    // Set the direction and position of the slice

That's it. Now you can use your arr2d in the same manner in which you 
would use any other Array2D.

Happy coding.

Cheers,
Raman

-- 
- Raman K Singh
- Opendtect Developer
-
- dGB Earth Sciences
- 304, Gateway Plaza, Hiranandani Gardens, Powai, Mumbai 400 076, India
- Phone: +91 22 25704984 , Fax: +91 22 25704977, Mobile: +91 9819082417
-mailto:raman.singh at dgbes.com,http://www.dgbes.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20110606/cc4f2015/attachment.html>


More information about the Developers mailing list