123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- #include "stdafx.h"
- //#include "OTSData.h"
- #include "STDItem.h"
- namespace OTSClassifyEngine {
- // CSTDItem
-
- // constructor
- CSTDItem::CSTDItem()
- {
- // initialization
- Init();
- }
- // copy constructor
- CSTDItem::CSTDItem(const CSTDItem& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CSTDItem::CSTDItem(CSTDItem* a_poSource)
- {
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- CSTDItem& CSTDItem::operator=(const CSTDItem& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // ==operator
- BOOL CSTDItem::operator==(const CSTDItem& a_oSource)
- {
- // element rangers list
- int nSize = (int)m_listElementRange.size();
- if (nSize != (int)a_oSource.m_listElementRange.size())
- {
- return FALSE;
- }
- for (int i = 0; i < nSize; ++i)
- {
- if ( !( *(m_listElementRange[i].get()) == *(a_oSource.m_listElementRange[i].get())))
- {
- return FALSE;
- }
- }
- // members
- return m_strName.Compare(a_oSource.m_strName) == 0 &&
- m_nSTDId == a_oSource.m_nSTDId &&
- m_clrColor == a_oSource.m_clrColor &&
- abs(m_dCircleRadio - a_oSource.m_dCircleRadio) < MIN_DOUBLE_VALUE &&
- abs(m_dRectRadio - a_oSource.m_dRectRadio) < MIN_DOUBLE_VALUE &&
- abs(m_dWidth_Height - a_oSource.m_dWidth_Height) < MIN_DOUBLE_VALUE &&
- *(m_poGrayLevel.get()) == *(a_oSource.m_poGrayLevel.get());
- }
- // destructor
- CSTDItem::~CSTDItem()
- {
- // cleanup
- Cleanup();
- }
- // CSTDItem member functions
- // public
- // serialization
-
- // element ranges list
- void CSTDItem::SetElementRangeList(CElementRangeList& a_listElementRange, BOOL a_bClear /*= TRUE*/)
- {
- // clear the element ranges list if necessary
- if (a_bClear)
- {
- m_listElementRange.clear();
- }
- // go through the input list
- for (auto pElementRange : a_listElementRange)
- {
- // create a element range copy
- CElementRangePtr pElementRangeNew(new CElementRange(pElementRange.get()));
- // add the new element range into element ranges list
- m_listElementRange.push_back(pElementRangeNew);
- }
- }
- // protected
- void CSTDItem::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- // name
- xmls::xString xstrName;
- // color
- xmls::xString xsclrColor;//COLORREF, C# can't access
- // circle radio
- xmls::xDouble xdCircleRadio;
- // rectangle radio
- xmls::xDouble xdRectRadio;
- // STD id
- xmls::xInt xnSTDId;
- // width/height radio
- xmls::xDouble xdWidth_Height;
- // element range num
- xmls::xInt xnElement;
- xmls::Collection< CElementRange> xElementRanges;
- xmls::Slo slo;
- slo.Register("Name", &xstrName);
- slo.Register("Color", &xsclrColor);
- slo.Register("CircleRadio", &xdCircleRadio);
- slo.Register("RectRadio", &xdRectRadio);
- slo.Register("STDId", &xnSTDId);
- slo.Register("Width_Height", &xdWidth_Height);
- slo.Register("GrayLevel", m_poGrayLevel.get());
- slo.Register("ElementRanges", &xElementRanges);
- if (isStoring)
- {
- xstrName = m_strName;
- xsclrColor = m_clrColor;
- xdCircleRadio = m_dCircleRadio;
- xdRectRadio = m_dRectRadio;
- xdWidth_Height = m_dWidth_Height;
- xnSTDId = m_nSTDId;
- xElementRanges.Clear();
- for (auto poElementRange : m_listElementRange)
- {
- xElementRanges.addItem(poElementRange.get());
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_strName = xstrName.value().c_str();
- m_clrColor = xsclrColor.value().c_str();
- m_dCircleRadio = xdCircleRadio.value();
- m_dRectRadio = xdRectRadio.value();
- m_dWidth_Height = xdWidth_Height.value();
- m_nSTDId = xnSTDId.value();
- m_listElementRange.clear();
- for (int i = 0; i < xElementRanges.size (); ++i)
- {
- m_listElementRange.push_back(CElementRangePtr(xElementRanges.getItem(i)));
- }
- xElementRanges.Clear();
- }
- }
- // cleanup
- void CSTDItem::Cleanup()
- {
- // need to do nothing at the moment
- }
- // initialization
- void CSTDItem::Init()
- {
- // initialization
- m_strName = _T("");
- m_clrColor = _T("");
- m_nSTDId = 0;
- m_dCircleRadio = 0.0;
- m_dRectRadio = 0;
- m_dWidth_Height = 0;
- m_poGrayLevel = CIntRangePtr(new CIntRange());
- m_listElementRange.clear();
- }
- // duplication
- void CSTDItem::Duplicate(const CSTDItem& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_strName = a_oSource.m_strName;
- m_clrColor = a_oSource.m_clrColor;
- m_nSTDId = a_oSource.m_nSTDId;
- m_dCircleRadio = a_oSource.m_dCircleRadio;
- m_dRectRadio = a_oSource.m_dRectRadio;
- m_dWidth_Height = a_oSource.m_dWidth_Height;
- m_poGrayLevel = CIntRangePtr(new CIntRange(a_oSource.m_poGrayLevel.get()));
- for (auto pElementRange : a_oSource.m_listElementRange)
- {
- CElementRangePtr pElementRangeNew = CElementRangePtr(new CElementRange(pElementRange.get()));
- m_listElementRange.push_back(pElementRange);
- }
- }
- }
|