[Paraview] problems linking a new filter

Natalie Happenhofer nataliehapp at hotmail.com
Thu Sep 4 12:31:52 EDT 2008


So, I´m really fed up with this:
Why does this filter link without problems :

vtkImageHorizontalAverage.h:
#ifndef __vtkImageHorizontalAverage_h
#define __vtkImageHorizontalAverage_h

// additional macro for paraview running under windows
//#define vtkImaging_EXPORTS

#include "vtkSimpleImageToImageFilter.h"

class VTK_IMAGING_EXPORT vtkImageHorizontalAverage: public vtkSimpleImageToImageFilter
{
public:
    static vtkImageHorizontalAverage *New();
    vtkTypeRevisionMacro(vtkImageHorizontalAverage,vtkSimpleImageToImageFilter);
//    void PrintSelf(ostream& os, vtkIndent indent);

      // Set/Get the isNormalize value.
      vtkSetMacro(Normalize,int);
      vtkGetMacro(Normalize,int);
    vtkBooleanMacro(Normalize, int);
      
protected:
    vtkImageHorizontalAverage();
    ~vtkImageHorizontalAverage() {};

    int Normalize;
    
    virtual void SimpleExecute(vtkImageData* input, vtkImageData* output);

private:
    vtkImageHorizontalAverage(const vtkImageHorizontalAverage&);  // Not implemented.
    void operator=(const vtkImageHorizontalAverage&);        // Not implemented.
};

#endif


vtkImageHorizontalAverage.cpp:
#include "vtkImageHorizontalAverage.h"

#include "vtkImageData.h"
#include "vtkObjectFactory.h"

vtkCxxRevisionMacro(vtkImageHorizontalAverage, "$Revision: 1.10 $");
vtkStandardNewMacro(vtkImageHorizontalAverage);


// constructor
vtkImageHorizontalAverage::vtkImageHorizontalAverage()
{
    this->Normalize = 0;
}

// The switch statement in Execute will call this method with
// the appropriate input type (IT). Note that this example assumes
// that the output data type is the same as the input data type.
// This is not always the case.
template <class IT>
void vtkImageHorizontalAverageExecute(vtkImageHorizontalAverage *self,
                                 vtkImageData* input,
                                 vtkImageData* output,
                                 IT* inPtr, IT* outPtr)
{
      int i,j,k,dims[3];
      input->GetDimensions(dims);
      if (input->GetScalarType() != output->GetScalarType())
    {
        vtkGenericWarningMacro(<< "Execute: input ScalarType, " << input->GetScalarType()
        << ", must match out ScalarType " << output->GetScalarType());
        return;
    }

      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];
            }
        }
    }
   
    // normalize with sigma    
    if (self->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;
}

void vtkImageHorizontalAverage::SimpleExecute(vtkImageData* input,
                                              vtkImageData* output)
{
  // copy information
  output->DeepCopy(input);

  void* inPtr = input->GetScalarPointer();
  void* outPtr = output->GetScalarPointer();

  switch(output->GetScalarType())
    {
    // This is simple a #define for a big case list. It handles
    // all data types vtk can handle.
    vtkTemplateMacro5(vtkImageHorizontalAverageExecute, this, input, output, 
                    (VTK_TT *)(inPtr), (VTK_TT *)(outPtr));
    default:
      vtkGenericWarningMacro("Execute: Unknown input ScalarType");
      return;
    }
}

and the other one does not???????????????????????????? (The other one - vtkHorizontalAverage - is posted in the post before)
Both should do the same thing, compute the horizontal average of the points of the grid, the only difference should be the data type of the input file! one is structured_points, the other one structured_grid!!!!!!

I´d be very grateful for any comments!
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/f4a25981/attachment-0001.htm>


More information about the ParaView mailing list