MfcLabel.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #include "MfcLabel.h"
  2. #ifdef OPENCV_USE
  3. void MfcLabel::mfcLabel::AnalysisCvCoutour(
  4. std::vector<std::vector<cv::Point>>* Coutours,
  5. std::vector<cv::Vec4i>* Coutour_hier,
  6. int heircount)
  7. {
  8. fPolygon polygon;
  9. polygon.iInnerCount = 0;
  10. ReceiveCvCoutour(&(*Coutours)[heircount], false, &(polygon.Outer));
  11. if ((*Coutour_hier)[heircount][2] != -1)
  12. {
  13. int innerindex = (*Coutour_hier)[heircount][2];
  14. //doѭ��ֱ�Ӱ����е�inner������������
  15. do
  16. {
  17. fRing temp_ring;
  18. ReceiveCvCoutour(&(*Coutours)[innerindex], false, &temp_ring);
  19. polygon.Inner.push_back(temp_ring);
  20. polygon.iInnerCount++;
  21. innerindex = (*Coutour_hier)[innerindex][0];
  22. }while (innerindex != -1);
  23. }
  24. polygons.push_back(polygon);
  25. if ((*Coutour_hier)[heircount][0] != -1)
  26. {
  27. AnalysisCvCoutour(Coutours, Coutour_hier, (*Coutour_hier)[heircount][0]);
  28. }
  29. return ;
  30. }
  31. bool MfcLabel::mfcLabel::ReceiveCvCoutour(std::vector<cv::Point>* coutour, bool Notinner, MfcLabel::fRing* ring)
  32. {
  33. if (coutour == NULL)
  34. return false;
  35. int coutourlength = coutour->size();
  36. delete[] ring->pPoints;
  37. ring->m_nPointsCount = coutourlength;
  38. ring->pPoints = new fPoint[coutourlength];
  39. for (int i = 0; i < coutourlength; i++)
  40. {
  41. ring->pPoints[i].x = float((*coutour)[i].x);
  42. ring->pPoints[i].y = float((*coutour)[i].y);
  43. }
  44. ring->ComputeBox();
  45. return true;
  46. }
  47. #endif
  48. bool MfcLabel::mfcLabel::Empty()
  49. {
  50. if (iPolyCount == 0)
  51. return true;
  52. else
  53. return false;
  54. }
  55. #ifdef AFX_WIN
  56. BOOL MfcLabel::mfcLabel::ShowLabelInCDC(CDC* pDC)
  57. {
  58. return FALSE;
  59. }
  60. BOOL MfcLabel::mfcLabel::Serialize_S()
  61. {
  62. CFile outfile((CString)filePath.c_str(), CFile::modeWrite | CFile::modeCreate);
  63. CArchive ar(&outfile, CArchive::store);
  64. Serialize_StringS(ar, modelName);
  65. ar << score;
  66. Serialize_StringS(ar, filePath);
  67. ar << iPolyCount;
  68. for (int i = 0; i < iPolyCount; i++)
  69. {
  70. Serialize_fpolygonS(ar, &polygons[i]);
  71. }
  72. ar.Close();
  73. outfile.Close();
  74. return 1;
  75. }
  76. BOOL MfcLabel::mfcLabel::Serialize_L()
  77. {
  78. CFileFind finder;
  79. if (!finder.FindFile((CString)filePath.c_str()))
  80. {
  81. return 0;
  82. }
  83. CFile file((CString)filePath.c_str(), CFile::modeRead);
  84. CArchive ar(&file, CArchive::load);
  85. Serialize_StringL(ar, modelName);
  86. ar >> score;
  87. Serialize_StringL(ar, filePath);
  88. ar >> iPolyCount;
  89. polygons.resize(iPolyCount);
  90. for (int i = 0; i < iPolyCount; i++)
  91. {
  92. Serialize_fpolygonL(ar, &polygons[i]);
  93. }
  94. ar.Close();
  95. return 1;
  96. }
  97. void MfcLabel::mfcLabel::Serialize_StringS(CArchive& ar, std::string& szString)
  98. {
  99. int length = szString.length();
  100. ar << length;
  101. for (int i = 0; i < length; i++)
  102. {
  103. ar << szString[i];
  104. }
  105. return;
  106. }
  107. void MfcLabel::mfcLabel::Serialize_StringL(CArchive & ar, std::string& szString)
  108. {
  109. int length = 0;
  110. ar >> length;
  111. szString.resize(length);
  112. for (int i = 0; i < length; i++)
  113. {
  114. ar >> szString[i];
  115. }
  116. return;
  117. }
  118. void MfcLabel::mfcLabel::Serialize_fPointArrayS(CArchive & ar, fRing * pfsend)
  119. {
  120. int size = pfsend->m_nPointsCount;
  121. ar << size;
  122. for (int i = 0; i < size; i++)
  123. {
  124. ar << pfsend->pPoints[i].x;
  125. ar << pfsend->pPoints[i].y;
  126. }
  127. return;
  128. }
  129. void MfcLabel::mfcLabel::Serialize_fPointArrayL(CArchive & ar, fRing * pfreceive)
  130. {
  131. int size = 0;
  132. ar >> size;
  133. pfreceive->m_nPointsCount = size;
  134. pfreceive->pPoints = new fPoint[size];
  135. for (int i = 0; i < size; i++)
  136. {
  137. ar >> pfreceive->pPoints[i].x;
  138. ar >> pfreceive->pPoints[i].y;
  139. }
  140. return;
  141. }
  142. void MfcLabel::mfcLabel::Serialize_fpolygonS(CArchive & ar, fPolygon * pfsend)
  143. {
  144. Serialize_StringS(ar, pfsend->name);
  145. ar << pfsend->score;
  146. Serialize_fPointArrayS(ar, &pfsend->Outer);
  147. int size = pfsend->iInnerCount;
  148. ar << size;
  149. for (int i = 0; i < size; i++)
  150. {
  151. Serialize_fPointArrayS(ar, &pfsend->Inner[i]);
  152. }
  153. return;
  154. }
  155. void MfcLabel::mfcLabel::Serialize_fpolygonL(CArchive & ar, fPolygon * pfreceive)
  156. {
  157. Serialize_StringL(ar, pfreceive->name);
  158. ar >> pfreceive->score;
  159. Serialize_fPointArrayL(ar, &pfreceive->Outer);
  160. ar >> pfreceive->iInnerCount;
  161. pfreceive->Inner.resize(pfreceive->iInnerCount);
  162. for (int i = 0; i < pfreceive->iInnerCount; i++)
  163. {
  164. Serialize_fPointArrayL(ar, &pfreceive->Inner[i]);
  165. }
  166. return;
  167. }
  168. #endif // AFX_WIN
  169. MfcLabel::fPoint MfcLabel::fRing::GetTwoSegmentIntersectPt(fPoint FstStartPt, fPoint FstEndPt, fPoint SecStartPt, fPoint SecEndPt)
  170. {
  171. double x;
  172. double y;
  173. MfcLabel::fPoint result(-1, -1);
  174. if (MfcLabel::fRing::JudgeTwoSegmentIntersect(FstStartPt, FstEndPt, SecStartPt, SecEndPt))
  175. {
  176. const float WEIGHT_EPS = 1e-5f;
  177. double k = (FstStartPt.y - FstEndPt.y) / (FstStartPt.x - FstEndPt.x+ WEIGHT_EPS);
  178. double b = FstStartPt.y - k * FstStartPt.x;
  179. double k1 = (SecStartPt.y - SecEndPt.y) / (SecStartPt.x - SecEndPt.x+ WEIGHT_EPS);
  180. double b1 = SecStartPt.y - k1 * SecStartPt.x;
  181. x = (b1 - b) / (k - k1);
  182. y = k * x + b;
  183. result.x = float(x);
  184. result.y = float(y);
  185. }
  186. return result;
  187. }
  188. MfcLabel::fRing MfcLabel::fRing::GetTwoRingIntersectRing(fRing & FstRing, fRing & SecRing)
  189. {
  190. //���ȼ��һ�����������Ƿ����㹻��ĵ�
  191. if (FstRing.size() < 3 || SecRing.size() < 3)
  192. {
  193. return fRing();
  194. }
  195. long x, y;
  196. //���������
  197. std::vector<MfcLabel::fPoint> InterPtVec;
  198. for (int i = 0; i < FstRing.size(); i++)
  199. {
  200. //
  201. int poly1_next_idx = (i + 1) % FstRing.size();
  202. for (int j = 0; j < SecRing.size(); j++)
  203. {
  204. int poly2_next_idx = (j + 1) % SecRing.size();
  205. fPoint InterPt = GetTwoSegmentIntersectPt(FstRing.pPoints[i], FstRing.pPoints[poly1_next_idx],
  206. SecRing.pPoints[j], SecRing.pPoints[poly2_next_idx]);
  207. if (abs(InterPt.x - (-1))>FLT_EPSILON || abs(InterPt.y - (-1))>FLT_EPSILON)
  208. {
  209. InterPtVec.push_back(InterPt);
  210. }
  211. }
  212. }
  213. //���������ڲ���
  214. for (int i = 0; i < FstRing.size(); i++)
  215. {
  216. if (SecRing.JudgePtInRingOrNot(FstRing.pPoints[i]))
  217. {
  218. InterPtVec.push_back(FstRing.pPoints[i]);
  219. }
  220. }
  221. for (int i = 0; i < SecRing.size(); i++)
  222. {
  223. if (FstRing.JudgePtInRingOrNot(SecRing.pPoints[i]))
  224. {
  225. InterPtVec.push_back(SecRing.pPoints[i]);
  226. }
  227. }
  228. if (InterPtVec.size() <= 0)
  229. return MfcLabel::fRing();
  230. //�㼯����
  231. ClockwiseSortPoints(InterPtVec);
  232. //������ת��ΪfRing�����õ�
  233. MfcLabel::fRing ResRing;
  234. ResRing.m_nPointsCount =int( InterPtVec.size());
  235. ResRing.pPoints = new MfcLabel::fPoint[ResRing.m_nPointsCount];
  236. for (int i = 0; i < ResRing.m_nPointsCount; i++)
  237. ResRing.pPoints[i] = InterPtVec[i];
  238. ResRing.ComputeBox();
  239. return ResRing;
  240. }
  241. //����a���ڵ�b,����a�ڵ�b˳ʱ�뷽��,����true,���򷵻�false
  242. bool MfcLabel::fRing::PointCmp(const fPoint & a, const fPoint & b, const fPoint & center)
  243. {
  244. if (a.x >= 0 && b.x < 0)
  245. return true;
  246. if (a.x == 0 && b.x == 0)
  247. return a.y > b.y;
  248. //����OA������OB�IJ��
  249. int det =int( (a.x - center.x) * (b.y - center.y) )-int( (b.x - center.x) * (a.y - center.y));
  250. if (det < 0)
  251. return true;
  252. if (det > 0)
  253. return false;
  254. //����OA������OB���ߣ��Ծ����жϴ�С
  255. int d1 = int((a.x - center.x) * (a.x - center.x)) + int((a.y - center.y) * (a.y - center.y));
  256. int d2 = int((b.x - center.x) * (b.x - center.y)) + int((b.y - center.y) * (b.y - center.y));
  257. return d1 > d2;
  258. }
  259. void MfcLabel::fRing::ClockwiseSortPoints(std::vector<fPoint>& vPoints)
  260. {
  261. //��������
  262. MfcLabel::fPoint center;
  263. double x = 0, y = 0;
  264. for (int i = 0; i < vPoints.size(); i++)
  265. {
  266. x += vPoints[i].x;
  267. y += vPoints[i].y;
  268. }
  269. center.x = (int)x / vPoints.size();
  270. center.y = (int)y / vPoints.size();
  271. //����
  272. for (int i = 0; i < vPoints.size() - 1; i++)
  273. {
  274. for (int j = 0; j < vPoints.size(); j++)
  275. {
  276. if (j< vPoints.size() - 1)
  277. {
  278. if (PointCmp(vPoints[j], vPoints[j + 1], center))
  279. {
  280. MfcLabel::fPoint tmp = vPoints[j];
  281. vPoints[j] = vPoints[j + 1];
  282. vPoints[j + 1] = tmp;
  283. }
  284. }
  285. else
  286. {
  287. if (PointCmp(vPoints[j], vPoints[0], center))
  288. {
  289. MfcLabel::fPoint tmp = vPoints[j];
  290. vPoints[j] = vPoints[0];
  291. vPoints[0] = tmp;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. float MfcLabel::fRing::Area()
  298. {
  299. if (m_nPointsCount < 3) return 0.0;
  300. double s = pPoints[0].y * (pPoints[m_nPointsCount - 1].x - pPoints[1].x);
  301. for (int i = 1; i < m_nPointsCount; ++i)
  302. s += pPoints[i].y * (pPoints[i - 1].x - pPoints[(i + 1) % m_nPointsCount].x);
  303. return fabs(float(s * 0.5));
  304. }
  305. bool MfcLabel::fRect::JudgePtInRectBoxOrNot(fPoint TestPt)
  306. {
  307. if (TestPt.x > Right ||
  308. TestPt.x < Left ||
  309. TestPt.y > Bottom ||
  310. TestPt.y < Top)
  311. return false;
  312. else
  313. return true;
  314. }
  315. /***************************************************************************************************************************************
  316. �������ƣ�JudgePointInContour
  317. �����������жϵ��Ƿ��������ڲ��ĺ���
  318. ���������
  319. Point ���жϵĵ�
  320. ����ֵ��
  321. BOOL 1���������ڲ� ��1���������� ��0 ����������
  322. ˵����
  323. ��1���ú�����һ��Ҫ�󣬼��ж�֮ǰ����Ҫ����һ�ΰ�Χ���жϣ�����õ���������Χ���ڲ������������õ�ˮƽ���߳����㹻��������������
  324. ������ܳ��ֵ����������֮�⣬����̽�����޷����������������е������
  325. ***************************************************************************************************************************************/
  326. bool MfcLabel::fRing::JudgePtInRingOrNot(fPoint TestPt)
  327. {
  328. double dbRadio = 2 * (RectBox.Right - RectBox.Left);//���߳���
  329. fPoint OrigPt = TestPt;//������ʼ��
  330. fPoint EndPt(TestPt.x + float(dbRadio), TestPt.y);//���߽�����
  331. int nInterCount = 0;//�������
  332. int nContourVecLength = (int)m_nPointsCount;//�����������������
  333. std::vector<std::pair<int, bool>> SegIntersectPtVec;//�������ڵıߵ���ź��Ƿ�Ϊ�������������
  334. std::pair<int, bool> SegIntersectPt;//�ɶԵĽṹ
  335. std::vector<fPoint> ExpandPtVec;//�������ʹ�õ���չ����
  336. //������������3���ߣ��򲻹��ɶ�����İ�Χ��ֱ�ӷ���false
  337. if (nContourVecLength < 3)
  338. {
  339. return false;
  340. }
  341. if (TestPt.x < RectBox.Left
  342. || TestPt.x > RectBox.Right
  343. || TestPt.y < RectBox.Top
  344. || TestPt.y > RectBox.Bottom)
  345. return false;
  346. //Ϊ��������߼������ʼ��ExpandPtVec����������Contour������ǰ����չ2���㣬��ѭ���ķ�ʽend->0 ��������쳣��ԭ��,
  347. //������չ����ij���ΪnContourLength+4
  348. ExpandPtVec.push_back(pPoints[nContourVecLength - 2]);
  349. ExpandPtVec.push_back(pPoints[nContourVecLength - 1]);
  350. for (int i = 0; i < nContourVecLength; i++)
  351. {
  352. ExpandPtVec.push_back(pPoints[i]);
  353. }
  354. ExpandPtVec.push_back(pPoints[0]);
  355. ExpandPtVec.push_back(pPoints[1]);
  356. //ͨ����������Ƿ����߶���
  357. for (int i = 2; i < nContourVecLength + 2; i++)
  358. {
  359. double Product = (OrigPt.x - ExpandPtVec[i].x) * (ExpandPtVec[i + 1].y - ExpandPtVec[i].y) - (ExpandPtVec[i + 1].x - ExpandPtVec[i].x) * (OrigPt.y - ExpandPtVec[i].y);
  360. if (fabs(Product) < DBL_EPSILON)
  361. {
  362. return true;
  363. }
  364. }
  365. //��������Χ�ڵ������߳����������ߵ�����Ƿ�����������ݲ�ͬ������ñ�־λ
  366. for (int i = 2; i < nContourVecLength + 2; i++)
  367. {
  368. //��������������ϵ��ཻ������Ժ�������
  369. if (JudgeTwoSegmentIntersect(OrigPt, EndPt, ExpandPtVec[i], ExpandPtVec[i + 1]))
  370. {
  371. //�ص���Խˮƽ�����
  372. if (ExpandPtVec[i].y == ExpandPtVec[i + 1].y)
  373. {
  374. SegIntersectPt.first = i;
  375. SegIntersectPt.second = true;
  376. SegIntersectPtVec.push_back(SegIntersectPt);
  377. }
  378. //��Խ����������
  379. else if (OrigPt.y == ExpandPtVec[i].y || OrigPt.y == ExpandPtVec[i + 1].y)
  380. {
  381. SegIntersectPt.first = i;
  382. SegIntersectPt.second = true;
  383. SegIntersectPtVec.push_back(SegIntersectPt);
  384. }
  385. //��ͨ�Ĵ�Խ�����ߵ����
  386. else
  387. {
  388. SegIntersectPt.first = i;
  389. SegIntersectPt.second = false;
  390. SegIntersectPtVec.push_back(SegIntersectPt);
  391. }
  392. }
  393. }
  394. //�������õı�־λ�ж�������������������ص���Խˮƽ�����������Խ�������������е��ظ����ֵı���Ϊ��ȵıߣ��Ա�����ļ������ж�ȥ���ظ�
  395. int nInterVecLength = (int)SegIntersectPtVec.size();
  396. for (int i = 0; i < nInterVecLength; i++)
  397. {
  398. if (i != (nInterVecLength - 1) && SegIntersectPtVec[i].second && SegIntersectPtVec[i + 1].second)
  399. {
  400. if (SegIntersectPtVec[i].first + 1 == SegIntersectPtVec[i + 1].first)
  401. SegIntersectPtVec[i].first = SegIntersectPtVec[i + 1].first;
  402. }
  403. else if (SegIntersectPtVec[i].second && SegIntersectPtVec[0].second)
  404. {
  405. if (SegIntersectPtVec[i].first + 1 == SegIntersectPtVec[0].first)
  406. SegIntersectPtVec[i].first = SegIntersectPtVec[0].first;
  407. }
  408. }
  409. //��ʼ�����ܹ��еĽ������
  410. for (int i = 0; i < nInterVecLength; i++)
  411. {
  412. //�����ʶΪFalse˵������ͨ��Խ�����ֱ�ӽ��㣫1
  413. if (!SegIntersectPtVec[i].second)
  414. {
  415. nInterCount += 1;
  416. }
  417. else
  418. {
  419. //ͨ����һ���ҵ��Ĵ�Խ����Ϊ�����Ļ�ʯ�����ҳ��ô�Խ���ڴ�Խ�������ڵı߽磬�´�ѭ����Խ���õ㴦����һ����
  420. int j = SegIntersectPtVec[i].first;
  421. while (SegIntersectPtVec[i].first == j)
  422. {
  423. if (i == nInterVecLength - 1)
  424. {
  425. i++;
  426. break;
  427. }
  428. i++;
  429. }
  430. i--;
  431. //��������д��������ﴦ�����ص���Խˮƽ�������
  432. if (ExpandPtVec[j].y == ExpandPtVec[j + 1].y)
  433. {
  434. if (
  435. (ExpandPtVec[j - 1].y > OrigPt.y)
  436. && (ExpandPtVec[j + 2].y > OrigPt.y))
  437. {
  438. nInterCount += 2;
  439. }
  440. else if ((ExpandPtVec[j - 1].y < OrigPt.y)
  441. && (ExpandPtVec[j + 2].y < OrigPt.y))
  442. {
  443. nInterCount += 2;
  444. }
  445. else if ((ExpandPtVec[j - 1].y < OrigPt.y)
  446. && (ExpandPtVec[j + 2].y > OrigPt.y))
  447. {
  448. nInterCount += 1;
  449. }
  450. else if ((ExpandPtVec[j - 1].y > OrigPt.y)
  451. && (ExpandPtVec[j + 2].y < OrigPt.y))
  452. {
  453. nInterCount += 1;
  454. }
  455. }
  456. else
  457. {
  458. //��������д��������ﴦ������Խ������������
  459. if (
  460. (ExpandPtVec[j - 1].y > OrigPt.y)
  461. && (ExpandPtVec[j + 1].y > OrigPt.y))
  462. {
  463. nInterCount += 2;
  464. }
  465. else if ((ExpandPtVec[j - 1].y < OrigPt.y)
  466. && (ExpandPtVec[j + 1].y < OrigPt.y))
  467. {
  468. nInterCount += 2;
  469. }
  470. else if ((ExpandPtVec[j - 1].y < OrigPt.y)
  471. && (ExpandPtVec[j + 1].y > OrigPt.y))
  472. {
  473. nInterCount += 1;
  474. }
  475. else if ((ExpandPtVec[j - 1].y > OrigPt.y)
  476. && (ExpandPtVec[j + 1].y < OrigPt.y))
  477. {
  478. nInterCount += 1;
  479. }
  480. }
  481. }
  482. }
  483. std::vector<fPoint>().swap(ExpandPtVec);
  484. //����Ϊż�����ж�Ϊ���������⣬����Ϊ�������ж�����������
  485. if (nInterCount % 2 == 0)
  486. {
  487. return false;
  488. }
  489. return true;
  490. }
  491. bool MfcLabel::fRing::JudgeRingIntersectOrNot(fRing & TestRing)
  492. {
  493. //�����ж�����ring��Box�Ƿ��ཻ
  494. if (JudgeRectBoxIntersectOrNot(TestRing.RectBox, RectBox))
  495. {
  496. for (int referLine = 0; referLine < m_nPointsCount; referLine++)
  497. {
  498. int nNextReferPtIndex = (referLine + 1) % m_nPointsCount;
  499. for (int testLine = 0; testLine < TestRing.m_nPointsCount; testLine++)
  500. {
  501. int nNextTestPtIndex = (testLine + 1) % TestRing.m_nPointsCount;
  502. if (JudgeTwoSegmentIntersect(pPoints[referLine], pPoints[nNextReferPtIndex], TestRing.pPoints[testLine], TestRing.pPoints[nNextTestPtIndex]))
  503. return true;
  504. else
  505. continue;
  506. }
  507. }
  508. }
  509. return false;
  510. }
  511. bool MfcLabel::fRing::JudgeTwoSegmentIntersect(fPoint& FirstLineStartPt, fPoint& FirstLineEndPt, fPoint& SecondLineStartPt, fPoint& SecondLineEndPt)
  512. {
  513. //�������������߶ε��Ƿ��ų��ʵ�顣
  514. fRect test, refer;
  515. test = GetRectWithTwoPoint(FirstLineStartPt, FirstLineEndPt);
  516. refer = GetRectWithTwoPoint(SecondLineStartPt, SecondLineEndPt);
  517. if (!JudgeRectBoxIntersectOrNot(test, refer))
  518. {
  519. return false;
  520. }
  521. //todo��Ҫ�޸�
  522. //��Ҫ����ֱ���໥�����ſ���
  523. if (FirstLineStartPt.VectorSub(SecondLineStartPt).GetVectorProduct(SecondLineEndPt.VectorSub(SecondLineStartPt))
  524. * SecondLineEndPt.VectorSub(SecondLineStartPt).GetVectorProduct(FirstLineEndPt.VectorSub(SecondLineStartPt)) >= -DBL_EPSILON)
  525. {
  526. if (SecondLineStartPt.VectorSub(FirstLineStartPt).GetVectorProduct(FirstLineEndPt.VectorSub(FirstLineStartPt)) *
  527. FirstLineEndPt.VectorSub(FirstLineStartPt).GetVectorProduct(SecondLineEndPt.VectorSub(FirstLineStartPt)) >= -DBL_EPSILON)
  528. return true;
  529. else
  530. return false;
  531. }
  532. else
  533. return false;
  534. }
  535. MfcLabel::fRect MfcLabel::fRing::GetRectWithTwoPoint(fPoint& Pt1, fPoint& Pt2)
  536. {
  537. fRect TwoPtRcbox;
  538. if (Pt1.x <= Pt2.x)
  539. {
  540. TwoPtRcbox.Left = (long)Pt1.x;
  541. TwoPtRcbox.Right = (long)Pt2.x;
  542. }
  543. else
  544. {
  545. TwoPtRcbox.Left = (long)Pt2.x;
  546. TwoPtRcbox.Right = (long)Pt1.x;
  547. }
  548. //���Pt1����Pt2���ϱߣ���Crect �����±߽�ȷ��
  549. if (Pt1.y <= Pt2.y)
  550. {
  551. TwoPtRcbox.Top = (long)Pt1.y;
  552. TwoPtRcbox.Bottom = (long)Pt2.y;
  553. }
  554. else
  555. {
  556. TwoPtRcbox.Top = (long)Pt2.y;
  557. TwoPtRcbox.Bottom = (long)Pt1.y;
  558. }
  559. return TwoPtRcbox;
  560. }
  561. bool MfcLabel::fRing::JudgeRectBoxIntersectOrNot(fRect& Rect1, fRect& Rect2)
  562. {
  563. if (Rect1.Right<Rect2.Left
  564. || Rect1.Left >Rect2.Right
  565. || Rect1.Top > Rect2.Bottom
  566. || Rect1.Bottom < Rect2.Top)
  567. {
  568. return false;
  569. }
  570. return true;
  571. }
  572. double MfcLabel::fPoint::GetVectorProduct(fPoint B)
  573. {
  574. return x * B.y - B.x * y;
  575. }
  576. MfcLabel::fPoint MfcLabel::fPoint::VectorSub(fPoint B)
  577. {
  578. return fPoint(x-B.x,y-B.y);
  579. }