?? 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 + -