Skip to content

Commit

Permalink
[Feature Branch] - CMarkup --> Tinyxml2 : SetImageSettings() (#73)
Browse files Browse the repository at this point in the history
* Saving progress.

* Added 'SetForceSettings' function.

* Remove unnecessary explicit string-construction.

---------

Co-authored-by: johannes.gotlen <johannes.gotlen@qualisys.se>
  • Loading branch information
OliverGlandberger and qjgn authored Feb 3, 2025
1 parent 2ed1b91 commit d345239
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 49 deletions.
2 changes: 1 addition & 1 deletion RTProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,7 @@ bool CRTProtocol::SetImageSettings(
const unsigned int* pnWidth, const unsigned int* pnHeight, const float* pfLeftCrop,
const float* pfTopCrop, const float* pfRightCrop, const float* pfBottomCrop)
{
auto serializer = CMarkupSerializer(mnMajorVersion, mnMinorVersion);
CTinyxml2Serializer serializer (mnMajorVersion, mnMinorVersion);
auto message = serializer.SetImageSettings(
nCameraID, pbEnable, peFormat,
pnWidth, pnHeight, pfLeftCrop,
Expand Down
110 changes: 64 additions & 46 deletions Tinyxml2Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@

using namespace qualisys_cpp_sdk;

void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool* pbValue, const char* tTrue, const char* tFalse)
void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML)
{
//if (pbValue)
//{
// oXML->AddElem(tTag, *pbValue ? tTrue : tFalse);
//}
if (pbValue)
{
tinyxml2::XMLElement* pElement = oXML.NewElement(tTag);
pElement->SetText(*pbValue ? "True" : "False");
parent.InsertEndChild(pElement);
}
}

void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool pbValue, const char* tTrue, const char* tFalse)
void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML)
{
//oXML->AddElem(tTag, pbValue ? tTrue : tFalse);
tinyxml2::XMLElement* pElement = oXML.NewElement(tTag);
pElement->SetText(pbValue ? "True" : "False");
parent.InsertEndChild(pElement);
}

void CTinyxml2Serializer::AddXMLElementInt(tinyxml2::XMLDocument* oXML, const char* tTag, const int* pnValue)
Expand Down Expand Up @@ -223,7 +227,6 @@ namespace
};
str.erase(std::remove_if(str.begin(), str.end(), isInvalidChar), str.end());
}

}

bool CTinyxml2Deserializer::ReadXmlBool(tinyxml2::XMLDocument* xml, const std::string& element, bool& value) const
Expand Down Expand Up @@ -3452,52 +3455,67 @@ std::string CTinyxml2Serializer::SetImageSettings(const unsigned int pCameraId,
const CRTPacket::EImageFormat* peFormat, const unsigned int* pnWidth, const unsigned int* pnHeight,
const float* pfLeftCrop, const float* pfTopCrop, const float* pfRightCrop, const float* pfBottomCrop)
{
//CTinyxml2 oXML;
tinyxml2::XMLDocument oXML;

//oXML.AddElem("QTM_Settings");
//oXML.IntoElem();
//oXML.AddElem("Image");
//oXML.IntoElem();
// Root element
tinyxml2::XMLElement* pRoot = oXML.NewElement("QTM_Settings");
oXML.InsertFirstChild(pRoot);

//oXML.AddElem("Camera");
//oXML.IntoElem();
// Image element
tinyxml2::XMLElement* pImage = oXML.NewElement("Image");
pRoot->InsertEndChild(pImage);

//AddXMLElementUnsignedInt(&oXML, "ID", &pCameraId);
// Camera element
tinyxml2::XMLElement* pCamera = oXML.NewElement("Camera");
pImage->InsertEndChild(pCamera);

//AddXMLElementBool(&oXML, "Enabled", pbEnable);
// ID
AddXMLElementUnsignedInt(*pCamera, "ID", pCameraId, oXML);

//if (peFormat)
//{
// switch (*peFormat)
// {
// case CRTPacket::FormatRawGrayscale:
// oXML.AddElem("Format", "RAWGrayscale");
// break;
// case CRTPacket::FormatRawBGR:
// oXML.AddElem("Format", "RAWBGR");
// break;
// case CRTPacket::FormatJPG:
// oXML.AddElem("Format", "JPG");
// break;
// case CRTPacket::FormatPNG:
// oXML.AddElem("Format", "PNG");
// break;
// }
//}
//AddXMLElementUnsignedInt(&oXML, "Width", pnWidth);
//AddXMLElementUnsignedInt(&oXML, "Height", pnHeight);
//AddXMLElementFloat(&oXML, "Left_Crop", pfLeftCrop);
//AddXMLElementFloat(&oXML, "Top_Crop", pfTopCrop);
//AddXMLElementFloat(&oXML, "Right_Crop", pfRightCrop);
//AddXMLElementFloat(&oXML, "Bottom_Crop", pfBottomCrop);
// Enabled
AddXMLElementBool(*pCamera, "Enabled", pbEnable, oXML);

//oXML.OutOfElem(); // Camera
//oXML.OutOfElem(); // Image
//oXML.OutOfElem(); // QTM_Settings
// Format
if (peFormat)
{
const char* formatStr = nullptr;
switch (*peFormat)
{
case CRTPacket::FormatRawGrayscale:
formatStr = "RAWGrayscale";
break;
case CRTPacket::FormatRawBGR:
formatStr = "RAWBGR";
break;
case CRTPacket::FormatJPG:
formatStr = "JPG";
break;
case CRTPacket::FormatPNG:
formatStr = "PNG";
break;
}

//return oXML.GetDoc();
if (formatStr)
{
tinyxml2::XMLElement* pFormat = oXML.NewElement("Format");
pFormat->SetText(formatStr);
pCamera->InsertEndChild(pFormat);
}
}

return "";
// Other settings
AddXMLElementUnsignedInt(*pCamera, "Width", pnWidth, oXML);
AddXMLElementUnsignedInt(*pCamera, "Height", pnHeight, oXML);
AddXMLElementFloat(*pCamera, "Left_Crop", pfLeftCrop, 6, oXML);
AddXMLElementFloat(*pCamera, "Top_Crop", pfTopCrop, 6, oXML);
AddXMLElementFloat(*pCamera, "Right_Crop", pfRightCrop, 6, oXML);
AddXMLElementFloat(*pCamera, "Bottom_Crop", pfBottomCrop, 6, oXML);

// Convert to string
tinyxml2::XMLPrinter printer;
oXML.Print(&printer);

return printer.CStr();
}

std::string CTinyxml2Serializer::SetForceSettings(const unsigned int pPlateId, const SPoint* pCorner1,
Expand Down
4 changes: 2 additions & 2 deletions Tinyxml2Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ namespace qualisys_cpp_sdk {
private:
std::uint32_t mnMajorVersion;
std::uint32_t mnMinorVersion;
void AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool* pbValue, const char* tTrue = "True", const char* tFalse = "False");
void AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool bValue, const char* tTrue = "True", const char* tFalse = "False");
void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML);
void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML);
void AddXMLElementInt(tinyxml2::XMLDocument* oXML, const char* tTag, const int* pnValue);
void AddXMLElementUnsignedInt(tinyxml2::XMLElement& parent, const char* tTag, const unsigned int nValue, tinyxml2::XMLDocument& oXML);
void AddXMLElementUnsignedInt(tinyxml2::XMLElement& parent, const char* tTag, const unsigned int* pnValue, tinyxml2::XMLDocument& oXML);
Expand Down

0 comments on commit d345239

Please sign in to comment.