Commit bda13aa1 authored by Emmanuel Promayon's avatar Emmanuel Promayon

FIXED infinite loop in vtk mesh stencil writer

Prevented by providing non-zero dimension and spacing to compute
the stencil (automatically compute dimension if equals to zero)
parent 08517a8f
......@@ -65,7 +65,7 @@ MeshToImageStencil::MeshToImageStencil(ActionExtension* extension) : Action(exte
Property* originProperty = new Property(tr("Origin"), QVariant(QVector3D(0.0, 0.0, 0.0)), tr("The origin frame position"), "");
addParameter(originProperty);
Property* spacingProperty = new Property(tr("Spacing"), QVariant(QVector3D(0.0, 0.0, 0.0)), tr("The spacing between each voxel"), "");
Property* spacingProperty = new Property(tr("Spacing"), QVariant(QVector3D(1.0, 1.0, 1.0)), tr("The spacing between each voxel"), "");
addParameter(spacingProperty);
Property* outputFileProperty = new Property(tr("Output file"), "", tr("The output filename"), "");
......@@ -124,10 +124,18 @@ Action::ApplyStatus MeshToImageStencil::process(MeshComponent* comp) {
// compute dimensions
int dim[3];
dim[0] = dimension.x();
dim[1] = dimension.y();
dim[2] = dimension.z();
// if no dimension are specified used the bounds and spacing to compute a default value
if (dimension.x() == dimension.y() == dimension.z() == 0.0) {
for (int i = 0; i < 3; i++) {
dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) / spacing[i]));
}
CAMITK_WARNING(QString("Dimensions not set → set to (%1,%2,%3), deduced using bounds and spacing").arg(dim[0]).arg(dim[1]).arg(dim[2]));
}
else {
dim[0] = dimension.x();
dim[1] = dimension.y();
dim[2] = dimension.z();
}
colorImage->SetDimensions(dim);
colorImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);
......@@ -160,8 +168,6 @@ Action::ApplyStatus MeshToImageStencil::process(MeshComponent* comp) {
vtkSmartPointer<vtkImageStencil> imgstenc = vtkSmartPointer<vtkImageStencil>::New();
imgstenc->SetInputData(colorImage);
imgstenc->SetStencilConnection(pol2stenc->GetOutputPort());
imgstenc->ReverseStencilOff();
imgstenc->SetBackgroundValue(outval);
imgstenc->Update();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment