|
8 | 8 | #include <vtkCallbackCommand.h>
|
9 | 9 | #include <vtkCamera.h>
|
10 | 10 | #include <vtkExtractVOI.h>
|
| 11 | +#include <vtkGeometryFilter.h> |
11 | 12 | #include <vtkImageConnectivityFilter.h>
|
12 | 13 | #include <vtkImageDilateErode3D.h>
|
13 | 14 | #include <vtkImageGaussianSmooth.h>
|
@@ -65,6 +66,7 @@ VisualizationContainer::VisualizationContainer(vtkRenderWindowInteractor* volume
|
65 | 66 | filterRegions = false;
|
66 | 67 |
|
67 | 68 | brushRadius = 1;
|
| 69 | + neighborRadius = 0.0; |
68 | 70 |
|
69 | 71 | // Qt main window
|
70 | 72 | qtWindow = mainWindow;
|
@@ -421,6 +423,7 @@ VisualizationContainer::FileErrorCode VisualizationContainer::SaveImageData(cons
|
421 | 423 | shiftScale->SetInputDataObject(data);
|
422 | 424 |
|
423 | 425 | vtkSmartPointer<vtkTIFFWriter> writer = vtkSmartPointer<vtkTIFFWriter>::New();
|
| 426 | + writer->SetCompressionToNoCompression(); |
424 | 427 | writer->SetFileName(fileName.c_str());
|
425 | 428 | writer->SetInputConnection(shiftScale->GetOutputPort());
|
426 | 429 | writer->Update();
|
@@ -458,6 +461,7 @@ VisualizationContainer::FileErrorCode VisualizationContainer::SaveSegmentationDa
|
458 | 461 | }
|
459 | 462 | else if (extension == "tif" || extension == "tiff") {
|
460 | 463 | vtkSmartPointer<vtkTIFFWriter> writer = vtkSmartPointer<vtkTIFFWriter>::New();
|
| 464 | + writer->SetCompressionToNoCompression(); |
461 | 465 | writer->SetFileName(fileName.c_str());
|
462 | 466 | writer->SetInputDataObject(labels);
|
463 | 467 | writer->Update();
|
@@ -945,22 +949,70 @@ void VisualizationContainer::ShowPlaneRegions() {
|
945 | 949 | void VisualizationContainer::ShowNeighborRegions() {
|
946 | 950 | if (!regions) return;
|
947 | 951 |
|
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); |
950 | 970 |
|
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); |
954 | 973 |
|
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 | + } |
958 | 1007 | }
|
959 | 1008 | else {
|
960 | 1009 | region->SetVisible(false);
|
961 | 1010 | }
|
962 | 1011 | }
|
963 |
| - else { |
| 1012 | + } |
| 1013 | + else { |
| 1014 | + for (RegionCollection::Iterator it = regions->Begin(); it != regions->End(); it++) { |
| 1015 | + Region* region = regions->Get(it); |
964 | 1016 | region->SetVisible(false);
|
965 | 1017 | }
|
966 | 1018 | }
|
@@ -2211,6 +2263,14 @@ void VisualizationContainer::SetBrushRadius(int radius) {
|
2211 | 2263 | Render();
|
2212 | 2264 | }
|
2213 | 2265 |
|
| 2266 | +double VisualizationContainer::GetNeighborRadius() { |
| 2267 | + return neighborRadius; |
| 2268 | +} |
| 2269 | + |
| 2270 | +void VisualizationContainer::SetNeighborRadius(double radius) { |
| 2271 | + neighborRadius = radius; |
| 2272 | +} |
| 2273 | + |
2214 | 2274 | void VisualizationContainer::Render() {
|
2215 | 2275 | volumeView->Render();
|
2216 | 2276 | sliceView->Render();
|
|
0 commit comments