[vtkusers] extracting binary label image from poly data contour
kent williams
nkwmailinglists at gmail.com
Wed Feb 18 09:53:13 EST 2009
Lars, I don't know enough about the process you're using, but we do
essentially the same thing in our program, BRAINSTracer, which is a
public project on the NITRC website:
http://www.nitrc.org/projects/brainstracer
We don't do anything nearly that involved; instead, I do this:
Create black image
For each contour
Find contour bounds
For each voxel within contour bounds
If the voxel is inside the contour, set it to white
End
End
You can look at my source code, but it is complicated by a bunch of
other concerns, starting with subsampling the voxel space, and
coloring the voxel if the majority of its subvoxels are inside the
polygon.
The only part of the code is testing polygon membership. There's
probable something to do that in VTK, but I found the function I've
adapted here by googling before I turned up anything in VTK.
// This is a 2D test -- testPoint points to point
// data defined as 'double testPoint[2];' -- and though vtkPoints is
3D point data,
// only the first two components of each point are used.
inline
bool PointInPoly(int numPts,vtkPoints *pts,double *testPoint)
{
int i, j;
bool c(false);
for (i = 0, j = numPts-1; i < numPts; j = i++)
{
double pI[3];
pts->GetPoint(i,pI);
double pJ[3];
pts->GetPoint(j,pJ);
if ((((pI[1] <= testPoint[1]) && (testPoint[1] < pJ[1])) ||
((pJ[1] <= testPoint[1]) && (testPoint[1] < pI[1]))) &&
(testPoint[0] < (pJ[0] - pI[0]) * (testPoint[1] - pI[1]) /
(pJ[1] - pI[1]) + pI[0]))
{
c = !c;
}
}
return c;
}
More information about the vtkusers
mailing list