Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix illegal extent request in ImageThresholdConnectivity.
When asked for an output extent that was smaller than the input extent, this filter would pass an illegal extent to GetScalarPointerForExtent(). It is possible that older versions of VTK would allow this, but in VTK 6 it raises an error. It has a high probability of causing a segfault. Change-Id: Ic024f9aa97335f1ba29b47be89a4e5be8195b00f
- Loading branch information
Showing
5 changed files
with
160 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vtk_add_test_cxx(${vtk-module}CxxTests tests | ||
TestImageThresholdConnectivity.cxx | ||
) | ||
|
||
vtk_test_cxx_executable(${vtk-module}CxxTests tests | ||
RENDERING_FACTORY | ||
) |
133 changes: 133 additions & 0 deletions
133
Imaging/Morphological/Testing/Cxx/TestImageThresholdConnectivity.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/*========================================================================= | ||
Program: Visualization Toolkit | ||
Module: TestImageThresholdConnectivity.cxx | ||
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen | ||
All rights reserved. | ||
See Copyright.txt or http://www.kitware.com/Copyright.htm for details. | ||
This software is distributed WITHOUT ANY WARRANTY; without even | ||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
PURPOSE. See the above copyright notice for more information. | ||
=========================================================================*/ | ||
// Test the vtkImageThresholdConnectivity class | ||
// | ||
// The command line arguments are: | ||
// -I => run in interactive mode | ||
|
||
#include "vtkCamera.h" | ||
#include "vtkImageData.h" | ||
#include "vtkImageProperty.h" | ||
#include "vtkImageReader2.h" | ||
#include "vtkImageSlice.h" | ||
#include "vtkImageSliceMapper.h" | ||
#include "vtkImageThresholdConnectivity.h" | ||
#include "vtkInteractorStyleImage.h" | ||
#include "vtkPoints.h" | ||
#include "vtkRenderWindow.h" | ||
#include "vtkRenderWindowInteractor.h" | ||
#include "vtkRenderer.h" | ||
#include "vtkSmartPointer.h" | ||
|
||
#include "vtkTestUtilities.h" | ||
|
||
int TestImageThresholdConnectivity(int argc, char *argv[]) | ||
{ | ||
vtkSmartPointer<vtkRenderWindowInteractor> iren = | ||
vtkSmartPointer<vtkRenderWindowInteractor>::New(); | ||
vtkSmartPointer<vtkInteractorStyleImage> style = | ||
vtkSmartPointer<vtkInteractorStyleImage>::New(); | ||
style->SetInteractionModeToImageSlicing(); | ||
vtkSmartPointer<vtkRenderWindow> renWin = | ||
vtkSmartPointer<vtkRenderWindow>::New(); | ||
iren->SetRenderWindow(renWin); | ||
iren->SetInteractorStyle(style); | ||
|
||
char* fname = | ||
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter"); | ||
|
||
vtkSmartPointer<vtkImageReader2> reader = | ||
vtkSmartPointer<vtkImageReader2>::New(); | ||
reader->SetDataByteOrderToLittleEndian(); | ||
reader->SetDataExtent(0, 63, 0, 63, 2, 4); | ||
reader->SetDataSpacing(3.2, 3.2, 1.5); | ||
reader->SetFilePrefix(fname); | ||
|
||
delete [] fname; | ||
|
||
vtkSmartPointer<vtkPoints> seeds = | ||
vtkSmartPointer<vtkPoints>::New(); | ||
seeds->InsertNextPoint(1, 1, 5.25); | ||
seeds->InsertNextPoint(100.8, 100.8, 5.25); | ||
|
||
for (int i = 0; i < 12; i++) | ||
{ | ||
int j = i % 4; | ||
int k = i / 4; | ||
vtkSmartPointer<vtkRenderer> renderer = | ||
vtkSmartPointer<vtkRenderer>::New(); | ||
vtkCamera *camera = renderer->GetActiveCamera(); | ||
renderer->SetBackground(0.0, 0.0, 0.0); | ||
renderer->SetViewport(k/3.0, j/4.0, (k + 1)/3.0, (j + 1)/4.0); | ||
renWin->AddRenderer(renderer); | ||
|
||
vtkSmartPointer<vtkImageThresholdConnectivity> connectivity = | ||
vtkSmartPointer<vtkImageThresholdConnectivity>::New(); | ||
connectivity->SetInputConnection(reader->GetOutputPort()); | ||
connectivity->SetSeedPoints(seeds); | ||
connectivity->SetInValue(2000); | ||
connectivity->SetOutValue(0); | ||
connectivity->SetReplaceIn((j & 2) == 0); | ||
connectivity->SetReplaceOut((j & 1) == 0); | ||
if (k == 0) | ||
{ | ||
connectivity->ThresholdByLower(800); | ||
} | ||
else if (k == 1) | ||
{ | ||
connectivity->ThresholdByUpper(1200); | ||
} | ||
else | ||
{ | ||
connectivity->ThresholdBetween(800, 1200); | ||
} | ||
|
||
// test a previous bug where OutputExtent != InputExtent cause a crash. | ||
int extent[6] = { 0, 63, 0, 63, 3, 3 }; | ||
connectivity->UpdateInformation(); | ||
connectivity->SetUpdateExtent(extent); | ||
connectivity->Update(); | ||
|
||
vtkSmartPointer<vtkImageSliceMapper> imageMapper = | ||
vtkSmartPointer<vtkImageSliceMapper>::New(); | ||
imageMapper->SetInputConnection(connectivity->GetOutputPort()); | ||
imageMapper->BorderOn(); | ||
imageMapper->SliceFacesCameraOn(); | ||
imageMapper->SliceAtFocalPointOn(); | ||
|
||
double point[3] = { 100.8, 100.8, 5.25 }; | ||
camera->SetFocalPoint(point); | ||
point[2] += 500.0; | ||
camera->SetPosition(point); | ||
camera->SetViewUp(0.0, 1.0, 0.0); | ||
camera->ParallelProjectionOn(); | ||
camera->SetParallelScale(3.2*32); | ||
|
||
vtkSmartPointer<vtkImageSlice> image = | ||
vtkSmartPointer<vtkImageSlice>::New(); | ||
image->SetMapper(imageMapper); | ||
image->GetProperty()->SetColorWindow(2000); | ||
image->GetProperty()->SetColorLevel(1000); | ||
renderer->AddViewProp(image); | ||
} | ||
|
||
renWin->SetSize(192, 256); | ||
|
||
iren->Initialize(); | ||
renWin->Render(); | ||
iren->Start(); | ||
|
||
return EXIT_SUCCESS; | ||
} |
1 change: 1 addition & 0 deletions
1
Imaging/Morphological/Testing/Data/Baseline/TestImageThresholdConnectivity.png.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
743051aab9188a75d9ecc13a506d27fa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters