首页 > 其他分享 >应用开发---VTK放大镜(区域放大)功能实现

应用开发---VTK放大镜(区域放大)功能实现

时间:2024-09-05 21:20:40浏览次数:6  
标签:VTKIS wxInteractorStyleImage 放大镜 double VTK virtual --- include void

 VTK 医学图像处理---放大镜/区域放大功能

 本博文主要内容为:实现放大镜的源代码;实现思路;具体代码说明。

简介:

       放大镜(局部放大)在医学图像处理软件中是一个常用的功能,本博文基于VTK实现放大镜功能,该功能主要涉及到交互和放大镜功能实现,具体实现过程中(源代码中),wxInteractorStyleImage类主要实现左键按下、移动到抬起这个过程中局部图像放大的交互;wxMagnifierAcotor类实现局部图像方法功能的实现和显示。

1  放大镜源代码

Main函数入口和主体在 <021_Magnifier.cpp>文件中,wxInteractorStyleImage类主要实现鼠标的交互功能,wxMagnifierAcotor类实现局部图像方法功能的实现和显示。项目工程组织如下图:

 

在自己的项目中添加 wxInteractorStyleImage 和 wxMagnifierAcotor 两个类的源码(可以自己新建类,把下面代码拷贝进来,然后修改下文件名称即可),然后将Magnifier.cpp文件中的内容拷贝到自己项目main函数所在文件,就可以直接运行。

1 wxInteractorStyleImage 类源代码

头文件如下:


#ifndef wxInteractorStyleImage_h
#define wxInteractorStyleImage_h

#include "vtkInteractorStyleTrackballCamera.h"

// Motion flags

#define VTKIS_WINDOW_LEVEL 1024
#define VTKIS_SLICE        1025
#define VTKIS_MAGNIFIER    1026  /* 添加放大镜事件 ID */

// Style flags

#define VTKIS_IMAGE2D 2
#define VTKIS_IMAGE3D 3
#define VTKIS_IMAGE_SLICING 4

class vtkImageProperty;
class wxMagnifierAcotor;

class wxInteractorStyleImage : public vtkInteractorStyleTrackballCamera
{
public:
	static wxInteractorStyleImage *New();
	vtkTypeMacro(wxInteractorStyleImage, vtkInteractorStyleTrackballCamera);
	void PrintSelf(ostream& os, vtkIndent indent) override;


	virtual void SetMagnifier(wxMagnifierAcotor* pActor);
	//@{
	/**
	 * Some useful information for handling window level
	 */
	vtkGetVector2Macro(WindowLevelStartPosition, int);
	vtkGetVector2Macro(WindowLevelCurrentPosition, int);
	//@}

	//@{
	/**
	 * Event bindings controlling the effects of pressing mouse buttons
	 * or moving the mouse.
	 */
	void onm ouseMove() override;
	void OnLeftButtonDown() override;
	void OnLeftButtonUp() override;
	void OnMiddleButtonDown() override;
	void OnMiddleButtonUp() override;
	void OnRightButtonDown() override;
	void OnRightButtonUp() override;
	//@}

	/**
	 * Override the "fly-to" (f keypress) for images.
	 */
	void OnChar() override;

	// These methods for the different interactions in different modes
	// are overridden in subclasses to perform the correct motion. Since
	// they might be called from OnTimer, they do not have mouse coord parameters
	// (use interactor's GetEventPosition and GetLastEventPosition)
	virtual void WindowLevel();
	virtual void Pick();
	virtual void Slice();

	// Interaction mode entry points used internally.
	virtual void StartWindowLevel();
	virtual void EndWindowLevel();
	virtual void StartPick();
	virtual void EndPick();
	virtual void StartSlice();
	virtual void EndSlice();

	virtual void StartMagnifier();
	virtual void EndMagnifier();
	virtual void Magnifier();

	//@{
	/**
	 * Set/Get current mode to 2D or 3D.  The default is 2D.  In 3D mode,
	 * it is possible to rotate the camera to view oblique slices.  In Slicing
	 * mode, it is possible to slice through the data, but not to generate oblique
	 * views by rotating the camera.
	 */
	vtkSetClampMacro(InteractionMode, int, VTKIS_IMAGE2D, VTKIS_IMAGE_SLICING);
	vtkGetMacro(InteractionMode, int);
	void SetInteractionModeToImage2D() {
		this->SetInteractionMode(VTKIS_IMAGE2D);
	}
	void SetInteractionModeToImage3D() {
		this->SetInteractionMode(VTKIS_IMAGE3D);
	}
	void SetInteractionModeToImageSlicing() {
		this->SetInteractionMode(VTKIS_IMAGE_SLICING);
	}
	//@}

