vtk.js鼠标左键滑动改变窗位和窗宽

61 篇文章 0 订阅
46 篇文章 20 订阅
本文介绍了如何使用JavaScript和jQuery实现了一个可拖动的组件,通过鼠标操作调整vtkObj中的图像显示参数,如颜色级和颜色窗口。通过`DragObj`类封装,用户可以方便地在内容区contentX上进行灰度调整,影响到不同视图的窗口和宽度设置。
摘要由CSDN通过智能技术生成
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');

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值