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