CGBCalculate.cpp 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "CGBCalculate.h"
  4. #include "OTSFieldData.h"
  5. #include "GBImgPropCal.h"
  6. #include "OTSHelper.h"
  7. #include "MultiLang.h"
  8. namespace OTSMODEL
  9. {
  10. using namespace OTSDATA;
  11. using namespace OTSIMGPROC;
  12. CGBCalculate::CGBCalculate(CReportProjFileMgr* rptMgrPtr)
  13. {
  14. m_rptMgrPtr = rptMgrPtr;
  15. }
  16. CGBCalculate::~CGBCalculate()
  17. {
  18. }
  19. // class methods
  20. // public
  21. CGridDatasList CGBCalculate::GetGBInclusion()
  22. {
  23. // use the dll resource
  24. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  25. CGBFieldList listCGBField;
  26. //CGBFieldMgr pCGBFieldMgr;
  27. COTSParticleList listOTSParticle;
  28. COTSParticlePtr pOTSParticle;
  29. CGBImgPropCal pGBImgPropCal;
  30. CGridDatasList listGridData;
  31. listGridData.clear();
  32. CGridDatasList multGridList;
  33. multGridList.clear();
  34. // depart compound source name
  35. CPropParamPtr currentProp = m_rptMgrPtr->GetCurrentPropParam();
  36. std::vector<CString> listDataSource = currentProp->GetDataSourceList();
  37. int nSelectedDataSourceIndex = currentProp->GetDataSourceId();
  38. CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex];
  39. std::vector<CString> listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+"));
  40. for (auto strDataSourceName : listSelectedDataSource)
  41. {
  42. listCGBField.clear();
  43. CGridDataPtr pGridData = CGridDataPtr(new CGridData());
  44. // data source id
  45. std::vector<CString> listDataSource;
  46. listDataSource.clear();
  47. listDataSource = currentProp->GetDataSourceList();
  48. pGridData->SetDataSourceList(listDataSource);
  49. int nDataSourceId = currentProp->GetDataSourceId();
  50. pGridData->SetDataSourceId(nDataSourceId);
  51. CSmplMsrResultFileMgrPtr rstFileMgrPrt = m_rptMgrPtr->GetASmplMsrResultMgrByFileName(strDataSourceName);
  52. // sample measurment result file manager
  53. CSmplMsrResultFileMgr* pSmplMsrResultFileMgr;
  54. pSmplMsrResultFileMgr = rstFileMgrPrt.get();
  55. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile();
  56. COTSSamplePtr pSample = pSmplMsrResultFile->GetSample();
  57. double dPixelSize = pSample->CalculatePixelSize();
  58. SetPixSize(dPixelSize);
  59. CGBFieldList listRawGBFields = CalGBFields(pSmplMsrResultFileMgr);
  60. listCGBField = listRawGBFields;
  61. //for each (COTSFieldDataPtr GBfield in listRawGBFields)
  62. //{
  63. // listOTSParticle = GBfield->GetParticleList();
  64. // for each (COTSParticlePtr Particle in listOTSParticle)
  65. // {
  66. // double a_dPartFTD;
  67. // double a_dMinWidth;
  68. // double a_dMaxLength;
  69. // double a_dRatio;
  70. // /*pGBImgPropCal.GetParticleFTD(Particle, dPixelSize, a_dPartFTD, a_dMinWidth , a_dMaxLength, a_dRatio);
  71. //
  72. // Particle->SetFeretDiameter(a_dPartFTD);
  73. //
  74. // Particle->SetWidth(a_dMinWidth);
  75. // Particle->SetHeight(a_dMaxLength);*/
  76. // }
  77. // //cal stdFrame
  78. // CGBFieldDataPtr GBFld(new CGBFieldData());
  79. // GBFld->SetParticleList(listOTSParticle,TRUE);
  80. // GBFld->SetPosition(GBfield->GetPosition());
  81. //
  82. // listCGBField.push_back(GBFld);
  83. //}
  84. CALCULATE_TABLE_TYPE ty = m_rptMgrPtr->GetCurrentPropParam()->GetCalTableType();
  85. if (ty == CALCULATE_TABLE_TYPE::DIN)
  86. {
  87. listGridData = this->GetGridDataListForOneDataSourceDIN(pSmplMsrResultFile->GetAllParticles());
  88. }
  89. else
  90. {
  91. listGridData = this->GetGridDataListForOneDataSource(listCGBField);
  92. }
  93. multGridList.insert(multGridList.end(), listGridData.begin(), listGridData.end());
  94. }
  95. return multGridList;
  96. }
  97. CGridDatasList CGBCalculate::GetGridDataListForOneDataSource(CGBFieldList listCGBField)
  98. {
  99. CGridDatasList listGridData;
  100. //Definition numbers
  101. //use the nXLevel array to memory how many fields in each level.
  102. CONST int LEVEL_LENGTH = 11;
  103. int nALevel[LEVEL_LENGTH]; //nALevelZero, nALevel_0_5, nALevel_1_0, nALevel_1_5, nALevel_2_0, nALevel_2_5, nALevel_3_0, nALevel_3_5, nALevel_4_0, nALevel_4_5, nALevel_5_0 ;
  104. int nALevel_w[LEVEL_LENGTH]; //nALevelZero_f, nALevel_0_5_f, nALevel_1_0_f, nALevel_1_5_f, nALevel_2_0_f, nALevel_2_5_f, nALevel_3_0_f, nALevel_3_5_f, nALevel_4_0_f, nALevel_4_5_f, nALevel_5_0_f;
  105. int nALevel_s[LEVEL_LENGTH];
  106. int nBLevel[LEVEL_LENGTH]; //nBLevelZero, nBLevel_0_5, nBLevel_1_0, nBLevel_1_5, nBLevel_2_0, nBLevel_2_5, nBLevel_3_0, nBLevel_3_5, nBLevel_4_0, nBLevel_4_5, nBLevel_5_0;
  107. int nBLevel_w[LEVEL_LENGTH]; //nBLevelZero_f, nBLevel_0_5_f, nBLevel_1_0_f, nBLevel_1_5_f, nBLevel_2_0_f, nBLevel_2_5_f, nBLevel_3_0_f, nBLevel_3_5_f, nBLevel_4_0_f, nBLevel_4_5_f, nBLevel_5_0_f;
  108. int nBLevel_s[LEVEL_LENGTH];
  109. int nCLevel[LEVEL_LENGTH]; //nCLevelZero, nCLevel_0_5, nCLevel_1_0, nCLevel_1_5, nCLevel_2_0, nCLevel_2_5, nCLevel_3_0, nCLevel_3_5, nCLevel_4_0, nCLevel_4_5, nCLevel_5_0;
  110. int nCLevel_w[LEVEL_LENGTH]; //nCLevelZero_f, nCLevel_0_5_f, nCLevel_1_0_f, nCLevel_1_5_f, nCLevel_2_0_f, nCLevel_2_5_f, nCLevel_3_0_f, nCLevel_3_5_f, nCLevel_4_0_f, nCLevel_4_5_f, nCLevel_5_0_f;
  111. int nCLevel_s[LEVEL_LENGTH];
  112. int nDLevel[LEVEL_LENGTH];// nDLevelZero, nDLevel_0_5, nDLevel_1_0, nDLevel_1_5, nDLevel_2_0, nDLevel_2_5, nDLevel_3_0, nDLevel_3_5, nDLevel_4_0, nDLevel_4_5, nDLevel_5_0;
  113. int nDLevel_w[LEVEL_LENGTH]; //nDLevelZero_f, nDLevel_0_5_f, nDLevel_1_0_f, nDLevel_1_5_f, nDLevel_2_0_f, nDLevel_2_5_f, nDLevel_3_0_f, nDLevel_3_5_f, nDLevel_4_0_f, nDLevel_4_5_f, nDLevel_5_0_f;
  114. int nDLevel_s[LEVEL_LENGTH];
  115. int nDSulfideLevel[LEVEL_LENGTH];// nDLevelZero, nDLevel_0_5, nDLevel_1_0, nDLevel_1_5, nDLevel_2_0, nDLevel_2_5, nDLevel_3_0, nDLevel_3_5, nDLevel_4_0, nDLevel_4_5, nDLevel_5_0;
  116. int nDSulfideLevel_w[LEVEL_LENGTH]; //nDLevelZero_f, nDLevel_0_5_f, nDLevel_1_0_f, nDLevel_1_5_f, nDLevel_2_0_f, nDLevel_2_5_f, nDLevel_3_0_f, nDLevel_3_5_f, nDLevel_4_0_f, nDLevel_4_5_f, nDLevel_5_0_f;
  117. int nDSulfideLevel_s[LEVEL_LENGTH];
  118. CGBFieldList listDSFrame;
  119. //initlize
  120. for (int i = 0; i < LEVEL_LENGTH; i++)
  121. {
  122. nALevel[i] = 0;
  123. nALevel_w[i] = 0;
  124. nALevel_s[i] = 0;
  125. nBLevel[i] = 0;
  126. nBLevel_w[i] = 0;
  127. nBLevel_s[i] = 0;
  128. nCLevel[i] = 0;
  129. nCLevel_w[i] = 0;
  130. nCLevel_s[i] = 0;
  131. nDLevel[i] = 0;
  132. nDLevel_w[i] = 0;
  133. nDLevel_s[i] = 0;
  134. nDSulfideLevel[i] = 0;
  135. nDSulfideLevel_w[i] = 0;
  136. nDSulfideLevel_s[i] = 0;
  137. }
  138. //loop CGBField list and cal the level numbers
  139. for each (CGBFieldDataPtr GBFld in listCGBField)
  140. {
  141. //CalLevel mode
  142. switch (m_rptMgrPtr->GetCurrentPropParam()->GetCalTableType())
  143. {
  144. case CALCULATE_TABLE_TYPE::GB_Method1:
  145. GBFld->CaculateLevelByMethod1();
  146. break;
  147. case CALCULATE_TABLE_TYPE::GB_Method2:
  148. GBFld->CaculateLevelByMethod2();
  149. break;
  150. case CALCULATE_TABLE_TYPE::ASTM:
  151. GBFld->CaculateLevelASTM();
  152. break;
  153. default:
  154. break;
  155. }
  156. GB_GRADE_TYPE levelt = GBFld->GetALevel()->GetThinGrade();
  157. GB_GRADE_TYPE levelw = GBFld->GetALevel()->GetWideGrade();
  158. GB_GRADE_TYPE levels = GBFld->GetALevel()->GetSuperGrade();
  159. SetFrameLevelNo(levelt, nALevel);
  160. SetFrameLevelNo(levelw, nALevel_w);
  161. SetFrameLevelNo(levels, nALevel_s);
  162. levelt = GBFld->GetBLevel()->GetThinGrade();
  163. levelw = GBFld->GetBLevel()->GetWideGrade();
  164. levels = GBFld->GetBLevel()->GetSuperGrade();
  165. SetFrameLevelNo(levelt, nBLevel);
  166. SetFrameLevelNo(levelw, nBLevel_w);
  167. SetFrameLevelNo(levels, nBLevel_s);
  168. levelt = GBFld->GetCLevel()->GetThinGrade();
  169. levelw = GBFld->GetCLevel()->GetWideGrade();
  170. levels = GBFld->GetCLevel()->GetSuperGrade();
  171. SetFrameLevelNo(levelt, nCLevel);
  172. SetFrameLevelNo(levelw, nCLevel_w);
  173. SetFrameLevelNo(levels, nCLevel_s);
  174. levelt = GBFld->GetDLevel()->GetThinGrade();
  175. levelw = GBFld->GetDLevel()->GetWideGrade();
  176. levels = GBFld->GetDLevel()->GetSuperGrade();
  177. SetFrameLevelNo(levelt, nDLevel);
  178. SetFrameLevelNo(levelw, nDLevel_w);
  179. SetFrameLevelNo(levels, nDLevel_s);
  180. }
  181. //Get ListGrid for Level
  182. //CalLevel mode
  183. CGridDataPtr AGrid;
  184. CGridDataPtr BGrid;
  185. CGridDataPtr CGrid;
  186. CGridDataPtr DGrid;
  187. CGridDataPtr DSulfideGrid;
  188. CGridDataPtr DSGrid;
  189. CGridDataPtr GBFieldGrid;
  190. switch (m_rptMgrPtr->GetCurrentPropParam()->GetCalTableType())
  191. {
  192. case CALCULATE_TABLE_TYPE::GB_Method1:
  193. AGrid = GetGridLevel("A", nALevel, nALevel_w, nALevel_s);
  194. BGrid = GetGridLevel("B", nBLevel, nBLevel_w, nBLevel_s);
  195. CGrid = GetGridLevel("C", nCLevel, nCLevel_w, nCLevel_s);
  196. DGrid = GetGridLevel("D", nDLevel, nDLevel_w, nDLevel_s);
  197. DSGrid = GetGridDSLevel(listCGBField);
  198. GBFieldGrid = GetGBFieldGrid(listCGBField);
  199. listGridData.push_back(AGrid);
  200. listGridData.push_back(BGrid);
  201. listGridData.push_back(CGrid);
  202. listGridData.push_back(DGrid);
  203. listGridData.push_back(DSGrid);
  204. listGridData.push_back(GBFieldGrid);
  205. //listGridData
  206. return listGridData;
  207. break;
  208. case CALCULATE_TABLE_TYPE::GB_Method2:
  209. AGrid = GetGridLevel("A", nALevel, nALevel_w, nALevel_s);
  210. BGrid = GetGridLevel("B", nBLevel, nBLevel_w, nBLevel_s);
  211. CGrid = GetGridLevel("C", nCLevel, nCLevel_w, nCLevel_s);
  212. DGrid = GetGridLevel("D", nDLevel, nDLevel_w, nDLevel_s);
  213. DSulfideGrid = GetGridLevel("DSulfide", nDSulfideLevel, nDSulfideLevel_w, nDSulfideLevel_s);
  214. DSGrid = GetGridDSLevel(listCGBField);
  215. GBFieldGrid = GetGBFieldGrid(listCGBField);
  216. listGridData.push_back(AGrid);
  217. listGridData.push_back(BGrid);
  218. listGridData.push_back(CGrid);
  219. listGridData.push_back(DGrid);
  220. listGridData.push_back(DSulfideGrid);
  221. listGridData.push_back(DSGrid);
  222. listGridData.push_back(GBFieldGrid);
  223. //listGridData
  224. return listGridData;
  225. break;
  226. case CALCULATE_TABLE_TYPE::ASTM:
  227. AGrid = GetGridLevel("A", nALevel, nALevel_w, nALevel_s);
  228. BGrid = GetGridLevel("B", nBLevel, nBLevel_w, nBLevel_s);
  229. CGrid = GetGridLevel("C", nCLevel, nCLevel_w, nCLevel_s);
  230. DGrid = GetGridLevel("D", nDLevel, nDLevel_w, nDLevel_s);
  231. DSGrid = GetGridDSLevel(listCGBField);
  232. GBFieldGrid = GetGBFieldGrid(listCGBField);
  233. listGridData.push_back(AGrid);
  234. listGridData.push_back(BGrid);
  235. listGridData.push_back(CGrid);
  236. listGridData.push_back(DGrid);
  237. listGridData.push_back(DSGrid);
  238. listGridData.push_back(GBFieldGrid);
  239. //listGridData
  240. return listGridData;
  241. break;
  242. default:
  243. return listGridData;
  244. break;
  245. }
  246. }
  247. CGridDatasList CGBCalculate::GetGridDataListForOneDataSourceDIN(COTSParticleList listParticle)
  248. {
  249. CGridDatasList listGridData;
  250. COTSParticleList cotsparticlelistA;
  251. set<COTSParticlePtr> cotsparticlelistB;
  252. COTSParticleList cotsparticlelistC;
  253. COTSParticleList cotsparticlelistD;
  254. //loop CGBField list and cal the level numbers
  255. CGBFieldDataPtr GBFld(new CGBFieldData());
  256. GBFld->SetParticleList(listParticle, TRUE);
  257. GBFld->CaculateLevelDIN(listParticle);
  258. cotsparticlelistA = GBFld->listAThinParticles;
  259. cotsparticlelistB = GBFld->listBThinParticles;
  260. cotsparticlelistC = GBFld->listCThinParticles;
  261. cotsparticlelistD = GBFld->listDThinParticles;
  262. //Get ListGrid for Level
  263. //CalLevel mode
  264. CGridDataPtr AGrid;
  265. AGrid = GetGridDIN(cotsparticlelistA, cotsparticlelistB, cotsparticlelistC, cotsparticlelistD);
  266. listGridData.push_back(AGrid);
  267. //listGridData
  268. return listGridData;
  269. }
  270. //CGridDataPtr CGBFieldMgr::GetGBFieldGrid(CGBFieldList listCGBField, CGridInPtr a_pGridIn);
  271. CGridDataPtr CGBCalculate::GetGBFieldGrid(CGBFieldList listCGBField)
  272. {
  273. CGridDataPtr pGridData = CGridDataPtr(new CGridData());
  274. std::vector<CString> listDataSource;
  275. listDataSource.clear();
  276. listDataSource = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceList();
  277. pGridData->SetDataSourceList(listDataSource);
  278. int nDataSourceId = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceId();
  279. pGridData->SetDataSourceId(nDataSourceId);
  280. //amounts
  281. CGridColumnsList listCol;
  282. listCol.clear();
  283. int columnNum = 11;//表格总列数 fieldpos 占2列,ABCDDS 占5列,particle占1列,particle 类别占1列,particle宽度占1列
  284. CGridColumnPtr pColumn;
  285. for (int i = 0; i < columnNum; i++)
  286. {
  287. CString strName;
  288. CGridRowsList listRows;
  289. CGridRowPtr pRow;
  290. switch (i)
  291. {
  292. case 0:
  293. pColumn = CGridColumnPtr(new CGridColumn());
  294. pColumn->SetName("FieldPosX");
  295. for (auto GBF : listCGBField)
  296. {
  297. for (auto p : GBF->GetParticleList())
  298. {
  299. pRow = CGridRowPtr(new CGridRow());
  300. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  301. pRow->SetIntValue(GBF->GetPosition().x);
  302. listRows.push_back(pRow);
  303. }
  304. }
  305. pColumn->SetGridRowsList(listRows);
  306. listCol.push_back(pColumn);
  307. break;
  308. case 1:
  309. pColumn = CGridColumnPtr(new CGridColumn());
  310. pColumn->SetName("FieldPosY");
  311. for (auto GBF : listCGBField)
  312. {
  313. for (auto p : GBF->GetParticleList())
  314. {
  315. pRow = CGridRowPtr(new CGridRow());
  316. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  317. pRow->SetIntValue(GBF->GetPosition().y);
  318. listRows.push_back(pRow);
  319. }
  320. }
  321. pColumn->SetGridRowsList(listRows);
  322. listCol.push_back(pColumn);
  323. break;
  324. case 2:
  325. pColumn = CGridColumnPtr(new CGridColumn());
  326. pColumn->SetName("ALevel");
  327. for (auto GBF : listCGBField)
  328. {
  329. for (auto p : GBF->GetParticleList())
  330. {
  331. pRow = CGridRowPtr(new CGridRow());
  332. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  333. std::string Athin, Awide, Asuper;
  334. auto Alevel = GBF->GetALevel();
  335. auto thin = Alevel->GetThinGrade();
  336. Athin = GetLevelStr(thin);
  337. Awide = GetLevelStr(Alevel->GetWideGrade());
  338. Asuper = GetLevelStr(Alevel->GetSuperGrade());
  339. pRow->SetStringValue((Athin + "," + Awide + "," + Asuper).c_str());
  340. listRows.push_back(pRow);
  341. }
  342. }
  343. pColumn->SetGridRowsList(listRows);
  344. listCol.push_back(pColumn);
  345. break;
  346. case 3:
  347. pColumn = CGridColumnPtr(new CGridColumn());
  348. pColumn->SetName("BLevel");
  349. for (auto GBF : listCGBField)
  350. {
  351. for (auto p : GBF->GetParticleList())
  352. {
  353. pRow = CGridRowPtr(new CGridRow());
  354. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  355. std::string thin, wide, super;
  356. auto level = GBF->GetBLevel();
  357. thin = GetLevelStr(level->GetThinGrade());
  358. wide = GetLevelStr(level->GetWideGrade());
  359. super = GetLevelStr(level->GetSuperGrade());
  360. pRow->SetStringValue((thin + "," + wide + "," + super).c_str());
  361. listRows.push_back(pRow);
  362. }
  363. }
  364. pColumn->SetGridRowsList(listRows);
  365. listCol.push_back(pColumn);
  366. break;
  367. case 4:
  368. pColumn = CGridColumnPtr(new CGridColumn());
  369. pColumn->SetName("CLevel");
  370. for (auto GBF : listCGBField)
  371. {
  372. for (auto p : GBF->GetParticleList())
  373. {
  374. pRow = CGridRowPtr(new CGridRow());
  375. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  376. std::string thin, wide, super;
  377. auto level = GBF->GetCLevel();
  378. thin = GetLevelStr(level->GetThinGrade());
  379. wide = GetLevelStr(level->GetWideGrade());
  380. super = GetLevelStr(level->GetSuperGrade());
  381. pRow->SetStringValue((thin + "," + wide + "," + super).c_str());
  382. listRows.push_back(pRow);
  383. }
  384. }
  385. pColumn->SetGridRowsList(listRows);
  386. listCol.push_back(pColumn);
  387. break;
  388. case 5:
  389. pColumn = CGridColumnPtr(new CGridColumn());
  390. pColumn->SetName("DLevel");
  391. for (auto GBF : listCGBField)
  392. {
  393. for (auto p : GBF->GetParticleList())
  394. {
  395. pRow = CGridRowPtr(new CGridRow());
  396. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  397. std::string thin, wide, super;
  398. auto level = GBF->GetDLevel();
  399. thin = GetLevelStr(level->GetThinGrade());
  400. wide = GetLevelStr(level->GetWideGrade());
  401. super = GetLevelStr(level->GetSuperGrade());
  402. pRow->SetStringValue((thin + "," + wide + "," + super).c_str());
  403. listRows.push_back(pRow);
  404. }
  405. }
  406. pColumn->SetGridRowsList(listRows);
  407. listCol.push_back(pColumn);
  408. break;
  409. case 6:
  410. pColumn = CGridColumnPtr(new CGridColumn());
  411. pColumn->SetName("DSLevel");
  412. for (auto GBF : listCGBField)
  413. {
  414. for (auto p : GBF->GetParticleList())
  415. {
  416. pRow = CGridRowPtr(new CGridRow());
  417. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  418. std::string thin, wide, super;
  419. auto level = GBF->GetDSLevel();
  420. thin = GetLevelStr(level->GetThinGrade());
  421. wide = GetLevelStr(level->GetWideGrade());
  422. super = GetLevelStr(level->GetSuperGrade());
  423. pRow->SetStringValue((thin + "," + wide + "," + super).c_str());
  424. listRows.push_back(pRow);
  425. }
  426. }
  427. pColumn->SetGridRowsList(listRows);
  428. listCol.push_back(pColumn);
  429. break;
  430. case 7:
  431. pColumn = CGridColumnPtr(new CGridColumn());
  432. pColumn->SetName("DSulfideLevel");
  433. for (auto GBF : listCGBField)
  434. {
  435. for (auto p : GBF->GetParticleList())
  436. {
  437. pRow = CGridRowPtr(new CGridRow());
  438. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  439. std::string thin, wide, super;
  440. auto level = GBF->GetDSulfideLevel();
  441. thin = GetLevelStr(level->GetThinGrade());
  442. wide = GetLevelStr(level->GetWideGrade());
  443. super = GetLevelStr(level->GetSuperGrade());
  444. pRow->SetStringValue((thin + "," + wide + "," + super).c_str());
  445. listRows.push_back(pRow);
  446. }
  447. }
  448. pColumn->SetGridRowsList(listRows);
  449. listCol.push_back(pColumn);
  450. break;
  451. case 8:
  452. pColumn = CGridColumnPtr(new CGridColumn());
  453. pColumn->SetName("Particle");
  454. for (auto GBF : listCGBField)
  455. {
  456. for (auto p : GBF->GetParticleList())
  457. {
  458. pRow = CGridRowPtr(new CGridRow());
  459. pRow->SetParticle(p);
  460. listRows.push_back(pRow);
  461. }
  462. }
  463. pColumn->SetGridRowsList(listRows);
  464. listCol.push_back(pColumn);
  465. break;
  466. case 9:
  467. pColumn = CGridColumnPtr(new CGridColumn());
  468. pColumn->SetName("ParticleGBClass");
  469. for (auto GBF : listCGBField)
  470. {
  471. for (auto p : GBF->GetParticleList())
  472. {
  473. int l = (int)GBF->mapAllParticles[p].myType;
  474. pRow = CGridRowPtr(new CGridRow());
  475. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  476. pRow->SetIntValue(l);
  477. listRows.push_back(pRow);
  478. }
  479. }
  480. pColumn->SetGridRowsList(listRows);
  481. listCol.push_back(pColumn);
  482. break;
  483. case 10:
  484. pColumn = CGridColumnPtr(new CGridColumn());
  485. pColumn->SetName("ParticleGBWidthClass");
  486. for (auto GBF : listCGBField)
  487. {
  488. for (auto p : GBF->GetParticleList())
  489. {
  490. int w = (int)GBF->mapAllParticles[p].myWidth;
  491. pRow = CGridRowPtr(new CGridRow());
  492. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  493. pRow->SetIntValue(w);
  494. listRows.push_back(pRow);
  495. }
  496. }
  497. pColumn->SetGridRowsList(listRows);
  498. listCol.push_back(pColumn);
  499. break;
  500. default:
  501. break;
  502. }
  503. }
  504. pGridData->SetGridColumnList(listCol);
  505. return pGridData;
  506. }
  507. std::string CGBCalculate::GetLevelStr(GB_GRADE_TYPE l)
  508. {
  509. std::string s;
  510. switch (l)
  511. {
  512. case GB_GRADE_TYPE::POINT_0_0:
  513. s = "0";
  514. break;
  515. case GB_GRADE_TYPE::POINT_0_5:
  516. s = "0.5";
  517. break;
  518. case GB_GRADE_TYPE::POINT_1_0:
  519. s = "1";
  520. break;
  521. case GB_GRADE_TYPE::POINT_1_5:
  522. s = "1.5";
  523. break;
  524. case GB_GRADE_TYPE::POINT_2_0:
  525. s = "2";
  526. break;
  527. case GB_GRADE_TYPE::POINT_2_5:
  528. s = "2.5";
  529. break;
  530. case GB_GRADE_TYPE::POINT_3_0:
  531. s = "3";
  532. break;
  533. case GB_GRADE_TYPE::POINT_3_5:
  534. s = "3.5";
  535. break;
  536. case GB_GRADE_TYPE::POINT_4_0:
  537. s = "4";
  538. break;
  539. case GB_GRADE_TYPE::POINT_4_5:
  540. s = "4.5";
  541. break;
  542. case GB_GRADE_TYPE::POINT_5_0:
  543. s = "5";
  544. break;
  545. default:
  546. s = "0";
  547. break;
  548. }
  549. return s;
  550. }
  551. //get grid with level ABCD
  552. CGridDataPtr CGBCalculate::GetGridLevel(CString GridType, int a_nLevel[], int a_nLevel_w[], int a_nLevel_s[])
  553. {
  554. CGridDataPtr pGridData = CGridDataPtr(new CGridData());
  555. std::vector<CString> listDataSource;
  556. listDataSource.clear();
  557. listDataSource = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceList();
  558. pGridData->SetDataSourceList(listDataSource);
  559. int nDataSourceId = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceId();
  560. pGridData->SetDataSourceId(nDataSourceId);
  561. //amounts
  562. CGridColumnsList listCol;
  563. listCol.clear();
  564. int columnNum = 11 + 1 + 1;//表格总列数 12个级别再加上前面的“分类”列和“宽度/um”列
  565. CGridColumnPtr pColumn;
  566. for (int i = 0; i < columnNum; i++)
  567. {
  568. CString strName;
  569. CGridRowsList listRows;
  570. CGridRowPtr pRow;
  571. CString strWidthName1, strWidthName2, strWidthName3;
  572. switch (i)
  573. {
  574. case 0:
  575. pColumn = CGridColumnPtr(new CGridColumn());
  576. strName = MultiLang::GetInstance().GetCStringByKey(GBStr1);
  577. pColumn->SetName(strName);
  578. pRow = CGridRowPtr(new CGridRow());
  579. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  580. pRow->SetStringValue(MultiLang::GetInstance().GetCStringByKey(GBStr2));
  581. listRows.push_back(pRow);
  582. pRow = CGridRowPtr(new CGridRow());
  583. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  584. pRow->SetStringValue(MultiLang::GetInstance().GetCStringByKey(GBStr3));
  585. listRows.push_back(pRow);
  586. pRow = CGridRowPtr(new CGridRow());
  587. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  588. pRow->SetStringValue(MultiLang::GetInstance().GetCStringByKey(GBStr4));
  589. listRows.push_back(pRow);
  590. pColumn->SetGridRowsList(listRows);
  591. listCol.push_back(pColumn);
  592. break;
  593. case 1:
  594. pColumn = CGridColumnPtr(new CGridColumn());
  595. strName = MultiLang::GetInstance().GetCStringByKey(GBStr5);
  596. pColumn->SetName(strName);
  597. if (GridType == "A")
  598. {
  599. strWidthName1 = "2.0~4.0";
  600. strWidthName2 = "4.0~12.0";
  601. strWidthName3 = ">12.0";
  602. }
  603. if (GridType == "B")
  604. {
  605. strWidthName1 = "2.0~9.0";
  606. strWidthName2 = "9.0~15.0";
  607. strWidthName3 = ">15.0";
  608. }
  609. if (GridType == "C")
  610. {
  611. strWidthName1 = "2.0~5.0";
  612. strWidthName2 = "5.0~12.0";
  613. strWidthName3 = ">12.0";
  614. }
  615. if (GridType == "D")
  616. {
  617. strWidthName1 = "2.0~8.0";
  618. strWidthName2 = "8.0~13.0";
  619. strWidthName3 = ">13.0";
  620. }
  621. if (GridType == "DSulfide")
  622. {
  623. strWidthName1 = "2.0~8.0";
  624. strWidthName2 = "8.0~13.0";
  625. strWidthName3 = ">13.0";
  626. }
  627. pRow = CGridRowPtr(new CGridRow());
  628. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  629. pRow->SetStringValue(strWidthName1);
  630. listRows.push_back(pRow);
  631. pRow = CGridRowPtr(new CGridRow());
  632. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  633. pRow->SetStringValue(strWidthName2);
  634. listRows.push_back(pRow);
  635. pRow = CGridRowPtr(new CGridRow());
  636. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  637. pRow->SetStringValue(strWidthName3);
  638. listRows.push_back(pRow);
  639. pColumn->SetGridRowsList(listRows);
  640. listCol.push_back(pColumn);
  641. break;
  642. default:
  643. pColumn = CGridColumnPtr(new CGridColumn());
  644. CString name;
  645. name.Format(_T("%.1f"), (i - 2) / 2.0);//i=2 输出0 i=3 输出0.5 i=4 输出1 以此类推
  646. pColumn->SetName(name);
  647. CGridRowsList listRows;
  648. pRow = CGridRowPtr(new CGridRow());
  649. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  650. pRow->SetIntValue(a_nLevel[i - 2]);
  651. listRows.push_back(pRow);
  652. pRow = CGridRowPtr(new CGridRow());
  653. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  654. pRow->SetIntValue(a_nLevel_w[i - 2]);
  655. listRows.push_back(pRow);
  656. pRow = CGridRowPtr(new CGridRow());
  657. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  658. pRow->SetIntValue(a_nLevel_s[i - 2]);
  659. listRows.push_back(pRow);
  660. pColumn->SetGridRowsList(listRows);
  661. listCol.push_back(pColumn);
  662. break;
  663. }
  664. }
  665. pGridData->SetGridColumnList(listCol);
  666. return pGridData;
  667. }
  668. CGridDataPtr CGBCalculate::GetGridDSLevel(CGBFieldList listCGBField)
  669. {
  670. CGridDataPtr pGridData = CGridDataPtr(new CGridData());
  671. std::vector<CString> listDataSource;
  672. listDataSource.clear();
  673. listDataSource = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceList();
  674. pGridData->SetDataSourceList(listDataSource);
  675. int nDataSourceId = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceId();
  676. pGridData->SetDataSourceId(nDataSourceId);
  677. //amounts
  678. CGridColumnsList listCol;
  679. listCol.clear();
  680. int columnNum = 6;
  681. CGridColumnPtr pColumn;
  682. for (int i = 0; i < columnNum; i++)
  683. {
  684. CString strName;
  685. CGridRowsList listRows[6];
  686. CGridRowPtr pRow;
  687. CString strWidthName1, strWidthName2, strWidthName3;
  688. switch (i)
  689. {
  690. case 0:
  691. pColumn = CGridColumnPtr(new CGridColumn());
  692. strName = MultiLang::GetInstance().GetCStringByKey(GBStr6);
  693. pColumn->SetName(strName);
  694. pColumn->SetGridRowsList(listRows[0]);
  695. listCol.push_back(pColumn);
  696. break;
  697. case 1:
  698. pColumn = CGridColumnPtr(new CGridColumn());
  699. strName = MultiLang::GetInstance().GetCStringByKey(GBStr7);
  700. pColumn->SetName(strName);
  701. pColumn->SetGridRowsList(listRows[1]);
  702. listCol.push_back(pColumn);
  703. break;
  704. case 2:
  705. pColumn = CGridColumnPtr(new CGridColumn());
  706. strName = MultiLang::GetInstance().GetCStringByKey(GBStr8);
  707. pColumn->SetName(strName);
  708. pColumn->SetGridRowsList(listRows[2]);
  709. listCol.push_back(pColumn);
  710. break;
  711. case 3:
  712. pColumn = CGridColumnPtr(new CGridColumn());
  713. strName = "X/mm";
  714. pColumn->SetName(strName);
  715. pColumn->SetGridRowsList(listRows[3]);
  716. listCol.push_back(pColumn);
  717. break;
  718. case 4:
  719. pColumn = CGridColumnPtr(new CGridColumn());
  720. strName = "Y/mm";
  721. pColumn->SetName(strName);
  722. pColumn->SetGridRowsList(listRows[4]);
  723. listCol.push_back(pColumn);
  724. break;
  725. case 5:
  726. pColumn = CGridColumnPtr(new CGridColumn());
  727. strName = MultiLang::GetInstance().GetCStringByKey(GBStr9);
  728. pColumn->SetName(strName);
  729. pColumn->SetGridRowsList(listRows[5]);
  730. listCol.push_back(pColumn);
  731. break;
  732. }
  733. }
  734. for each(CGBFieldDataPtr frame in listCGBField)
  735. {
  736. for (int i = 0; i < columnNum; i++)
  737. {
  738. CString strName;
  739. CGridRowsList listRows;
  740. CGridRowPtr pRow;
  741. CString strWidthName1, strWidthName2, strWidthName3;
  742. switch (i)
  743. {
  744. case 0:
  745. pColumn = listCol.at(0);
  746. pRow = CGridRowPtr(new CGridRow());
  747. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  748. pRow->SetIntValue(frame->GetFrameId());
  749. pColumn->GetRowList().push_back(pRow);
  750. break;
  751. case 1:
  752. pColumn = listCol.at(1);
  753. pRow = CGridRowPtr(new CGridRow());
  754. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  755. pRow->SetIntValue(0);
  756. pColumn->GetRowList().push_back(pRow);
  757. break;
  758. case 2:
  759. pColumn = listCol.at(2);
  760. pRow = CGridRowPtr(new CGridRow());
  761. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  762. pRow->SetIntValue((int)frame->GetDSLevel()->GetMaxFeretDiameter());
  763. pColumn->GetRowList().push_back(pRow);
  764. break;
  765. case 3:
  766. pColumn = listCol.at(3);
  767. pRow = CGridRowPtr(new CGridRow());
  768. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  769. pRow->SetIntValue(0);
  770. pColumn->GetRowList().push_back(pRow);
  771. break;
  772. case 4:
  773. pColumn = listCol.at(4);
  774. pRow = CGridRowPtr(new CGridRow());
  775. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  776. pRow->SetIntValue(0);
  777. pColumn->GetRowList().push_back(pRow);
  778. break;
  779. case 5:
  780. pColumn = listCol.at(5);
  781. pRow = CGridRowPtr(new CGridRow());
  782. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  783. pRow->SetDoubleValue((double)frame->GetDSLevel()->GetMyDSGrade());
  784. pColumn->GetRowList().push_back(pRow);
  785. break;
  786. }
  787. }
  788. }
  789. pGridData->SetGridColumnList(listCol);
  790. return pGridData;
  791. }
  792. //get grid with level ABCD
  793. CGridDataPtr CGBCalculate::GetGridDIN(COTSParticleList cotsparticlelistA, set<COTSParticlePtr> cotsparticlelistB, COTSParticleList cotsparticlelistC, COTSParticleList cotsparticlelistD)
  794. {
  795. CGridDataPtr pGridData = CGridDataPtr(new CGridData());
  796. std::vector<CString> listDataSource;
  797. listDataSource.clear();
  798. listDataSource = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceList();
  799. pGridData->SetDataSourceList(listDataSource);
  800. int nDataSourceId = m_rptMgrPtr->GetCurrentPropParam()->GetDataSourceId();
  801. pGridData->SetDataSourceId(nDataSourceId);
  802. //amounts
  803. CGridColumnsList listCol;
  804. listCol.clear();
  805. int columnNum = 12;//表格总列数 11个级别再加上前面的“分类”列
  806. CGridColumnPtr pColumn;
  807. int levA[9] = { 0,0,0,0,0,0,0,0,0 };
  808. int levB[9] = { 0,0,0,0,0,0,0,0,0 };
  809. int levC[9] = { 0,0,0,0,0,0,0,0,0 };
  810. int levD[9] = { 0,0,0,0,0,0,0,0,0 };
  811. double fg[9] = { 0.05,0.1,0.2,0.5,1,2,5,10,20 };
  812. //指数
  813. double ka = 0, kb = 0, kc = 0, kd = 0;
  814. //统计不同大小颗粒出现次数
  815. for (auto pParticle : cotsparticlelistA)
  816. {
  817. double area = pParticle->GetArea();
  818. for (int i = 0; i < 8; i++)
  819. {
  820. if (area >= fg[i] && area < fg[i + 1])
  821. {
  822. levA[i] += 1;
  823. ka = ka + fg[i];
  824. }
  825. }
  826. if (area >= fg[8])
  827. {
  828. levA[8] += 1;
  829. ka = ka + fg[8];
  830. }
  831. }
  832. for (auto pParticle : cotsparticlelistB)
  833. {
  834. double area = pParticle->GetArea();
  835. for (int i = 0; i < 8; i++)
  836. {
  837. if (area >= fg[i] && area < fg[i + 1])
  838. {
  839. levB[i] += 1;
  840. kb = kb + fg[i];
  841. }
  842. }
  843. if (area >= fg[8])
  844. {
  845. levB[8] += 1;
  846. kb = kb + fg[8];
  847. }
  848. }
  849. for (auto pParticle : cotsparticlelistC)
  850. {
  851. double area = pParticle->GetArea();
  852. for (int i = 0; i < 8; i++)
  853. {
  854. if (area >= fg[i] && area < fg[i + 1])
  855. {
  856. levC[i] += 1;
  857. kc = kc + fg[i];
  858. }
  859. }
  860. if (area >= fg[8])
  861. {
  862. levC[8] += 1;
  863. kc = kc + fg[8];
  864. }
  865. }
  866. for (auto pParticle : cotsparticlelistD)
  867. {
  868. double area = pParticle->GetArea();
  869. for (int i = 0; i < 8; i++)
  870. {
  871. if (area >= fg[i] && area < fg[i + 1])
  872. {
  873. levD[i] += 1;
  874. kd = kd + fg[i];
  875. }
  876. }
  877. if (area >= fg[8])
  878. {
  879. levD[8] += 1;
  880. kd = kd + fg[8];
  881. }
  882. }
  883. double to = kb + kc + kd;
  884. for (int i = 0; i < columnNum; i++)
  885. {
  886. CString strName;
  887. CGridRowsList listRows;
  888. CGridRowPtr pRow;
  889. CString strWidthName1, strWidthName2, strWidthName3, strWidthName4;
  890. switch (i)
  891. {
  892. case 0:
  893. pColumn = CGridColumnPtr(new CGridColumn());
  894. strName = "Class";
  895. pColumn->SetName(strName);
  896. pRow = CGridRowPtr(new CGridRow());
  897. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  898. pRow->SetStringValue("SS");
  899. listRows.push_back(pRow);
  900. pRow = CGridRowPtr(new CGridRow());
  901. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  902. pRow->SetStringValue("OA");
  903. listRows.push_back(pRow);
  904. pRow = CGridRowPtr(new CGridRow());
  905. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  906. pRow->SetStringValue("OS");
  907. listRows.push_back(pRow);
  908. pRow = CGridRowPtr(new CGridRow());
  909. pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING);
  910. pRow->SetStringValue("OG");
  911. listRows.push_back(pRow);
  912. pColumn->SetGridRowsList(listRows);
  913. listCol.push_back(pColumn);
  914. break;
  915. case 10:
  916. pColumn = CGridColumnPtr(new CGridColumn());
  917. strName = "S";
  918. pColumn->SetName(strName);
  919. strWidthName1.Format(_T("%lf"), ka);
  920. strWidthName2 = "";
  921. strWidthName3 = "";
  922. strWidthName4 = "";
  923. pRow = CGridRowPtr(new CGridRow());
  924. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  925. pRow->SetDoubleValue(ka);
  926. listRows.push_back(pRow);
  927. pRow = CGridRowPtr(new CGridRow());
  928. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  929. pRow->SetDoubleValue(0);
  930. listRows.push_back(pRow);
  931. pRow = CGridRowPtr(new CGridRow());
  932. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  933. pRow->SetDoubleValue(0);
  934. listRows.push_back(pRow);
  935. pRow = CGridRowPtr(new CGridRow());
  936. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  937. pRow->SetDoubleValue(0);
  938. listRows.push_back(pRow);
  939. pColumn->SetGridRowsList(listRows);
  940. listCol.push_back(pColumn);
  941. break;
  942. case 11:
  943. pColumn = CGridColumnPtr(new CGridColumn());
  944. strName = "O";
  945. pColumn->SetName(strName);
  946. strWidthName1.Format(_T("%lf"), to);
  947. strWidthName2 = "";
  948. strWidthName3 = "";
  949. strWidthName4 = "";
  950. pRow = CGridRowPtr(new CGridRow());
  951. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  952. pRow->SetDoubleValue(0);
  953. listRows.push_back(pRow);
  954. pRow = CGridRowPtr(new CGridRow());
  955. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  956. pRow->SetDoubleValue(kb);
  957. listRows.push_back(pRow);
  958. pRow = CGridRowPtr(new CGridRow());
  959. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  960. pRow->SetDoubleValue(kc);
  961. listRows.push_back(pRow);
  962. pRow = CGridRowPtr(new CGridRow());
  963. pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT);
  964. pRow->SetDoubleValue(kd);
  965. listRows.push_back(pRow);
  966. pColumn->SetGridRowsList(listRows);
  967. listCol.push_back(pColumn);
  968. break;
  969. default:
  970. pColumn = CGridColumnPtr(new CGridColumn());
  971. strName.Format("%d", i - 1);
  972. pColumn->SetName(strName);
  973. CGridRowsList listRows;
  974. pRow = CGridRowPtr(new CGridRow());
  975. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  976. pRow->SetIntValue(levA[i - 1]);
  977. listRows.push_back(pRow);
  978. pRow = CGridRowPtr(new CGridRow());
  979. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  980. pRow->SetIntValue(levB[i - 1]);
  981. listRows.push_back(pRow);
  982. pRow = CGridRowPtr(new CGridRow());
  983. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  984. pRow->SetIntValue(levC[i - 1]);
  985. listRows.push_back(pRow);
  986. pRow = CGridRowPtr(new CGridRow());
  987. pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT);
  988. pRow->SetIntValue(levD[i - 1]);
  989. listRows.push_back(pRow);
  990. pColumn->SetGridRowsList(listRows);
  991. listCol.push_back(pColumn);
  992. break;
  993. }
  994. }
  995. pGridData->SetGridColumnList(listCol);
  996. return pGridData;
  997. }
  998. void CGBCalculate::SetFrameLevelNo(GB_GRADE_TYPE a_level, int a_nLevel[])
  999. {
  1000. a_nLevel[(int)a_level] += 1;
  1001. }
  1002. // calculate GB fields
  1003. CGBFieldList CGBCalculate::CalGBFields(CSmplMsrResultFileMgr* pSmplMgr)
  1004. {
  1005. CGBFieldList m_listGBFields;
  1006. m_listGBFields.clear();
  1007. ASSERT(pSmplMgr);
  1008. if (!pSmplMgr) {
  1009. LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: invalid m_pSmplMsrResultFileMgr ."));
  1010. return m_listGBFields;
  1011. }
  1012. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMgr->GetSmplMsrResultFile();
  1013. ASSERT(pSmplMsrResultFile);
  1014. if (!pSmplMsrResultFile) {
  1015. LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: invalid pSmplMsrResultFile ."));
  1016. return m_listGBFields;
  1017. }
  1018. COTSSamplePtr pOTSSample = pSmplMsrResultFile->GetSample();
  1019. ASSERT(pOTSSample);
  1020. if (!pOTSSample) {
  1021. LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: invalid pOTSSample ."));
  1022. return m_listGBFields;
  1023. }
  1024. CSEMDataMsrPtr pEMDataMsrPtr = pOTSSample->GetSEMDataMsr();
  1025. ASSERT(pEMDataMsrPtr);
  1026. if (!pEMDataMsrPtr) {
  1027. LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: invalid pEMDataMsrPtr ."));
  1028. return m_listGBFields;
  1029. }
  1030. // get field width
  1031. int nOTSFieldWidth = pEMDataMsrPtr->GetScanFieldSize();
  1032. if (nOTSFieldWidth == 0)
  1033. {
  1034. LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: field width is zero ."));
  1035. return m_listGBFields;
  1036. }
  1037. // cal a gb field need how many ots fields rows and columns
  1038. int nOTSRowsForGBFld, nOTSColumnsForGBFld;
  1039. CalOTSFieldsNo(nOTSRowsForGBFld, nOTSColumnsForGBFld, nOTSFieldWidth);
  1040. if (nOTSRowsForGBFld == 0 || nOTSColumnsForGBFld == 0)
  1041. {
  1042. LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: nOTSRow|nOTSColumn is zero ."));
  1043. return m_listGBFields;
  1044. }
  1045. // scan parameters
  1046. CMsrParamsPtr pMsrParam = pOTSSample->GetMsrParams();
  1047. COTSImageScanParamPtr pImgScanParam = pMsrParam->GetImageScanParam();
  1048. // get image size
  1049. OTS_FIVE_TIES_OPTIONS nImageSizeId = pImgScanParam->GetImagePixelSize();
  1050. int nResulotionId = RESOLUTION_ID_FIRST_TIE + (int)nImageSizeId;
  1051. CSize sizePixelImage = RESOLUTION_VALUE[nResulotionId];
  1052. //use OTSField width cal the OTSField height
  1053. //get OTSfilds list
  1054. COTSFieldDataList allOTSFields;
  1055. allOTSFields = pSmplMsrResultFile->GetFieldData();
  1056. // convert ots fields to gb fields
  1057. if (!OTSFieldToGBField(allOTSFields, &m_listGBFields, nOTSRowsForGBFld, nOTSColumnsForGBFld, sizePixelImage, nOTSFieldWidth))
  1058. {
  1059. LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: call OTSFieldToGBField failed."));
  1060. return m_listGBFields;
  1061. }
  1062. return m_listGBFields;
  1063. }
  1064. // protected
  1065. // cal a gb field need how many ots fields rows and columns
  1066. void CGBCalculate::CalOTSFieldsNo(int& a_nRow, int& a_nColumn, int a_nFieldWidth)
  1067. {
  1068. a_nRow = 0;
  1069. a_nColumn = 0;
  1070. if (a_nFieldWidth > 0)
  1071. {
  1072. a_nColumn = (int)ceil((double)GB_FIELD_WIDTH / (double)a_nFieldWidth);
  1073. //OTSField Height always equal to 3 / 4 OTSField Width
  1074. double dFieldHeight = (double)a_nFieldWidth * 3 / 4;
  1075. a_nRow = (int)ceil((double)GB_FIELD_WIDTH / dFieldHeight);
  1076. }
  1077. }
  1078. // Turn OTSField to GBField
  1079. BOOL CGBCalculate::OTSFieldToGBField(COTSFieldDataList allOTSFields, CGBFieldList* m_listGBFields, int nOTSRowsPerGBfld, int nOTSColumnsPerGBFld, CSize sizePixelImage, int nOTSFieldWidth)
  1080. {
  1081. int nFieldHeight = (int)((double)nOTSFieldWidth * 3 / 4);
  1082. // doing nothing if no field at all
  1083. if (allOTSFields.empty())
  1084. {
  1085. LogTrace(__FILE__, __LINE__, _T("CalGBFields: listOTSFields is empty ."));
  1086. return TRUE;
  1087. }
  1088. // get topleft point and bottomright point of the measurement convered area
  1089. CPoint pointTopleft, pointBottomright;
  1090. pointTopleft = pointBottomright = allOTSFields[0]->GetPosition();
  1091. //判断有效区域
  1092. for (unsigned int i = 0; i < allOTSFields.size(); i++)
  1093. {
  1094. //get current OTSField Position,the position is in the center of the field
  1095. CPoint poiOTSFieldPosition = allOTSFields[i]->GetPosition();
  1096. pointTopleft.x = min(poiOTSFieldPosition.x, pointTopleft.x);
  1097. pointTopleft.y = min(poiOTSFieldPosition.y, pointTopleft.y);
  1098. pointBottomright.x = max(poiOTSFieldPosition.x, pointBottomright.x);
  1099. pointBottomright.y = max(poiOTSFieldPosition.y, pointBottomright.y);
  1100. }
  1101. // cal ots columns 有效区域内所有的OTScolumn数
  1102. int nOTSColumnNum = ((pointBottomright.x - pointTopleft.x) / nOTSFieldWidth) + 1;
  1103. // cal ots rows有效区域内所有的OTSRow数
  1104. int nOTSRowNum = ((pointBottomright.y - pointTopleft.y) / nFieldHeight) + 1;
  1105. int nPossibleGBFieldRowNum = nOTSRowNum / nOTSRowsPerGBfld;//可能有的国标field行数
  1106. int nPossibleGBFieldColNum = nOTSColumnNum / nOTSColumnsPerGBFld;//列数
  1107. // cal possible GBFields area
  1108. CPoint pointPosibleAreaTopLeft = pointTopleft;
  1109. //CPoint poiPosAreaBottomRight = poiBottomright;
  1110. CPoint pointPossibleAreaBottomRight = pointTopleft;
  1111. pointPosibleAreaTopLeft.x -= nOTSFieldWidth / 2;
  1112. pointPosibleAreaTopLeft.y -= nFieldHeight / 2;
  1113. //pointPossibleAreaBottomRight.x += (nPossibleGBFieldColNum * nOTSColumnsPerGBFld * nOTSFieldWidth - nOTSFieldWidth / 2);
  1114. pointPossibleAreaBottomRight.x += (nPossibleGBFieldColNum * nOTSColumnsPerGBFld * nOTSFieldWidth);
  1115. //pointPossibleAreaBottomRight.y += (nPossibleGBFieldRowNum * nOTSRowsPerGBfld * nFieldHeight - nFieldHeight / 2);
  1116. pointPossibleAreaBottomRight.y += (nPossibleGBFieldRowNum * nOTSRowsPerGBfld * nFieldHeight);
  1117. // form rectangle of GBFields area
  1118. CRect rectOTSFieldsCuted(pointPosibleAreaTopLeft, pointPossibleAreaBottomRight);
  1119. rectOTSFieldsCuted.NormalizeRect();
  1120. if (rectOTSFieldsCuted.IsRectEmpty())
  1121. {
  1122. LogTrace(__FILE__, __LINE__, _T("CalGBFields: GBFields area is empty ."));
  1123. return TRUE;
  1124. }
  1125. // find all OTSFields inside GBFields area
  1126. COTSFieldDataList OTSFieldsInGBFieldsArea;
  1127. OTSFieldsInGBFieldsArea.clear();
  1128. CPoint poiOTSFieldPosition;
  1129. for (auto OTSField : allOTSFields)
  1130. {
  1131. poiOTSFieldPosition = OTSField->GetPosition();
  1132. //if over the edge
  1133. if (rectOTSFieldsCuted.PtInRect(poiOTSFieldPosition))
  1134. {
  1135. OTSFieldsInGBFieldsArea.push_back(OTSField);
  1136. }
  1137. }
  1138. //get possible OTSFields
  1139. m_listGBFields->clear();
  1140. CPoint pointGBFieldPosition;
  1141. int nOTSFieldsPerGBField = nOTSRowsPerGBfld * nOTSColumnsPerGBFld;
  1142. for (int i = 0; i < nPossibleGBFieldRowNum; i++)
  1143. {
  1144. for (int j = 0; j < nPossibleGBFieldColNum; j++)
  1145. {
  1146. // cal GB field rectangle
  1147. CPoint poiCurGBFieldTopLeft, poiCurGBFieldBottomRight;
  1148. poiCurGBFieldTopLeft = pointPosibleAreaTopLeft;
  1149. //获得左上角的坐标
  1150. poiCurGBFieldTopLeft.x += nOTSColumnsPerGBFld * j * nOTSFieldWidth;
  1151. poiCurGBFieldTopLeft.y += nOTSRowsPerGBfld * i * nFieldHeight;
  1152. //获得右下角的坐标
  1153. poiCurGBFieldBottomRight.x = poiCurGBFieldTopLeft.x + nOTSColumnsPerGBFld * nOTSFieldWidth;
  1154. poiCurGBFieldBottomRight.y = poiCurGBFieldTopLeft.y + nOTSRowsPerGBfld * nFieldHeight;
  1155. CRect rectGBField(poiCurGBFieldTopLeft, poiCurGBFieldBottomRight);
  1156. rectGBField.NormalizeRect();
  1157. CGBFieldDataPtr pGBFieldData;
  1158. //切割组合的矩形成为GBfield,并处理其中的segment
  1159. pGBFieldData = GetOneGBField(rectGBField, OTSFieldsInGBFieldsArea, nOTSRowsPerGBfld, nOTSColumnsPerGBFld, sizePixelImage, nOTSFieldWidth);
  1160. if (!pGBFieldData)
  1161. {
  1162. continue;
  1163. }
  1164. rectGBField.bottom = rectGBField.top + GB_FIELD_WIDTH;
  1165. rectGBField.right = rectGBField.left + GB_FIELD_WIDTH;
  1166. CPoint poiNewPosition;
  1167. poiNewPosition.x = rectGBField.left + GB_FIELD_WIDTH / 2;
  1168. poiNewPosition.y = rectGBField.top + GB_FIELD_WIDTH / 2;
  1169. pGBFieldData->SetPosition(poiNewPosition);
  1170. // add the GBField into the GBFields list
  1171. m_listGBFields->push_back(pGBFieldData);
  1172. }
  1173. }
  1174. // ok, return TRUE
  1175. return TRUE;
  1176. }
  1177. // Custom collation rules
  1178. BOOL comp(const COTSFieldDataPtr &a, const COTSFieldDataPtr &b)
  1179. {
  1180. if (a->GetPosition().y <= b->GetPosition().y)
  1181. {
  1182. if (a->GetPosition().y == b->GetPosition().y)
  1183. {
  1184. if (a->GetPosition().x < b->GetPosition().x)
  1185. {
  1186. return TRUE;
  1187. }
  1188. }
  1189. else {
  1190. return TRUE;
  1191. }
  1192. }
  1193. return FALSE;
  1194. }
  1195. // get the GB field within a rectangle
  1196. CGBFieldDataPtr CGBCalculate::GetOneGBField(CRect a_rectGBField,
  1197. COTSFieldDataList& allOTSFields,
  1198. int nOTSRowsPerGBFld,
  1199. int nOTSColumnsPerGBFld,
  1200. CSize a_sizePixelImage,
  1201. int nOTSFieldWidth)
  1202. {
  1203. // GB Field handle
  1204. CGBFieldDataPtr pGBFieldData = nullptr;
  1205. // get OTS fields within the rectangle
  1206. COTSFieldDataList myOTSFields;
  1207. myOTSFields.clear();
  1208. COTSFieldDataList::iterator itr = allOTSFields.begin();
  1209. while (itr != allOTSFields.end())
  1210. {
  1211. // get an OTS field
  1212. CPoint poiOTSField = (*itr)->GetPosition();
  1213. //check if the field is within the rectangle
  1214. if (a_rectGBField.PtInRect(poiOTSField))
  1215. {
  1216. // found a field
  1217. // add into the list
  1218. myOTSFields.push_back(*itr);
  1219. // remove the field from the measurement field list
  1220. // move to the next item
  1221. //itr = allOTSFields.erase(itr);//There's no need to delete the field. gsp
  1222. itr++;
  1223. // jump over
  1224. continue;
  1225. }
  1226. // move to the next item
  1227. itr++;
  1228. }
  1229. // make sure GBFields list has enough OTSFields
  1230. int nOTSFieldsOfAGBField = nOTSRowsPerGBFld * nOTSColumnsPerGBFld;
  1231. if (myOTSFields.size() == nOTSFieldsOfAGBField)
  1232. {
  1233. // sort the GBFields list
  1234. sort(myOTSFields.begin(), myOTSFields.end(), comp);
  1235. // normalize particles for the GBFields
  1236. pGBFieldData = NormalizeParticles(a_rectGBField, myOTSFields, a_sizePixelImage, nOTSFieldWidth);
  1237. pGBFieldData->myReleventOTSFlds = myOTSFields;
  1238. }
  1239. // return GB Field handle
  1240. return pGBFieldData;
  1241. }
  1242. // Custom collation rules
  1243. BOOL compSegment(const COTSSegmentPtr &a, const COTSSegmentPtr &b)
  1244. {
  1245. if (a->GetHeight() <= b->GetHeight())
  1246. {
  1247. if (a->GetHeight() == b->GetHeight())
  1248. {
  1249. if (a->GetStart() < b->GetStart())
  1250. {
  1251. return TRUE;
  1252. }
  1253. }
  1254. else {
  1255. return TRUE;
  1256. }
  1257. }
  1258. return FALSE;
  1259. }
  1260. // normalize particles for the GBFields
  1261. CGBFieldDataPtr CGBCalculate::NormalizeParticles(CRect a_rectGBField, COTSFieldDataList myOTSFields, CSize a_sizePixelImage, int nOTSFieldWidth)
  1262. {
  1263. // inits
  1264. CGBFieldDataPtr pGBFieldData(new CGBFieldData);
  1265. int nFieldHeight = (int)((double)nOTSFieldWidth * 3 / 4);
  1266. //go through all OTS fields form the GB field to get all segments of the GB field
  1267. COTSSegmentsList listGBFieldSegments;
  1268. CPoint pointGBFieldRectTopLeft = a_rectGBField.TopLeft();
  1269. int nBeforeCalNo = 0;
  1270. int nAfterCalNo = 0;
  1271. for (auto OTSField : myOTSFields)
  1272. {
  1273. CPoint pointField = OTSField->GetPosition();
  1274. COTSParticleList myOTSParticles = OTSField->GetParticleList();
  1275. long fieldLeftTopX, fieldLeftTopY;
  1276. CPoint pointCalculate;
  1277. fieldLeftTopX = pointField.x - (nOTSFieldWidth / 2);
  1278. fieldLeftTopY = pointField.y - (nFieldHeight / 2);
  1279. pointCalculate.x = fieldLeftTopX - pointGBFieldRectTopLeft.x;
  1280. pointCalculate.y = fieldLeftTopY - pointGBFieldRectTopLeft.y;
  1281. //found the field's Column and Row
  1282. int nColum = (int)(((double)pointCalculate.x / (double)nOTSFieldWidth) + 0.5);
  1283. int nRow = (int)(((double)pointCalculate.y / (double)nFieldHeight) + 0.5);
  1284. //function Get GBField's FieldSegments List
  1285. nBeforeCalNo = (int)listGBFieldSegments.size();
  1286. GetGBFieldSegmentsList(nColum, nRow, myOTSParticles, nAfterCalNo, listGBFieldSegments, a_sizePixelImage, nOTSFieldWidth);
  1287. nAfterCalNo = nBeforeCalNo;
  1288. }
  1289. COTSParticleList listNormalizedParticles;
  1290. // get new particles
  1291. GetGBParticles(listGBFieldSegments, listNormalizedParticles);
  1292. // put new particle in the GB Field
  1293. pGBFieldData->SetParticleList(listNormalizedParticles);
  1294. return pGBFieldData;
  1295. }
  1296. //function Get GBField's FieldSegments List
  1297. BOOL CGBCalculate::GetGBFieldSegmentsList(int a_nColum, int a_nRow, COTSParticleList a_listOTSFieldParticles, int a_nCalNo, COTSSegmentsList &a_listGBFieldSegments, CSize a_sizePixelImage, int a_nFieldWidth)
  1298. {
  1299. CRect rectParticle;
  1300. CPoint poiParticleTopLeft;
  1301. COTSSegmentsList listOTSFieldSegments;
  1302. long nNewStart = 0, nNewLength = 0, nNewHeight;
  1303. long nOffsetX = a_nColum * a_sizePixelImage.cx;
  1304. long nOffsetY = a_nRow * a_sizePixelImage.cy;
  1305. // get one pixel width
  1306. //double dPixelsize = (double)a_nFieldWidth / a_sizePixelImage.cx;
  1307. double dPixelsize = (double)a_sizePixelImage.cx / a_nFieldWidth;
  1308. double dGBwidth = sqrt(0.5) * 1000;
  1309. long nGBpixcel = (long)(dGBwidth * dPixelsize);
  1310. //cal the new segment coordinate
  1311. for (auto Particle : a_listOTSFieldParticles)
  1312. {
  1313. //get the Particle rect
  1314. rectParticle = Particle->GetParticleRect();
  1315. poiParticleTopLeft = rectParticle.TopLeft();
  1316. listOTSFieldSegments = Particle->GetFeature()->GetSegmentsList();
  1317. for (auto Segment : listOTSFieldSegments)
  1318. {
  1319. BOOL bMerge = (a_nColum > 0) && (Segment->GetStart() == 0);
  1320. // off set the segment
  1321. nNewStart = Segment->GetStart() + nOffsetX;
  1322. nNewHeight = Segment->GetHeight() + nOffsetY;
  1323. // check should we need to keep the segment
  1324. // cal if the Segment in the GB 0.5/m2
  1325. if (nNewStart > nGBpixcel)
  1326. {
  1327. continue;
  1328. }
  1329. if (nNewHeight > nGBpixcel)
  1330. {
  1331. continue;
  1332. }
  1333. // do we need to cut the segment
  1334. //if over 0.5m2 cut it
  1335. //get GBField's a_nHeight, long a_nStart, long a_nLength
  1336. nNewLength = Segment->GetLength();
  1337. if (nNewStart + Segment->GetLength() > nGBpixcel)
  1338. {
  1339. nNewLength = (long)(nGBpixcel - nNewStart);
  1340. }
  1341. COTSSegmentPtr pGBFieldSegment(new COTSSegment(nNewHeight, nNewStart, nNewLength));
  1342. //merge the segment
  1343. if (bMerge && MergSegment(a_listGBFieldSegments, pGBFieldSegment, a_nCalNo))
  1344. {
  1345. continue;
  1346. }
  1347. a_listGBFieldSegments.push_back(pGBFieldSegment);
  1348. }
  1349. }
  1350. return TRUE;
  1351. }
  1352. // merge the segment
  1353. BOOL CGBCalculate::MergSegment(COTSSegmentsList &a_listGBFieldSegments, COTSSegmentPtr a_pGBFieldSegment, int a_nCalNo)
  1354. {
  1355. //search merge segments only on last field
  1356. COTSSegmentsList::iterator itr = a_listGBFieldSegments.begin() + a_nCalNo;
  1357. while (itr != a_listGBFieldSegments.end())
  1358. {
  1359. COTSSegmentPtr pSegmentHead = *itr;
  1360. long nNextX = pSegmentHead->GetStart() + pSegmentHead->GetLength();
  1361. //merge only when height are the same
  1362. if (pSegmentHead->GetHeight() == a_pGBFieldSegment->GetHeight())
  1363. {
  1364. //end to start
  1365. if ((nNextX + 1) == a_pGBFieldSegment->GetStart())
  1366. {
  1367. //merge and return true
  1368. pSegmentHead->SetLength(pSegmentHead->GetLength() + a_pGBFieldSegment->GetLength());
  1369. return TRUE;
  1370. }
  1371. }
  1372. itr++;
  1373. }
  1374. //didn't merge return false
  1375. return FALSE;
  1376. }
  1377. // merge the segment,get new particles
  1378. BOOL CGBCalculate::GetGBParticles(COTSSegmentsList a_listGBFieldSegments, COTSParticleList &a_listNormalizedParticles)
  1379. {
  1380. //change segments to Particles
  1381. COTSFeatureList listFeatures;
  1382. if (a_listGBFieldSegments.size() == 0)
  1383. {
  1384. return FALSE;
  1385. }
  1386. GetFeatureList1(a_listGBFieldSegments, listFeatures);
  1387. ChangeFeaturelist(listFeatures, a_listNormalizedParticles);
  1388. COTSFieldMgr::CalMergedParticleImageProp(a_listNormalizedParticles, PixSize);
  1389. return TRUE;
  1390. }
  1391. // get feature list of up-down segment
  1392. BOOL CGBCalculate::GetFeatureList(COTSSegmentsList& a_listSegments, COTSFeatureList& a_listFeatures)
  1393. {
  1394. a_listFeatures.clear();
  1395. int nStart = 0;
  1396. int nSizeCur = (int)a_listSegments.size();
  1397. COTSSegmentPtr pSegmentCur;
  1398. COTSSegmentPtr pSegmentNew;
  1399. COTSSegmentsList listSegmentNew;
  1400. COTSSegmentPtr pSegment;
  1401. int nHeightCur, nHeightNew;
  1402. while (true)
  1403. {
  1404. nStart = 0;
  1405. pSegmentCur = a_listSegments[nStart];
  1406. nHeightCur = pSegmentCur->GetHeight();
  1407. //save the new temp segment list
  1408. listSegmentNew.clear();
  1409. //get the first Segment to a feature
  1410. listSegmentNew.push_back(pSegmentCur);
  1411. a_listSegments.erase(a_listSegments.begin());
  1412. if (a_listSegments.size() == 0)
  1413. {
  1414. break;
  1415. }
  1416. nSizeCur--;
  1417. //get the up-down connection segment
  1418. int nindex = 0;
  1419. while (true)
  1420. {
  1421. pSegment = a_listSegments[nindex];
  1422. bool ifConnect = false;
  1423. for (auto seg : listSegmentNew)
  1424. {
  1425. if (seg->UpDownConection(*pSegment))
  1426. {
  1427. pSegmentNew = COTSSegmentPtr(new COTSSegment(*pSegment));
  1428. pSegmentCur = pSegmentNew;
  1429. listSegmentNew.push_back(pSegmentNew);
  1430. a_listSegments.erase(a_listSegments.begin() + nindex);
  1431. nSizeCur--;
  1432. ifConnect = true;
  1433. break;
  1434. }
  1435. }
  1436. if (!ifConnect)
  1437. {
  1438. nindex++;
  1439. }
  1440. if (nindex == nSizeCur || nSizeCur == 0)
  1441. {
  1442. break;
  1443. }
  1444. }
  1445. COTSFeaturePtr pFeature = COTSFeaturePtr(new COTSFeature());
  1446. pFeature->SetSegmentsList(listSegmentNew);
  1447. a_listFeatures.push_back(pFeature);
  1448. nStart++;
  1449. if (nStart == nSizeCur || nSizeCur == 0)
  1450. {
  1451. if (a_listSegments.size() != 0)
  1452. {
  1453. //save the new temp segment list
  1454. listSegmentNew.clear();
  1455. //get the first Segment to a feature
  1456. listSegmentNew.push_back(pSegmentCur);
  1457. a_listSegments.erase(a_listSegments.begin());
  1458. nSizeCur--;
  1459. COTSFeaturePtr pFeature = COTSFeaturePtr(new COTSFeature());
  1460. pFeature->SetSegmentsList(listSegmentNew);
  1461. a_listFeatures.push_back(pFeature);
  1462. }
  1463. break;
  1464. }
  1465. }
  1466. if ((int)a_listFeatures.size() == 0)
  1467. {
  1468. LogErrorTrace(__FILE__, __LINE__, _T("no particle is found"));
  1469. return FALSE;
  1470. }
  1471. return TRUE;
  1472. }
  1473. BOOL CGBCalculate::GetFeatureList1(COTSSegmentsList& a_listSegments, COTSFeatureList& a_listFeatures)
  1474. {
  1475. COTSSegmentsList listSegmentNew;
  1476. std::map<long, COTSSegmentsList > mapOneLineSegments;
  1477. for each(auto s in a_listSegments)
  1478. {
  1479. mapOneLineSegments[s->GetHeight()].push_back(s);
  1480. }
  1481. std::map<long, COTSSegmentsList >::iterator lineItr = mapOneLineSegments.begin();//find the highest line
  1482. while (lineItr != mapOneLineSegments.end())
  1483. {
  1484. for (auto s = lineItr->second.begin(); s < lineItr->second.end(); )//find one segment of this line.
  1485. {
  1486. COTSSegmentPtr bottomSeg = *s;
  1487. listSegmentNew.clear();
  1488. listSegmentNew.push_back(*s);
  1489. s = lineItr->second.erase(s);
  1490. std::map<long, COTSSegmentsList >::iterator tempItr = lineItr;
  1491. tempItr++;
  1492. for (; tempItr != mapOneLineSegments.end(); tempItr++)//find all other lines of segments
  1493. {
  1494. for (auto nextLineSegment = tempItr->second.begin(); nextLineSegment < tempItr->second.end();)//find next line's all segments
  1495. {
  1496. if (bottomSeg->UpDownConection(**nextLineSegment))
  1497. {
  1498. listSegmentNew.push_back(*nextLineSegment);
  1499. bottomSeg = *nextLineSegment;
  1500. nextLineSegment = tempItr->second.erase(nextLineSegment);
  1501. break;
  1502. }
  1503. if (tempItr->second.size() > 0)
  1504. {
  1505. nextLineSegment++;
  1506. }
  1507. else
  1508. {
  1509. break;
  1510. }
  1511. }
  1512. }
  1513. COTSFeaturePtr pFeature = COTSFeaturePtr(new COTSFeature());
  1514. pFeature->SetSegmentsList(listSegmentNew);
  1515. //check if this new feature is connected with other found feature.
  1516. COTSSegmentPtr topSeg = listSegmentNew[0];//find the toppest segment of this new feature.
  1517. COTSSegmentPtr bottomSegment = listSegmentNew[listSegmentNew.size() - 1];//find the lowest segment of this new feature.
  1518. bool haveMerged = false;
  1519. for each(auto f in a_listFeatures)
  1520. {
  1521. for (auto seg : f->GetSegmentsList())
  1522. {
  1523. if (bottomSegment->UpDownConection(*seg) || topSeg->UpDownConection(*seg))
  1524. {
  1525. COTSSegmentsList segs = f->GetSegmentsList();
  1526. for (auto s : listSegmentNew)
  1527. {
  1528. segs.push_back(s);
  1529. }
  1530. f->SetSegmentsList(segs);
  1531. haveMerged = true;
  1532. break;
  1533. }
  1534. }
  1535. if (haveMerged)
  1536. {
  1537. break;
  1538. }
  1539. }
  1540. if (!haveMerged)
  1541. {
  1542. a_listFeatures.push_back(pFeature);
  1543. }
  1544. if (lineItr->second.size() == 0)
  1545. {
  1546. break;
  1547. }
  1548. }
  1549. lineItr++;
  1550. }
  1551. return true;
  1552. }
  1553. // change feature into particle
  1554. BOOL CGBCalculate::ChangeFeaturelist(COTSFeatureList& a_listFeatures, COTSParticleList& a_listParticle)
  1555. {
  1556. if (a_listFeatures.size() == 0)
  1557. {
  1558. LogErrorTrace(__FILE__, __LINE__, _T("ChangeFeaturelist: there is no feature in the list."));
  1559. return FALSE;
  1560. }
  1561. // compute Rect
  1562. for (auto pFeature : a_listFeatures)
  1563. {
  1564. COTSParticlePtr pParticle = COTSParticlePtr(new COTSParticle());
  1565. COTSFeaturePtr pFeatureNew = COTSFeaturePtr(new COTSFeature(*pFeature.get()));
  1566. pParticle->SetFeature(pFeatureNew);
  1567. if (!pParticle->CalCoverRect())
  1568. {
  1569. LogErrorTrace(__FILE__, __LINE__, _T("ChangeFeaturelist: failed to get particle rect."));
  1570. return FALSE;
  1571. }
  1572. a_listParticle.push_back(pParticle);
  1573. }
  1574. if ((int)a_listParticle.size() == 0)
  1575. {
  1576. LogErrorTrace(__FILE__, __LINE__, _T("Can't get particle."));
  1577. return FALSE;
  1578. }
  1579. return TRUE;
  1580. }
  1581. void CGBCalculate::SetPixSize(double p)
  1582. {
  1583. PixSize = p;
  1584. }
  1585. }