[vtkusers] Need help deriving classes from vtkImplicitFunction

Lina fazeleap at yahoo.com
Sat Sep 20 02:02:30 EDT 2003


Hi, I'm trying to construct a blobby from scattered 3d
points using the gaussian equation f(x,y,z) = Sum to
k(B*exp(-ar^2))+Threshold, where r^2 is the distance
to another pt and a, B are parameters to control the
blobbiness. I've tried to make this a subclass of
vtkImplicitFunction but it doesn't work. Nothing gets
rendered in the window. The pipeline is
MyBlob->SampleFunction->ContourFilter->PolyDataMapper->Actor.
Please help. Thanks

#include "vtkImplicitFunction.h"
#include "vtkPoints.h"

class MyBlob : public vtkImplicitFunction 
{
public:
	// Construct sphere with center at (0,0,0) and
radius=0.5
	static MyBlob *New();

	// Evaluate blob equation
	float EvaluateFunction(float x[3]);
	float EvaluateFunction(float x, float y, float z)
		{return
this->vtkImplicitFunction::EvaluateFunction(x,y,z); };
	
	// Evaluate blob gradient
	void EvaluateGradient(float x[3], float n[3]);

	// Pass in dataset of all points
	void SetPoints(vtkPoints *allPts);

protected:
	MyBlob();
	~MyBlob() {};

	vtkPoints *allPts;
};

MyBlob* MyBlob::New()
{
 return new MyBlob;
}

MyBlob::MyBlob()
{
}

void MyBlob::SetPoints(vtkPoints *allPts)
{
 this->allPts = allPts;
}

// Evaluate equation 
float MyBlob::EvaluateFunction(float x[3])
{
 int i, numPts;
 float function, blo, rad, par, xx, yy, zz, r, arg;
 float pt[3];
 blo = 0.0;
 rad = (double)(1.6/(2*9));
 par = (double)(0.009);
 if( this->allPts )
 {
  numPts = this->allPts->GetNumberOfPoints();

  for(i=0; i<numPts; i++)
  {
   this->allPts->GetPoint(i, pt);
   xx = x[0] - pt[0];
   yy = x[1] - pt[1];
   zz = x[2] - pt[2];
   r = sqrt(xx*xx + yy*yy + zz*zz);
   arg = -r/par;
   blo += rad*exp(arg);
  }
  function = blo + rad;
 }
 return function;
}
// Evaluate blob gradient
void MyBlob::EvaluateGradient(float x[3], float n[3])
{
 float f0,dx[3],delta=0.0001;  /*this delta is to be
dependent on the shape size. */
 dx[0]=x[0];
 dx[1]=x[1];
 dx[2]=x[2];

 f0=this->EvaluateFunction((float *)x);
 dx[0]=dx[0]+delta;
 n[0]=(this->EvaluateFunction((float *)dx)-f0)/delta;
 dx[0]=x[0];
 dx[1]=dx[1]+delta;
 n[1]=(this->EvaluateFunction((float *)dx)-f0)/delta;
 dx[1]=x[1];
 dx[2]=dx[2]+delta;
 n[2]=(this->EvaluateFunction((float *)dx)-f0)/delta;
 dx[2]=x[2];
}



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



More information about the vtkusers mailing list