[vtkusers] Slow rendering of derived class of vtkImplicitFunction
#LIM LAY NA#
wolken at pmail.ntu.edu.sg
Wed Oct 8 01:29:46 EDT 2003
Hi all,
I'm having problems rendering my own derived class of
vtkImplicitFunction.
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.
The pipeline is
MyBlob->SampleFunction->ContourFilter->PolyDataNormals->PolyDataMapper->
Actor.
It takes about 1.5min to render the surface which is too long. It's
supposed to be almost instant because
user interaction is needed. I've tried changing the contour filter to
vtkMarchingContourFilter but there
wasn't any improvement. Can anyone point out to me which part of the
pipeline is slowing it down or whether it
is anything to do with the code for the derived class. Thanks a lot.
// .NAME MyBlob - implicit function for blobby shape from 3D points
// .SECTION Description
// MyBlob computes the implicit function and/or gradient for a blobby
shape from a set of points.
// MyBlobis a concrete implementation of vtkImplicitFunction.
class MyBlob : public vtkImplicitFunction
{
public:
vtkTypeMacro(MyBlob,vtkImplicitFunction);
void PrintSelf(ostream& os, vtkIndent indent);
// Description
// Construct blob with scale factor = 0.6, exp factor =
25.0, threshold = 0.5, delta = 0.0001
static MyBlob *New();
// Description
// Evaluate blob equation
float EvaluateFunction(float x[3]);
float EvaluateFunction(float x, float y, float z)
{return
this->vtkImplicitFunction::EvaluateFunction(x,y,z); };
// Description
// Evaluate blob gradient
void EvaluateGradient(float x[3], float n[3]);
// Description
// Set all points used in implicit function
void SetPoints(vtkPoints *allPts);
// Description:
// Set / get the bounds
vtkSetVectorMacro(Bounds, float, 6);
vtkGetVectorMacro(Bounds, float, 6);
protected:
MyBlob();
~MyBlob() {};
vtkPoints *allPts;
float ExponentFactor, ScaleFactor, Threshold, Bounds[6];
int numPts;
float *x, *y, *z;
};
vtkStandardNewMacro(MyBlob);
// Construct blob equation with default parameters
MyBlob::MyBlob()
{
ExponentFactor = 25.0;
ScaleFactor = 0.5;
Threshold = 0.5;
}
// Input points needed to calculate the implicit function
void MyBlob::SetPoints(vtkPoints *allPts)
{
float pt[3];
if(!allPts)
return;
this->allPts = allPts;
this->numPts = allPts->GetNumberOfPoints();
this->x = new float[this->numPts];
this->y = new float[this->numPts];
this->z = new float[this->numPts];
for(int i = 0; i<this->numPts; i++)
{
allPts->GetPoint(i,pt);
this->x[i] = pt[0];
this->y[i] = pt[1];
this->z[i] = pt[2];
}
this->SetBounds(allPts->GetBounds());
for(i=0; i<6; i+=2)
{
this->Bounds[i] -= 110;
}
for(i=1; i<6; i+=2)
{
this->Bounds[i] += 110;
}
}
// Evaluate blob equation
float MyBlob::EvaluateFunction(float xyz[3])
{
float xx, yy, zz, distance;
float sum = 0.0;
float pt[3];
if( this->allPts )
{
for(int i=0; i<numPts; i++)
{
xx = xyz[0] - x[i];
yy = xyz[1] - y[i];
zz = xyz[2] - z[i];
distance = sqrt(xx*xx + yy*yy +
zz*zz);
sum = sum +
ScaleFactor*exp(-distance/ExponentFactor);
}
}
return sum-Threshold;
}
// Evaluate blob gradient
void MyBlob::EvaluateGradient(float xyz[3], float n[3])
{
float xx, yy, zz, distance;
n[0]=n[1]=n[2]=0;
if( this->allPts )
{
for(int i=0; i<numPts; i++)
{
xx = xyz[0] - x[i];
yy = xyz[1] - y[i];
zz = xyz[2] - z[i];
distance = sqrt(xx*xx + yy*yy + zz*zz);
n[0] = n[0] -(ScaleFactor*xx*exp(-distance/ExponentFactor))/distance;
n[1] = n[1] -(ScaleFactor*yy*exp(-distance/ExponentFactor))/distance;
n[2] = n[2] -(ScaleFactor*zz*exp(-distance/ExponentFactor))/distance;
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20031008/84cb0af1/attachment.htm>
More information about the vtkusers
mailing list