void CUIDesignerView::OnEditCopy() { ASSERT(m_cfUI != NULL); TiXmlDocument xmlDoc; TiXmlDeclaration Declaration("1.0","utf-8","yes"); xmlDoc.InsertEndChild(Declaration); TiXmlElement* pCopyElm = new TiXmlElement("UICopy"); CopyUI(pCopyElm); xmlDoc.InsertEndChild(*pCopyElm); TiXmlPrinter printer; xmlDoc.Accept(&printer); delete pCopyElm; CSharedFile file(GMEM_MOVEABLE, printer.Size() + 1); file.Write(printer.CStr(), printer.Size()); file.Write("\0", 1); COleDataSource* pDataSource = NULL; TRY { pDataSource = new COleDataSource; pDataSource->CacheGlobalData(m_cfUI, file.Detach()); pDataSource->SetClipboard(); } CATCH_ALL(e) { delete pDataSource; THROW_LAST(); } END_CATCH_ALL }
bool CXBMCTinyXML::SaveFile(const std::string& filename) const { XFILE::CFile file; if (file.OpenForWrite(filename, true)) { TiXmlPrinter printer; Accept(&printer); return file.Write(printer.CStr(), printer.Size()) == static_cast<ssize_t>(printer.Size()); } return false; }
HRESULT CombineMasterSlaveXmlParam( const char* szXmlParamMaster, const char* szXmlParamSlave, char* szXmlParamAll, DWORD32& dwLen ) { TiXmlElement* pMasterRootElement = NULL; TiXmlDocument cXmlDocMaster; if ( szXmlParamMaster && cXmlDocMaster.Parse(szXmlParamMaster) ) { pMasterRootElement = cXmlDocMaster.RootElement(); } TiXmlElement* pSlaveRootElement = NULL; TiXmlDocument cXmlDocSlave; if ( szXmlParamSlave && cXmlDocSlave.Parse(szXmlParamSlave) ) { pSlaveRootElement = cXmlDocSlave.RootElement(); } if ( NULL == pMasterRootElement || NULL == pSlaveRootElement ) { dwLen = 0; return E_FAIL; } else { // 将主CPU参数内的所有Section结点插入到从CPU参数内的HvParam结点下。 TiXmlElement* pMasterHvParamElement = NULL; TiXmlElement* pSlaveHvParamElement = NULL; pMasterHvParamElement = pMasterRootElement->FirstChildElement("HvParam"); pSlaveHvParamElement = pSlaveRootElement->FirstChildElement("HvParam"); if ( pMasterHvParamElement && pSlaveHvParamElement) { TiXmlElement* pMasterSectionElement = NULL; pMasterSectionElement = pMasterHvParamElement->FirstChildElement(); while (pMasterSectionElement) { pSlaveHvParamElement->LinkEndChild(pMasterSectionElement->Clone()); pMasterSectionElement = pMasterSectionElement->NextSiblingElement(); } } TiXmlPrinter cTxPr; cXmlDocSlave.Accept(&cTxPr); DWORD32 dwXmlLen = (DWORD32)cTxPr.Size(); if ( dwLen > dwXmlLen ) { dwLen = dwXmlLen; memcpy(szXmlParamAll, cTxPr.CStr(), dwXmlLen); return S_OK; } else { dwLen = 0; return E_FAIL; } } }
size_t XMLSource::getText(const char*& outputBuffer) { TiXmlPrinter printer; printer.SetStreamPrinting(); xassert(doc, "No document to save."); doc->Accept(&printer); outputBuffer = printer.CStr(); return printer.Size(); }
bool TinyXML::SaveDocument(const wxString& filename, TiXmlDocument* doc) { if (!doc) return false; TiXmlPrinter printer; printer.SetIndent("\t"); doc->Accept(&printer); return Manager::Get()->GetFileManager()->SaveUTF8(filename, printer.CStr(), printer.Size()); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void XmlDocumentImpl::getAsRawData(cvf::UByteArray* buffer) const { TiXmlPrinter printer; // Use tab as indent marker printer.SetIndent( "\t" ); // Link document to printer Accept(&printer); buffer->assign((cvf::ubyte*)printer.CStr(), (size_t)printer.Size()); }
bool CXBMCTinyXML::SaveFile(const CStdString &filename) const { XFILE::CFile file; if (file.OpenForWrite(filename, true)) { TiXmlPrinter printer; Accept(&printer); file.Write(printer.CStr(), printer.Size()); return true; } return false; }
bool MainFrame::TiXmlSaveDocument(const wxString& filename, TiXmlDocument* doc) { if (!doc) return false; TiXmlPrinter printer; printer.SetIndent("\t"); doc->Accept(&printer); wxTempFile file(filename); if(file.IsOpened()) if(file.Write(printer.CStr(), printer.Size()) && file.Commit()) return true; return false; }// TiXmlSaveDocument
// QC:? void ScriptableObject::saveAOD(VFS::File* file) { TiXmlDocument* doc = new TiXmlDocument(); TiXmlElement* xml = aod()->Clone()->ToElement(); cleanPtrInAOD(xml); doc->LinkEndChild(xml); TiXmlPrinter printer; printer.SetStreamPrinting(); doc->Accept(&printer); file->truncate(); file->write((char*)printer.CStr(), printer.Size()); delete doc; }
bool TinyXML::SaveDocument(const wxString& filename, TiXmlDocument* doc) { if (!doc) return false; TiXmlPrinter printer; printer.SetIndent("\t"); doc->Accept(&printer); return Manager::Get()->GetFileManager()->Save(filename, printer.CStr(), printer.Size()); // wxTempFile file(filename); // if(file.IsOpened()) // if(file.Write(Printer.CStr(), Printer.Size()) && file.Commit()) // return true; // return false; }
void ProcessFile(const char* fileName) { TiXmlDocument doc; doc.LoadFile(fileName); if (doc.Error()) { printf("Error in file %s: %s\n", fileName, doc.ErrorDesc()); return; } TiXmlPrinter printer; printer.SetStreamPrinting(); doc.Accept(&printer); FILE *f = fopen(fileName, "wb"); if (!f) return; fwrite(printer.CStr(), printer.Size(), 1, f); fclose(f); }
/************************************************************************** * name : GetXMLStream * description: 获取xml流 * input : NA * output : nXMLStreamLength * return : const char* xml流 * remark : NA **************************************************************************/ const char* CXml::GetXMLStream(unsigned int &uiXMLStreamLength) { TiXmlPrinter xmlPrinter; xmlPrinter.SetStreamPrinting(); if (NULL == m_pXMlDoc) { SAFE_NEW(m_pXMlDoc, TiXmlDocument);//lint !e774 } CHECK_POINTER(m_pXMlDoc, NULL);//lint !e774 if (!m_pXMlDoc->Accept(&xmlPrinter)) { return NULL; } uiXMLStreamLength = xmlPrinter.Size(); m_strStream = xmlPrinter.CStr(); return m_strStream.c_str(); }
HRESULT CHVC::BuildPlateString( char* pszPlateString, int* piPlateStringSize, CARLEFT_INFO_STRUCT *pCarLeftInfo ) { if (pCarLeftInfo == NULL || pszPlateString == NULL || piPlateStringSize == NULL) return E_INVALIDARG; if (!m_pXmlDoc) //如果文档为空则创建新文档 { m_pXmlDoc = new TiXmlDocument; TiXmlDeclaration* pDecl = new TiXmlDeclaration("1.0", "GB2312", "yes"); TiXmlElement* pRoot = new TiXmlElement("HvcResultDoc"); if ( !m_pXmlDoc || !pDecl || !pRoot ) { SAFE_DELETE(m_pXmlDoc); SAFE_DELETE(pDecl); SAFE_DELETE(pRoot); return E_OUTOFMEMORY; } m_pXmlDoc->LinkEndChild(pDecl); m_pXmlDoc->LinkEndChild(pRoot); } //取得ResultSet段 TiXmlElement* pResultSet = m_pXmlDoc->RootElement()->FirstChildElement("ResultSet"); if (!pResultSet) { pResultSet = new TiXmlElement("ResultSet"); if ( !pResultSet ) return E_OUTOFMEMORY; m_pXmlDoc->RootElement()->LinkEndChild(pResultSet); } //注意:一定要删除已经存在的节 TiXmlNode* pResultOld = pResultSet->FirstChild("Result"); if ( pResultOld ) { pResultSet->RemoveChild(pResultOld); } //写入Result TiXmlElement* pResult = new TiXmlElement("Result"); if (pResult) { pResultSet->LinkEndChild(pResult); //车牌 char szConf[32] = {0}; char szPlateName[32] = {0}; char szFrameName[64] = {0}; GetPlateNameAlpha( (char*)szPlateName, ( PLATE_TYPE )pCarLeftInfo->cCoreResult.nType, ( PLATE_COLOR )pCarLeftInfo->cCoreResult.nColor, pCarLeftInfo->cCoreResult.rgbContent ); if (strstr(szPlateName, "11111") != NULL) { HV_Trace(5, "M"); //return S_FALSE; } HV_Trace(5,"%s\n", szPlateName); //输出车牌字符串 TiXmlElement* pValue = new TiXmlElement("PlateName"); TiXmlText* pText = new TiXmlText(szPlateName); if (pValue && pText) { pValue->LinkEndChild(pText); pResult->LinkEndChild(pValue); } int nColorType = 0; if (strncmp(szPlateName, "蓝", 2) == 0) { nColorType = 1; } else if (strncmp(szPlateName, "黄", 2) == 0) { nColorType = 2; } else if (strncmp(szPlateName, "黑", 2) == 0) { nColorType = 3; } else if (strncmp(szPlateName, "白", 2) == 0) { nColorType = 4; } else if (strncmp(szPlateName, "绿", 2) == 0) { nColorType = 5; } else { nColorType = 0; } int nPlateType = 0; switch ( pCarLeftInfo->cCoreResult.nType ) { case PLATE_NORMAL: case PLATE_POLICE: nPlateType = 1; break; case PLATE_WJ: nPlateType = 2; break; case PLATE_POLICE2: nPlateType = 3; break; case PLATE_DOUBLE_YELLOW: case PLATE_DOUBLE_MOTO: nPlateType = 4; break; default: nPlateType = 0; break; } pValue = new TiXmlElement("Color"); if ( pValue ) { pValue->SetAttribute("raw_value", pCarLeftInfo->cCoreResult.nColor); pValue->SetAttribute("value", nColorType); pResult->LinkEndChild(pValue); } pValue = new TiXmlElement("Type"); if ( pValue ) { pValue->SetAttribute("raw_value", pCarLeftInfo->cCoreResult.nType); pValue->SetAttribute("value", nPlateType); pResult->LinkEndChild(pValue); } //如果输出附加信息 if (m_cModuleParams.cResultSenderParam.fOutputAppendInfo) { if (m_cModuleParams.cResultSenderParam.fOutputObservedFrames) { //有效帧数 pValue = new TiXmlElement("ObservedFrames"); if (pValue) { pValue->SetAttribute("value", "1"); pValue->SetAttribute("chnname", "有效帧数"); pResult->LinkEndChild(pValue); } } //可信度 pValue = new TiXmlElement("Confidence"); if (pValue) { sprintf(szConf, "%.3f", exp(log(pCarLeftInfo->cCoreResult.fltAverageConfidence) * 0.143)); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "平均可信度"); pResult->LinkEndChild(pValue); } //首字符可信度 pValue = new TiXmlElement("FirstCharConf"); if (pValue) { sprintf(szConf, "%.3f", pCarLeftInfo->cCoreResult.fltFirstAverageConfidence); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "首字可信度"); pResult->LinkEndChild(pValue); } //车身颜色 if (m_cModuleParams.cTrackerCfgParam.fEnableRecgCarColor) { pValue = new TiXmlElement("CarColor"); if (pValue) { GetCarColor(pCarLeftInfo, szConf); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车身颜色"); pResult->LinkEndChild(pValue); } } //车牌HSL值 if(m_cModuleParams.cTrackerCfgParam.fProcessPlate_BlackPlate_Enable) //黑牌参数使能 { pValue = new TiXmlElement("HSL"); if (pValue) { HV_Trace(5,"---AppendInfo:H:%d\tS:%d\tL:%d\n", pCarLeftInfo->cCoreResult.iH, pCarLeftInfo->cCoreResult.iS, pCarLeftInfo->cCoreResult.iL); sprintf(szConf, "H:%d\tS:%d\tL:%d", pCarLeftInfo->cCoreResult.iH, pCarLeftInfo->cCoreResult.iS, pCarLeftInfo->cCoreResult.iL); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车牌HSL值"); pResult->LinkEndChild(pValue); } } //处理时间 DWORD32 dwProcTime = GetSystemTick() - pCarLeftInfo->cCoreResult.cResultImg.pimgBestSnapShot->GetRefTime(); if (dwProcTime > 180) { dwProcTime = 180 - DWORD32(1 + (54.0 * rand() / (RAND_MAX + 1.0)) - 27); } pValue = new TiXmlElement("ProcTime"); if (pValue) { sprintf(szConf, "%d", dwProcTime); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "处理时间"); pResult->LinkEndChild(pValue); } } // end of if (m_cModuleParams.cResultSenderParam.fOutputAppendInfo) } // end of if (pResult) TiXmlPrinter cTxPr; if (m_pXmlDoc) { cTxPr.SetStreamPrinting(); m_pXmlDoc->Accept(&cTxPr); int nCpyLen = MIN_INT(*piPlateStringSize, (int)cTxPr.Size() + 1); HV_memcpy( pszPlateString, cTxPr.CStr(), nCpyLen ); pszPlateString[nCpyLen - 1] = '\0'; *piPlateStringSize = nCpyLen; } else { *piPlateStringSize = 0; } return S_OK; }
HRESULT CAutotest::GetAutotestStatus(PVOID* ppvOutBuf, DWORD* pdwOutSize) { #define HV_XML_CMD_VERSION_NO "3.0" #define HVXML_VER "Ver" #define HVXML_HVCMD "HvCmd" #define HVXML_HVCMDRESPOND "HvCmdRespond" #define HVXML_RETCODE "RetCode" #define HVXML_RETMSG "RetMsg" #define HVXML_CMDNAME "CmdName" #define HVXML_RETURNLEN "RetLen" if (NULL == ppvOutBuf || NULL == pdwOutSize) { SW_TRACE_DEBUG("Err: NULL == ppvOutBuf || NULL == pdwOutSize\n"); return E_INVALIDARG; } if (!m_fInited) { SW_TRACE_DEBUG("Err: not inited yet!\n"); return E_NOTIMPL; } TiXmlDocument xmlOutDoc; TiXmlDeclaration *pDeclaration = NULL; TiXmlElement *pRootEle = NULL; pDeclaration = new TiXmlDeclaration("1.0","GB2312","yes"); if (NULL == pDeclaration) { SW_TRACE_DEBUG("Err: no memory for pDeclaration\n"); return E_OUTOFMEMORY; } xmlOutDoc.LinkEndChild(pDeclaration); pRootEle = new TiXmlElement(HVXML_HVCMDRESPOND); if (NULL == pRootEle) { SW_TRACE_DEBUG("Err: no memory for pRootEle\n"); return E_OUTOFMEMORY; } xmlOutDoc.LinkEndChild(pRootEle); pRootEle->SetAttribute(HVXML_VER, HV_XML_CMD_VERSION_NO); TiXmlElement *pReplyEle = new TiXmlElement(HVXML_CMDNAME); if (NULL == pReplyEle) { SW_TRACE_DEBUG("Err: no memory for pReplyEle\n"); return E_OUTOFMEMORY; } pRootEle->LinkEndChild(pReplyEle); TiXmlText * pReplyText = new TiXmlText("GetAutotestProgress"); if (NULL == pReplyText) { SW_TRACE_DEBUG("Err: no memory for pReplyText\n"); return E_OUTOFMEMORY; } pReplyEle->LinkEndChild(pReplyText); if (0 == m_dwTestProgress) { pReplyEle->SetAttribute(HVXML_RETCODE, 0); pReplyEle->SetAttribute(HVXML_RETMSG, "TestOK"); } else if (1 == m_dwTestProgress) { pReplyEle->SetAttribute(HVXML_RETCODE, 0); pReplyEle->SetAttribute(HVXML_RETMSG, "Testing"); } else if (2 == m_dwTestProgress) { pReplyEle->SetAttribute(HVXML_RETCODE, 0); pReplyEle->SetAttribute(HVXML_RETMSG, "TestFailed"); } else { pReplyEle->SetAttribute(HVXML_RETCODE, -1); pReplyEle->SetAttribute(HVXML_RETMSG, "GetAutotestProgress Failed"); } TiXmlPrinter xmlPrinter; xmlOutDoc.Accept(&xmlPrinter); *pdwOutSize = xmlPrinter.Size()+1; *ppvOutBuf = swpa_mem_alloc(*pdwOutSize); if (NULL == *ppvOutBuf) { SW_TRACE_DEBUG("Err: no memory for *ppvOutBuf!\n"); return E_OUTOFMEMORY; } swpa_memset(*ppvOutBuf, 0, *pdwOutSize); swpa_strncpy((CHAR*)*ppvOutBuf, xmlPrinter.CStr(), xmlPrinter.Size()); return S_OK; }
HRESULT CTrafficGate::BuildPlateString( char* pszPlateString, int* piPlateStringSize, CARLEFT_INFO_STRUCT *pCarLeftInfo ) { if (pCarLeftInfo == NULL || pszPlateString == NULL || piPlateStringSize == NULL) return E_INVALIDARG; if (!m_pXmlDoc) //如果文档为空则创建新文档 { m_pXmlDoc = new TiXmlDocument; TiXmlDeclaration* pDecl = new TiXmlDeclaration("1.0", "GB2312", "yes"); TiXmlElement* pRoot = new TiXmlElement("HvcResultDoc"); if ( !m_pXmlDoc || !pDecl || !pRoot ) { SAFE_DELETE(m_pXmlDoc); SAFE_DELETE(pDecl); SAFE_DELETE(pRoot); return E_OUTOFMEMORY; } m_pXmlDoc->LinkEndChild(pDecl); m_pXmlDoc->LinkEndChild(pRoot); } //取得ResultSet段 TiXmlElement* pResultSet = m_pXmlDoc->RootElement()->FirstChildElement("ResultSet"); if (!pResultSet) { pResultSet = new TiXmlElement("ResultSet"); if ( !pResultSet ) return E_OUTOFMEMORY; m_pXmlDoc->RootElement()->LinkEndChild(pResultSet); } //注意:一定要删除已经存在的节 TiXmlNode* pResultOld = pResultSet->FirstChild("Result"); if ( pResultOld ) { pResultSet->RemoveChild(pResultOld); } //写入Result TiXmlElement* pResult = new TiXmlElement("Result"); if (pResult) { pResultSet->LinkEndChild(pResult); //车牌 static char szConf[128] = {0}; static char szPlateName[32] = {0}; static char szFrameName[64] = {0}; static char szCarType[16] = {0}; bool fIsNoPlate = false; bool fIsCar = true; bool fIsDouble = false; bool fIsDoubleMoto = false; GetPlateNameAlpha( (char*)szPlateName, ( PLATE_TYPE )pCarLeftInfo->cCoreResult.nType, ( PLATE_COLOR )pCarLeftInfo->cCoreResult.nColor, pCarLeftInfo->cCoreResult.rgbContent ); if (strstr(szPlateName, "11111") != NULL) { HV_Trace(5, "M"); return S_FALSE; } //获取车辆类型 GetCarType(&pCarLeftInfo->cCoreResult, szCarType); //车辆类型为行人、或者非机动车时,将"无车牌"替换为车辆类型 if (strcmp(szCarType, "行人") == 0 || strcmp(szCarType, "非机动车") == 0) { strcpy(szPlateName, " "); strcat(szPlateName, szCarType); fIsCar = false; } if (pCarLeftInfo->cCoreResult.nType == PLATE_DOUBLE_YELLOW) { fIsDouble = true; } if (pCarLeftInfo->cCoreResult.nType == PLATE_DOUBLE_MOTO) { fIsDoubleMoto = true; } HV_Trace(5, "%s\n", szPlateName); //输出车牌字符串 //无牌车 if ((*(pCarLeftInfo->cCoreResult.rgbContent)) == 0) { fIsNoPlate = true; } TiXmlElement* pValue = new TiXmlElement("PlateName"); TiXmlText* pText = new TiXmlText(szPlateName); if (pValue && pText) { pValue->LinkEndChild(pText); pResult->LinkEndChild(pValue); } int nColorType = 0; if (strncmp(szPlateName, "蓝", 2) == 0) { nColorType = 1; } else if (strncmp(szPlateName, "黄", 2) == 0) { nColorType = 2; } else if (strncmp(szPlateName, "黑", 2) == 0) { nColorType = 3; } else if (strncmp(szPlateName, "白", 2) == 0) { nColorType = 4; } else if (strncmp(szPlateName, "绿", 2) == 0) { nColorType = 5; } else { nColorType = 0; } int nPlateType = 0; switch ( pCarLeftInfo->cCoreResult.nType ) { case PLATE_NORMAL: case PLATE_POLICE: nPlateType = 1; break; case PLATE_WJ: nPlateType = 2; break; case PLATE_POLICE2: nPlateType = 3; break; case PLATE_DOUBLE_YELLOW: case PLATE_DOUBLE_MOTO: nPlateType = 4; break; default: nPlateType = 0; break; } pValue = new TiXmlElement("Color"); if ( pValue ) { pValue->SetAttribute("raw_value", pCarLeftInfo->cCoreResult.nColor); pValue->SetAttribute("value", nColorType); pResult->LinkEndChild(pValue); } pValue = new TiXmlElement("Type"); if ( pValue ) { pValue->SetAttribute("raw_value", pCarLeftInfo->cCoreResult.nType); pValue->SetAttribute("value", nPlateType); pResult->LinkEndChild(pValue); } //如果输出附加信息 if (m_cModuleParams.cResultSenderParam.fOutputAppendInfo) { //输出车辆逆行标识 if (m_cModuleParams.cTrackerCfgParam.nDetReverseRunEnable) { pValue = new TiXmlElement("ReverseRun"); if (pValue) { sprintf(szConf, "%s", pCarLeftInfo->cCoreResult.fReverseRun ? "是" : "否"); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车辆逆向行驶"); pResult->LinkEndChild(pValue); } } //如果无车牌则将速度值取随机,车身颜色为灰色 if (fIsNoPlate && fIsCar) { if (m_cModuleParams.cTrackerCfgParam.cScaleSpeed.fEnable) { srand(GetSystemTick()); pCarLeftInfo->cCoreResult.fltCarspeed = rand() % 20 + 20.0f; } pCarLeftInfo->cCoreResult.nCarColor = CC_GREY; } //输出速度值 if (pCarLeftInfo->cCoreResult.fltCarspeed > 0.0f) { pValue = new TiXmlElement("VideoScaleSpeed"); if (pValue) { sprintf(szConf, "%d Km/h", (int)(pCarLeftInfo->cCoreResult.fltCarspeed)); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "视频测速"); pResult->LinkEndChild(pValue); } //如果有事件检测功能,则把限速值发出去 if (pCarLeftInfo->cCoreResult.nDetectCrossLineEnable || pCarLeftInfo->cCoreResult.nDetectOverYellowLineEnable) { pValue = new TiXmlElement("SpeedLimit"); if (pValue) { sprintf(szConf, "%d Km/h", m_cModuleParams.cResultSenderParam.iSpeedLimit); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "限速值"); pResult->LinkEndChild(pValue); } } //距离计算的误差比例 pValue = new TiXmlElement("ScaleSpeedOfDistance"); if (pValue) { sprintf(szConf, "%0.2f", pCarLeftInfo->cCoreResult.fltScaleOfDistance); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "距离测量误差比例"); pResult->LinkEndChild(pValue); } } if (m_cModuleParams.cResultSenderParam.fOutputObservedFrames) { //有效帧数 pValue = new TiXmlElement("ObservedFrames"); if (pValue) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.iObservedFrames); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "有效帧数"); pResult->LinkEndChild(pValue); } //可信度 pValue = new TiXmlElement("Confidence"); if (pValue) { sprintf( szConf, "%.3f", exp(log(pCarLeftInfo->cCoreResult.fltAverageConfidence) * 0.143) ); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "平均可信度"); pResult->LinkEndChild(pValue); } //首字符可信度 pValue = new TiXmlElement("FirstCharConf"); if (pValue) { sprintf(szConf, "%.3f", pCarLeftInfo->cCoreResult.fltFirstAverageConfidence); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "首字可信度"); pResult->LinkEndChild(pValue); } } //车辆检测时间 if (m_cModuleParams.cResultSenderParam.fOutputCarArriveTime) { pValue = new TiXmlElement("CarArriveTime"); if (pValue) { sprintf(szConf, "%u", pCarLeftInfo->cCoreResult.nFirstFrameTime); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车辆检测时间"); pResult->LinkEndChild(pValue); } } if (fIsDouble) { //双层牌 pValue = new TiXmlElement("DoublePlate"); if (pValue) { pValue->SetAttribute("value", "双"); pValue->SetAttribute("chnname", "车牌类型"); pResult->LinkEndChild(pValue); } } if (fIsDoubleMoto) { //摩托 pValue = new TiXmlElement("DoubleMoto"); if (pValue) { pValue->SetAttribute("value", "摩"); pValue->SetAttribute("chnname", "车牌类型"); pResult->LinkEndChild(pValue); } } //环境光亮度 pValue = new TiXmlElement("AmbientLight"); if (pValue) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.iAvgY); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "环境亮度"); pResult->LinkEndChild(pValue); } //车牌亮度 pValue = new TiXmlElement("PlateLight"); if (pValue) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.iCarAvgY); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车牌亮度"); pResult->LinkEndChild(pValue); } //车牌对比度 pValue = new TiXmlElement("PlateVariance"); if (pValue) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.iCarVariance); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车牌对比度"); pResult->LinkEndChild(pValue); } //车辆尺寸 if (m_cModuleParams.cTrackerCfgParam.fOutputCarSize && pCarLeftInfo->cCoreResult.nCarType != CT_WALKMAN && pCarLeftInfo->cCoreResult.nCarType != CT_BIKE && pCarLeftInfo->cCoreResult.nType != PLATE_DOUBLE_MOTO) { pValue = new TiXmlElement("CarSize"); if (pValue) { if (pCarLeftInfo->cCoreResult.cCarSize.nOutType == 0) { sprintf( szConf, "%d 车长(像素):%d", (int)pCarLeftInfo->cCoreResult.cCarSize.iCarWidth, (int)pCarLeftInfo->cCoreResult.cCarSize.iCarHeight ); } else { sprintf( szConf, "%.2f 车长(米):%.2f", pCarLeftInfo->cCoreResult.cCarSize.iCarWidth, pCarLeftInfo->cCoreResult.cCarSize.iCarHeight ); } pValue->SetAttribute("value", szConf); sprintf( szConf, "车宽(%s)", pCarLeftInfo->cCoreResult.cCarSize.nOutType == 0 ? "像素" : "米" ); pValue->SetAttribute("chnname", szConf); pResult->LinkEndChild(pValue); } } //车辆类型 pValue = new TiXmlElement("CarType"); if (pValue) { pValue->SetAttribute("value", szCarType); pValue->SetAttribute("chnname", "车辆类型"); pResult->LinkEndChild(pValue); } //车身颜色 if (m_cModuleParams.cTrackerCfgParam.fEnableRecgCarColor) { pValue = new TiXmlElement("CarColor"); if (pValue) { GetCarColor(pCarLeftInfo, szConf); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车身颜色"); pResult->LinkEndChild(pValue); } } //车道号 pValue = new TiXmlElement("RoadNumber"); if (pValue) { if (m_cModuleParams.cTrackerCfgParam.iStartRoadNum == 0) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.nRoadNo); } else { if (pCarLeftInfo->cCoreResult.nRoadNo == 255) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.nRoadNo); } else { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.nRoadNo + 1); } } pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "车道"); pResult->LinkEndChild(pValue); } //起始车道号 pValue = new TiXmlElement("BeginRoadNumber"); if (pValue) { if (m_cModuleParams.cTrackerCfgParam.iRoadNumberBegin == 0) { sprintf(szConf, "<左,%d>", m_cModuleParams.cTrackerCfgParam.iStartRoadNum); } else { sprintf(szConf, "<右,%d>", m_cModuleParams.cTrackerCfgParam.iStartRoadNum); } pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "起始车道号"); pResult->LinkEndChild(pValue); } //路口名称 pValue = new TiXmlElement("StreetName"); if (pValue) { pValue->SetAttribute("value", m_cModuleParams.cResultSenderParam.szStreetName); pValue->SetAttribute("chnname", "路口名称"); pResult->LinkEndChild(pValue); } //路口方向 pValue = new TiXmlElement("StreetDirection"); if (pValue) { pValue->SetAttribute("value", m_cModuleParams.cResultSenderParam.szStreetDirection); pValue->SetAttribute("chnname", "路口方向"); pResult->LinkEndChild(pValue); } //事件检测信息 pValue = new TiXmlElement("EventCheck"); if (pValue) { GetEventDetInfo(pCarLeftInfo, szConf); if (strlen(szConf) != 0) { pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "事件检测"); pResult->LinkEndChild(pValue); } } if (pCarLeftInfo->cCoreResult.cResultImg.pimgBestSnapShot) { //视频帧名 strcpy( szFrameName, pCarLeftInfo->cCoreResult.cResultImg.pimgBestSnapShot->GetFrameName() ); if (strlen(szFrameName) != 0 #ifdef SINGLE_BOARD_PLATFORM && m_cModuleParams.cCamCfgParam.iCamType == 0 // 单板下0才是测试协议 #else && m_cModuleParams.cCamCfgParam.iCamType == 1 #endif ) { pValue = new TiXmlElement("FrameName"); if ( pValue ) { char *pFirst = szFrameName, *pSecond = szFrameName; char *pTemp = strstr(pFirst, "."); while (pTemp) { pSecond = pTemp; pTemp = strstr(pTemp + 1, "."); } szFrameName[pSecond - pFirst] = 0; pValue->SetAttribute("value", szFrameName); pValue->SetAttribute("chnname", "视频帧名"); pResult->LinkEndChild(pValue); } } } //当前亮度级别 pValue = new TiXmlElement("PlateLightType"); if (pValue) { sprintf(szConf, "%02d级", pCarLeftInfo->cCoreResult.nPlateLightType); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "摄像机亮度等级"); pResult->LinkEndChild(pValue); } //} // end of if (m_cModuleParams.cResultSenderParam.fOutputAppendInfo) #ifndef SINGLE_BOARD_PLATFORM //当前偏光镜状态 pValue = new TiXmlElement("CplStatus"); if (pValue) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.iCplStatus); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "偏光镜状态"); pResult->LinkEndChild(pValue); } if (g_iControllPannelWorkStyle == 1) { //当前补光灯脉宽级别 pValue = new TiXmlElement("PulseLevel"); if (pValue) { sprintf(szConf, "%d", pCarLeftInfo->cCoreResult.iPulseLevel); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "补光脉宽等级"); pResult->LinkEndChild(pValue); } //补光灯状态判断 static int iFillLightCount = 0; static int iFillLightMaxCount = (m_cModuleParams.cTrackerCfgParam.nPlateLightCheckCount << 1); if(iFillLightMaxCount < 20) iFillLightMaxCount = 20; int iMinAvgY = m_cModuleParams.cTrackerCfgParam.nMinPlateBrightness; if (pCarLeftInfo->cCoreResult.iPulseLevel > 0) { if (pCarLeftInfo->cCoreResult.iCarAvgY < 50) { iFillLightCount++; } else { iFillLightCount = 0; } if (m_nLastLightLevel != pCarLeftInfo->cCoreResult.iPulseLevel) { iFillLightCount = 0; m_nLastLightLevel = pCarLeftInfo->cCoreResult.iPulseLevel; } if (iFillLightCount > iFillLightMaxCount ) { iFillLightCount = iFillLightMaxCount; pValue = new TiXmlElement("FlashLightStatus"); if (pValue) { sprintf(szConf, "%s", "异常"); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "补光灯工作状态"); pResult->LinkEndChild(pValue); } } else { pValue = new TiXmlElement("FlashLightStatus"); if (pValue) { sprintf(szConf, "%s", "正常"); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "补光灯工作状态"); pResult->LinkEndChild(pValue); } } } //闪光灯状态判断,无车牌时不进行判断 static int iFlashLampCount = 0; if (pCarLeftInfo->cCoreResult.fIsCapture) { if (pCarLeftInfo->cCoreResult.rgbContent[0] != 0) { if (pCarLeftInfo->cCoreResult.iPulseLevel > 0) { if (pCarLeftInfo->cCoreResult.iCapturerAvgY - pCarLeftInfo->cCoreResult.iAvgY < m_nFlashLampDiff) { iFlashLampCount++; } else { iFlashLampCount = 0; } if (iFlashLampCount > 5) { iFlashLampCount = 5; pValue = new TiXmlElement("CaptureLightStatus"); if (pValue) { sprintf(szConf, "%s", "异常"); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "闪光灯工作状态"); pResult->LinkEndChild(pValue); } } else { pValue = new TiXmlElement("CaptureLightStatus"); if (pValue) { sprintf(szConf, "%s", "正常"); pValue->SetAttribute("value", szConf); pValue->SetAttribute("chnname", "闪光灯工作状态"); pResult->LinkEndChild(pValue); } } } else { iFlashLampCount = 0; } } } else { if (pCarLeftInfo->cCoreResult.rgbContent[0] != 0) iFlashLampCount = 0; } } #endif } // end of if (m_cModuleParams.cResultSenderParam.fOutputAppendInfo) m_pLightTypeSaver->SaveLightType( pCarLeftInfo->cCoreResult.nPlateLightType, pCarLeftInfo->cCoreResult.iPulseLevel, pCarLeftInfo->cCoreResult.iCplStatus, pCarLeftInfo->cCoreResult.nCarArriveTime ); } // end of if (pResult) TiXmlPrinter cTxPr; if (m_pXmlDoc) { cTxPr.SetStreamPrinting(); m_pXmlDoc->Accept(&cTxPr); int nCpyLen = MIN_INT(*piPlateStringSize, (int)cTxPr.Size() + 1); HV_memcpy( pszPlateString, cTxPr.CStr(), nCpyLen ); pszPlateString[nCpyLen - 1] = '\0'; *piPlateStringSize = nCpyLen; } else { *piPlateStringSize = 0; } return S_OK; }
void mitk::PlanarFigureWriter::GenerateData() { m_Success = false; if (!m_WriteToMemory && m_FileName.empty()) { MITK_ERROR << "Could not write planar figures. File name is invalid"; throw std::invalid_argument("file name is empty"); } TiXmlDocument document; auto decl = new TiXmlDeclaration( "1.0", "", "" ); // TODO what to write here? encoding? etc.... document.LinkEndChild( decl ); auto version = new TiXmlElement("Version"); version->SetAttribute("Writer", __FILE__ ); version->SetAttribute("CVSRevision", "$Revision: 17055 $" ); version->SetAttribute("FileVersion", 1 ); document.LinkEndChild(version); /* create xml element for each input */ for ( unsigned int i = 0 ; i < this->GetNumberOfInputs(); ++i ) { // Create root element for this PlanarFigure InputType::Pointer pf = this->GetInput( i ); if (pf.IsNull()) continue; auto pfElement = new TiXmlElement("PlanarFigure"); pfElement->SetAttribute("type", pf->GetNameOfClass()); document.LinkEndChild(pfElement); if ( pf->GetNumberOfControlPoints() == 0 ) continue; //PlanarFigure::VertexContainerType* vertices = pf->GetControlPoints(); //if (vertices == NULL) // continue; // Serialize property list of PlanarFigure mitk::PropertyList::Pointer propertyList = pf->GetPropertyList(); mitk::PropertyList::PropertyMap::const_iterator it; for ( it = propertyList->GetMap()->begin(); it != propertyList->GetMap()->end(); ++it ) { // Create seralizer for this property const mitk::BaseProperty* prop = it->second; std::string serializerName = std::string( prop->GetNameOfClass() ) + "Serializer"; std::list< itk::LightObject::Pointer > allSerializers = itk::ObjectFactoryBase::CreateAllInstance( serializerName.c_str() ); if ( allSerializers.size() != 1 ) { // No or too many serializer(s) found, skip this property continue; } mitk::BasePropertySerializer* serializer = dynamic_cast< mitk::BasePropertySerializer* >( allSerializers.begin()->GetPointer() ); if ( serializer == nullptr ) { // Serializer not valid; skip this property } auto keyElement = new TiXmlElement( "property" ); keyElement->SetAttribute( "key", it->first ); keyElement->SetAttribute( "type", prop->GetNameOfClass() ); serializer->SetProperty( prop ); TiXmlElement* valueElement = nullptr; try { valueElement = serializer->Serialize(); } catch (...) { } if ( valueElement == nullptr ) { // Serialization failed; skip this property continue; } // Add value to property element keyElement->LinkEndChild( valueElement ); // Append serialized property to property list pfElement->LinkEndChild( keyElement ); } // Serialize control points of PlanarFigure auto controlPointsElement = new TiXmlElement("ControlPoints"); pfElement->LinkEndChild(controlPointsElement); for (unsigned int i = 0; i < pf->GetNumberOfControlPoints(); i++) { auto vElement = new TiXmlElement("Vertex"); vElement->SetAttribute("id", i); vElement->SetDoubleAttribute("x", pf->GetControlPoint(i)[0]); vElement->SetDoubleAttribute("y", pf->GetControlPoint(i)[1]); controlPointsElement->LinkEndChild(vElement); } auto geoElement = new TiXmlElement("Geometry"); const PlaneGeometry* planeGeo = dynamic_cast<const PlaneGeometry*>(pf->GetPlaneGeometry()); if (planeGeo != nullptr) { // Write parameters of IndexToWorldTransform of the PlaneGeometry typedef mitk::Geometry3D::TransformType TransformType; const TransformType* affineGeometry = planeGeo->GetIndexToWorldTransform(); const TransformType::ParametersType& parameters = affineGeometry->GetParameters(); auto vElement = new TiXmlElement( "transformParam" ); for ( unsigned int i = 0; i < affineGeometry->GetNumberOfParameters(); ++i ) { std::stringstream paramName; paramName << "param" << i; vElement->SetDoubleAttribute( paramName.str().c_str(), parameters.GetElement( i ) ); } geoElement->LinkEndChild( vElement ); // Write bounds of the PlaneGeometry typedef mitk::Geometry3D::BoundsArrayType BoundsArrayType; const BoundsArrayType& bounds = planeGeo->GetBounds(); vElement = new TiXmlElement( "boundsParam" ); for ( unsigned int i = 0; i < 6; ++i ) { std::stringstream boundName; boundName << "bound" << i; vElement->SetDoubleAttribute( boundName.str().c_str(), bounds.GetElement( i ) ); } geoElement->LinkEndChild( vElement ); // Write spacing and origin of the PlaneGeometry Vector3D spacing = planeGeo->GetSpacing(); Point3D origin = planeGeo->GetOrigin(); geoElement->LinkEndChild(this->CreateXMLVectorElement("Spacing", spacing)); geoElement->LinkEndChild(this->CreateXMLVectorElement("Origin", origin)); pfElement->LinkEndChild(geoElement); } } if(m_WriteToMemory) { // Declare a printer TiXmlPrinter printer; // attach it to the document you want to convert in to a std::string document.Accept(&printer); // Create memory buffer and print tinyxmldocument there... m_MemoryBufferSize = printer.Size() + 1; m_MemoryBuffer = new char[m_MemoryBufferSize]; strcpy(m_MemoryBuffer,printer.CStr()); } else { if (document.SaveFile( m_FileName) == false) { MITK_ERROR << "Could not write planar figures to " << m_FileName << "\nTinyXML reports '" << document.ErrorDesc() << "'"; throw std::ios_base::failure("Error during writing of planar figure xml file."); } } m_Success = true; }