⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageprocess.cpp

📁 CT工作站具有打印报告、病历管理、图像处理专家词库等功能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				dc->LineTo(m_end);

				GetArrow(m_start,m_end,m_pointa,m_pointb);
				dc->MoveTo(m_start);
				dc->LineTo(m_pointa);

				dc->MoveTo(m_start);
				dc->LineTo(m_pointb);
				dc->SelectObject(oldpen);
				break;
			case ACTION_DELETE:
				SelectNone();
				item *p;
				for (p = mark->m_itemhead->next; p != NULL; p = p->next)
				{
					if (abs(long(p->x0 * m_width) - point.x+left) < 20 && 
						abs(long(p->y0 * m_height) - point.y+top) < 20)
					{
						m_selitem = p;
						m_hilight = false;
						SetTimer(3,500,NULL);
						break;
					}
				}
				break;
			case ACTION_TEXT:
				break;
			case ACTION_CROSS:
				oldpen	= dc->SelectObject(&pen);
				dc->SetROP2(R2_XORPEN);
				dc->MoveTo(m_end.x,m_end.y - CROSS_LENGTH);
				dc->LineTo(m_end.x,m_end.y + CROSS_LENGTH + 1);
				dc->MoveTo(m_end.x - CROSS_LENGTH,m_end.y);
				dc->LineTo(m_end.x + CROSS_LENGTH + 1,m_end.y);
				break;
			default:
				mouseAction	= 100;
				oldPoint = point;
			}
			
			ReleaseDC(dc);	
			DeleteObject(&pen);
		}
		break;
	}
	
	if(imgNum>1)
	{
		if(oldcurpic != curPicNum )
		{
			CDC *xdc=ff[curPicNum-TopPicNum+1].GetDC();
			CRect rf;
			ff[1].GetWindowRect(&rf);
			mpp[curPicNum]->DrawBMP(xdc,0 ,0 ,rf.Width(),rf.Height(),stretch,true);
			ReleaseDC(xdc);
			xdc=ff[oldcurpic-TopPicNum+1].GetDC();
			mpp[oldcurpic]->DrawBMP(xdc,0 ,0 ,rf.Width(),rf.Height(),stretch);
			ReleaseDC(xdc);
		}
		char scurp[10];
		sprintf(scurp,"%d",curPicNum);
		GetDlgItem(IDC_CURPIC)->SetWindowText(scurp);
	}	
}

