本文整理汇总了C++中QPolygon::intersected方法的典型用法代码示例。如果您正苦于以下问题:C++ QPolygon::intersected方法的具体用法?C++ QPolygon::intersected怎么用?C++ QPolygon::intersected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPolygon
的用法示例。
在下文中一共展示了QPolygon::intersected方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readDetectionAreaFile
bool DataManager::readDetectionAreaFile(bool clipToCamera) {
QFile areaFile(m_config->detectionAreaFile());
QDomDocument doc;
QDomElement root;
int x = 0;
int y = 0;
int cameraId = m_config->cameraIndex();
int cameraWidth = m_config->cameraWidth();
int cameraHeight = m_config->cameraHeight();
QPolygon cameraRectangle;
bool polygonsClipped = false;
bool polygonWasClosed = false;
if(!areaFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString errorMsg = tr("Failed to open the detection area file %1. Please create it in Settings dialog or manually.").arg(areaFile.fileName());
emit messageBroadcasted(errorMsg);
return false;
}
if(!doc.setContent(&areaFile)) {
QString errorMsg = tr("Error reading the detection area file %1").arg(areaFile.fileName());
areaFile.close();
emit messageBroadcasted(errorMsg);
return false;
}
areaFile.close();
root = doc.documentElement();
if (root.nodeName() != "detectionarealist") {
QString errorMsg = tr("Expected <detectionarealist> tag in detection area file but not found");
emit messageBroadcasted(errorMsg);
return false;
}
QDomNodeList areaList = root.childNodes();
if (areaList.count() > 1) {
QString errorMsg = tr("More than one detection areas defined, combining all together");
emit messageBroadcasted(errorMsg);
}
for (int i = 0; i < areaList.count(); i++) {
QDomNode area = areaList.at(i);
QDomNodeList areaNodes = area.childNodes();
if (area.nodeName() != "detectionarea") {
QString errorMsg = tr("Expected <detectionarea> tag in detection area file but not found.");
emit messageBroadcasted(errorMsg);
return false;
}
QDomNodeList cameraList = area.toElement().elementsByTagName("camera");
if (cameraList.count() != 1) {
QString errorMsg = tr("Expected single <camera> tag in detection area. Assuming camera index 0.");
emit messageBroadcasted(errorMsg);
}
for (int c = 0; c < cameraList.count(); c++) {
QDomElement cameraElement = cameraList.at(c).toElement();
cameraId = cameraElement.attribute("id").toInt();
cameraWidth = cameraElement.attribute("width").toInt();
cameraHeight = cameraElement.attribute("height").toInt();
if (cameraId == m_config->cameraIndex()) {
break;
}
}
cameraRectangle << QPoint(0, 0) << QPoint(0, cameraHeight - 1)
<< QPoint(cameraWidth - 1, cameraHeight - 1) << QPoint(cameraWidth - 1, 0);
while (!m_detectionAreaPolygons.isEmpty()) {
QPolygon* polygon = m_detectionAreaPolygons.takeLast();
delete polygon;
}
for (int a = 0; a < areaNodes.count(); a++) {
QDomNode areaSubNode = areaNodes.at(a);
if (areaSubNode.nodeName() == "polygon") {
QDomNodeList pointList = areaSubNode.childNodes();
QPolygon* polygon = new QPolygon();
for (int p = 0; p < pointList.count(); p++) {
QDomElement pointElement = pointList.at(p).toElement();
if (pointElement.nodeName() == "point") {
x = pointElement.attribute("x").toInt();
y = pointElement.attribute("y").toInt();
polygon->append(QPoint(x, y));
}
}
if (clipToCamera && polygon->size() &&
!cameraRectangle.boundingRect().contains(polygon->boundingRect()))
{
if (polygon->first() == polygon->last()) {
polygonWasClosed = true;
}
*polygon = polygon->intersected(cameraRectangle);
polygonsClipped = true;
if (!polygonWasClosed) {
// intersected() treats polygon as implicitly closed
// so extra node is added: remove it
//.........这里部分代码省略.........