Skip to content

Commit

Permalink
Implement region highlighting from table for 3D view
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborland committed Jan 3, 2020
1 parent 13b3e4a commit c847597
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 17 deletions.
28 changes: 21 additions & 7 deletions Region.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "RegionSurface.h"
#include "RegionOutline.h"
#include "RegionVoxelOutlines.h"
#include "RegionHighlight3D.h"

Region::Region(unsigned short regionLabel, double regionColor[3], vtkImageData* inputData) {
modified = false;
Expand Down Expand Up @@ -79,11 +80,13 @@ Region::Region(unsigned short regionLabel, double regionColor[3], vtkImageData*
threshold->ThresholdBetween(label, label);
threshold->SetInputConnection(cells->GetOutputPort());

UpdateExtent();
voi->Update();

surface = new RegionSurface(this, color);
outline = new RegionOutline(this, color);
voxelOutlines = new RegionVoxelOutlines(this, color);

UpdateExtent();
highlight3D = new RegionHighlight3D(this, color, inputData->GetLength() * 0.01);
}

Region::~Region() {
Expand Down Expand Up @@ -113,6 +116,10 @@ RegionVoxelOutlines* Region::GetVoxelOutlines() {
return voxelOutlines;
}

RegionHighlight3D* Region::GetHighlight3D() {
return highlight3D;
}

void Region::SetExtent(int newExtent[6]) {
for (int i = 0; i < 6; i++) {
extent[i] = newExtent[i];
Expand Down Expand Up @@ -174,10 +181,18 @@ void Region::UpdateExtent() {
voi->SetVOI(padExtent);
}

bool Region::GetModified() {
return modified;
}

void Region::SetModified(bool isModified) {
modified = isModified;
}

bool Region::GetDone() {
return done;
}

void Region::SetDone(bool isDone) {
done = isDone;

Expand Down Expand Up @@ -218,15 +233,14 @@ const int* Region::GetExtent() {
return extent;
}

bool Region::GetDone() {
return done;
double* Region::GetCenter() {
return voi->GetOutput()->GetCenter();
}

bool Region::GetModified() {
return modified;
double Region::GetLength() {
return voi->GetOutput()->GetLength();
}


void Region::ClearLabels() {
for (int i = extent[0]; i <= extent[1]; i++) {
for (int j = extent[2]; j <= extent[3]; j++) {
Expand Down
12 changes: 9 additions & 3 deletions Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class vtkImageDataCells;
class RegionSurface;
class RegionOutline;
class RegionVoxelOutlines;
class RegionHighlight3D;

class Region {
public:
Expand All @@ -26,20 +27,23 @@ class Region {
RegionSurface* GetSurface();
RegionOutline* GetOutline();
RegionVoxelOutlines* GetVoxelOutlines();
RegionHighlight3D* GetHighlight3D();

void SetExtent(int newExtent[6]);
void UpdateExtent(int x, int y, int z);

bool GetModified();
void SetModified(bool isModified);

bool GetDone();
void SetDone(bool isDone);

unsigned short GetLabel();
const double* GetColor();
int GetNumVoxels();
const int* GetExtent();

bool GetModified();
bool GetDone();
double* GetCenter();
double GetLength();

protected:
unsigned short label;
Expand All @@ -57,6 +61,8 @@ class Region {
RegionOutline* outline;
RegionVoxelOutlines* voxelOutlines;

RegionHighlight3D* highlight3D;

void UpdateExtent();
void ClearLabels();
};
Expand Down
51 changes: 51 additions & 0 deletions RegionHighlight3D.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "RegionHighlight3D.h"

#include <vtkActor.h>
#include <vtkDiskSource.h>
#include <vtkLookupTable.h>
#include <vtkFollower.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>

#include "Region.h"

RegionHighlight3D::RegionHighlight3D(Region* inputRegion, double color[3], double width) {
region = inputRegion;

double r = region->GetLength() / 2;
double ir = r;
double or = ir + width;

vtkSmartPointer<vtkDiskSource> disk = vtkSmartPointer<vtkDiskSource>::New();
disk->SetInnerRadius(ir);
disk->SetOuterRadius(or);
disk->SetCircumferentialResolution(32);

vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->ScalarVisibilityOff();
mapper->SetInputConnection(disk->GetOutputPort());

actor = vtkSmartPointer<vtkFollower>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(color);
actor->GetProperty()->SetDiffuse(0.0);
actor->GetProperty()->SetAmbient(1.0);
actor->GetProperty()->SetSpecular(0.0);
actor->GetProperty()->SetOpacity(0.5);
actor->SetPosition(region->GetCenter());
}

RegionHighlight3D::~RegionHighlight3D() {
while (actor->GetNumberOfConsumers() > 0) {
vtkRenderer::SafeDownCast(actor->GetConsumer(0))->RemoveActor(actor);
}
}

void RegionHighlight3D::SetCamera(vtkCamera* camera) {
actor->SetCamera(camera);
}

vtkSmartPointer<vtkActor> RegionHighlight3D::GetActor() {
return actor;
}
27 changes: 27 additions & 0 deletions RegionHighlight3D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef RegionHighlight3D_H
#define RegionHighlight3D_H

#include "vtkSmartPointer.h"

class vtkActor;
class vtkCamera;
class vtkFollower;

class Region;

class RegionHighlight3D {
public:
RegionHighlight3D(Region* inputRegion, double color[3], double width);
~RegionHighlight3D();

void SetCamera(vtkCamera* camera);

vtkSmartPointer<vtkActor> GetActor();

protected:
Region* region;

vtkSmartPointer<vtkFollower> actor;
};

#endif
8 changes: 6 additions & 2 deletions RegionTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ void RegionTable::on_cellEntered(int row, int column) {
ti->setBackgroundColor(QColor("white"));
}
}

emit(highlightRegion(rowLabel(row)));
}
else {
// Clear highlight
Expand All @@ -229,9 +231,9 @@ void RegionTable::on_cellEntered(int row, int column) {

ti->setBackgroundColor(QColor("white"));
}
}

emit(highlightRegion(rowLabel(row)));
emit(highlightRegion(0));
}
}

void RegionTable::on_cellClicked(int row, int column) {
Expand All @@ -249,6 +251,8 @@ void RegionTable::leaveEvent(QEvent* event) {

ti->setBackgroundColor(QColor("white"));
}

emit(highlightRegion(0));
}

int RegionTable::rowLabel(int row) {
Expand Down
4 changes: 2 additions & 2 deletions VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,8 @@ void VisualizationContainer::RemoveRegion(unsigned short label) {
void VisualizationContainer::HighlightRegion(unsigned short label) {
Region* region = regions->Get(label);

// std::cout << "HIGHLIGHT" << std::endl;

volumeView->HighlightRegion(region);
Render();
}

Expand Down
24 changes: 21 additions & 3 deletions VolumeView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "InteractionEnums.h"
#include "Region.h"
#include "RegionSurface.h"
#include "RegionHighlight3D.h"
#include "RegionCollection.h"

double rescale(double value, double min, double max) {
Expand Down Expand Up @@ -124,10 +125,17 @@ void VolumeView::SetRegions(vtkImageData* data, RegionCollection* newRegions) {
}

void VolumeView::AddRegion(Region* region) {
region->GetSurface()->SetSmoothSurface(smoothSurfaces);
region->GetSurface()->SetSmoothShading(smoothShading);
RegionSurface* surface = region->GetSurface();
RegionHighlight3D* highlight = region->GetHighlight3D();

renderer->AddActor(region->GetSurface()->GetActor());
surface->SetSmoothSurface(smoothSurfaces);
surface->SetSmoothShading(smoothShading);

highlight->GetActor()->VisibilityOff();
highlight->SetCamera(renderer->GetActiveCamera());

renderer->AddActor(surface->GetActor());
renderer->AddActor(highlight->GetActor());
}

void VolumeView::SetCurrentRegion(Region* region) {
Expand All @@ -144,6 +152,16 @@ void VolumeView::SetCurrentRegion(Region* region) {
FilterRegions();
}

void VolumeView::HighlightRegion(Region* region) {
for (RegionCollection::Iterator it = regions->Begin(); it != regions->End(); it++) {
regions->Get(it)->GetHighlight3D()->GetActor()->VisibilityOff();
}

if (region) {
region->GetHighlight3D()->GetActor()->VisibilityOn();
}
}

void VolumeView::SetShowProbe(bool show) {
probe->SetVisibility(show && regions != nullptr);
}
Expand Down
2 changes: 2 additions & 0 deletions VolumeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class VolumeView {

void SetCurrentRegion(Region* region);

void HighlightRegion(Region* region);

bool GetSmoothSurfaces();
void SetSmoothSurfaces(bool smooth);
void ToggleSmoothSurfaces();
Expand Down

0 comments on commit c847597

Please sign in to comment.