📄 mysegplugin.cpp
字号:
// MySegPlugin.cpp: implementation of the CMySegPlugin class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SegPlugin.h"
#include "MySegPlugin.h"
//PluginsSDK头文件
#include "medVolume.h"
//对话框头文件
#include "DialogParameter.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SEGMENTATION(CMySegPlugin, "My Segmentation Plugin")
CMySegPlugin::CMySegPlugin()
{
}
CMySegPlugin::~CMySegPlugin()
{
}
bool CMySegPlugin::Show(void)
{
//MFC的规定,必须先调用这个宏.
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//弹出域值选择对话框.
CDialogParameter paraDialog;
paraDialog.SetLowThre(0.0f);
paraDialog.SetHighThre(255.0f);
if(paraDialog.DoModal() == IDOK)
{
//作实际的域值分割工作.
return this->doSegmentation(paraDialog.GetLowThre(),
paraDialog.GetHighThre());
}
return false;
}
template <class T>
void t_ExecuteSegmentation(T *inData, unsigned char *outData,
medVolume *inVolume,
float lowThresh, float highThresh)
{
//得到图像的一些属性信息.
int imageWidth = inVolume->GetWidth();
int imageHeight = inVolume->GetHeight();
int imageNum = inVolume->GetImageNum();
int i, j, k;
//循环遍历整个数据.
for(k = 0; k < imageNum; k++)
{
for(j = 0; j < imageHeight; j++)
{
for(i = 0; i < imageWidth; i++)
{
//如果数据值在指定的域值范围内,
//则输出的数据二值化为255.
if(*inData >= lowThresh && *inData <= highThresh)
{
*outData = 255;
}
//否则为0.
else
{
*outData = 0;
}
//输入数据和输出数据指针前移.
inData++;
outData++;
}
}
}
}
bool CMySegPlugin::doSegmentation(float lowThre, float highThre)
{
if(lowThre >= highThre)
return false;
medVolume *inVolume = this->GetInput();
if(inVolume == NULL)
{
AfxMessageBox("输入数据为空");
return false;
}
if(inVolume->GetNumberOfChannel() != 1)
{
AfxMessageBox("对不起,只支持单通道的数据");
return false;
}
//生成输出数据(即分割后数据).
m_OutData = new medVolume;
//设置分割后数据的属性,
//和原始数据大部分一致.
medVolume *outVolume = this->GetOutput();
outVolume->SetWidth(inVolume->GetWidth());
outVolume->SetHeight(inVolume->GetHeight());
outVolume->SetImageNum(inVolume->GetImageNum());
outVolume->SetSpacingX(inVolume->GetSpacingX());
outVolume->SetSpacingY(inVolume->GetSpacingY());
outVolume->SetSpacingZ(inVolume->GetSpacingZ());
outVolume->SetNumberOfChannel(inVolume->GetNumberOfChannel());
//分割后的数据为二值数据,
//因此这里将数据类型设置为unsigned char(8bit).
outVolume->SetDataType(MED_UNSIGNED_CHAR);
//为分割后的数据分配实际内存.
unsigned char *outData = (unsigned char*) outVolume->Allocate();
//得到输入数据的内存指针.
void *inData = inVolume->GetRawData();
//根据输入数据的类型,
//使用模板函数来完成实际分割过程.
switch(inVolume->GetDataType())
{
case MED_CHAR:
t_ExecuteSegmentation((char*) inData, outData, inVolume,
lowThre, highThre);
break;
case MED_UNSIGNED_CHAR:
t_ExecuteSegmentation((unsigned char*) inData, outData,
inVolume, lowThre, highThre);
break;
case MED_SHORT:
t_ExecuteSegmentation((short*) inData, outData, inVolume,
lowThre, highThre);
break;
case MED_UNSIGNED_SHORT:
t_ExecuteSegmentation((unsigned short*) inData, outData,
inVolume, lowThre, highThre);
break;
case MED_INT:
t_ExecuteSegmentation((int*) inData, outData, inVolume,
lowThre, highThre);
break;
case MED_UNSIGNED_INT:
t_ExecuteSegmentation((unsigned int*) inData, outData,
inVolume, lowThre, highThre);
break;
case MED_LONG:
t_ExecuteSegmentation((long*) inData, outData, inVolume,
lowThre, highThre);
break;
case MED_UNSIGNED_LONG:
t_ExecuteSegmentation((unsigned long*) inData, outData,
inVolume, lowThre, highThre);
break;
case MED_FLOAT:
t_ExecuteSegmentation((float*) inData, outData, inVolume,
lowThre, highThre);
break;
case MED_DOUBLE:
t_ExecuteSegmentation((double*) inData, outData, inVolume,
lowThre, highThre);
break;
default:
AfxMessageBox("不支持的数据类型!");
return false;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -