Hi! I'm new to MFC in Visual C++ programming. I had previously used it to do console applications but never used MFC before. I had a problem; I was told to set a 4 by 4 area by using Matrix in MFC coding and use it to check whether the image has any little "black spots". If it does, I have to set these small little "black spots" of the image from "255" or anything else to zero.
So How do I do it?
Pls do kindly reply. I needed this asap. Thanks!
Ps: here are all my codings:
<br />
<br />
<br />
#include "stdafx.h"<br />
#include "MediVision.h"<br />
#include "PatientDialogBox.h"<br />
#include "MediVisionDoc.h"<br />
#include "MediVisionView.h"<br />
#include "Glob.h"<br />
#include "Math.h"<br />
#include "Edit_Patient_Data.h"<br />
#include "Expand_Pixel.h"<br />
#include "Rows_Cols.h"<br />
<br />
#include <vector><br />
#include <string><br />
<br />
typedef std::vector<std::string> StringArray;
using namespace std;
<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif<br />
<br />
unsigned char *argbPixelsPtr;<br />
unsigned char *rgbPixelsPtr;<br />
unsigned int argbPixels[512][512];<br />
unsigned int argb256Pixels[256][256];<br />
unsigned int rgbPixels[512][512];<br />
unsigned int rgb256Pixels[256][256];<br />
unsigned int storeargbPixels[512][512];<br />
<br />
<br />
int *Bitmap_r, *Bitmap_g, *Bitmap_b;<br />
int *image[5], *store[5], *image256, *store256, *image512, *store512, *image32, *store32,*image16, *store16;<br />
int mouse1_x, mouse1_y, mouse2_x, mouse2_y;
int rows1,rows2,cols1,cols2;<br />
int clk_mouse_x, clk_mouse_y;
int ref_selected_x, ref_selected_y;
int ref_intensity;
int Grad_x, Grad_y, Grad_z;
<br />
<br />
short dcmPixel[480][262144];<br />
<br />
<br />
float alphaTable[262144];<br />
float luminanceTable[262144];<br />
float MidX, MidY, MidZ;<br />
float Translation[4][4];<br />
float Rotation[4][4];<br />
float pt_x[5], pt_y[5], pt_z[5];<br />
<br />
<br />
char UID[30];<br />
<br />
<br />
int *pixelvalue, maxpix;<br />
int box_x, box_y;
CDC *pDC;<br />
HDC hdc;<br />
int n_rows, n_cols;<br />
int k = 0;<br />
int Expand_Pixel;<br />
int s, nCount;<br />
<br />
<br />
CString strAppDirectory;<br />
long position, sliceThickness_position,ImageNo_position,Axis_position,PixelSize_position;<br />
int ** region;<br />
int pass;
bool insert, rightbut;<br />
bool noFile, Flag3D;
bool box, ref_pt;
<br />
<br />
int magnification;<br />
bool zoom, grid;<br />
<br />
bool eraser, leftbut;<br />
bool multiple_open;<br />
bool cancel1,cancel2;<br />
CPoint er_point;<br />
CPoint Anchor;<br />
FILE *fp, *fw, *fe;
<br />
char *st;<br />
<br />
bool edited;<br />
void SetClassificationTable();<br />
void DrawRectn();<br />
<br />
bool Rectn;
<br />
<br />
int mouse_x, mouse_y;
<br />
int num;
<br />
int r, c;
<br />
int max, min;
<br />
int point_x, point_y;
<br />
int point_x1, point_y1;
<br />
int point_w1, point_z1;<br />
<br />
bool minflag, maxflag;<br />
<br />
int sg_length, sg_height;
<br />
<br />
<br />
IMPLEMENT_DYNCREATE(CMediVisionView, CView)<br />
BEGIN_MESSAGE_MAP(CMediVisionView, CView)<br />
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)<br />
ON_WM_ERASEBKGND()<br />
ON_COMMAND(ID_3D_MAXIMUMINTENSITY, On3dMaximumintensity)<br />
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)<br />
ON_COMMAND(ID_3D_SURFACERENDERING, On3dSurfacerendering)<br />
ON_WM_LBUTTONDOWN()<br />
ON_WM_LBUTTONUP()<br />
ON_WM_MOUSEMOVE()<br />
ON_COMMAND(ID_SEGMENTATION_REGIONGROWING, OnSegmentationRegiongrowing)<br />
ON_WM_SETCURSOR()<br />
ON_COMMAND(ID_FILE_MULTIPLEOPEN, OnFileMultipleopen)<br />
ON_COMMAND(ID_RToolbar_3DIntensity, OnRToolbar3DIntensity)<br />
ON_COMMAND(ID_RToolbar_Multipleopen, OnRToolbarMultipleopen)<br />
ON_COMMAND(ID_RToolbar2_Region, OnRToolbar2Region)<br />
ON_COMMAND(ID_3D_VOLUMERENDERING, On3dVolumerendering)<br />
ON_COMMAND(ID_TOOLS_ERASER, OnToolsEraser)<br />
ON_COMMAND(ID_TOOLS_BOOLEAN, OnToolsBoolean)<br />
ON_COMMAND(ID_TOOLS_MAXIMATION, OnToolsMaximation)<br />
ON_COMMAND(ID_ERASER, OnEraser)<br />
ON_COMMAND(ID_TOOLS_PEN, OnToolsPen)<br />
ON_COMMAND(ID_PEN, OnPen)<br />
ON_COMMAND(ID_EDIT_PATIENT_DATA, OnEditPatientData)<br />
ON_COMMAND(ID_MORPHOLOFICAL, OnMorpholofical)<br />
ON_COMMAND(ID_ZOOM_2X, OnZoom2x)<br />
ON_COMMAND(ID_ZOOM_4X, OnZoom4x)<br />
ON_COMMAND(ID_TOOLS_EXPANSION, OnToolsExpansion)<br />
ON_COMMAND(ID_LINE_OBJECTS, OnLineObjects)<br />
ON_WM_RBUTTONDOWN()<br />
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)<br />
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)<br />
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)<br />
END_MESSAGE_MAP()<br />
<br />
<br />
CMediVisionView::CMediVisionView()<br />
{<br />
m_File1 = _T(" ");<br />
pixelmax = 256;<br />
maxpix = 256;<br />
multiple_open = false;<br />
no_of_rows = 0;<br />
no_of_cols = 0;<br />
box = false;<br />
eraser = false;<br />
leftbut = false;<br />
ref_pt = false;<br />
MotionFix = 0;<br />
m_Dragging = false;<br />
Expand_Pixel = 0;<br />
<br />
<br />
Rectn = false;
MDrag = false;
Motion = 0;
mini = 0;<br />
maxi=0;<br />
<br />
<br />
<br />
<br />
}<br />
<br />
CMediVisionView::~CMediVisionView()<br />
{<br />
}<br />
<br />
BOOL CMediVisionView::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
<br />
return CView::PreCreateWindow(cs);<br />
}<br />
<br />
<br />
<br />
void FrameLines(CDC *pDC) {<br />
<br />
<br />
CBrush brush, *pOB;<br />
<br />
int xSize=::GetSystemMetrics(SM_CXSCREEN);<br />
int ySize=::GetSystemMetrics(SM_CYSCREEN);<br />
<br />
brush.CreateSolidBrush(RGB(210,220,205)); <br />
pOB = pDC->SelectObject(&brush);<br />
<br />
pDC->Rectangle(525, -1, 530, ySize);<br />
pDC->Rectangle(529, (ySize/2 - 45), xSize, (ySize/2-40));<br />
}<br />
<br />
<br />
<br />
void CMediVisionView::OnDraw(CDC* pDC)<br />
{<br />
CMediVisionDoc* pDoc = GetDocument();<br />
ASSERT_VALID(pDoc);<br />
<br />
<br />
if (First==TRUE) {<br />
First=FALSE;<br />
Draw();
CClientDC ClientDC(this);<br />
FrameLines(&ClientDC);<br />
<br />
}<br />
else { <br />
ReDraw();
}<br />
}<br />
<br />
void DrawBox(CDC *pdc,CPoint m_One, CPoint m_Two)<br />
{<br />
pdc->MoveTo(m_One);<br />
pdc->LineTo(m_One.x, m_Two.y);<br />
<br />
pdc->MoveTo(m_One);<br />
pdc->LineTo(m_Two.x, m_One.y);<br />
<br />
pdc->MoveTo(m_Two.x,m_One.y);<br />
pdc->LineTo(m_Two.x, m_Two.y);<br />
<br />
pdc->MoveTo(m_One.x,m_Two.y);<br />
pdc->LineTo(m_Two.x, m_Two.y);<br />
<br />
}<br />
<br />
<br />
BOOL CMediVisionView::OnPreparePrinting(CPrintInfo* pInfo)<br />
{<br />
return DoPreparePrinting(pInfo);<br />
}<br />
<br />
void CMediVisionView::OnBeginPrinting(CDC* , CPrintInfo* )<br />
{<br />
}<br />
<br />
void CMediVisionView::OnEndPrinting(CDC* , CPrintInfo* )<br />
{<br />
}<br />
<br />
<br />
#ifdef _DEBUG<br />
void CMediVisionView::AssertValid() const<br />
{<br />
CView::AssertValid();<br />
}<br />
<br />
void CMediVisionView::Dump(CDumpContext& dc) const<br />
{<br />
CView::Dump(dc);<br />
}<br />
<br />
CMediVisionDoc* CMediVisionView::GetDocument()
{<br />
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMediVisionDoc)));<br />
return (CMediVisionDoc*)m_pDocument;<br />
}<br />
#endif //_DEBUG<br />
<br />
<br />
<br />
<br />
CString file;<br />
<br />
void CMediVisionView::OnFileOpen() <br />
{<br />
<br />
<br />
multiple_open=false;<br />
image_no=0;<br />
OpenFile(); <br />
}<br />
<br />
<br />
<br />
void CMediVisionView::OnInitialUpdate() <br />
{<br />
CView::OnInitialUpdate();<br />
<br />
SetBackgroundColor(RGB(50, 50, 50));<br />
CMediVisionDoc* pDoc = GetDocument();<br />
pDoc->SetPathName("LEO",TRUE);<br />
}<br />
<br />
void CMediVisionView::SetBackgroundColor(COLORREF crBackground)<br />
{<br />
m_crBackground = crBackground;<br />
if (m_wndbkBrush.GetSafeHandle())<br />
m_wndbkBrush.DeleteObject();<br />
m_wndbkBrush.CreateSolidBrush(m_crBackground);<br />
}<br />
<br />
<br />
BOOL CMediVisionView::OnEraseBkgnd(CDC* pDC) <br />
{<br />
CRect rect;<br />
GetClientRect(rect);<br />
pDC->FillRect(&rect, &m_wndbkBrush);<br />
return TRUE;<br />
<br />
}<br />
<br />
<br />
<br />
void CMediVisionView::ReDraw()<br />
{<br />
int row, col;<br />
int p, q, n;<br />
int cx_position[6], cy_position[6]; <br />
unsigned int data;<br />
<br />
BITMAPINFOHEADER infoHeader;<br />
infoHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
infoHeader.biWidth = n_cols;<br />
infoHeader.biHeight = n_rows;<br />
infoHeader.biPlanes=1;<br />
infoHeader.biBitCount= 24;<br />
infoHeader.biCompression=0;<br />
infoHeader.biSizeImage=0;<br />
infoHeader.biXPelsPerMeter=0;<br />
infoHeader.biYPelsPerMeter=0;<br />
infoHeader.biClrUsed=0;<br />
infoHeader.biClrImportant=0;<br />
<br />
int xSize=::GetSystemMetrics(SM_CXSCREEN)-80;<br />
int ySize=::GetSystemMetrics(SM_CYSCREEN);<br />
<br />
CClientDC ClientDC(this);
FrameLines(&ClientDC);<br />
<br />
if (n_rows== 256 && multiple_open) {<br />
if(image_no == 1) {<br />
cx_position[1] = ((xSize/2) - (n_cols/2));<br />
cy_position[1] = ((ySize/2) - (n_rows/2)) - 70;<br />
}<br />
else if(image_no == 2) {<br />
cx_position[1] = ((xSize/2) - (n_cols+10));<br />
cy_position[1] = ((ySize/2) - (n_rows/2)) - 70;<br />
cx_position[2] = ((xSize/2) + 10);<br />
cy_position[2] = ((ySize/2) - (n_rows/2)) - 70;<br />
}<br />
else if(image_no == 3) {<br />
cx_position[1] = 5;<br />
cy_position[1] = ((ySize/2) - (n_rows/2)) - 70;<br />
cx_position[2] = 5 + n_cols + 5;<br />
cy_position[2] = ((ySize/2) - (n_rows/2)) - 70;<br />
cx_position[3] = 5 + n_cols + 5 + n_cols + 5;<br />
cy_position[3] = ((ySize/2) - (n_rows/2)) - 70;<br />
}<br />
else if(image_no == 4) {<br />
cx_position[1] = ((xSize/2) - (n_cols+20));<br />
cy_position[1] = ((ySize/2) - (n_rows+20)) - 50;<br />
cx_position[2] = ((xSize/2) +20);<br />
cy_position[2] = ((ySize/2) - (n_rows+20)) - 50;<br />
cx_position[3] = ((xSize/2) - (n_cols+20));<br />
cy_position[3] = ((ySize/2) +10) - 70;<br />
cx_position[4] = ((xSize/2) +20);<br />
cy_position[4] = ((ySize/2) +10) - 70;<br />
}<br />
<br />
for(int s=1;s<=image_no;s++) {<br />
n = 0;<br />
for(int p=0;p<n_rows;p++) {<br />
for(int q=0;q<n_cols;q++) {<br />
data = image256[n];<br />
if (data <= 0) {<br />
argb256Pixels[p][q] = (unsigned int)(0 | 0 | 0 | 0);<br />
}<br />
else {<br />
argb256Pixels[p][q] = (unsigned int)(data<<24 | data<<16 | data<<8 | data);<br />
}<br />
n++;<br />
}<br />
}<br />
<br />
argbPixelsPtr = (unsigned char *) argb256Pixels;<br />
rgbPixelsPtr = (unsigned char *) rgb256Pixels;<br />
<br />
for (row=0; row<n_rows; row++) {<br />
for(col=0; col<n_cols; col++) {<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
argbPixelsPtr++;<br />
} <br />
}<br />
<br />
StretchDIBits(hdc, cx_position[s], cy_position[s], n_rows, n_cols, 0, 0, n_rows, n_cols, rgb256Pixels,(BITMAPINFO*) &infoHeader, 0, SRCCOPY); <br />
}<br />
}<br />
<br />
<br />
else if (n_rows== 256 && !multiple_open) {<br />
n = 0;<br />
for (p=0; p<n_rows; p++) {<br />
for (q=0; q<n_cols; q++) {<br />
data = image256[n];<br />
if (data <= 0) {<br />
argb256Pixels[p][q] = (unsigned int)(0 | 0 | 0 | 0);<br />
}<br />
else {<br />
argb256Pixels[p][q] = (unsigned int)(data<<24 | data<<16 | data<<8 | data);<br />
}<br />
n++;<br />
}<br />
}<br />
<br />
argbPixelsPtr = (unsigned char *) argb256Pixels;<br />
rgbPixelsPtr = (unsigned char *) rgb256Pixels;<br />
<br />
for (row=0; row<n_rows; row++) {<br />
for(col=0; col<n_cols; col++) {<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
argbPixelsPtr++;<br />
} <br />
}<br />
StretchDIBits(hdc, posx256, posy256, n_rows, n_cols, 0, 0, n_rows, n_cols, rgb256Pixels,(BITMAPINFO*) &infoHeader, 0, SRCCOPY); <br />
<br />
}<br />
<br />
else if(n_rows==512){<br />
n = 0;<br />
for (p=0; p<n_rows; p++) {<br />
for (q=0; q<n_cols; q++) {<br />
data = image512[n];<br />
if (data <=0) {<br />
argbPixels[p][q] = (unsigned int)(0 | 0 | 0 | 0); <br />
}<br />
else {<br />
argbPixels[p][q] = (unsigned int)(data<<24 | data<<16 | data<<8 | data);<br />
}<br />
n++;<br />
}<br />
}<br />
<br />
argbPixelsPtr = (unsigned char *) argbPixels;<br />
rgbPixelsPtr = (unsigned char *) rgbPixels;<br />
<br />
for (row=0; row<n_rows; row++) {<br />
for(col=0; col<n_cols; col++) {<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
argbPixelsPtr++;<br />
} <br />
} <br />
StretchDIBits(hdc, posx512,posy512, n_rows, n_cols, 0, 0, n_rows, n_cols, rgbPixels,(BITMAPINFO*) &infoHeader, 0, SRCCOPY); <br />
} <br />
}<br />
<br />
void CMediVisionView::On3dMaximumintensity() <br />
{<br />
<br />
static char BASED_CODE szFilter[] = "All Files (*.*)|*.*|Dicom Files (*.dcm)|*.dcm||";<br />
CFileDialog dlg( TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_EXPLORER, szFilter);<br />
<br />
Flag3D = true;<br />
multiple_open = false;<br />
pass = 0;<br />
DWORD MAXFILE = 13562;
dlg.m_ofn.nMaxFile = MAXFILE;<br />
<br />
char* buffer = new char[MAXFILE];<br />
<br />
dlg.m_ofn.lpstrFile = buffer;<br />
dlg.m_ofn.lpstrFile[0] = NULL;<br />
<br />
int iReturn = dlg.DoModal();<br />
<br />
nCount = 0;
<br />
if (iReturn == 1) {<br />
POSITION pos = dlg.GetStartPosition();<br />
POSITION pos1 = dlg.GetStartPosition();<br />
if (pos1) {<br />
do {<br />
std::string Pathname;<br />
Pathname = dlg.GetNextPathName(pos1);<br />
nCount++;
} while (pos1); <br />
}<br />
<br />
if(pos) {<br />
<br />
image_no=1;<br />
<br />
do {<br />
<br />
m_File1 = dlg.GetNextPathName(pos);<br />
if ((fp = fopen(m_File1, "rb")) == NULL) {<br />
noFile = true;<br />
}<br />
else {<br />
noFile = false;<br />
}<br />
<br />
ReadFile();<br />
<br />
<br />
if (Flag3D == true) {<br />
delete [] pixelvalue;<br />
if (pass < nCount) {<br />
if (n_rows == 512) {<br />
delete [] image512;
delete [] store512;<br />
}<br />
else if (n_rows == 256 && !multiple_open) {<br />
delete [] image256;
delete [] store256;<br />
}<br />
else if (n_rows == 256 && multiple_open) {<br />
delete [] image[image_no];<br />
delete [] store[image_no];<br />
}<br />
}<br />
}<br />
<br />
} while(pos); <br />
<br />
}<br />
<br />
if (no_of_rows==256) {<br />
image256=new int [no_of_rows*no_of_cols];
store256=new int [no_of_rows*no_of_cols];<br />
}<br />
else {<br />
image512 = new int [no_of_rows*no_of_cols];<br />
store512 = new int [no_of_rows*no_of_cols];<br />
}<br />
<br />
Compute_Vol_Max_Intensity();<br />
Invalidate();
UpdateWindow();<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
Draw();<br />
<br />
} <br />
}<br />
<br />
void CMediVisionView::ReadFile()<br />
{<br />
<br />
int i, loop, n, p,q;<br />
short tag[2];<br />
long num;<br />
char a;<br />
char VR[2], DICM[5], *string;
int iLength;<br />
short ValueLength; <br />
short ValueField;<br />
short ReservedField;
unsigned short sdata;<br />
unsigned int idata;<br />
bool flag, pixelread;<br />
<br />
if ((fw = fopen("test.dcm","w+b")) == NULL) <br />
AfxMessageBox("Cannot open binary file for some reason");<br />
<br />
if (noFile == false) {<br />
flag = true;<br />
pixelread = true;<br />
pixelmax = 256;<br />
n=0;<br />
fseek(fp, 128, 0);
fseek(fw, 128, 0);<br />
fgets(DICM,5,fp);<br />
<br />
<br />
if (strcmp(DICM, "DICM")!=0) {
fseek(fp, 0, 0);
fseek(fw, 0, 0); <br />
string=new char[20];
strcpy(UID, "1.2.840.10008.1.2"); <br />
}<br />
else<br />
fwrite(DICM, sizeof(char), 4, fw);<br />
<br />
while (flag == true) {<br />
for (i=0; i<2;i++) {
fread(&tag[i], sizeof(unsigned short), 1, fp);
fwrite(&tag[i], sizeof(unsigned short), 1, fw);<br />
}<br />
<br />
<br />
if (tag[0] < 32736) {<br />
if (tag[0]==2) {
strcpy(VR, " ");<br />
fgets(VR,3,fp);
fwrite(VR, sizeof(char), 2, fw);<br />
<br />
if (tag[1]==16) {
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
<br />
fgets(UID,ValueLength+1,fp);<br />
fwrite(UID, sizeof(char), ValueLength, fw);<br />
}<br />
else {<br />
if (strcmp(VR, "UL")==0) {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&ValueField, sizeof(unsigned long), 1, fp);
fwrite(&ValueField, sizeof(unsigned long), 1, fw);<br />
}<br />
<br />
else if (strcmp(VR,"OB")==0) {<br />
fread(&ReservedField, sizeof(unsigned short), 1, fp);
fwrite(&ReservedField, sizeof(unsigned short), 1, fw);<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&ValueField, sizeof(unsigned long), 1, fp);
fwrite(&ValueField, sizeof(unsigned long), 1, fw);<br />
}<br />
<br />
else if (strcmp(VR, "UI")==0 || strcmp(VR, "SH")==0 || strcmp(VR, "AE")==0) {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
string=new char[ValueLength+1];<br />
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char),ValueLength,fw);<br />
}<br />
<br />
else {
num = (int)VR[0];<br />
fgetc(fp);<br />
<br />
for (loop=0; loop<num+2; loop++) {<br />
a = fgetc(fp);<br />
fputc(a,fw);<br />
}<br />
}<br />
}<br />
}<br />
<br />
else {
if (strcmp(UID, "1.2.840.10008.1.2.1")==0) {<br />
strcpy(VR, " ");<br />
fgets(VR,3,fp);<br />
fwrite(VR, sizeof(char), 2, fw);<br />
<br />
if (tag[0]==40) {<br />
if (tag[1]==16) {
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&sdata, sizeof(unsigned short), 1, fp);
fwrite(&sdata, sizeof(unsigned short), 1, fw);<br />
no_of_rows = sdata;<br />
n_rows = no_of_rows;<br />
}<br />
else if (tag[1]==17) {
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&sdata, sizeof(unsigned short), 1, fp);
fwrite(&sdata, sizeof(unsigned short), 1, fw);<br />
no_of_cols = sdata;<br />
n_cols = no_of_cols;<br />
}<br />
else if (tag[1]==263) {
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&sdata, sizeof(unsigned short), 1, fp);
fwrite(&sdata, sizeof(unsigned short), 1, fw);<br />
if (sdata <= 5) pixelmax=256;
else pixelmax = sdata;<br />
}<br />
else {<br />
if (strcmp(VR, "UL") ==0) {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp); <br />
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&ValueField, sizeof(unsigned long), 1, fp);<br />
fwrite(&ValueField, sizeof(unsigned long), 1, fw);<br />
}<br />
else if (strcmp(VR,"FL")==0) {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&iLength, sizeof(unsigned int), 1, fp);
fwrite(&iLength, sizeof(unsigned int), 1, fp);<br />
} <br />
else if (strcmp(VR, "OB") ==0) {<br />
fread(&ReservedField, sizeof(unsigned short), 1, fp);<br />
fwrite(&ReservedField, sizeof(unsigned short), 1, fw);<br />
fread(&iLength, sizeof(unsigned int), 1, fp);<br />
fwrite(&iLength, sizeof(unsigned int), 1, fw);<br />
for (int te=0; te<iLength; te++) {<br />
a=getc(fp);<br />
putc(a,fw);<br />
}<br />
}<br />
<br />
else if (strcmp(VR, "SQ") ==0) {<br />
fread(&ReservedField, sizeof(unsigned short), 1, fp);<br />
fwrite(&ReservedField, sizeof(unsigned short), 1, fw);<br />
fread(&iLength, sizeof(unsigned int), 1, fp);<br />
fwrite(&iLength, sizeof(unsigned int), 1, fw);<br />
for (int te=0; te<iLength; te++) {<br />
a=getc(fp);<br />
putc(a,fw);<br />
}<br />
}<br />
else {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp); <br />
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
string=new char[ValueLength+1];
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
}<br />
}<br />
} <br />
<br />
else {<br />
<br />
if (strcmp(VR, "UL") ==0) {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp); <br />
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&ValueField, sizeof(unsigned long), 1, fp);<br />
fwrite(&ValueField, sizeof(unsigned long), 1, fw); <br />
}<br />
else if (strcmp(VR, "OB") ==0) {<br />
fread(&ReservedField, sizeof(unsigned short), 1, fp);<br />
fwrite(&ReservedField, sizeof(unsigned short), 1, fw);<br />
fread(&iLength, sizeof(unsigned int), 1, fp);<br />
fwrite(&iLength, sizeof(unsigned int), 1, fw);<br />
for (int te=0; te<iLength; te++) {<br />
a=getc(fp);<br />
putc(a,fw);<br />
}<br />
}<br />
else if (strcmp(VR,"FL")==0) {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp);
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
fread(&iLength, sizeof(unsigned int), 1, fp);
fwrite(&iLength, sizeof(unsigned int), 1, fw);<br />
}<br />
else if (strcmp(VR, "SQ") ==0) {<br />
fread(&ReservedField, sizeof(unsigned short), 1, fp);<br />
fwrite(&ReservedField, sizeof(unsigned short), 1, fw);<br />
fread(&iLength, sizeof(unsigned int), 1, fp);<br />
fwrite(&iLength, sizeof(unsigned int), 1, fw);<br />
<br />
for (int te=0; te<iLength; te++) {<br />
a=fgetc(fp);<br />
fputc(a,fw);<br />
}<br />
}<br />
else {<br />
fread(&ValueLength, sizeof(unsigned short), 1, fp); <br />
fwrite(&ValueLength, sizeof(unsigned short), 1, fw);<br />
string=new char[ValueLength+1];
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
}<br />
}<br />
}<br />
else if (strcmp(UID, "1.2.840.10008.1.2")==0) {<br />
fread(&ValueLength, sizeof(unsigned int), 1, fp);
fwrite(&ValueLength, sizeof(unsigned int), 1, fw);<br />
<br />
if (tag[0]==40) {<br />
if (tag[1] == 0x30) {<br />
<br />
PixelSize_position =ftell(fp);<br />
string=new char[ValueLength+1];<br />
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
}<br />
else if (tag[1]==16) {
fread(&sdata, sizeof(unsigned short), 1, fp);
fwrite(&sdata, sizeof(unsigned short), 1, fw);<br />
no_of_rows = sdata;<br />
n_rows = no_of_rows;<br />
}<br />
else if (tag[1]==17) {
fread(&sdata, sizeof(unsigned short), 1, fp);
fwrite(&sdata, sizeof(unsigned short), 1, fw);<br />
no_of_cols = sdata;<br />
n_cols = no_of_cols;<br />
}<br />
else if (tag[1]==263) {
fread(&sdata, sizeof(unsigned short), 1, fp);
fwrite(&sdata, sizeof(unsigned short), 1, fw);<br />
if (sdata <= 5) pixelmax=256;
else pixelmax = sdata;<br />
}<br />
else {<br />
string=new char[ValueLength+1]; <br />
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
}<br />
}<br />
<br />
<br />
<br />
else if ( tag[0] == 0x18 && tag[1] == 0x50 ) {<br />
sliceThickness_position = ftell(fp);<br />
string=new char[ValueLength+1]; <br />
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
<br />
}<br />
else if ( tag[0] == 0x20 && tag[1] == 0x13) {<br />
ImageNo_position = ftell(fp);<br />
string=new char[ValueLength+1]; <br />
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
<br />
}<br />
else if ( tag[0] == 0x20 && tag[1] == 0x32) { <br />
Axis_position = ftell(fp);<br />
string=new char[ValueLength+1]; <br />
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
<br />
}<br />
<br />
<br />
<br />
<br />
else if (tag[0] == 0x817) {<br />
fseek(fp, ValueLength, SEEK_CUR);<br />
fseek(fw, ValueLength, SEEK_CUR);<br />
}<br />
else {<br />
string=new char[ValueLength+1];
fgets(string,ValueLength+1,fp);<br />
fwrite(string, sizeof(char), ValueLength, fw);<br />
}<br />
}
}
}<br />
<br />
else {<br />
<br />
if (no_of_rows == 512) {<br />
fread(&idata, sizeof(unsigned int), 1, fp);<br />
fwrite(&idata, sizeof(unsigned int), 1, fw);<br />
fread(&idata, sizeof(unsigned int), 1, fp);<br />
fwrite(&idata, sizeof(unsigned int), 1, fw);<br />
}<br />
else if (no_of_rows == 256) {<br />
fread(&idata, sizeof(unsigned int), 1, fp);<br />
fwrite(&idata, sizeof(unsigned int), 1, fw);<br />
fread(&idata, sizeof(unsigned int), 1, fp);<br />
fwrite(&idata, sizeof(unsigned int), 1, fw);<br />
}<br />
<br />
position = ftell(fw);<br />
fclose (fw);<br />
<br />
pixelvalue = new int[no_of_rows*no_of_cols];<br />
if (no_of_rows==256 && multiple_open) {<br />
image[image_no]=new int [no_of_rows*no_of_cols];
store[image_no]=new int [no_of_rows*no_of_cols];<br />
}<br />
else if (no_of_rows==256 && !multiple_open){<br />
image256=new int [no_of_rows*no_of_cols];
store256=new int [no_of_rows*no_of_cols];<br />
}<br />
else {<br />
image512 = new int [no_of_rows*no_of_cols];<br />
store512 = new int [no_of_rows*no_of_cols];<br />
}<br />
while (pixelread==true) {<br />
fread(&sdata, sizeof(unsigned short), 1, fp);
<br />
if (sdata>5000) <br />
sdata = 0;
pixelmax = (sdata > pixelmax)? sdata : pixelmax;<br />
maxpix = pixelmax;<br />
pixelvalue[n] = sdata;<br />
<br />
n++;
<br />
if (n==(no_of_rows*no_of_cols))
pixelread=false;<br />
}<br />
<br />
flag=false;<br />
}<br />
}
<br />
fclose (fp);<br />
}<br />
<br />
<br />
n=0;<br />
for (p=0; p<n_rows; p++) {<br />
for (q=0; q<n_cols; q++) {<br />
pixelvalue[n] = ((float)pixelvalue[n]/(float)(pixelmax+1))*256;<br />
if (Flag3D==true) dcmPixel[pass][n] = pixelvalue[n]; <br />
if (n_rows==256 && multiple_open) {<br />
image[image_no][n]=pixelvalue[n];
store[image_no][n]=pixelvalue[n];
}<br />
else if (n_rows==256 && !multiple_open) {<br />
image256[n]=pixelvalue[n];
store256[n]=pixelvalue[n];
}<br />
else {<br />
image512[n] = pixelvalue[n];<br />
store512[n]=pixelvalue[n];<br />
}<br />
n++;<br />
}<br />
}<br />
<br />
pass++;
<br />
delete string;<br />
return;<br />
}<br />
<br />
<br />
void CMediVisionView::Compute_Vol_Max_Intensity()<br />
{<br />
int x1, y1;<br />
int i,j;<br />
<br />
<br />
x1 = 0;<br />
y1 = no_of_rows - 1;<br />
<br />
if (no_of_rows==256) {<br />
for(i=0;i<no_of_rows*no_of_cols;i++) {<br />
image256[i]=0;<br />
for(j=0;j<nCount;j++) {<br />
image256[i] = <br />
(dcmPixel[j][i] > image256[i] ? dcmPixel[j][i] : image256[i]);<br />
store256[i] = image256[i];<br />
}<br />
}<br />
}<br />
else {<br />
for(i=0;i<no_of_rows*no_of_cols;i++) {<br />
image512[i]=0;<br />
for(j=0;j<nCount;j++) {<br />
<br />
if (dcmPixel[j][i] > 0) {<br />
image512[i] = <br />
(dcmPixel[j][i] > image512[i] ? dcmPixel[j][i] : image512[i]);<br />
store512[i]=image512[i];<br />
}<br />
<br />
}<br />
}<br />
}<br />
<br />
<br />
return;<br />
}<br />
<br />
void CMediVisionView::OnFileSaveAs() <br />
{<br />
FILE *fs;<br />
<br />
int n;<br />
unsigned short sdata;<br />
<br />
static char BASED_CODE szFilter[] = "DICOM Files (*.dcm)|*.dcm|All Files (*.*)|*.*||"; <br />
CFileDialog dlg_save_as(FALSE, "dcm", NULL, OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY, szFilter);<br />
<br />
if(dlg_save_as.DoModal() == IDOK) {<br />
fs = fopen("test.dcm","a+b");<br />
fseek(fs , position, 0);<br />
<br />
for (n=0; n<n_rows*n_cols; n++) { <br />
if(n_rows == 256) {<br />
sdata = image256[n]*((float)maxpix/256.0f); <br />
}<br />
else {<br />
sdata = image512[n]*((float)maxpix/256.0f);
}<br />
fwrite(&sdata, sizeof(unsigned short), 1, fs);
}<br />
<br />
fclose (fs);<br />
MoveFile( "test.dcm",dlg_save_as.GetPathName());<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
void CMediVisionView::On3dSurfacerendering() <br />
{<br />
int x1, y1;<br />
int i,j;<br />
<br />
<br />
x1 = 0;<br />
y1 = no_of_rows - 1;<br />
<br />
if (no_of_rows==256) {<br />
<br />
j=0;<br />
for(i=0;i<no_of_rows*no_of_cols;i++) {<br />
image256[i]=0;<br />
for (j=0; j<nCount; j++) {<br />
if (dcmPixel[j][i]>10) {<br />
image256[i] = dcmPixel[j][i]; <br />
store256[i] = image256[i];<br />
break;<br />
}<br />
}<br />
}<br />
}<br />
<br />
else {<br />
<br />
j=0;<br />
for(i=0;i<no_of_rows*no_of_cols;i++) {<br />
image512[i]=0;<br />
for (j=0; j<nCount; j++) {<br />
if (dcmPixel[j][i]>0) {<br />
image512[i] = dcmPixel[j][i];<br />
store512[i] = image512[i];<br />
break;<br />
}<br />
} <br />
} <br />
}<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
Draw();<br />
return;<br />
}<br />
<br />
void CMediVisionView::OnLButtonDown(UINT nFlags, CPoint point) <br />
{<br />
<br />
<br />
if (box) {<br />
m_PointOrigin = point;<br />
mouse1_x = point.x;<br />
mouse1_y = point.y;<br />
m_Dragging = true;<br />
<br />
}<br />
<br />
if (ref_pt && !box) {
ref_pt = false;<br />
clk_mouse_x = point.x;
clk_mouse_y = point.y;<br />
Segment_Region();
<br />
}<br />
<br />
<br />
if (Rectn) {
<br />
m_PO = point;
m1_x = point.x;
m1_y = point.y;
MDrag = true;
<br />
}<br />
<br />
if (!Rectn) {
mouse_x = point.x;
mouse_y = point.y; <br />
<br />
<br />
}<br />
<br />
<br />
<br />
if(eraser==true) {
leftbut=true;<br />
}<br />
<br />
if(insert==true)
{ <br />
rightbut=true;<br />
}<br />
<br />
CView::OnLButtonDown(nFlags, point);<br />
}<br />
<br />
void CMediVisionView::OnLButtonUp(UINT nFlags, CPoint point) <br />
{<br />
if (m_Dragging) {<br />
mouse2_x = point.x;<br />
mouse2_y = point.y;<br />
<br />
box = false;<br />
m_Dragging = false;<br />
MotionFix=0;<br />
ref_pt = true;
}<br />
<br />
<br />
if (MDrag) {<br />
<br />
Rectn = false;
MDrag = false;
Motion =0;
AreaSegmentation();
MessageBox("Pls Right-Click to find the minimum point WITHIN the box!!");<br />
minflag = true;
}<br />
<br />
<br />
<br />
zoom = false;<br />
leftbut = false;<br />
<br />
eraser = false;<br />
leftbut = false;<br />
insert = false;<br />
rightbut = false;<br />
<br />
<br />
CView::OnLButtonUp(nFlags, point);<br />
}<br />
<br />
void CMediVisionView::OnMouseMove(UINT nFlags, CPoint point) <br />
{<br />
int cur_pos_x, cur_pos_y;<br />
int n;<br />
<br />
if(eraser==true) {
if(leftbut==true){<br />
er_point = point;<br />
<br />
cur_pos_x = er_point.x - posx512;
cur_pos_y = er_point.y - posy512;<br />
n = (512-(cur_pos_y))*512 + cur_pos_x;
<br />
for (int i=0; i<7; i++) {<br />
image512[n+i] = 0;
image512[(n-512)+i] =0;
image512[(n-512*2)+i]=0;
image512[(n-512*3)+i]=0;<br />
image512[(n-512*4)+i]=0;<br />
image512[(n-512*5)+i]=0;<br />
image512[(n-512*6)+i]=0;<br />
<br />
store512[n+i] = 0;<br />
store512[(n-512)+i] = 0;<br />
store512[(n-512*2)+i] = 0;<br />
store512[(n-512*3)+i] = 0;<br />
store512[(n-512*4)+i] = 0;<br />
store512[(n-512*5)+i] = 0;<br />
store512[(n-512*6)+i] = 0;<br />
<br />
}<br />
<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
<br />
Draw();<br />
}<br />
}<br />
if(insert==true)
{ <br />
if(rightbut==true)<br />
{<br />
if (no_of_rows == 256)<br />
{<br />
er_point = point;<br />
<br />
cur_pos_x = er_point.x - posx256;
cur_pos_y = er_point.y - posy256;<br />
n = (256-(cur_pos_y))*256 + cur_pos_x;
<br />
for (int i=0; i<2; i++) <br />
{<br />
image256[n+i] = 255;
image256[(n-256)+i] =255;
<br />
store256[n+i] = 255;<br />
store256[(n-256)+i] = 255;<br />
}<br />
}<br />
<br />
if (no_of_rows == 512)<br />
{<br />
er_point = point;<br />
<br />
cur_pos_x = er_point.x - posx512;
cur_pos_y = er_point.y - posy512;<br />
n = (512-(cur_pos_y))*512 + cur_pos_x;
<br />
for (int i=0; i<10; i++) <br />
{<br />
image512[n+i] = 255;
image512[(n-512)+i] =255;
image512[(n-512*2)+i]=255;
image512[(n-512*3)+i]=255;<br />
image512[(n-512*4)+i]=255;<br />
image512[(n-512*5)+i]=255;<br />
image512[(n-512*6)+i]=255;<br />
image512[(n-512*7)+i]=255;<br />
image512[(n-512*8)+i]=255;<br />
image512[(n-512*9)+i]=255;<br />
<br />
<br />
store512[n+i] = 255;<br />
store512[(n-512)+i] = 255;<br />
store512[(n-512*2)+i] = 255;<br />
store512[(n-512*3)+i] = 255;<br />
store512[(n-512*4)+i] = 255;<br />
store512[(n-512*5)+i] = 255;<br />
store512[(n-512*6)+i] = 255;<br />
store512[(n-512*7)+i] = 255;<br />
store512[(n-512*8)+i] = 255;<br />
store512[(n-512*9)+i] = 255;<br />
<br />
}<br />
}<br />
<br />
<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
<br />
Draw();<br />
}<br />
}<br />
<br />
if (zoom == true)
{<br />
{<br />
<br />
if (no_of_rows == 256) <br />
{<br />
<br />
<br />
er_point = point;<br />
<br />
cur_pos_x = er_point.x - posx256;
cur_pos_y = er_point.y - posy256;<br />
<br />
Draw_Zoom(cur_pos_x, cur_pos_y);<br />
<br />
}<br />
<br />
<br />
if (no_of_rows == 512) <br />
{<br />
<br />
<br />
er_point = point;<br />
<br />
cur_pos_x = er_point.x - posx512;
cur_pos_y = er_point.y - posy512;<br />
<br />
Draw_Zoom(cur_pos_x, cur_pos_y);<br />
<br />
<br />
}<br />
<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
<br />
Draw();<br />
<br />
CClientDC zoomDC(this);<br />
zoomDC.SetROP2(R2_NOTXORPEN);<br />
DrawZoomBox(&zoomDC, cur_pos_x, cur_pos_y);<br />
<br />
}<br />
<br />
<br />
}<br />
<br />
<br />
if (m_Dragging && m_PointOrigin!=point ) {<br />
<br />
CClientDC ClientDC (this);<br />
mouse2_x = point.x;<br />
mouse2_y = point.y; <br />
<br />
ClientDC.SetROP2(R2_NOTXORPEN);
<br />
if (MotionFix) DrawBox(&ClientDC,m_PointOrigin,m_PointOld);<br />
MotionFix++;<br />
<br />
DrawBox(&ClientDC,m_PointOrigin,point);<br />
}<br />
<br />
m_PointOld = point;<br />
<br />
<br />
<br />
if (MDrag && m_PO!=point) {
<br />
Rectn= true;<br />
CClientDC FDC (this);<br />
m2_x = point.x;<br />
m2_y = point.y; <br />
<br />
FDC.SetROP2(R2_NOTXORPEN);
<br />
if (Motion) DrawRectn(&FDC, m_PO, m_OldPO);
Motion++;<br />
<br />
<br />
<br />
DrawRectn(&FDC,m_PO,point);<br />
<br />
<br />
}<br />
<br />
m_OldPO = point;<br />
<br />
<br />
<br />
<br />
<br />
CView::OnMouseMove(nFlags, point);<br />
}<br />
<br />
<br />
void CMediVisionView::DrawZoomBox(CDC *pdc, int mouse_x, int mouse_y)<br />
{<br />
int half_box_length;<br />
<br />
half_box_length = (ZOOM_BOX / 2);<br />
<br />
if (no_of_rows == 512)<br />
{<br />
if (((mouse_x-half_box_length) > 0) && ((mouse_x+half_box_length) < no_of_rows) && ((mouse_y-half_box_length) > 0) && ((mouse_y+half_box_length) < no_of_rows))<br />
{<br />
<br />
CPoint top_left;<br />
CPoint bottom_right;<br />
<br />
top_left.x = mouse_x-(half_box_length)+10;<br />
top_left.y = mouse_y-(half_box_length)+10;<br />
bottom_right.x = mouse_x+(half_box_length)+10;<br />
bottom_right.y = mouse_y+(half_box_length)+10;<br />
<br />
pdc->MoveTo(top_left);
pdc->LineTo(top_left.x+ZOOM_BOX, top_left.y);
pdc->LineTo(bottom_right);
<br />
pdc->MoveTo(bottom_right);
pdc->LineTo(bottom_right.x-ZOOM_BOX, bottom_right.y);
pdc->LineTo(top_left);
<br />
if (grid == true)<br />
{<br />
<br />
}<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
void CMediVisionView::Draw_Zoom(int mx, int my)<br />
{<br />
<br />
int ref=0, r=0, c=0, n=0, m=0;<br />
<br />
int row=0, col=0;<br />
unsigned int data=0;<br />
<br />
<br />
int zoom_rows = ZOOM_BOX;<br />
int zoom_cols = ZOOM_BOX;<br />
<br />
if(n_rows==256)<br />
{<br />
StretchBlt(hdc, posxZOOM,posyZOOM, zoom_rows*magnification, zoom_cols*magnification, hdc, ((mx-(ZOOM_BOX/2))+10), ((my-(ZOOM_BOX/2))+10), zoom_rows, zoom_cols, SRCCOPY);
<br />
} <br />
<br />
<br />
if(n_rows==512)<br />
{ <br />
StretchBlt(hdc, posxZOOM,posyZOOM, zoom_rows*magnification, zoom_cols*magnification, hdc, ((mx-(ZOOM_BOX/2))+10), ((my-(ZOOM_BOX/2))+10), zoom_rows, zoom_cols, SRCCOPY);
}<br />
<br />
}<br />
<br />
void CMediVisionView::OnZoom2x() <br />
{<br />
<br />
image32 = new int [ZOOM_BOX * ZOOM_BOX];<br />
<br />
magnification = 2;<br />
<br />
if (!zoom)
zoom = true; <br />
else<br />
zoom = false;<br />
<br />
<br />
}<br />
<br />
void CMediVisionView::OnZoom4x() <br />
{<br />
<br />
image32 = new int [ZOOM_BOX * ZOOM_BOX];<br />
<br />
magnification = 4;<br />
<br />
if (!zoom)
zoom = true; <br />
else<br />
zoom = false;<br />
<br />
<br />
}<br />
<br />
void CMediVisionView::OnSegmentationRegiongrowing() <br />
{<br />
box = true;<br />
}<br />
<br />
BOOL CMediVisionView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) <br />
{<br />
<br />
if(box) {<br />
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));<br />
return TRUE;<br />
}<br />
<br />
if(Rectn) { <br />
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
return TRUE;<br />
<br />
}
<br />
<br />
if(zoom) {<br />
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));<br />
return TRUE;<br />
}<br />
if(eraser) {
CWinApp* pApp=AfxGetApp();
HICON hIconBang =pApp->LoadCursor(IDC_CURSOR1);<br />
SetCursor(hIconBang);<br />
return TRUE;<br />
<br />
}<br />
if(insert) {
CWinApp* pApp=AfxGetApp();
HICON hIconBang =pApp->LoadCursor(IDC_CURSOR2);<br />
SetCursor(hIconBang);<br />
return TRUE;<br />
<br />
}<br />
<br />
<br />
<br />
return CView::OnSetCursor(pWnd, nHitTest, message);<br />
}<br />
<br />
void CMediVisionView::Segment_Region()<br />
{<br />
int ref, r, c, n;<br />
<br />
int segment_length = abs(mouse2_x - mouse1_x);
int segment_height = abs(mouse2_y - mouse1_y);
<br />
<br />
region = new int*[segment_height]; <br />
for (int i=0; i<segment_height; i++) {<br />
region[i] = new int[segment_length];
}<br />
<br />
<br />
<br />
if (no_of_rows == 256 && !multiple_open) {<br />
box_x = mouse1_x - posx256;
box_y = mouse1_y - posy256;
<br />
n = (256-(box_y+1))*256 + box_x;
ref = 0;
<br />
for (r=0; r<segment_height; r++) {<br />
for (c=0; c<segment_length; c++) {<br />
region[r][c] = image256[n];<br />
<br />
n++;<br />
ref++; <br />
if (ref == segment_length) {
n = ((256-(box_y+1))-r)*256 + box_x;<br />
ref = 0;<br />
}<br />
} <br />
}<br />
<br />
<br />
ref_selected_x = clk_mouse_x - posx256;
ref_selected_y = clk_mouse_y - posy256;<br />
<br />
n = (256-(ref_selected_y))*256 + ref_selected_x;<br />
ref_intensity = image256[n];<br />
image256[n] = ref_intensity + 100;
<br />
for (r=0; r<segment_height; r++) {<br />
for (c=0; c<segment_length; c++) {<br />
if ((region[r][c] <= ref_intensity+10) && (region[r][c] >= ref_intensity-10)) {<br />
n = ((256-(box_y+1))-r)*256 + box_x+c;<br />
image256[n] = 255;<br />
}<br />
}<br />
}<br />
}<br />
if (no_of_rows == 512) {<br />
box_x = mouse1_x - posx512;
box_y = mouse1_y - posy512;
<br />
n = (512-(box_y+1))*512 + box_x;
ref = 0;
<br />
for (r=0; r<segment_height; r++) {<br />
for (c=0; c<segment_length; c++) {<br />
region[r][c] = image512[n];<br />
<br />
n++;<br />
ref++; <br />
if (ref == segment_length) {
n = ((512-(box_y+1))-r)*512 + box_x;<br />
ref = 0;<br />
}<br />
} <br />
}<br />
<br />
<br />
ref_selected_x = clk_mouse_x - posx512;
ref_selected_y = clk_mouse_y - posy512;<br />
<br />
n = (512-(ref_selected_y))*512 + ref_selected_x;<br />
ref_intensity = image512[n];<br />
image512[n] = ref_intensity + 100;
<br />
for (r=0; r<segment_height; r++) {<br />
for (c=0; c<segment_length; c++) {<br />
if ((region[r][c] <= ref_intensity+10) && (region[r][c] >= ref_intensity-10)) {<br />
n = ((512-(box_y+1))-r)*512 + box_x+c;<br />
image512[n] = 255;<br />
}<br />
}<br />
}<br />
}<br />
Draw();<br />
return;<br />
<br />
delete [] region;<br />
}<br />
<br />
void CMediVisionView::OnFileMultipleopen() <br />
{<br />
multiple_open = true;<br />
OpenFile();<br />
}<br />
<br />
void CMediVisionView::OpenFile()<br />
{<br />
static char BASED_CODE szFilter[] = "DICOM (*.dcm)|*.dcm|Bitmap (*.bmp)| *.bmp|";<br />
<br />
CFileDialog dlg(TRUE, NULL, NULL, NULL, szFilter);<br />
if (dlg.DoModal() == IDOK) {<br />
m_File1=dlg.GetFileName();<br />
file = m_File1;<br />
<br />
}<br />
<br />
if ((fp = fopen(m_File1, "rb")) == NULL) {<br />
noFile = true;<br />
}<br />
else {<br />
<br />
noFile = false;<br />
if (multiple_open) image_no++;<br />
}<br />
<br />
Flag3D = false;<br />
ReadFile();<br />
<br />
Invalidate();
<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
Draw();<br />
<br />
}<br />
<br />
void CMediVisionView::OnRToolbar3DIntensity() <br />
{<br />
<br />
On3dMaximumintensity();<br />
}<br />
<br />
void CMediVisionView::OnRToolbarMultipleopen() <br />
{<br />
OnFileMultipleopen();<br />
}<br />
<br />
<br />
void CMediVisionView::OnRToolbar2Region() <br />
{<br />
OnSegmentationRegiongrowing();<br />
}<br />
<br />
void CMediVisionView::On3dVolumerendering() <br />
{<br />
int s, n;<br />
int p=0, q=0;<br />
int iGm, Composite;<br />
float Grad_Mag, Ambient, Mag, Diffuse, Light_Mag, Luminance, Alpha, at, la, lum;<br />
float Intensity;<br />
float Light_x = 128+2.5;<br />
float Light_y = 128+2.5;<br />
float Light_z = 1+3.5;<br />
<br />
Light_Mag = (float)sqrt(Light_x*Light_x + Light_y*Light_y + Light_z*Light_z);<br />
Ambient = 0.4f;<br />
Diffuse = 0.6f;<br />
<br />
SetClassificationTable();<br />
<br />
if (no_of_rows==256) {<br />
<br />
n = 0;<br />
for (p=0; p<no_of_rows; p++) {<br />
for (q=0; q<no_of_cols; q++) {<br />
lum = 0;<br />
la = 0;<br />
for (s=1; s<nCount; s++) {<br />
if (dcmPixel[s][p*256+q] > 0) {<br />
Grad_x = dcmPixel[s][p*256+(q-1)] - dcmPixel[s][p*256+(q+1)]; <br />
Grad_y = dcmPixel[s][(p-1)*256+q] - dcmPixel[s][(p+1)*256+q];<br />
Grad_z = dcmPixel[s-1][n] - dcmPixel[s+1][n];<br />
Grad_Mag = (float)sqrt(Grad_x*Grad_x + Grad_y*Grad_y + Grad_z*Grad_z);<br />
iGm = (Grad_Mag/442.0f) * 64.0f;<br />
Composite = (iGm<<8) | (dcmPixel[s][p*256+q]);<br />
Alpha = (float)alphaTable[Composite]/255.0f; <br />
Luminance = (float)luminanceTable[Composite];;<br />
Mag =(Grad_x/Grad_Mag * Light_x/Light_Mag) + <br />
(Grad_y/Grad_Mag * Light_y/Light_Mag) +<br />
(Grad_z/Grad_Mag * Light_z/Light_Mag);<br />
<br />
if (Mag <0.0) Mag = 0.0;<br />
Intensity = Ambient + (Diffuse*Mag);<br />
Luminance = Luminance * Intensity;<br />
if (Alpha>0.0) {<br />
at = Alpha * (1.0f - la);<br />
lum = lum + (Luminance * at);<br />
la = la + at;<br />
if (la > 0.97) break;<br />
} <br />
}<br />
}<br />
n++;<br />
image256[n] = lum; <br />
}<br />
} <br />
}<br />
<br />
else {<br />
n = 0;<br />
for (p=0; p<no_of_rows; p++) {<br />
for (q=0; q<no_of_cols; q++) {<br />
lum = 0;<br />
la = 0;<br />
for (s=1; s<nCount; s++) {<br />
if (dcmPixel[s][p*512+q] > 0) {<br />
Grad_x = dcmPixel[s][p*512+(q-1)] - dcmPixel[s][p*512+(q+1)]; <br />
Grad_y = dcmPixel[s][(p-1)*512+q] - dcmPixel[s][(p+1)*512+q];<br />
Grad_z = dcmPixel[s-1][n] - dcmPixel[s+1][n];<br />
<br />
Grad_Mag = (float)sqrt(Grad_x*Grad_x + Grad_y*Grad_y + Grad_z*Grad_z);<br />
iGm = (Grad_Mag/442.0f) * 64.0f;<br />
Composite = (iGm<<8) | (dcmPixel[s][p*512+q]);<br />
Alpha = (float)alphaTable[Composite]/255.0f; <br />
Luminance = (float)luminanceTable[Composite]; <br />
Mag =(Grad_x/Grad_Mag * Light_x/Light_Mag) + <br />
(Grad_y/Grad_Mag * Light_y/Light_Mag) +<br />
(Grad_z/Grad_Mag * Light_z/Light_Mag);<br />
<br />
if (Mag <0.0) Mag = 0.0;<br />
Intensity = Ambient + (Diffuse*Mag);<br />
Luminance = Luminance * Intensity;<br />
if (Alpha>0.0) {<br />
at = Alpha * (1.0f - la);<br />
lum = lum + (Luminance * at);<br />
la = la + at;<br />
if (la > 0.97) break;<br />
} <br />
}<br />
}<br />
n++;<br />
image512[n] = lum; <br />
}<br />
} <br />
}<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
Draw();<br />
}<br />
<br />
void SetClassificationTable() {<br />
float alpha;<br />
float levWidth, levThreshold;<br />
int index, magnitude, intensity, ind;<br />
<br />
levThreshold = (float)128.0;<br />
levWidth = (float) 2.0;<br />
<br />
for (index=0; index<4; index++) {<br />
for (magnitude=0; magnitude < 64; magnitude ++) {<br />
for (intensity=0; intensity < 256; intensity++) {<br />
ind = intensity + (magnitude<<8) + (index<<14);<br />
<br />
if ((intensity >=levThreshold) && (intensity < (levThreshold + levWidth)))<br />
alpha = ((float)intensity - levThreshold)/levWidth;<br />
else if (intensity < levThreshold)<br />
alpha = (float)0.0;<br />
else<br />
alpha = (float)1.0;<br />
<br />
if (alpha>0.0) {<br />
alphaTable[ind] = (255.0*alpha);<br />
}<br />
else<br />
alphaTable[ind] = 0;<br />
<br />
luminanceTable[ind] = 255;<br />
}<br />
}<br />
}<br />
}<br />
<br />
void CMediVisionView::OnToolsEraser() <br />
{<br />
if (!eraser)
eraser = true;<br />
else<br />
eraser = false;<br />
}<br />
<br />
void CMediVisionView::OnToolsBoolean() <br />
{<br />
FILE* fb;
short c1, c2;<br />
int i, j, c;<br />
int BitmapWidth, BitmapHeight, intval, psize;<br />
short shortval;<br />
<br />
if ((fb=fopen("d:\\bmestudent\\Medical Visualization 32\\Chee-Boon_LEO-MedicalVisualization31\\512 bitmap\\bitmap512res2(3)-1.bmp", "rb")) == NULL) {<br />
AfxMessageBox("Cannot Open Bitmap File! ");<br />
fclose(fb);<br />
exit(1);<br />
}<br />
<br />
<br />
<br />
c1 = fgetc(fb);<br />
c2 = fgetc(fb);<br />
if (c1 != 'B' || c2 != 'M') {<br />
AfxMessageBox("Bitmap File Error 1! "); <br />
return; <br />
}<br />
<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
fread(&shortval, sizeof(unsigned short), 1, fb);<br />
fread(&shortval, sizeof(unsigned short), 1, fb);<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
<br />
<br />
<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
fread(&BitmapWidth, sizeof(unsigned int), 1, fb);<br />
fread(&BitmapHeight, sizeof(unsigned int), 1, fb);<br />
<br />
fread(&shortval, sizeof(unsigned short), 1, fb);<br />
fread(&shortval, sizeof(unsigned short), 1, fb);<br />
<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
fread(&psize, sizeof(unsigned int), 1, fb);<br />
fread(&intval, sizeof(unsigned int), 1, fb);<br />
<br />
<br />
<br />
for (i=0; i<psize; i++) {<br />
for (j=0; j<4; j++) {<br />
c=fgetc(fb);<br />
if (c== EOF) return;<br />
}<br />
}<br />
<br />
<br />
int n = 0;<br />
<br />
Bitmap_r = new int[BitmapWidth*BitmapHeight];<br />
Bitmap_g = new int[BitmapWidth*BitmapHeight];<br />
Bitmap_b = new int[BitmapWidth*BitmapHeight];<br />
<br />
for (j=0; j<BitmapHeight; j++) {<br />
for (i=0; i<BitmapWidth; i++) { <br />
Bitmap_r[n] = fgetc(fb);<br />
Bitmap_g[n] = fgetc(fb);<br />
Bitmap_b[n] = fgetc(fb);<br />
n++;<br />
}<br />
}<br />
<br />
n=0;<br />
for (j=0; j<BitmapHeight; j++) {<br />
for (i=0; i<BitmapWidth; i++) {<br />
if (Bitmap_r[n] <10) {<br />
image512[n] = 0;<br />
store512[n] = 0; <br />
}<br />
n++;<br />
}<br />
}<br />
<br />
pDC = GetDC();<br />
hdc=pDC->GetSafeHdc();<br />
Draw();<br />
<br />
fclose(fb);<br />
<br />
delete [] Bitmap_r;<br />
delete [] Bitmap_g;<br />
delete [] Bitmap_b;<br />
<br />
return;<br />
}<br />
<br />
void CMediVisionView::BmpDraw()<br />
{<br />
int row, col, data;<br />
int n=0;<br />
<br />
BITMAPINFOHEADER infoHeader;<br />
infoHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
infoHeader.biWidth = 512;<br />
infoHeader.biHeight = 512;<br />
infoHeader.biPlanes=1;<br />
infoHeader.biBitCount= 24;<br />
infoHeader.biCompression=0;<br />
infoHeader.biSizeImage=0;<br />
infoHeader.biXPelsPerMeter=0;<br />
infoHeader.biYPelsPerMeter=0;<br />
infoHeader.biClrUsed=0;<br />
infoHeader.biClrImportant=0;<br />
<br />
<br />
for(int p=0;p<512;p++) {<br />
for (int q=0;q<512;q++) {<br />
data=Bitmap_r[n];<br />
if(data <= 0) {<br />
argbPixels[p][q] = (unsigned int)(0 | 0 | 0 | 0);<br />
<br />
}<br />
else {<br />
argbPixels[p][q] = (unsigned int)(data << 24 | data <<16 | data<<8 | data);<br />
}<br />
n++; <br />
}<br />
}<br />
<br />
argbPixelsPtr = (unsigned char *) argbPixels;<br />
rgbPixelsPtr = (unsigned char *) rgbPixels;<br />
<br />
for (row=0; row<512; row++) {<br />
for(col=0; col<512; col++) {<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
*rgbPixelsPtr++ = *argbPixelsPtr++;<br />
argbPixelsPtr++;<br />
} <br />
}<br />
<br />
StretchDIBits(hdc, 10, 10, 512, 512, 0, 0, 512, 512, rgbPixels,(BITMAPINFO*) &infoHeader, 0, SRCCOPY); <br />
<br />
return;<br />
} <br />
<br />
<br />
void CMediVisionView::OnToolsMaximation() <br />
{<br />
int i, j, n;<br />
n=0;<br />
if (no_of_rows == 256) {<br />
for (j=0; j<no_of_cols; j++) {<br />
for (i=0; i<no_of_rows; i++) { <br />
if (image256[n]>150) {<br />
image256[n]=255;<br />
store256[n]=255;<br />
}<br />
n++;<br />
}<br />
}<br />
}<br />
else if (no_of_rows == 512) {<br />
for (j=0; j<no_of_cols; j++) {<br />
for (i=0; i<no_of_rows; i++) { <br />
if (image512[n]>150) {<br />
image512[n]=255;<br />
store512[n]=255;<br />
}<br />
n++;<br />
}<br />
}<br />
}<br />
Draw();<br />
}<br />
<br />
void CMediVisionView::OnEraser() <br />
{<br />
OnToolsEraser();<br />
}<br />
<br />
<br />
<br />
void CMediVisionView::OnToolsPen() <br />
{<br />
if (!insert)
insert = true;<br />
else<br />
insert = false;<br />
}<br />
<br />
void CMediVisionView::OnPen() <br />
{<br />
OnToolsPen();<br />
}<br />
<br />
void CMediVisionView::OnEditPatientData() <br />
{<br />
EditDlg = new CEdit_Patient_Data(this);<br />
EditDlg -> Create(CEdit_Patient_Data::IDD,this);<br />
EditDlg -> ShowWindow(SW_SHOW);<br />
EditDlg -> Edit_Patient();<br />
<br />
<br />
<br />
<br />
<br />
}<br />
<br />
void CMediVisionView::OnMorpholofical() <br />
{<br />
int n;<br />
int rows = 0, cols = 0;<br />
<br />
if (no_of_rows == 512){<br />
for(rows=0; rows<no_of_rows; rows=(rows+2)){<br />
for(cols=0;cols<no_of_cols;cols=(cols+2)){<br />
<br />
n = ((512-rows-1)*512)+(cols);<br />
if ((image512[n]>100)||(image512[(n+1)]>100)||(image512[(n-512)]>100)||(image512[((n-512)+1)]>100)){<br />
<br />
image512[n] =255;<br />
image512[(n+1)] =255;<br />
image512[(n-512)] =255;<br />
image512[(n-512)+1] =255;<br />
<br />
store512[n] =255;<br />
store512[(n+1)] =255;<br />
store512[(n-512)] =255;<br />
store512[(n-512)+1] =255;<br />
<br />
<br />
}<br />
}<br />
}<br />
pDC = GetDC();<br />
hdc= pDC->GetSafeHdc();<br />
Draw();<br />
<br />
}<br />
}<br />
<br />
<br />
void CMediVisionView::OnToolsExpansion() <br />
{<br />
cancel1= false;<br />
cancel2= false;<br />
CExpand_Pixel ExpandDlg(this);<br />
ExpandDlg.DoModal();<br />
if(cancel1==false)<br />
{<br />
CRows_Cols RowsColsDlg(this);<br />
RowsColsDlg.DoModal();<br />
if(cancel2== false)<br />
{ <br />
<br />
<br />
<br />
int n,q,i=0;<br />
int rows =0 , cols =0;<br />
int rows512 , cols512 ;<br />
int *temp;<br />
<br />
temp = new int [512*512];<br />
<br />
<br />
if (Expand_Pixel == 2) {<br />
for(rows=rows1; rows<rows2;rows++){<br />
for(cols=cols1;cols<cols2;cols++){<br />
<br />
<br />
<br />
n = ((512-rows-1)*512)+(cols);<br />
<br />
temp[i] =image512[n];<br />
i++;<br />
}<br />
}<br />
<br />
<br />
i=0;<br />
for(rows512=0; rows512<512;rows512=(rows512+2)){<br />
for(cols512=0;cols512<512;cols512=(cols512+2)){<br />
q = ((512-rows512-1)*512)+(cols512);<br />
<br />
image512[q] =temp[i];<br />
image512[q+1] =temp[i];<br />
image512[q-512] =temp[i];<br />
image512[(q-512)+1] =temp[i]; <br />
<br />
store512[q] =temp[i];<br />
store512[q+1] =temp[i];<br />
store512[q-512] =temp[i];<br />
store512[(q-512)+1] =temp[i];<br />
<br />
i++;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
if(Expand_Pixel == 3) <br />
{<br />
<br />
for(rows=rows1; rows<rows2; rows++)<br />
{<br />
for(cols=cols1;cols<cols2;cols++)<br />
{<br />
<br />
n = ((512-rows-1)*512)+(cols);<br />
<br />
temp[i] =image512[n];<br />
i++;<br />
}<br />
}<br />
<br />
<br />
i=0;<br />
for(rows512=0; rows512<509;rows512=(rows512+3))<br />
{<br />
for(cols512=0;cols512<509;cols512=(cols512+3))<br />
{<br />
<br />
q = ((512-rows512-1)*512)+(cols512);<br />
<br />
<br />
image512[q] =temp[i];<br />
image512[q+1] =temp[i];<br />
image512[q+2] =temp[i];<br />
image512[q-512] =temp[i];<br />
image512[(q-512)+1] =temp[i];<br />
image512[(q-512)+2] =temp[i];<br />
image512[(q-512)-512] =temp[i];<br />
image512[(q-1024)+1] =temp[i];<br />
image512[(q-1024)+2] =temp[i];<br />
<br />
store512[q] =temp[i];<br />
store512[q+1] =temp[i];<br />
store512[q+2] =temp[i];<br />
store512[q-512] =temp[i];<br />
store512[(q-512)+1] =temp[i];<br />
store512[(q-512)+2] =temp[i];<br />
store512[q-1024] =temp[i];<br />
store512[(q-1024)+1] =temp[i];<br />
store512[(q-1024)+2] =temp[i];<br />
<br />
<br />
i++;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
if(Expand_Pixel == 4 )<br />
{<br />
for(rows=rows1; rows<rows2;rows++)<br />
{<br />
for(cols=cols1;cols<cols2;cols++)<br />
{<br />
<br />
n = ((512-rows-1)*512)+(cols);<br />
temp[i] =image512[n];<br />
i++;<br />
}<br />
}<br />
<br />
<br />
i=0;<br />
for(rows512=0; rows512<508;rows512=(rows512+4))<br />
{<br />
for(cols512=0;cols512<508;cols512=(cols512+4))<br />
{<br />
q = ((512-rows512-1)*512)+(cols512);<br />
<br />
image512[q] =temp[i];<br />
image512[q+1] =temp[i];<br />
image512[q+2] =temp[i];<br />
image512[(q+3)] =temp[i];<br />
image512[q-512] =temp[i];<br />
image512[(q-512)+1] =temp[i];<br />
image512[(q-512)+2] =temp[i];<br />
image512[(q-512)+3] =temp[i];<br />
image512[(q-512)-512] =temp[i];<br />
image512[(q-1024)+1] =temp[i];<br />
image512[(q-1024)+2] =temp[i];<br />
image512[(q-1024)+3] =temp[i];<br />
image512[(q-1536)] =temp[i];<br />
image512[(q-1536)+1] =temp[i];<br />
image512[(q-1536)+2] =temp[i];<br />
image512[(q-1536)+3] =temp[i];<br />
<br />
<br />
<br />
<br />
store512[q] =temp[i];<br />
store512[q+1] =temp[i];<br />
store512[q+2] =temp[i];<br />
store512[q+3] =temp[i];<br />
store512[q-512] =temp[i];<br />
store512[(q-512)+1] =temp[i];<br />
store512[(q-512)+2] =temp[i];<br />
store512[(q-512)+3] =temp[i];<br />
store512[q-1024] =temp[i];<br />
store512[(q-1024)+1] =temp[i];<br />
store512[(q-1024)+2] =temp[i];<br />
store512[(q-1024)+3] =temp[i];<br />
store512[(q-1536)] =temp[i];<br />
store512[(q-1536)+1] =temp[i];<br />
store512[(q-1536)+2] =temp[i];<br />
store512[(q-1536)+3] =temp[i];<br />
<br />
i++;<br />
}<br />
}<br />
}<br />
}<br />
}<br />
<br />
<br />
Draw(); <br />
Expand_Pixel = 0;<br />
<br />
}<br />
<br />
void CMediVisionView::OnLineObjects() <br />
{<br />
<br />
Rectn = true;<br />
<br />
}<br />
<br />
<br />
<br />
<br />
void DrawRectn(CDC *pDc , CPoint m_1, CPoint m_2)<br />
{<br />
pDc->MoveTo(m_1);<br />
pDc->LineTo(m_1.x, m_2.y);<br />
<br />
pDc->MoveTo(m_1);<br />
pDc->LineTo(m_2.x, m_1.y);<br />
<br />
pDc->MoveTo(m_2.x,m_1.y);<br />
pDc->LineTo(m_2.x, m_2.y);<br />
<br />
pDc->MoveTo(m_1.x,m_2.y);<br />
pDc->LineTo(m_2.x, m_2.y);<br />
<br />
}<br />
<br />
<br />
<br />
void CMediVisionView::OnRButtonDown(UINT nFlags, CPoint point) <br />
{<br />
<br />
<br />
<br />
CPoint ptRefer;<br />
ptRefer = point;<br />
<br />
point_x = ptRefer.x;<br />
point_y = ptRefer.y;<br />
int n=0;<br />
<br />
if (minflag == true) {<br />
<br />
point_x1 = point_x - posx512; <br />
point_y1 = point_y - posy512; <br />
n = (512-(point_y1+1))*512 + point_x1; <br />
mini= image512[n];<br />
maxflag=true;<br />
MessageBox("Pls Right-Click to find Maximum point WITHIN the box.");<br />
}<br />
<br />
<br />
if(minflag==false && maxflag==true){<br />
<br />
point_w1 = point_x - posx512; <br />
point_z1 = point_y - posy512; <br />
n = (512-(point_z1+1))*512 + point_w1;<br />
maxi= image512[n];<br />
maxflag=false;<br />
}<br />
<br />
minflag = false;<br />
<br />
if(minflag==false && maxflag==false){<br />
int Column,Row;<br />
<br />
int length, height, refer;<br />
int diff = (maxi - mini);<br />
length= abs(m2_x - m1_x);
height= abs(m2_y - m1_y);<br />
<br />
Rectx = m1_x - posx512;<br />
Recty = m1_y - posy512;<br />
<br />
n = (512-(Recty+1))*512 + Rectx;<br />
<br />
refer=0;<br />
for (Row=0; Row<height; Row++) {<br />
for (Column=0; Column<length; Column++) { <br />
if ((image512[n]>maxi+(int)(0.2*diff)) || (image512[n]<mini+(int)(0.2*diff))) {<br />
image512[n] = 0;<br />
<br />
}<br />
<br />
if(refer == length){<br />
n = ((512-(Recty+1))-Row)*512 + Rectx;<br />
refer = 0; <br />
}<br />
refer++;<br />
n++;<br />
}<br />
}<br />
<br />
<br />
Draw();<br />
}<br />
<br />
<br />
<br />
<br />
CView::OnRButtonDown(nFlags, point);<br />
}<br />
<br />
<br />
<br />
<br />
void CMediVisionView::AreaSegmentation()<br />
{<br />
int i, j, n;<br />
n = 0;<br />
<br />
sg_length= abs(m2_x - m1_x);
sg_height = abs(m2_y - m1_y);
<br />
Rectn_x = m1_x - posx512;
Rectn_y = m1_y - posy512;
<br />
int reference;<br />
int row, column;<br />
<br />
<br />
if(no_of_rows == 512 && no_of_cols==512){
<br />
<br />
num = (512-(Rectn_y+1))*512 + Rectn_x;
reference = 0;<br />
<br />
n=0;
for(i=0; i<no_of_cols; i++) {
for(j=0; j<no_of_rows; j++) { <br />
<br />
store512[n] = 0;
n++;<br />
} <br />
}<br />
<br />
for (row=0; row<sg_height; row++) {<br />
for (column=0; column<sg_length; column++) {<br />
<br />
store512[num]= image512[num];
<br />
if(reference == sg_length){<br />
num = ((512-(Rectn_y+1))-row)*512 + Rectn_x;
reference = 0; <br />
<br />
} <br />
num++;<br />
reference++;<br />
}<br />
}<br />
<br />
n=0;<br />
for(i=0; i<no_of_cols; i++) { <br />
for(j=0; j<no_of_rows; j++) {<br />
image512[n]=0;
n++;<br />
}<br />
}<br />
<br />
n=0;<br />
for(i=0; i<no_of_cols; i++) {<br />
for(j=0; j<no_of_rows; j++) {<br />
image512[n]=store512[n];
n++;
} <br />
}<br />
<br />
}<br />
<br />
<br />
return; <br />
<br />
<br />
}<br />
<br />
|