Hi, I tired to use the "operation" feature of the paintbrush widget in a medical imaging application I am working on. I used it almost exactly as in vtkedge\Examples\GUI\KWWidgets\PaintbrushExample5.cxx however it always crashed. after some debugging I found that vtkKWEITKConfidenceConnectedPaintbrushOperation class probably has the following bug:
It does not take the origin of an image into account, and since the 3D
dataset used in the example had an origin of (0,0,0) it worked there.
I changed the code from :
template< class T > int
PaintbrushRunner( vtkKWEITKConfidenceConnectedPaintbrushOperation * self,
double center[3],
vtkImageStencilData *stencil,
T )
{
self->InternalFilter = NULL;
typedef vtkitk::vtkKWEITKConfidenceConnectedImageFilter< T >
PaintbrushFilterType;
typename PaintbrushFilterType::Pointer filter =
PaintbrushFilterType::New();
self->InternalFilter = filter;
// Set the update region to a certain region on either side of the center
int extent[6], imageExtent[6];
double spacing[3], origin[3];
self->GetImageData()->GetSpacing(spacing);
self->GetImageData()->GetExtent(imageExtent);
// Set the center and radius to mask out a spherical stencil, instead of
// one with rectangular jagged edges.
self->GetImageData()->GetOrigin(origin);
double radiusFactor = 10.0 * spacing[0];
int xyz[3] = { (int)(center[0]/spacing[0] + 0.5),
(int)(center[1]/spacing[1] + 0.5),
(int)(center[2]/spacing[2] + 0.5) };
double radius[3] = { radiusFactor/spacing[0],
radiusFactor/spacing[1],
radiusFactor/spacing[2] };
extent[0] = (int)((center[0] - radiusFactor)/spacing[0] + 0.5);
extent[1] = (int)((center[0] + radiusFactor)/spacing[0] + 0.5);
extent[2] = (int)((center[1] - radiusFactor)/spacing[1] + 0.5);
extent[3] = (int)((center[1] + radiusFactor)/spacing[1] + 0.5);
extent[4] = (int)((center[2] - radiusFactor)/spacing[2] + 0.5);
extent[5] = (int)((center[2] + radiusFactor)/spacing[2] + 0.5);
vtkKWEPaintbrushUtilities::GetIntersectingExtents(extent, imageExtent,
extent);
to:
template< class T > int
PaintbrushRunner( vtkKWEITKConfidenceConnectedPaintbrushOperation * self,
double center[3],
vtkImageStencilData *stencil,
T )
{
self->InternalFilter = NULL;
typedef vtkitk::vtkKWEITKConfidenceConnectedImageFilter< T >
PaintbrushFilterType;
typename PaintbrushFilterType::Pointer filter =
PaintbrushFilterType::New();
self->InternalFilter = filter;
// Set the update region to a certain region on either side of the center
int extent[6], imageExtent[6];
double spacing[3], origin[3];
self->GetImageData()->GetSpacing(spacing);
self->GetImageData()->GetExtent(imageExtent);
// Set the center and radius to mask out a spherical stencil, instead of
// one with rectangular jagged edges.
self->GetImageData()->GetOrigin(origin);
double radiusFactor = 5.0 * spacing[0];
int xyz[3] = { (int)((center[0]-origin[0])/spacing[0] + 0.5),
(int)((center[1]-origin[1])/spacing[1] + 0.5),
(int)((center[2]-origin[2])/spacing[2] + 0.5) };
double radius[3] = { radiusFactor/spacing[0],
radiusFactor/spacing[1],
radiusFactor/spacing[2] };
extent[0] = (int)((center[0] - radiusFactor-origin[0])/spacing[0] + 0.5);
extent[1] = (int)((center[0] + radiusFactor-origin[0])/spacing[0] + 0.5);
extent[2] = (int)((center[1] - radiusFactor-origin[1])/spacing[1] + 0.5);
extent[3] = (int)((center[1] + radiusFactor-origin[1])/spacing[1] + 0.5);
extent[4] = (int)((center[2] - radiusFactor-origin[2])/spacing[2] + 0.5);
extent[5] = (int)((center[2] + radiusFactor-origin[2])/spacing[2] + 0.5);
vtkKWEPaintbrushUtilities::GetIntersectingExtents(extent, imageExtent,
extent);
and now it is working. I have attached a patch with the changes to this
mail.
Thanks,
Ahmed
P.S. a similar situation might exist in
vtkKWEITKConnectedThresholdPaintbrushOperation it did not work right out of
the box for me, I had to play around the code a little. Let me know if you
need a batch for that one too, I'll clean up my changes and submit it.
patch1.patch
Description: Binary data
_______________________________________________ VtkEdge mailing list [email protected] http://public.kitware.com/cgi-bin/mailman/listinfo/vtkedge
