vtk.js鼠標左鍵滑動改變窗比特和窗寬

小江江12 2022-06-23 07:53:08 阅读数:175

vtk.jsvtkjs比特
var that = this;
function DragObj(selector) {
//保存節點
this.ele = $(selector).get(0);
//調用startDrag
this.startDrag();
}
/*封裝startDrag方法*/
DragObj.prototype.startDrag = function () {
var self = this;
//給當前對象的節點添加mousedown事件,鼠標按下事件後執行滑動事件
$(self.ele).on({
mousedown: function () {
self.drag();
}
})
}
/*封裝滑動事件*/
DragObj.prototype.drag = function () {
var self = this;
/*初始化self.newDisance*/
self.newDisance = {
X:that.vtkObj['imageActorI'].getProperty().getColorLevel(),
Y:that.vtkObj['imageActorI'].getProperty().getColorWindow()
}
//給X窗口對象添加移動和結束事件
$('#contentX').on({
/*根據移動的距離來判斷器是增加灰度還是减小灰度,左右為wl,上下為ww*/
mousemove: function (oEvent) {
if(self.disance && self.disance.X){
self.newDisance.X = that.vtkObj['imageActorI'].getProperty().getColorLevel() + (oEvent.pageX - self.disance.X);
self.newDisance.Y = that.vtkObj['imageActorI'].getProperty().getColorWindow() + (oEvent.pageY - self.disance.Y);
}
self.disance = {
X: oEvent.pageX,
Y: oEvent.pageY
};
//矢狀面,冠狀面,軸向面同時改變窗比特和窗寬
['X','Y','Z'].forEach((type) => {
that.vtkObj['imageActor' + that.typeMap[type]].getProperty().setColorLevel(self.newDisance.X);
that.vtkObj['imageActor' + that.typeMap[type]].getProperty().setColorWindow(self.newDisance.Y);
})
$(".colorLevel").val(self.newDisance.X);
$(".colorWindow").val(self.newDisance.Y);
},
mouseup: function () {
/*放開鼠標後重置距離,讓其重新計算*/
self.disance = {};
self.newDisance = {
X:that.vtkObj['imageActorI'].getProperty().getColorLevel(),
Y:that.vtkObj['imageActorI'].getProperty().getColorWindow()
};
$("#contentX").off('mousemove mouseup');
}
})
}
new DragObj('#contentX');

 

版权声明:本文为[小江江12]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/174/202206230726577767.html