	//@{
	/**
	 * Set the orientations that will be used when the X, Y, or Z
	 * keys are pressed.  See SetImageOrientation for more information.
	 */
	vtkSetVector3Macro(XViewRightVector, double);
	vtkGetVector3Macro(XViewRightVector, double);
	vtkSetVector3Macro(XViewUpVector, double);
	vtkGetVector3Macro(XViewUpVector, double);
	vtkSetVector3Macro(YViewRightVector, double);
	vtkGetVector3Macro(YViewRightVector, double);
	vtkSetVector3Macro(YViewUpVector, double);
	vtkGetVector3Macro(YViewUpVector, double);
	vtkSetVector3Macro(ZViewRightVector, double);
	vtkGetVector3Macro(ZViewRightVector, double);
	vtkSetVector3Macro(ZViewUpVector, double);
	vtkGetVector3Macro(ZViewUpVector, double);
	//@}

	/**
	 * Set the view orientation, in terms of the horizontal and
	 * vertical directions of the computer screen.  The first
	 * vector gives the direction that will correspond to moving
	 * horizontally left-to-right across the screen, and the
	 * second vector gives the direction that will correspond to
	 * moving bottom-to-top up the screen.  This method changes
	 * the position of the camera to provide the desired view.
	 */
	void SetImageOrientation(const double leftToRight[3],
		const double bottomToTop[3]);

	/**
	 * Set the image to use for WindowLevel interaction.
	 * Any images for which the Pickable flag is off are ignored.
	 * Images are counted back-to-front, so 0 is the rearmost image.
	 * Negative values can be used to count front-to-back, so -1 is
	 * the frontmost image, -2 is the image behind that one, etc.
	 * The default is to use the frontmost image for interaction.
	 * If the specified image does not exist, then no WindowLevel
	 * interaction will take place.
	 */
	virtual void SetCurrentImageNumber(int i);
	int GetCurrentImageNumber() { return this->CurrentImageNumber; }

	/**
	 * Get the current image property, which is set when StartWindowLevel
	 * is called immediately before StartWindowLevelEvent is generated.
	 * This is the image property of the topmost vtkImageSlice in the
	 * renderer or nullptr if no image actors are present.
	 */
	vtkImageProperty *GetCurrentImageProperty() {
		return this->CurrentImageProperty;
	}

protected:
	wxInteractorStyleImage();
	~wxInteractorStyleImage() override;

	wxMagnifierAcotor* MagnifierAcotor;

	int WindowLevelStartPosition[2];
	int WindowLevelCurrentPosition[2];
	double WindowLevelInitial[2];
	vtkImageProperty *CurrentImageProperty;
	int CurrentImageNumber;

	int InteractionMode;
	double XViewRightVector[3];
	double XViewUpVector[3];
	double YViewRightVector[3];
	double YViewUpVector[3];
	double ZViewRightVector[3];
	double ZViewUpVector[3];

private:
	wxInteractorStyleImage(const wxInteractorStyleImage&) = delete;
	void operator=(const wxInteractorStyleImage&) = delete;
};

#endif

wxInteractorStyleImage类源代码 具体实现.cpp文件源码如下:

#include "wxInteractorStyleImage.h"


#include "vtkAbstractPropPicker.h"
#include "vtkAssemblyPath.h"
#include "vtkPropCollection.h"

#include "vtkCallbackCommand.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageSlice.h"
#include "vtkImageMapper3D.h"
#include "vtkImageProperty.h"
#include "wxMagnifierAcotor.h"

vtkStandardNewMacro(wxInteractorStyleImage);

