Skip to content

Commit d5d8f37

Browse files
committed
Add neighbor radius control, use more accurate neighbor method
1 parent 9a8cd66 commit d5d8f37

6 files changed

+133
-12
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ set(UI_RESOURCES
6767
# Create executable
6868
qt5_wrap_ui(UISrcs ${UI_FILES} )
6969
# CMAKE_AUTOMOC is ON so the MOC headers will be automatically wrapped.
70-
add_executable(Segmentor MACOSX_BUNDLE WIN32 ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
71-
#add_executable(Segmentor MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
70+
#add_executable(Segmentor MACOSX_BUNDLE WIN32 ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
71+
add_executable(Segmentor MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
7272
qt5_use_modules(Segmentor Core Gui)
7373
target_link_libraries(Segmentor ${VTK_LIBRARIES})
7474
install(TARGETS Segmentor

qt/SettingsDialog.cxx

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ void SettingsDialog::initializeSettings() {
5353

5454
// Surface opacity
5555
surfaceOpacitySpinBox->setValue(volumeView->GetVisibleOpacity());
56+
57+
// Neighbor radius
58+
neighborRadiusSpinBox->setValue(visualizationContainer->GetNeighborRadius());
5659
}
5760

5861
void SettingsDialog::on_windowSpinBox_valueChanged(double value) {
@@ -87,6 +90,10 @@ void SettingsDialog::on_surfaceOpacityDown() {
8790
surfaceOpacitySpinBox->stepDown();
8891
}
8992

93+
void SettingsDialog::on_neighborRadiusSpinBox_valueChanged(double value) {
94+
visualizationContainer->SetNeighborRadius(value);
95+
}
96+
9097
void SettingsDialog::on_voxelSizeSpinBox() {
9198
visualizationContainer->SetVoxelSize(
9299
xSizeSpinBox->value(),

qt/SettingsDialog.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public slots:
3131
virtual void on_surfaceOpacityUp();
3232
virtual void on_surfaceOpacityDown();
3333

34+
virtual void on_neighborRadiusSpinBox_valueChanged(double value);
35+
3436
virtual void on_voxelSizeSpinBox();
3537

3638
virtual void on_windowLevelChanged(double window, double level);

qt/SettingsDialog.ui

+47-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>314</width>
10-
<height>425</height>
10+
<height>486</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -299,6 +299,52 @@
299299
</layout>
300300
</widget>
301301
</item>
302+
<item>
303+
<widget class="QGroupBox" name="groupBox_6">
304+
<property name="title">
305+
<string>Neighbor visibility</string>
306+
</property>
307+
<layout class="QVBoxLayout" name="verticalLayout_6">
308+
<item>
309+
<layout class="QHBoxLayout" name="horizontalLayout_9">
310+
<item>
311+
<widget class="QLabel" name="label_5">
312+
<property name="text">
313+
<string>Radius</string>
314+
</property>
315+
</widget>
316+
</item>
317+
<item>
318+
<spacer name="horizontalSpacer_5">
319+
<property name="orientation">
320+
<enum>Qt::Horizontal</enum>
321+
</property>
322+
<property name="sizeHint" stdset="0">
323+
<size>
324+
<width>40</width>
325+
<height>20</height>
326+
</size>
327+
</property>
328+
</spacer>
329+
</item>
330+
<item>
331+
<widget class="QDoubleSpinBox" name="neighborRadiusSpinBox">
332+
<property name="minimum">
333+
<double>0.000000000000000</double>
334+
</property>
335+
<property name="maximum">
336+
<double>10.000000000000000</double>
337+
</property>
338+
<property name="singleStep">
339+
<double>1.000000000000000</double>
340+
</property>
341+
</widget>
342+
</item>
343+
</layout>
344+
</item>
345+
</layout>
346+
</widget>
347+
</item>
302348
<item>
303349
<widget class="QGroupBox" name="groupBox_4">
304350
<property name="title">

visualization/VisualizationContainer.cxx

+69-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <vtkCallbackCommand.h>
99
#include <vtkCamera.h>
1010
#include <vtkExtractVOI.h>
11+
#include <vtkGeometryFilter.h>
1112
#include <vtkImageConnectivityFilter.h>
1213
#include <vtkImageDilateErode3D.h>
1314
#include <vtkImageGaussianSmooth.h>
@@ -65,6 +66,7 @@ VisualizationContainer::VisualizationContainer(vtkRenderWindowInteractor* volume
6566
filterRegions = false;
6667

6768
brushRadius = 1;
69+
neighborRadius = 0.0;
6870

6971
// Qt main window
7072
qtWindow = mainWindow;
@@ -421,6 +423,7 @@ VisualizationContainer::FileErrorCode VisualizationContainer::SaveImageData(cons
421423
shiftScale->SetInputDataObject(data);
422424

423425
vtkSmartPointer<vtkTIFFWriter> writer = vtkSmartPointer<vtkTIFFWriter>::New();
426+
writer->SetCompressionToNoCompression();
424427
writer->SetFileName(fileName.c_str());
425428
writer->SetInputConnection(shiftScale->GetOutputPort());
426429
writer->Update();
@@ -458,6 +461,7 @@ VisualizationContainer::FileErrorCode VisualizationContainer::SaveSegmentationDa
458461
}
459462
else if (extension == "tif" || extension == "tiff") {
460463
vtkSmartPointer<vtkTIFFWriter> writer = vtkSmartPointer<vtkTIFFWriter>::New();
464+
writer->SetCompressionToNoCompression();
461465
writer->SetFileName(fileName.c_str());
462466
writer->SetInputDataObject(labels);
463467
writer->Update();
@@ -945,22 +949,70 @@ void VisualizationContainer::ShowPlaneRegions() {
945949
void VisualizationContainer::ShowNeighborRegions() {
946950
if (!regions) return;
947951

948-
for (RegionCollection::Iterator it = regions->Begin(); it != regions->End(); it++) {
949-
Region* region = regions->Get(it);
952+
if (currentRegion) {
953+
int extent[6];
954+
currentRegion->GetExtent(extent);
955+
956+
double a[6];
957+
a[0] = extent[0] - neighborRadius;
958+
a[1] = extent[1] + neighborRadius;
959+
a[2] = extent[2] - neighborRadius;
960+
a[3] = extent[3] + neighborRadius;
961+
a[4] = extent[4] - neighborRadius;
962+
a[5] = extent[5] + neighborRadius;
963+
964+
vtkSmartPointer<vtkGeometryFilter> aSurface = vtkSmartPointer<vtkGeometryFilter>::New();
965+
aSurface->SetInputConnection(currentRegion->GetCells());
966+
aSurface->Update();
967+
968+
for (RegionCollection::Iterator it = regions->Begin(); it != regions->End(); it++) {
969+
Region* region = regions->Get(it);
950970

951-
if (currentRegion) {
952-
double d = sqrt(vtkMath::Distance2BetweenPoints(currentRegion->GetCenter(), region->GetCenter()));
953-
double r = (currentRegion->GetLength() + region->GetLength()) / 4;
971+
int b[6];
972+
region->GetExtent(b);
954973

955-
if (d <= r * 1.05) {
956-
region->SetVisible(true);
957-
//surface->GetActor()->GetProperty()->SetOpacity(neighborOpacity);
974+
bool intersect = !(
975+
b[0] > a[1] || b[1] < a[0] ||
976+
b[2] > a[3] || b[3] < a[2] ||
977+
b[4] > a[5] || b[5] < a[4]
978+
);
979+
980+
if (intersect) {
981+
vtkSmartPointer<vtkGeometryFilter> bSurface = vtkSmartPointer<vtkGeometryFilter>::New();
982+
bSurface->SetInputConnection(region->GetCells());
983+
bSurface->Update();
984+
985+
double min = VTK_DOUBLE_MAX;
986+
for (int i = 0; i < aSurface->GetOutput()->GetNumberOfPoints(); i++) {
987+
double a[3];
988+
aSurface->GetOutput()->GetPoint(i, a);
989+
990+
for (int j = 0; j < bSurface->GetOutput()->GetNumberOfPoints(); j++) {
991+
double b[3];
992+
bSurface->GetOutput()->GetPoint(j, b);
993+
994+
double d = vtkMath::Distance2BetweenPoints(a, b);
995+
996+
if (d < min) min = d;
997+
}
998+
}
999+
1000+
if (min <= neighborRadius) {
1001+
region->SetVisible(true);
1002+
//surface->GetActor()->GetProperty()->SetOpacity(neighborOpacity);
1003+
}
1004+
else {
1005+
region->SetVisible(false);
1006+
}
9581007
}
9591008
else {
9601009
region->SetVisible(false);
9611010
}
9621011
}
963-
else {
1012+
}
1013+
else {
1014+
for (RegionCollection::Iterator it = regions->Begin(); it != regions->End(); it++) {
1015+
Region* region = regions->Get(it);
9641016
region->SetVisible(false);
9651017
}
9661018
}
@@ -2211,6 +2263,14 @@ void VisualizationContainer::SetBrushRadius(int radius) {
22112263
Render();
22122264
}
22132265

2266+
double VisualizationContainer::GetNeighborRadius() {
2267+
return neighborRadius;
2268+
}
2269+
2270+
void VisualizationContainer::SetNeighborRadius(double radius) {
2271+
neighborRadius = radius;
2272+
}
2273+
22142274
void VisualizationContainer::Render() {
22152275
volumeView->Render();
22162276
sliceView->Render();

visualization/VisualizationContainer.h

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class VisualizationContainer {
130130
int GetBrushRadius();
131131
void SetBrushRadius(int radius);
132132

133+
double GetNeighborRadius();
134+
void SetNeighborRadius(double radius);
135+
133136
void Render();
134137

135138
void Undo();
@@ -191,6 +194,9 @@ class VisualizationContainer {
191194
// Brush radius
192195
int brushRadius;
193196

197+
// Neighbor radius
198+
double neighborRadius;
199+
194200
void SetImageData(vtkImageData* imageData);
195201
bool SetLabelData(vtkImageData* labelData, const std::vector<RegionInfo>& metadata);
196202

0 commit comments

Comments
 (0)