void ImageProcess::OnLButtonUp(UINT nFlags, CPoint point) 
{
	mouseAction	= 0;
	m_mousedown	= false;

	CDC *dc = GetDC();
	CPen pen,*oldpen;
	pen.CreatePen(PS_SOLID,1,RGB(255,255,0));
	oldpen = dc->SelectObject(&pen);
	dc->SetTextColor(RGB(255,0,0));
	item *last = NULL,*node = NULL;

	ReleaseCapture();

	if (m_action	== ACTION_MEASCHAOSAREA2)
	{
		if (nFlags & MK_CONTROL)
		{
			if (plh->next != NULL && plh->next->next != NULL)
			{
				dc->SetROP2(R2_XORPEN);
				dc->MoveTo(m_start);
				dc->LineTo(m_end);
				dc->MoveTo(m_start);
				dc->LineTo(plh->p);

				// -> Record
				POINT_LIST *p;
				double x0,x1,y0,y1;

				meas->BeginRecord();
				for (p = plh; NULL != p; p = p->next)
				{
					x0	= (p->p.x - left) / m_width;
					y0	= (p->p.y - top) / m_height;
					if (NULL == p->next)
					{
						x1	= (plh->p.x - left) / m_width;
						y1	= (plh->p.y - top) / m_height;
					}
					else
					{
						x1	= (p->next->p.x - left) / m_width;
						y1	= (p->next->p.y - top) / m_height;
					}
					meas->InsertLine(x0,y0,x1,y1);
				}
				meas->EndRecord();
				// <- Record


				float area	= m_chaos_area;
				char buf[200];

				area *= (m_d2 * m_d2) / (m_d1 * m_d1);

				sprintf(buf,"该不规则图形面积为:%5.2f 平方%s",
					area,m_unit.GetBuffer(m_unit.GetLength()));
				AfxMessageBox(buf);

				((CBxtDlg *)AfxGetMainWnd())->
					dispmeasure->
					m_state.SetWindowText("");
			
				m_action	= (nFlags & MK_SHIFT)?ACTION_MEASLINEDIST:ACTION_NOTHING;


				////////////////////////////
				POINT_LIST *next;
				m_cp	= plh->next;
				for (;;)
				{

					if (m_cp != NULL)
						next	= m_cp->next;
					else
						break;
					delete m_cp;
					m_cp	= next;
				}
				plh->next	= NULL;
//				for (m_cp = plh->next; m_cp != NULL; m_cp = m_cp->next)
//				{
//					next	= m_cp->next;
//					delete m_cp;
//				}
//
//					delete m_cp;
//				plh->next	= NULL;
				////////////////////////////
			}
			else
			{
				node2	= new POINT_LIST;

				for (m_cp = plh; m_cp->next != NULL; m_cp = m_cp->next);
				m_cp->next = node2;

				node2->p	= point;
				node2->next	= NULL;
				node2->last	= m_cp;

				m_action	= ACTION_MEASCHAOSAREA2;
				m_start2	= m_end;
			}
		}
		else
		{
			node2	= new POINT_LIST;

			for (m_cp = plh; m_cp->next != NULL; m_cp = m_cp->next);
			m_cp->next = node2;

			node2->p	= point;
			node2->next	= NULL;
			node2->last	= m_cp;

			m_action	= ACTION_MEASCHAOSAREA2;
			m_start2	= m_end;

			if (plh->next != NULL && plh->next->next != NULL)
			{
				POINT_LIST *p1,*p2,*p3;
				p1	= plh;
				for (p3 = plh->next->next; p3->next != NULL; p3 = p3->next);
				p2	= p3->last;

				float d1_2,d2_2,d3_2,d1,d2,d3,sl;

				d1_2	=	(p2->p.x - p1->p.x) * (p2->p.x - p1->p.x) +
							(p2->p.y - p1->p.y) * (p2->p.y - p1->p.y);
				d2_2	=	(p3->p.x - p2->p.x) * (p3->p.x - p2->p.x) +
							(p3->p.y - p2->p.y) * (p3->p.y - p2->p.y);
				d3_2	=	(p1->p.x - p3->p.x) * (p1->p.x - p3->p.x) +
							(p1->p.y - p3->p.y) * (p1->p.y - p3->p.y);

				d1	= sqrt(d1_2);
				d2	= sqrt(d2_2);
				d3	= sqrt(d3_2);

				sl	= (d1 + d2 + d3) / 2;

				m_chaos_area	+= sqrt(sl * (sl - d1) * (sl - d2) * (sl - d3));
			}
		}
/*
		if (plh != NULL && plh->next != NULL && plh->next->next != NULL)
		{
			if (nFlags & MK_CONTROL)
			{
				dc->SetROP2(R2_XORPEN);
				dc->MoveTo(m_start);
				dc->LineTo(m_end);
				dc->MoveTo(m_start);
				dc->LineTo(plh->p);

				float area	= 100;
				char buf[200];
				sprintf(buf,"该不规则图形面积为:%5.2f 平方%s",
					area,m_unit.GetBuffer(m_unit.GetLength()));
				AfxMessageBox(buf);
				((CBxtDlg *)AfxGetMainWnd())->
					dispmeasure->
					m_state.SetWindowText("");
			
				m_action	= (nFlags & MK_SHIFT)?ACTION_MEASLINEDIST:ACTION_NOTHING;

				for (m_cp = plh->next; m_cp != NULL; m_cp = m_cp->next)
					delete m_cp;
				plh->next	= NULL;
			}
			else
			{
				// 计算面积
				POINT_LIST *p1,*p2,*p3;
				p1	= plh;
				for (p3 = plh->next->next; p3->next != NULL; p3 = p3->next);
				p2	= p3->last;

				float d1_2,d2_2,d3_2,d1,d2,d3,sl;

				d1_2	=	(p2->p.x - p1->p.x) * (p2->p.x - p1->p.x) +
							(p2->p.y - p1->p.y) * (p2->p.y - p1->p.y);
				d2_2	=	(p3->p.x - p2->p.x) * (p3->p.x - p2->p.x) +
							(p3->p.y - p2->p.y) * (p3->p.y - p2->p.y);
				d3_2	=	(p1->p.x - p3->p.x) * (p1->p.x - p3->p.x) +
							(p1->p.y - p3->p.y) * (p1->p.y - p3->p.y);

				d1	= sqrt(d1_2);
				d2	= sqrt(d2_2);
				d3	= sqrt(d3_2);

				sl	= (d1 + d2 + d3) / 2;

				m_chaos_area	+= sqrt(sl * (sl - d1) * (sl - d2) * (sl - d3));
			}
		}
		else
		{
			node2	= new POINT_LIST;

			for (m_cp = plh; m_cp->next != NULL; m_cp = m_cp->next);
			m_cp->next = node2;

			node2->p	= point;
			node2->next	= NULL;
			node2->last	= m_cp;

			m_action	= ACTION_MEASCHAOSAREA2;
			m_start2	= m_end;
		}
*/
	}
	else if (m_action	== ACTION_MEASCHAOSAREA)
	{
		node2	= new POINT_LIST;
		plh->next	= node2;

		node2->p	= point;
		node2->next	= NULL;
		node2->last	= plh;

		m_action	= ACTION_MEASCHAOSAREA2;
		m_start2	= m_end;

		// -> Record
/*		double x0,x1,y0,y1;

		x0	= (m_start.x - left) / m_width;
		y0	= (m_start.y - top) / m_height;
		x1	= (m_end.x - left) / m_width;
		y1	= (m_end.y - top) / m_height;

		meas->BeginRecord();
		meas->InsertLine(x0,y0,x1,y1);
*/
		// <- Record
	}
	else if (m_action	== ACTION_MEASCHAOSANGLE2)
	{
		m_anglep2	= m_start;
		m_anglep3	= m_end;

		// -> Record
		double x0,x1,y0,y1;

		x0	= (m_start.x - left) / m_width;
		y0	= (m_start.y - top) / m_height;
		x1	= (m_end.x - left) / m_width;
		y1	= (m_end.y - top) / m_height;

		meas->InsertLine(x0,y0,x1,y1);
		meas->EndRecord();
		// <- Record

		float angle	= GetAngle();
		char buf[200];
		sprintf(buf,"该角度值为:%5.2f 度",angle);

		AfxMessageBox(buf);
		((CBxtDlg *)AfxGetMainWnd())->
			dispmeasure->
			m_state.SetWindowText("");
		m_action	= (nFlags & MK_SHIFT)?ACTION_MEASCHAOSANGLE:ACTION_NOTHING;
	}
	else if (m_action	== ACTION_MEASCHAOSANGLE)
	{
		m_anglep0	= m_start;
		m_anglep1	= m_end;
		m_action	= ACTION_MEASCHAOSANGLE2;

		// -> Record
		double x0,x1,y0,y1;

		x0	= (m_start.x - left) / m_width;
		y0	= (m_start.y - top) / m_height;
		x1	= (m_end.x - left) / m_width;
		y1	= (m_end.y - top) / m_height;

		meas->BeginRecord();
		meas->InsertLine(x0,y0,x1,y1);
		// <- Record

	}
	else if (m_action	== ACTION_MEASANGLE2)
	{
		m_anglep2	= m_start;
		m_anglep3	= m_end;

		float angle	= GetAngle();
		char buf[200];
		// -> Record
		double x0,y0,x1,y1,x2,y2,x3,y3;

		x0	= (m_start.x - left) / m_width;
		y0	= (m_start.y - top) / m_height;
		x1	= (m_end.x - left) / m_width;
		y1	= (m_end.y - top) / m_height;

		x3	= (m_anglep0.x - left) / m_width;
		y3	= (m_anglep0.y - top ) / m_height;
		x2	= (m_anglep3.x - left) / m_width;
		y2	= (m_anglep3.y - top ) / m_height;

		meas->InsertLine(x0,y0,x1,y1);
		meas->InsertArc(x0,y0,x2,y2,x3,y3);

		meas->EndRecord();
		// <- Record

		sprintf(buf,"该角度值为:%5.2f 度",angle);

		AfxMessageBox(buf);
		((CBxtDlg *)AfxGetMainWnd())->
			dispmeasure->
			m_state.SetWindowText("");
		m_action	= (nFlags & MK_SHIFT)?ACTION_MEASANGLE:ACTION_NOTHING;
	}
	else if (m_action	== ACTION_MEASANGLE)
	{
		m_anglep0	= m_start;
		m_anglep1	= m_end;
		m_action	= ACTION_MEASANGLE2;
		m_start2	= m_end;

		// -> Record
		double x0,x1,y0,y1;

		x0	= (m_start.x - left) / m_width;
		y0	= (m_start.y - top) / m_height;
		x1	= (m_end.x - left) / m_width;
		y1	= (m_end.y - top) / m_height;

		meas->BeginRecord();
		meas->InsertLine(x0,y0,x1,y1);
		// <- Record
	}
	else if (m_action	== ACTION_MEASLINEDIST | m_action	== ACTION_MEASLINEDIST2)
	{
		m_len	+=	sqrt((m_end.x - m_start.x) * (m_end.x - m_start.x) +
						(m_end.y - m_start.y) * (m_end.y - m_start.y))
						* m_d2 / m_d1;

		double x0,x1,y0,y1;

		x0	= (m_start.x - left) / m_width;
		y0	= (m_start.y - top) / m_height;
		x1	= (m_end.x - left) / m_width;
		y1	= (m_end.y - top) / m_height;

		if (ACTION_MEASLINEDIST	== m_action)
			meas->BeginRecord();

		meas->InsertLine(x0,y0,x1,y1);

		if (nFlags & MK_CONTROL)
		{
			char buf[200];
			meas->EndRecord();

			sprintf(buf,"该折线段的长度为:%5.2f %s",
				m_len,m_unit.GetBuffer(m_unit.GetLength()));
			AfxMessageBox(buf);
			((CBxtDlg *)AfxGetMainWnd())->
				dispmeasure->
				m_state.SetWindowText("");
		
			m_action	= (nFlags & MK_SHIFT)?ACTION_MEASLINEDIST:ACTION_NOTHING;
		}
		else
		{
			m_action	= ACTION_MEASLINEDIST2;
			m_start2	= m_end;
		}
	}
	else if (m_action	== ACTION_MEASRECTAREA)
	{
		CString msg;
		float w1,h1,w2,h2,area;
		double x0,x1,y0,y1;

		x0	= (m_start.x - left) / m_width;
		y0	= (m_start.y - top) / m_height;
		x1	= (m_end.x - left) / m_width;
		y1	= (m_end.y - top) / m_height;

		meas->BeginRecord();
		meas->InsertLine(x0,y0,x1,y0);
		meas->InsertLine(x1,y0,x1,y1);
		meas->InsertLine(x1,y1,x0,y1);
		meas->InsertLine(x0,y1,x0,y0);
		meas->EndRecord();

		w1	= m_end.x - m_start.x;
		h1	= m_end.y - m_start.y;

		w2	= w1 * m_d2 / m_d1;
		h2	= h1 * m_d2 / m_d1;

		area	= fabs(w2 * h2);

		char buf[200];
		sprintf(buf,"该矩形的面积为:%5.2f 平方%s",
			area,m_unit.GetBuffer(m_unit.GetLength()));
		AfxMessageBox(buf);
		((CBxtDlg *)AfxGetMainWnd())->
			dispmeasure->
			m_state.SetWindowText("");

		if (!(nFlags & MK_SHIFT)) m_action	= ACTION_NOTHING;
	}
	else if (m_action	== ACTION_SETSTANDARDLENGTH)
	{
		CStandardLength dlg;
		if (dlg.DoModal() == IDOK) 
		{
			m_d1	= sqrt((m_end.x - m_start.x) * (m_end.x - m_start.x) + 
							(m_end.y - m_start.y) * (m_end.y - m_start.y));
			m_d2	= dlg.m_length;
			m_unit	= dlg.m_unit;
		}
		((CBxtDlg *)AfxGetMainWnd())->
			dispmeasure->
			m_state.SetWindowText("");

		meas->BeginRecord();
		meas->InsertLine((m_start.x - left) / m_width,
							(m_start.y - top) / m_height,
							(m_end.x - left) / m_width,
							(m_end.y - top) / m_height);
		meas->EndRecord();

		if (!(nFlags & MK_SHIFT)) m_action	= ACTION_NOTHING;
	}
	else if (m_action	== ACTION_ARROW)
	{
		node = new item;
		node->x0 = (m_start.x-left) / m_width;
		node->y0 = (m_start.y-top) / m_height;
		node->x1 = (point.x-left) / m_width;
		node->y1 = (point.y -top)/ m_height;
		node->type = ACTION_ARROW;
		memset(node->word,0,MAX_TEXT_LENGTH);
		mark->AddNode(node);
		delete node;

		if (!(nFlags & MK_SHIFT)) m_action	= ACTION_NOTHING;
	}
	else if (m_action	== ACTION_CROSS)
	{
		node = new item;
		node->x1 = node->x0 = (point.x-left) / m_width;
		node->y1 = node->y0 = (point.y-top) / m_height;
		node->type = ACTION_CROSS;
		memset(node->word,0,MAX_TEXT_LENGTH);
		mark->AddNode(node);
		delete node;

		if (!(nFlags & MK_SHIFT)) m_action	= ACTION_NOTHING;
	}
	else if (m_action	== ACTION_TEXT)
	{
		dc->SetBkMode(TRANSPARENT);
		dc->TextOut(point.x,point.y,m_msg);

		node = new item;
		node->x1 = node->x0 = (point.x-left)/m_width;
		node->y1 = node->y0 = (point.y-top)/m_height;
		node->type = ACTION_TEXT;
		strcpy(node->word,m_msg);
		mark->AddNode(node);
		delete node;
		
		if (!(nFlags & MK_SHIFT)) m_action	= ACTION_NOTHING;
	}
	else if (m_action	== ACTION_DELETE)
	{
	}

	dc->SelectObject(oldpen);
	ReleaseDC(dc);
	DeleteObject(&pen);
	CDialog::OnLButtonUp(nFlags, point);
}

