[vtkusers] Need help deriving classes from vtkImplicitFunction

David.Pont at ForestResearch.co.nz David.Pont at ForestResearch.co.nz
Sun Sep 21 17:42:50 EDT 2003


Hi Lina,
   I think you are on the right track with your pipeline
(http://public.kitware.com/cgi-bin/cvsweb.cgi/~checkout~/VTK/Examples/Modelling/Tcl/iceCream.tcl).
Check the ModelBounds and SampleDimensions used with vtkSampleFunction, you
might need relatively high SampleDimensions (50+) to adequately sample the
surface, which might be slow.
Another possibility is your EvaluateFunction algorithm is not producing the
values you expect.
Perhaps try visualising a slice (vtkCutter) through the StructuredPoints
output of vtkSampleFunction to see the actual output values and compare
with the value you are using with vtkContourFilter.
   Dave Pont



|---------+---------------------------->
|         |           Lina             |
|         |           <fazeleap at yahoo.c|
|         |           om>              |
|         |           Sent by:         |
|         |           vtkusers-admin at vt|
|         |           k.org            |
|         |                            |
|         |                            |
|         |           20/09/2003 18:02 |
|         |                            |
|---------+---------------------------->
  >--------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                                |
  |       To:       vtkusers at vtk.org                                                                                               |
  |       cc:                                                                                                                      |
  |       Subject:  [vtkusers] Need help deriving classes from vtkImplicitFunction                                                 |
  >--------------------------------------------------------------------------------------------------------------------------------|




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
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: <
http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers








More information about the vtkusers mailing list