|
|
@@ -42,156 +42,226 @@ bool ParticleClassifyEngine::Init()
|
|
|
bool ParticleClassifyEngine::Classify(COTSParticlePtr particle, CPosXrayPtr xray)
|
|
|
{
|
|
|
|
|
|
- if (particle == nullptr || xray == nullptr) return false;
|
|
|
-
|
|
|
- auto& originalPartEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
|
|
|
- //以下为调试用代码段(在log中打出颗粒元素),不要删除----------
|
|
|
- /*std::string allele="";
|
|
|
- for (auto che : originalPartEles)
|
|
|
+ if (particle != nullptr && xray != nullptr)
|
|
|
{
|
|
|
- allele += che->GetName().GetBuffer() ;
|
|
|
- allele += ":";
|
|
|
- allele += std::to_string(che->GetPercentage()).c_str();
|
|
|
- allele += " ";
|
|
|
- }
|
|
|
- LogTrace(__FILE__, __LINE__, allele.c_str());*/
|
|
|
- //-----------------------------
|
|
|
- //zero element process,if satisfied the condition than erase the element from the list.
|
|
|
|
|
|
- auto partEles=ZeroElementProcess(particle, xray);//auto partEles = xray->GetElementQuantifyData();
|
|
|
|
|
|
-
|
|
|
- std::map<std::string, CElementChemistryPtr> mapChemistrys;
|
|
|
- for (auto ch : partEles)
|
|
|
- {
|
|
|
- mapChemistrys[ch->GetName().GetBuffer()] = ch;
|
|
|
- }
|
|
|
|
|
|
+ auto& originalPartEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
|
|
|
+ //以下为调试用代码段(在log中打出颗粒元素),不要删除----------
|
|
|
+ /*std::string allele="";
|
|
|
+ for (auto che : originalPartEles)
|
|
|
+ {
|
|
|
+ allele += che->GetName().GetBuffer() ;
|
|
|
+ allele += ":";
|
|
|
+ allele += std::to_string(che->GetPercentage()).c_str();
|
|
|
+ allele += " ";
|
|
|
+ }
|
|
|
+ LogTrace(__FILE__, __LINE__, allele.c_str());*/
|
|
|
+ //-----------------------------
|
|
|
+ //zero element process,if satisfied the condition than erase the element from the list.
|
|
|
|
|
|
- PartSTDItemList stdItems = m_std->GetSTDItems();
|
|
|
+ auto partEles = ZeroElementProcess(particle, xray);//auto partEles = xray->GetElementQuantifyData();
|
|
|
|
|
|
- for (auto itm : stdItems)
|
|
|
- {
|
|
|
- std::string exp = itm->GetExpressionStr();
|
|
|
|
|
|
- //if the element quantity is not match the std item's keyelement num than is unsatisfied.
|
|
|
- if (partEles.size() <itm->GetKeyElementList().size())
|
|
|
+ std::map<std::string, CElementChemistryPtr> mapChemistrys;
|
|
|
+ for (auto ch : partEles)
|
|
|
+ {
|
|
|
+ mapChemistrys[ch->GetName().GetBuffer()] = ch;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ PartSTDItemList stdItems = m_std->GetSTDItems();
|
|
|
+
|
|
|
+ for (auto itm : stdItems)
|
|
|
+ {
|
|
|
+ std::string exp = itm->GetExpressionStr();
|
|
|
+
|
|
|
+ //if the element quantity is not match the std item's keyelement num than is unsatisfied.
|
|
|
+ if (partEles.size() < itm->GetKeyElementList().size())
|
|
|
{
|
|
|
/*std::string s = std::to_string(partEles.size()) + ":" + std::to_string(itm->GetKeyElementList().size());
|
|
|
LogTrace(__FILE__, __LINE__, s.c_str());*///调试用代码段
|
|
|
particle->SetClassifyId(9);
|
|
|
particle->TypeName("Not Identified");
|
|
|
-
|
|
|
+
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- auto& mapStdEles = itm->GetMapElements();
|
|
|
- bool bMatch=true;
|
|
|
- // if the particle does not contain all the key elements of the item than is unsatisfied.
|
|
|
- for (auto che : mapStdEles)
|
|
|
- {
|
|
|
-
|
|
|
- auto chemical= mapChemistrys.find(che.second->GetName().GetBuffer());
|
|
|
- if (chemical == mapChemistrys.end())
|
|
|
+
|
|
|
+ auto& mapStdEles = itm->GetMapElements();
|
|
|
+ bool bMatch = true;
|
|
|
+ // if the particle does not contain all the key elements of the item than is unsatisfied.
|
|
|
+ for (auto che : mapStdEles)
|
|
|
{
|
|
|
- particle->SetClassifyId(9);
|
|
|
- particle->TypeName("Not Identified");
|
|
|
- bMatch=false;
|
|
|
- break;
|
|
|
+
|
|
|
+ auto chemical = mapChemistrys.find(che.second->GetName().GetBuffer());
|
|
|
+ if (chemical == mapChemistrys.end())
|
|
|
+ {
|
|
|
+ particle->SetClassifyId(9);
|
|
|
+ particle->TypeName("Not Identified");
|
|
|
+ bMatch = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (!bMatch) continue;
|
|
|
|
|
|
- // process the special property name such as "first_elem" and "Element#1" etc.
|
|
|
- for (std::string s : itm->GetUsingOtherpropertyList())
|
|
|
- {
|
|
|
+ if (!bMatch) continue;
|
|
|
|
|
|
- if (s.find("_elem")!=std::string::npos)
|
|
|
+ // process the special property name such as "first_elem" and "Element#1" etc.
|
|
|
+ for (std::string s : itm->GetUsingOtherpropertyList())
|
|
|
{
|
|
|
- auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
|
|
|
-
|
|
|
- xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
+
|
|
|
+ if (s.find("_elem") != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
|
|
|
+
|
|
|
+ xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (s.find("Element#") != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
|
|
|
+ auto elelist = itm->GetKeyElementList();
|
|
|
+ elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
|
|
|
+ itm->SetKeyElementList(elelist);
|
|
|
+ xmls::ReplaceAll(exp, s, val.GetBuffer());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (s.find("Element#")!=std::string::npos)
|
|
|
+ for (auto eleChemistry : itm->GetAllSortedEleList())
|
|
|
{
|
|
|
- auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
|
|
|
- auto elelist = itm->GetKeyElementList();
|
|
|
- elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
|
|
|
- itm->SetKeyElementList(elelist);
|
|
|
- xmls::ReplaceAll(exp, s, val.GetBuffer());
|
|
|
+ auto e = mapChemistrys.find(eleChemistry->GetName().GetBuffer());
|
|
|
+
|
|
|
+ if (e != mapChemistrys.end())
|
|
|
+ {
|
|
|
+ std::string name = eleChemistry->GetName();
|
|
|
+
|
|
|
+ xmls::ReplaceAll(exp, name, std::to_string(e->second->GetPercentage()));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::string name = eleChemistry->GetName();
|
|
|
+
|
|
|
+ xmls::ReplaceAll(exp, name, "0");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- for (auto eleChemistry : itm->GetAllSortedEleList())
|
|
|
- {
|
|
|
- auto e = mapChemistrys.find(eleChemistry->GetName().GetBuffer());
|
|
|
|
|
|
- if (e != mapChemistrys.end())
|
|
|
+ //process the image property
|
|
|
+ for (std::string s : itm->GetUsingImgPropertyNameList())
|
|
|
{
|
|
|
- std::string name = eleChemistry->GetName();
|
|
|
+ auto val = particle->GetImgPropertyValueByName(s.c_str());
|
|
|
+ xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
+ }
|
|
|
+ //process the "true" keyword.
|
|
|
+ if (exp.find("true") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "true", "(1=1)");
|
|
|
+ }
|
|
|
+ //process the "false" keyword.
|
|
|
+ if (exp.find("false") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "false", "(1=0)");
|
|
|
+ }
|
|
|
+ for (int i = 0; i < 10; i++)
|
|
|
+ {
|
|
|
+ std::string macStr = "MAC#" + std::to_string(i);
|
|
|
+ if (exp.find(macStr) != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
|
|
|
+ xmls::ReplaceAll(exp, macStr, std::to_string(val));
|
|
|
+ }
|
|
|
|
|
|
- xmls::ReplaceAll(exp, name, std::to_string(e->second->GetPercentage()));
|
|
|
+ }
|
|
|
+ //LogInfoTrace(__FILE__, __LINE__, exp.c_str());//调试用代码段
|
|
|
+
|
|
|
+ //calculate the expression which has been processed.
|
|
|
+
|
|
|
+ bool rst = CalcuExp(exp);
|
|
|
+ if (rst)
|
|
|
+ {
|
|
|
+ //int id = itm->GetID();
|
|
|
+ particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
|
|
|
+ particle->SetClassifyId(itm->GetID());
|
|
|
+ particle->TypeColor(itm->GetColor());
|
|
|
+ particle->TypeName(itm->GetName());
|
|
|
+ particle->SetHardness(itm->GetHardness());
|
|
|
+ particle->SetDensity(itm->GetDensity());
|
|
|
+ particle->SetConductivity(itm->GetElectrical_conductivity());
|
|
|
+ return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- std::string name = eleChemistry->GetName();
|
|
|
-
|
|
|
- xmls::ReplaceAll(exp, name, "0");
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
- //process the image property
|
|
|
- for (std::string s : itm->GetUsingImgPropertyNameList())
|
|
|
- {
|
|
|
- auto val=particle->GetImgPropertyValueByName(s.c_str());
|
|
|
- xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
- }
|
|
|
- //process the "true" keyword.
|
|
|
- if (exp.find("true") != std::string::npos)
|
|
|
- {
|
|
|
- xmls::ReplaceAll(exp, "true", "(1=1)");
|
|
|
- }
|
|
|
- //process the "false" keyword.
|
|
|
- if (exp.find("false") != std::string::npos)
|
|
|
- {
|
|
|
- xmls::ReplaceAll(exp, "false", "(1=0)");
|
|
|
- }
|
|
|
- for (int i = 0; i < 10; i++)
|
|
|
+ particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
|
|
|
+ particle->TypeName("Not Identified");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else if(particle != nullptr && xray == nullptr)
|
|
|
+ {
|
|
|
+ PartSTDItemList stdItems = m_std->GetSTDItems();
|
|
|
+
|
|
|
+ for (auto itm : stdItems)
|
|
|
{
|
|
|
- std::string macStr = "MAC#" + std::to_string(i);
|
|
|
- if (exp.find(macStr) != std::string::npos)
|
|
|
+ std::string exp = itm->GetExpressionStr();
|
|
|
+
|
|
|
+ if (itm->GetKeyElementList().size() > 0 || itm->GetSubElementList().size() > 0)
|
|
|
{
|
|
|
- auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
|
|
|
- xmls::ReplaceAll(exp, macStr, std::to_string(val));
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- //LogInfoTrace(__FILE__, __LINE__, exp.c_str());//调试用代码段
|
|
|
+ //process the image property
|
|
|
+ for (std::string s : itm->GetUsingImgPropertyNameList())
|
|
|
+ {
|
|
|
+ auto val = particle->GetImgPropertyValueByName(s.c_str());
|
|
|
+ xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
+ }
|
|
|
+ //process the "true" keyword.
|
|
|
+ if (exp.find("true") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "true", "(1=1)");
|
|
|
+ }
|
|
|
+ //process the "false" keyword.
|
|
|
+ if (exp.find("false") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "false", "(1=0)");
|
|
|
+ }
|
|
|
+ for (int i = 0; i < 10; i++)
|
|
|
+ {
|
|
|
+ std::string macStr = "MAC#" + std::to_string(i);
|
|
|
+ if (exp.find(macStr) != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
|
|
|
+ xmls::ReplaceAll(exp, macStr, std::to_string(val));
|
|
|
+ }
|
|
|
|
|
|
- //calculate the expression which has been processed.
|
|
|
-
|
|
|
- bool rst=CalcuExp(exp);
|
|
|
- if (rst)
|
|
|
- {
|
|
|
- //int id = itm->GetID();
|
|
|
- particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
|
|
|
- particle->SetClassifyId(itm->GetID());
|
|
|
- particle->TypeColor(itm->GetColor());
|
|
|
- particle->TypeName(itm->GetName());
|
|
|
- particle->SetHardness(itm->GetHardness());
|
|
|
- particle->SetDensity(itm->GetDensity());
|
|
|
- particle->SetConductivity(itm->GetElectrical_conductivity());
|
|
|
- return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //calculate the expression which has been processed.
|
|
|
+
|
|
|
+ bool rst = CalcuExp(exp);
|
|
|
+ if (rst)
|
|
|
+ {
|
|
|
+ //int id = itm->GetID();
|
|
|
+ particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
|
|
|
+ particle->SetClassifyId(itm->GetID());
|
|
|
+ particle->TypeColor(itm->GetColor());
|
|
|
+ particle->TypeName(itm->GetName());
|
|
|
+ particle->SetHardness(itm->GetHardness());
|
|
|
+ particle->SetDensity(itm->GetDensity());
|
|
|
+ particle->SetConductivity(itm->GetElectrical_conductivity());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
+ particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
|
|
|
+ particle->TypeName("Not Identified");
|
|
|
+ return true;
|
|
|
}
|
|
|
- particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
|
|
|
- particle->TypeName("Not Identified");
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
|