void ImageProcess::OnMouseMove(UINT nFlags, CPoint point) 
{
	if (mouseAction == 100)
	{
		if(cp==NULL || DispStyle!=1) return;
		CRect rr;
		ff[1].GetWindowRect(&rr);
		CDC *dc=ff[1].GetDC();
		mpp[curPicNum]->ZoomBMP(dc,0,0,rr.Width(),rr.Height(),point.x-oldPoint.x,point.y-oldPoint.y);
		ReleaseDC(dc);
	}	

	if (!m_mousedown) return;
	CDC *dc = GetDC();

	CPen pen(PS_SOLID,1,RGB(255,255,0)),*oldpen;

	switch (m_action)
	{
	case ACTION_MEASCHAOSAREA2:
		oldpen	= dc->SelectObject(&pen);
		dc->SetROP2(R2_XORPEN);

		dc->MoveTo(m_start);
		dc->LineTo(m_end);

		
		if (!(nFlags & MK_CONTROL) || plh == NULL || plh->next == NULL || plh->next->next == NULL)
			m_end	= point;
		else
			m_end	= plh->p;

		dc->MoveTo(m_start);
		dc->LineTo(m_end);

		dc->SelectObject(oldpen);
		break;
	case ACTION_MEASCHAOSAREA:
	case ACTION_MEASCHAOSANGLE:
	case ACTION_MEASCHAOSANGLE2:
	case ACTION_MEASANGLE2:
	case ACTION_MEASANGLE:
	case ACTION_MEASLINEDIST2:
	case ACTION_MEASLINEDIST:
	case ACTION_SETSTANDARDLENGTH:
		oldpen	= dc->SelectObject(&pen);
		dc->SetROP2(R2_XORPEN);

		dc->MoveTo(m_start);
		dc->LineTo(m_end);

		m_end	= point;

		dc->MoveTo(m_start);
		dc->LineTo(m_end);

		dc->SelectObject(oldpen);
		break;
	case ACTION_MEASRECTAREA:
		oldpen	= dc->SelectObject(&pen);
		dc->SetROP2(R2_XORPEN);
		dc->MoveTo(m_start);
		dc->LineTo(m_end.x,m_start.y);
		dc->LineTo(m_end.x,m_end.y);
		dc->LineTo(m_start.x,m_end.y);
		dc->LineTo(m_start);

		m_end	= point;
		if (nFlags & MK_CONTROL)
		{
			if (abs(m_end.x - m_start.x) > abs(m_end.y - m_start.y))
			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -