Skip to content

Commit

Permalink
[#14] Add gradient attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
waynegm committed Jan 24, 2016
1 parent 0935ccd commit e69312f
Show file tree
Hide file tree
Showing 14 changed files with 612 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# OpendTect v5+ Plugins Release Notes
# OpendTect Plugins Release Notes

## Release 6.0.0
### GradientAttrib
- New attribute for calculating inline, crossline or z gradient using various derivative operators

## Release 6.0.0pre7-1
#### ExternalAttrib
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set ( PLUGINS RSpecAttrib uiRSpecAttrib
MLVFilterAttrib uiMLVFilterAttrib
AVOAttrib uiAVOAttrib
ExternalAttrib uiExternalAttrib
GradientAttrib uiGradientAttrib
LTFAttrib uiLTFAttrib )
OD_ADD_MODULES( plugins ${PLUGINS} )

Expand Down
3 changes: 2 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is the source code for a collection of plugins for the open source seismic interpretation system [OpendTect v5+](http://www.opendtect.org). All code is provided under the terms of the [GNU General Public License Version 3](./LICENSE.txt).

As of 24-Sep-2015 code development in the master branch is being transitioned to support the soon to be released OpendTect 6. If you are interested in the latest source code for OpendTect 5 please refer to the v5-stable branch of this repository.
As of 24-Sep-2015 code development in the master branch is for plugin development for OpendTect 6. If you are interested in the latest source code for OpendTect 5 please refer to the v5-stable branch of this repository.

For details please see the [documentation](http://waynegm.github.io/OpendTect-Plugin-Docs/).

Expand All @@ -12,6 +12,7 @@ For details please see the [documentation](http://waynegm.github.io/OpendTect-Pl
|--------|-------------|
| [AVOAttrib](http://waynegm.github.io/OpendTect-Plugin-Docs/Attributes/AVOAttrib/) | Six attributes derived from reflection intercept and gradient |
| [ExternalAttrib](http://waynegm.github.io/OpendTect-Plugin-Docs/Attributes/ExternalAttrib/) | Calculate attribute using an external process such as a python script |
| [GradientAttrib](http://waynegm.github.io/OpendTect-Plugin-Docs/Attributes/GradientAttrib/) | Calculate inline, crossline or z gradient using rotationally invariant operators |
| [LTFAttrib](http://waynegm.github.io/OpendTect-Plugin-Docs/Attributes/LTFAttrib/) | Local time-frequency decomposition |
| [MLVFilter](http://waynegm.github.io/OpendTect-Plugin-Docs/Attributes/MLVFilter/) | Structure preserving filtering |
| [RSpecAttrib](http://waynegm.github.io/OpendTect-Plugin-Docs/Attributes/RSpecAttrib/) | Recursive time-frequency decomposition |
Expand Down
6 changes: 5 additions & 1 deletion README.html

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions plugins/GradientAttrib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#_______________________Pmake___________________________________________________
#
# Makefile : GradientAttrib plugin
# Nov 2015 Wayne Mogg
#_______________________________________________________________________________

SET(OD_MODULE_DEPS AttributeEngine)
SET(OD_IS_PLUGIN yes)
SET(OD_MODULE_SOURCES
gradientattribpi.cc
gradientattrib.cc)
SET( OD_PLUGIN_ALO_EXEC ${OD_ATTRIB_EXECS} )
OD_INIT_MODULE()
220 changes: 220 additions & 0 deletions plugins/GradientAttrib/gradientattrib.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/*Copyright (C) 2015 Wayne Mogg All rights reserved.
This file may be used either under the terms of:
1. The GNU General Public License version 3 or higher, as published by
the Free Software Foundation,
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

/*+
________________________________________________________________________
Author: Wayne Mogg
Date: November 2015
________________________________________________________________________
-*/

#include "gradientattrib.h"

#include "arrayndimpl.h"
#include "attribdataholder.h"
#include "attribdesc.h"
#include "attribdescset.h"
#include "attribfactory.h"
#include "attribparam.h"
#include <math.h>

namespace Attrib
{

mAttrDefCreateInstance(GradientAttrib)


void GradientAttrib::initClass()
{
mAttrStartInitClass

EnumParam* op_type = new EnumParam( operatorStr() );
op_type->addEnum("Kroon_3");
op_type->addEnum("Farid_5");
op_type->addEnum("Farid_7");
op_type->setDefaultValue( GradientAttrib::Kroon_3 );
desc->addParam( op_type );

EnumParam* out_type = new EnumParam( outputStr() );
out_type->addEnum( "Inline" );
out_type->addEnum( "Crossline" );
out_type->addEnum( "Z" );
out_type->setDefaultValue( GradientAttrib::Z );
desc->addParam( out_type );

desc->addInput( InputSpec("Input data",true) );
desc->addOutputDataType( Seis::UnknowData );

desc->setLocality( Desc::MultiTrace );
mAttrEndInitClass
}

const float GradientAttrib::kroon_3_d[] = { -0.500000, 0.000000, 0.500000 };
const float GradientAttrib::kroon_3_s[] = { 0.178947, 0.642105, 0.178947 };
const float GradientAttrib::farid_5_d[] = { -0.109604, -0.276691, 0.000000, 0.276691, 0.109604 };
const float GradientAttrib::farid_5_s[] = { 0.037659, 0.249153, 0.426375, 0.249153, 0.037659 };
const float GradientAttrib::farid_7_d[] = { -.018708, -0.125376, -0.193091, 0.000000, 0.193091, 0.125376, 0.018708 };
const float GradientAttrib::farid_7_s[] = { 0.004711, 0.069321, 0.245410, 0.361117, 0.245410, 0.069321, 0.004711 };


GradientAttrib::GradientAttrib( Desc& desc )
: Provider( desc )
, size_(0)
, stepout_(0,0)
, zmargin_(0,0)
{
if ( !isOK() ) return;

inputdata_.allowNull(true);

mGetEnum( outtype_, outputStr() );
mGetEnum( optype_, operatorStr() );
float* skernel = NULL;
float* dkernel = NULL;

switch(optype_)
{
case Kroon_3: size_ = 3;
skernel = new float[size_];
dkernel = new float[size_];
OD::memCopy( skernel, kroon_3_s, size_*sizeof(float) );
OD::memCopy( dkernel, kroon_3_d, size_*sizeof(float) );
break;
case Farid_5: size_ = 5;
skernel = new float[size_];
dkernel = new float[size_];
OD::memCopy( skernel, farid_5_s, size_*sizeof(float) );
OD::memCopy( dkernel, farid_5_d, size_*sizeof(float) );
break;
case Farid_7: size_ = 7;
skernel = new float[size_];
dkernel = new float[size_];
OD::memCopy( skernel, farid_7_s, size_*sizeof(float) );
OD::memCopy( dkernel, farid_7_d, size_*sizeof(float) );
break;
};

ikernel_ = new float[size_];
xkernel_ = new float[size_];
zkernel_ = new float[size_];
OD::memCopy( ikernel_, skernel, size_*sizeof(float) );
OD::memCopy( xkernel_, skernel, size_*sizeof(float) );
OD::memCopy( zkernel_, skernel, size_*sizeof(float) );
switch(outtype_)
{
case Inline: OD::memCopy( ikernel_, dkernel, size_*sizeof(float) );
break;
case Crossline: OD::memCopy( xkernel_, dkernel, size_*sizeof(float) );
break;
case Z: OD::memCopy( zkernel_, dkernel, size_*sizeof(float) );
break;
};
delete [] skernel;
delete [] dkernel;

const int hsz = size_/2;

stepout_ = is2D() ? BinID(0,hsz) : BinID(hsz,hsz);
getTrcPos();
zmargin_ = Interval<int>(-hsz, hsz);
inputdata_.allowNull( true );
}

GradientAttrib::~GradientAttrib()
{
delete [] ikernel_;
delete [] xkernel_;
delete [] zkernel_;
}

bool GradientAttrib::getTrcPos()
{
trcpos_.erase();
BinID bid;
int trcidx = 0;
centertrcidx_ = 0;
for ( bid.inl()=-stepout_.inl(); bid.inl()<=stepout_.inl(); bid.inl()++ )
{
for ( bid.crl()=-stepout_.crl(); bid.crl()<=stepout_.crl(); bid.crl()++ )
{
if ( !bid.inl() && !bid.crl() )
centertrcidx_ = trcidx;
trcpos_ += bid;
trcidx++;
}
}

return true;
}

bool GradientAttrib::getInputData( const BinID& relpos, int zintv )
{
while ( inputdata_.size() < trcpos_.size() )
inputdata_ += 0;

const BinID bidstep = inputs_[0]->getStepoutStep();
for ( int idx=0; idx<trcpos_.size(); idx++ )
{
const DataHolder* data =
inputs_[0]->getData( relpos+trcpos_[idx]*bidstep, zintv );
if ( !data ) return false;
inputdata_.replace( idx, data );
}

dataidx_ = getDataIndex( 0 );

return true;
}

bool GradientAttrib::computeData( const DataHolder& output, const BinID& relpos,
int z0, int nrsamples, int threadid ) const
{

if ( inputdata_.isEmpty() ) return false;

const int sz = zmargin_.width() + nrsamples;
Array1DImpl<float> vals( sz );
const int hsz = size_/2;

for ( int idx=0; idx<sz; idx++ ) {
float reso = 0.0;
for (int iln=0; iln<size_; iln++) {
float res = 0.0;
for (int crl=0; crl<size_; crl++) {
const DataHolder* data = inputdata_[iln*size_+crl];
float val = getInputValue(*data, dataidx_, zmargin_.start+idx, z0);
res += mIsUdf(val)?0.0f:val*xkernel_[crl];
}
reso += ikernel_[iln]*res;
}
vals.set(idx, reso);
}

for (int idx=0; idx<nrsamples; idx++) {
float value = 0.0;
const int ipos = idx - zmargin_.start - hsz;
for (int zi=0; zi<size_; zi++) {
value += vals[ipos+zi]*zkernel_[zi];
}
setOutputValue( output, 0, idx, z0, value );
}
return true;
}


const BinID* GradientAttrib::desStepout( int inp, int out ) const
{ return inp ? 0 : &stepout_; }


}; //namespace

95 changes: 95 additions & 0 deletions plugins/GradientAttrib/gradientattrib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*Copyright (C) 2015 Wayne Mogg All rights reserved.
This file may be used either under the terms of:
1. The GNU General Public License version 3 or higher, as published by
the Free Software Foundation, or
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#ifndef gradientattrib_h
#define gradientattrib_h

/*+
________________________________________________________________________
Author: Wayne Mogg
Date: November 2015
________________________________________________________________________
-*/

#include "gradientattribmod.h"
#include "attribprovider.h"


/*!\brief Gradient Attribute
Calculate inline, crossline or Z gradient using the operators proposed by Kroon, 2009
*/


namespace Attrib
{

mClass(GradientAttrib) GradientAttrib : public Provider
{
public:
static void initClass();
GradientAttrib(Desc&);

static const char* attribName() { return "GradientAttrib"; }

static const char* operatorStr() { return "operator"; }
static const char* outputStr() { return "output"; }

enum OutputType { Inline, Crossline, Z };
enum OperatorType { Kroon_3, Farid_5, Farid_7};

static const float kroon_3_d[];
static const float kroon_3_s[];
static const float farid_5_d[];
static const float farid_5_s[];
static const float farid_7_d[];
static const float farid_7_s[];

protected:
~GradientAttrib();
static Provider* createInstance(Desc&);

bool allowParallelComputation() const
{ return true; }

bool getInputData(const BinID&,int zintv);
bool computeData(const DataHolder&, const BinID& relpos, int z0, int nrsamples, int threadid) const;

const BinID* desStepout(int input,int output) const;
const Interval<int>* desZSampMargin(int input,int output) const
{ return &zmargin_; }

bool getTrcPos();

BinID stepout_;
Interval<int> zmargin_;
TypeSet<BinID> trcpos_;
int centertrcidx_;
int outtype_;
int optype_;
int size_;

float *ikernel_, *xkernel_, *zkernel_;

int dataidx_;

ObjectSet<const DataHolder> inputdata_;
};

}; // namespace Attrib


#endif


Loading

0 comments on commit e69312f

Please sign in to comment.