[Insight-users] BinaryMask3DMeshSource and AntiAliasBinaryImageFilter

Paweł Andruszkiewicz pandruszkiewicz at o2.pl
Thu Nov 22 12:11:20 EST 2007


Hello

I'm using some segmentation routine to generate list of points being the
contour of 3D object. From this list I'm creating a binary image, which is
passed to BinaryMask3DMeshSource and using the output mesh to visualize the object
in OpenGL. However, the resulting object is not very smooth. I've read the
mailing list, and some of the posts mention the AntiAliasBinaryImageFilter as
a solution for this issue. When I try to apply this filter before the
BinaryMask3DMeshSource, I get 0 cells. What is the better way to acquire smooth
object? (note, that using the VTK is not possible). Also, if somebody can confirm
if my code iterating through the cells is correct, I'll be grateful.

The code:

typedef signed short PixelType;
typedef double DoublePixelType;
const unsigned int Dimension = 3;
typedef itk::Image<PixelType, Dimension> ImageType;
typedef itk::Image<DoublePixelType, Dimension> DoubleImageType;

typedef itk::AntiAliasBinaryImageFilter<DoubleImageType, DoubleImageType>
AntiAliasFilterType;
typedef itk::BinaryMask3DMeshSource<ImageType, MeshType> MeshSourceType;
typedef itk::CastImageFilter<DoubleImageType, ImageType>
CastToShortFilterType;
typedef itk::CastImageFilter<ImageType, DoubleImageType>
CastToDoubleFilterType;

typedef itk::Mesh<double, Dimension> MeshType;
typedef MeshType::CellsContainer::ConstIterator CellIterator;
typedef MeshType::CellType CellType;
typedef itk::TriangleCell<CellType> TriangleType;

//...
ImageType::Pointer image;
//...
//image is filled with 0's and the pixels containing the border are set to
1
//...
CastToDoubleFilterType::Pointer castToDouble =
CastToDoubleFilterType::New();
castToDouble->SetInput(image);

AntiAliasFilterType::Pointer antiAliasFilter = AntiAliasFilterType::New();
antiAliasFilter->SetMaximumRMSError(0.07);
antiAliasFilter->SetNumberOfIterations(30);
antiAliasFilter->SetNumberOfLayers(2);
antiAliasFilter->SetInput(castToDouble->GetOutput());
	
CastToShortFilterType::Pointer castToShort = CastToShortFilterType::New();
castToShort->SetInput(antiAliasFilter->GetOutput());
	
MeshSourceType::Pointer meshSource = MeshSourceType::New();
meshSource->SetObjectValue(1);
meshSource->SetInput(castToShort->GetOutput());

try {
    meshSource->Update();
    MeshType::Pointer mesh = meshSource->GetOutput();
    //...
    glBegin(GL_TRIANGLES);

    CellIterator cellIterator = mesh->GetCells()->Begin();
    CellIterator cellEnd = mesh->GetCells()->End();

    while(cellIterator != cellEnd) {
        CellType *cell = cellIterator.Value();
        if(cell->GetType() == CellType::TRIANGLE_CELL) {
            TriangleType *triangle = dynamic_cast<TriangleType *>(cell);
            TriangleType::PointIdIterator pit = triangle->PointIdsBegin();
            MeshType::PointType p;

            mesh->GetPoint(*pit++, &p);
            GLdouble y = computeY(p[2]);
            GLdouble x = computeX(p[0]);
            GLdouble z = computeZ(p[1]);
            glVertex3d(x, y, z);
    		
            mesh->GetPoint(*pit++, &p);
            y = computeY(p[2]);
            x = computeX(p[0]);
            z = computeZ(p[1]);
            glVertex3d(x, y, z);

            mesh->GetPoint(*pit++, &p);
            y = computeY(p[2]);
            x = computeX(p[0]);
            z = computeZ(p[1]);
            glVertex3d(x, y, z);
        }
    	
        ++cellIterator;
    }

    glEnd();
} catch( itk::ExceptionObject & ex ){
//report the error
}

kind regards, Pawel Andruszkiewicz


More information about the Insight-users mailing list