//----------------------------------------------------------------------------
wxInteractorStyleImage::wxInteractorStyleImage()
{
	this->WindowLevelStartPosition[0] = 0;
	this->WindowLevelStartPosition[1] = 0;

	this->WindowLevelCurrentPosition[0] = 0;
	this->WindowLevelCurrentPosition[1] = 0;

	this->WindowLevelInitial[0] = 1.0; // Window
	this->WindowLevelInitial[1] = 0.5; // Level

	this->CurrentImageProperty = nullptr;
	this->CurrentImageNumber = -1;

	this->MagnifierAcotor = nullptr;

	this->InteractionMode = VTKIS_IMAGE2D;

	this->XViewRightVector[0] = 0;
	this->XViewRightVector[1] = 1;
	this->XViewRightVector[2] = 0;

	this->XViewUpVector[0] = 0;
	this->XViewUpVector[1] = 0;
	this->XViewUpVector[2] = -1;

	this->YViewRightVector[0] 

标签:VTKIS,wxInteractorStyleImage,放大镜,double,VTK,virtual,---,include,void
From: https://blog.csdn.net/yunzhaoqiang/article/details/141933123

相关文章

  • 主成分分析-PCA
    文章目录一、简介1.意义2.PCA的应用3.PCA参数解释二、代码实现1.数据预处理2.主成分分析(PCA)3.数据划分4.模型训练与评估5.全部代码三、总结1.PCA的优点2.PCA的缺点一、简介1.意义PCA(主成分分析,PrincipalComponentAnalysis)是一种常用的数据降维技术。它的主......
  • Linux-目录结构和Vim编辑器
    目录Linux目录结构基本介绍​编辑具体的目录结构Vim编辑器vi和vim的基本介绍vi和vim常用的三种模式正常模式插入模式命令行模式各种模式的相互切换vim快捷键盘图粘贴与删除拷贝当前行并粘贴拷贝多行并粘贴删除当前行删除多行Vim的退出保存命令普通退出保存......
  • C语言习题--程序改错
     1.待修改代码#include<stdio.h>#include<stdlib.h>#include<string.h>intmain(){ char*src="hello,world"; char*dest=NULL; intlen=strlen(src); dest=(char*)malloc(len); ch......
  • LeetCode刷题-队列
    一:队列的基本操作1、先进先出;入队和出队、类似与排队2、单端队列3、队列的常见操作#在python中使用deque创建队列importcollectionsimportdequeduilie=deque()#创建队列defadd(nums):duilie.append()#给队列添加元素defpeek():returnduilie[0]#查看队首......
  • JavaScript中的数据类型-存储差别
    总结声明变量时不同的内存地址分配:简单类型的值存放在栈中,在栈中存放的是对应的值引用类型对应的值存储在堆中,在栈中存放的是指向堆内存的地址不同的类型数据导致赋值变量时的不同:简单类型赋值,是生成相同的值,两个对象对应不同的地址复杂类型赋值,是将保存对象的内存地......
  • JSP敬老院管理系统mq0e6--(程序+源码+数据库+调试部署+开发环境)
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表系统功能:用户,员工,老人信息,床位分配,员工薪资,员工请假,老人请假,入住费用,事故记录开题报告内容一、项目背景与意义随着我国人口老龄化的加剧,敬老院作为......
  • ERA5-Land
    ERA5-Land是由欧洲中期天气预报中心(ECMWF)作为欧洲哥白尼气候变化服务(C3S)的一部分开发的全球再分析数据集。这一数据集在现有ERA5再分析数据的基础上,专注于对陆地表面变量的细致刻画,特别是在水文和能量循环方面的建模,提供了高空间和时间分辨率的气象数据,对气候研究、天气预报、......
  • ctfshow-web入门-信息搜集(web1-web10)
    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录web1(查看源代码)右击页面查看源代码web2(js前台拦截===无效操作)打开题目地址采用burp抓包并进行重发数据包web3(没思路的时候抓个包看看,可能会有意外收获)打开题目链接查看源码无果采用burp抓包并......
  • C++学习笔记----6、内存管理(二)---- 数组指针的双向性
            你可能已经看到指针与数组之间的一些重叠。自由内存空间分配的数组由其第一个元素的指针进行访问。栈上的数组通过使用数组语法([])或者正常变量声明来访问。你还会看到的是,其重叠不仅如此,指针与数组有更复杂的关系。1、数组退化至指针        自由内......
  • 零知识证明-ZK-SNARKs基础(七)
    前言这章主要讲述ZK-SNARKs所用到的算术电路、R1CS、QAP等1:算术电路算术运算电路1>半加器:实现半加运算的逻辑电路2>全加器:能进行被加数,加数和来自低位的进位信号相加,并根据求和结果给出该位的进位信号说明:2进制加,低位进位相当于结果S为=A+B+C(地位进位)高位进......