[Paraview] problems linking a new filter

Natalie Happenhofer nataliehapp at hotmail.com
Thu Sep 4 08:20:36 EDT 2008


Well, I´m posting my source code here, maybe anyone finds the problem:

vtkHorizontalAverage.h:
#ifndef __vtkHorizontalAverage_h
#define __vtkHorizontalAverage_h

#include "vtkStructuredGridToStructuredGridFilter.h"

class VTK_EXPORT vtkHorizontalAverage: public vtkStructuredGridToStructuredGridFilter
{
public: 
    static vtkHorizontalAverage *New(){return new vtkHorizontalAverage;}
    vtkTypeMacro(vtkHorizontalAverage,vtkStructuredGridToStructuredGridFilter);
    vtkSetMacro(Normalize,int);
      vtkGetMacro(Normalize,int);
    vtkBooleanMacro(Normalize, int);

protected: vtkHorizontalAverage();
           ~vtkHorizontalAverage(){};
            
           int Normalize;

           virtual void Execute();
};
#endif


vtkHorizontalAverage.cxx:
#include "vtkHorizontalAverage.h"
#include "vtkStructuredGrid.h"
#include "vtkPointData.h"
#include "vtkObjectFactory.h"

vtkHorizontalAverage::vtkHorizontalAverage()
{
    this->Normalize = 0;
}

void vtkHorizontalAverage::Execute()
{vtkStructuredGrid *input = this->GetInput(); //"this" bezieht sich auf den Filter, auf ein vtkHorizontalAverage - Objekt, das die Methoden von vtkStructuredGridToStructuredGrid geerbt hat
 vtkStructuredGrid *output = this->GetOutput();

 vtkPointData *iPtr = input->GetPointData();
 vtkPointData *oPtr = output->GetPointData();

 double *inPtr = input->GetPoint(0);
 double *outPtr = output->GetPoint(0);

 int i,j,k,dims[3]; 
 input->GetDimensions(dims);

 double *horizontal = new double[dims[0]];
      double *horizontal_sigma = new double[dims[0]];
      int index;
      // compute the horizontal average
    for (i=0; i<dims[0]; i++) { 
        horizontal[i] = 0.0;
        for (j=0; j<dims[1]; j++) {
            for (k=0; k<dims[2]; k++) {
                index = k*(dims[1]*dims[0]) + j*dims[0] + i;
                horizontal[i] += inPtr[index];
            }
        }
        horizontal[i] = horizontal[i]/(dims[1]*dims[2]);
    }

    //subtract horizontal average
    for (i=0; i<dims[0]; i++) { 
        for (j=0; j<dims[1]; j++) {
            for (k=0; k<dims[2]; k++) {
                index = k*(dims[1]*dims[0]) + j*dims[0] + i;
                outPtr[index] = inPtr[index] - horizontal[i];
            }
        }
    }

    if (this->GetNormalize()) {
        // compute sigma
        for (i=0; i<dims[0]; i++) { 
            horizontal_sigma[i] = 0.0;
             for (j=0; j<dims[1]; j++) {
                for (k=0; k<dims[2]; k++) {
                     index = k*(dims[1]*dims[0]) + j*dims[0] + i;
                       horizontal_sigma[i] += (inPtr[index])*(inPtr[index]);
                }
            }
              horizontal_sigma[i] /= (dims[1]*dims[2]-1);
              horizontal_sigma[i] = sqrt(horizontal_sigma[i]);    
        }
        
        // now normalize
        for (i=0; i<dims[0]; i++) { 
             for (j=0; j<dims[1]; j++) {
                for (k=0; k<dims[2]; k++) {
                     index = k*(dims[1]*dims[0]) + j*dims[0] + i;
                       outPtr[index] /= horizontal_sigma[i];
                }
            }
         }
    }

    delete [] horizontal;
    delete [] horizontal_sigma;
    iPtr->Delete();
    oPtr->Delete();
    delete [] inPtr;
    delete [] outPtr;
}

I´m getting rather desperate..
thx,
NH

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20080904/f7c11d25/attachment.htm>


More information about the ParaView mailing list