Change DragActor transform logic, add map to world mode(once only map to image slice plane )
This commit is contained in:
@@ -72,17 +72,23 @@ DraggableActor::~DraggableActor() {
|
|||||||
renderData = nullptr;
|
renderData = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//暂时只解决正交坐标系问题!!!
|
void DraggableActor::MapScreenPointToWorld(double x, double y, vtkRenderer *renderer, double *result) {
|
||||||
void DraggableActor::GetSlicePlanePoint(double x, double y, vtkRenderer *renderer, double *result) {
|
|
||||||
vtkCamera *camera = renderer->GetActiveCamera();
|
vtkCamera *camera = renderer->GetActiveCamera();
|
||||||
double *fp = camera->GetFocalPoint();
|
double *fp = camera->GetFocalPoint();
|
||||||
double *dp = camera->GetDirectionOfProjection();
|
double *dp = camera->GetDirectionOfProjection();
|
||||||
renderer->SetDisplayPoint(x, y, 0);
|
renderer->SetDisplayPoint(x, y, 0);
|
||||||
renderer->DisplayToWorld();
|
renderer->DisplayToWorld();
|
||||||
double *p = renderer->GetWorldPoint();
|
double *p = renderer->GetWorldPoint();
|
||||||
result[0] = dp[0] > 0.0 ? fp[0] : p[0];
|
if (MapMode == MapToSlice){
|
||||||
result[1] = dp[1] > 0.0 ? fp[1] : p[1];
|
result[0] = dp[0] > 0.0 ? fp[0] : p[0];
|
||||||
result[2] = dp[2] > 0.0 ? fp[2] : p[2];
|
result[1] = dp[1] > 0.0 ? fp[1] : p[1];
|
||||||
|
result[2] = dp[2] > 0.0 ? fp[2] : p[2];
|
||||||
|
}
|
||||||
|
if(MapMode == MapToWorld){
|
||||||
|
result[0] = p[0];
|
||||||
|
result[1] = p[1];
|
||||||
|
result[2] = p[2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggableActor::Transform(float x, float y) {
|
void DraggableActor::Transform(float x, float y) {
|
||||||
@@ -118,7 +124,7 @@ void DraggableActor::ApplyTransform() {
|
|||||||
for (int i = 0; i < renderPoints->GetNumberOfPoints(); i++) {
|
for (int i = 0; i < renderPoints->GetNumberOfPoints(); i++) {
|
||||||
double *pos = renderPoints->GetPoint(i);
|
double *pos = renderPoints->GetPoint(i);
|
||||||
double wpos[3] = {0, 0, 0};
|
double wpos[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, wpos);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, wpos);
|
||||||
BaseDataPoints->InsertNextPoint(wpos);
|
BaseDataPoints->InsertNextPoint(wpos);
|
||||||
}
|
}
|
||||||
//vtk对象内部使用
|
//vtk对象内部使用
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ using DragCallBack = std::function<void(vtkPoints *callData)>;
|
|||||||
|
|
||||||
class DraggableActor : public vtkProp {
|
class DraggableActor : public vtkProp {
|
||||||
public:
|
public:
|
||||||
|
enum PointMapMode{
|
||||||
|
MapToSlice,
|
||||||
|
MapToWorld
|
||||||
|
};
|
||||||
//@{
|
//@{
|
||||||
/**
|
/**
|
||||||
* Standard methods for instances of this class.
|
* Standard methods for instances of this class.
|
||||||
@@ -132,6 +136,7 @@ public:
|
|||||||
|
|
||||||
void Show();
|
void Show();
|
||||||
|
|
||||||
|
vtkSetClampMacro(MapMode,PointMapMode,MapToSlice,MapToWorld);
|
||||||
protected:
|
protected:
|
||||||
DraggableActor();
|
DraggableActor();
|
||||||
|
|
||||||
@@ -148,14 +153,14 @@ protected:
|
|||||||
vtkActor2D *text;
|
vtkActor2D *text;
|
||||||
vtkRenderer *Renderer;
|
vtkRenderer *Renderer;
|
||||||
|
|
||||||
void GetSlicePlanePoint(double x, double y, vtkRenderer *renderer, double *result);
|
void MapScreenPointToWorld(double x, double y, vtkRenderer *renderer, double *result);
|
||||||
|
|
||||||
bool transforming = false;
|
bool transforming = false;
|
||||||
bool Highlighted = false;
|
bool Highlighted = false;
|
||||||
bool Selected = false;
|
bool Selected = false;
|
||||||
|
|
||||||
|
PointMapMode MapMode = MapToSlice;
|
||||||
void RebuildRenderPoint();
|
void RebuildRenderPoint();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DraggableActor(const DraggableActor &) = delete;
|
DraggableActor(const DraggableActor &) = delete;
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ void AngleAnnotationActor::controlPointCb(vtkObject *sender, unsigned long event
|
|||||||
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
||||||
double *pos = pts->GetPoint(0);
|
double *pos = pts->GetPoint(0);
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
BaseDataPoints->SetPoint(index, result);
|
BaseDataPoints->SetPoint(index, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,12 +210,12 @@ void AngleAnnotationActor::selfDragCb(vtkObject *, unsigned long, void *data) {
|
|||||||
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
||||||
double *pos = pts->GetPoint(0);
|
double *pos = pts->GetPoint(0);
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
controlP1->SetWorldPosition(result);
|
controlP1->SetWorldPosition(result);
|
||||||
pos = pts->GetPoint(1);
|
pos = pts->GetPoint(1);
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
controlP2->SetWorldPosition(result);
|
controlP2->SetWorldPosition(result);
|
||||||
pos = pts->GetPoint(2);
|
pos = pts->GetPoint(2);
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
controlP3->SetWorldPosition(result);
|
controlP3->SetWorldPosition(result);
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ void EllipseAnnotationActor::controlPointCb(vtkObject *sender, unsigned long eve
|
|||||||
double *pos = pts->GetPoint(0);
|
double *pos = pts->GetPoint(0);
|
||||||
|
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
|
|
||||||
//BaseDataPoints->SetPoint(index, result);
|
//BaseDataPoints->SetPoint(index, result);
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ void LineAnnotationActor::controlPointCb(vtkObject *sender, unsigned long event,
|
|||||||
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
||||||
double *pos = pts->GetPoint(0);
|
double *pos = pts->GetPoint(0);
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
BaseDataPoints->SetPoint(index, result);
|
BaseDataPoints->SetPoint(index, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,10 +79,10 @@ void LineAnnotationActor::selfDragCb(vtkObject *, unsigned long, void *data) {
|
|||||||
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
||||||
double *pos = pts->GetPoint(0);
|
double *pos = pts->GetPoint(0);
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
controlP1->SetWorldPosition(result);
|
controlP1->SetWorldPosition(result);
|
||||||
pos = pts->GetPoint(1);
|
pos = pts->GetPoint(1);
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
controlP2->SetWorldPosition(result);
|
controlP2->SetWorldPosition(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ void OpenPolyAnnotationActor::selfDragCb(vtkObject *, unsigned long event, void
|
|||||||
for (int i = 0; i < controlPointList.size(); ++i) {
|
for (int i = 0; i < controlPointList.size(); ++i) {
|
||||||
double *pos = pts->GetPoint(i);
|
double *pos = pts->GetPoint(i);
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
controlPointList[i]->SetWorldPosition(result);
|
controlPointList[i]->SetWorldPosition(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ void OpenPolyAnnotationActor::controlPointCb(vtkObject *sender, unsigned long ev
|
|||||||
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
||||||
double *pos = pts->GetPoint(0);
|
double *pos = pts->GetPoint(0);
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
BaseDataPoints->SetPoint(index, result);
|
BaseDataPoints->SetPoint(index, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ void TextAnnotationActor::selfDragCb(vtkObject *, unsigned long, void *data) {
|
|||||||
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
vtkPoints *pts = static_cast<vtkPoints *>(data);
|
||||||
double *pos = pts->GetPoint(0);
|
double *pos = pts->GetPoint(0);
|
||||||
double result[3] = {0, 0, 0};
|
double result[3] = {0, 0, 0};
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
pos = pts->GetPoint(1);
|
pos = pts->GetPoint(1);
|
||||||
GetSlicePlanePoint(pos[0], pos[1], this->Renderer, result);
|
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextAnnotationActor::selfPickCb(vtkObject *, unsigned long, void *data) {
|
void TextAnnotationActor::selfPickCb(vtkObject *, unsigned long, void *data) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "Rendering/Core/SmartFixedPointVolumeRayCastMapper.h"
|
#include "Rendering/Core/SmartFixedPointVolumeRayCastMapper.h"
|
||||||
#include "IO/DICOM/ExtendMedicalImageProperties.h"
|
#include "IO/DICOM/ExtendMedicalImageProperties.h"
|
||||||
#include "Rendering/Measure/ArrowAnnotationActor.h"
|
#include "Rendering/Measure/ArrowAnnotationActor.h"
|
||||||
|
#include "Rendering/Measure/VolArrowAnnotationActor.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
enum ViewDirection{
|
enum ViewDirection{
|
||||||
@@ -621,7 +622,7 @@ void VolumeRenderingViewer::pressedOrientationMarker(vtkObject* sender, unsigned
|
|||||||
void VolumeRenderingViewer::ActiveArrow() {
|
void VolumeRenderingViewer::ActiveArrow() {
|
||||||
auto style = VolumeInteractorStyle::SafeDownCast(this->InteractorStyle);
|
auto style = VolumeInteractorStyle::SafeDownCast(this->InteractorStyle);
|
||||||
if (style){
|
if (style){
|
||||||
style->ActiveMeasure(ArrowAnnotationActor::New());
|
style->ActiveMeasure(VolArrowAnnotationActor::New());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "dicomimageview.h"
|
#include "dicomimageview.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -171,7 +171,7 @@ void DicomImageView::loadSeries(SeriesImageSet *series) {
|
|||||||
|
|
||||||
ActorDraggableInteractorStyle *style = mImageViewer->GetInteractorStyle();
|
ActorDraggableInteractorStyle *style = mImageViewer->GetInteractorStyle();
|
||||||
style->AddObserver(AfterViewerClicked, this, &DicomImageView::clicked);
|
style->AddObserver(AfterViewerClicked, this, &DicomImageView::clicked);
|
||||||
style->AddObserver(vtkCommand::EventIds::WindowLevelEvent, this, &DicomImageView::windowLevelHandle);
|
style->AddObserver(vtkCommand::WindowLevelEvent, this, &DicomImageView::windowLevelHandle);
|
||||||
style->AddObserver(DoubleClickEvent, this, &DicomImageView::doubleClickHandle);
|
style->AddObserver(DoubleClickEvent, this, &DicomImageView::doubleClickHandle);
|
||||||
style->AddObserver(ScalarOpacityEvent, this, &DicomImageView::scalarEventHandle);
|
style->AddObserver(ScalarOpacityEvent, this, &DicomImageView::scalarEventHandle);
|
||||||
style->AddObserver(ScalarShiftEvent, this, &DicomImageView::scalarEventHandle);
|
style->AddObserver(ScalarShiftEvent, this, &DicomImageView::scalarEventHandle);
|
||||||
|
|||||||
Reference in New Issue
Block a user