fi[nIndex].rect = QRectF(SSetting::GetInstance()->nStarPos, dHeight, SSetting::GetInstance()->dvCameraFovWidth.at(0), SSetting::GetInstance()->dvCameraFovHeight.at(0));是什么意思
时间: 2024-04-07 18:32:33 浏览: 78
这行代码中,`fi` 是一个 `QVector<FovInfo>` 类型的向量,`nIndex` 是一个整数类型的变量,表示向量中的一个索引。`rect` 是 `FovInfo` 类的一个成员变量,是一个 `QRectF` 类型的变量,表示视野范围。`QRectF` 类型的变量表示一个矩形区域,由四个参数构成:左上角的坐标、宽度和高度。
具体来说,`SSetting::GetInstance()->nStarPos` 表示矩形左上角的坐标,是一个 `QPointF` 类型的变量,表示一个点的坐标;`dHeight` 是一个 `qreal` 类型的变量,表示矩形的高度;`SSetting::GetInstance()->dvCameraFovWidth.at(0)` 和 `SSetting::GetInstance()->dvCameraFovHeight.at(0)` 分别表示相机的水平视角和垂直视角,是一个 `qreal` 类型的变量。这一行代码的作用是将这些参数传递给 `QRectF` 的构造函数,创建一个矩形区域,并将其赋值给 `fi[nIndex].rect`,即 `fi` 向量中的第 `nIndex` 个元素的 `rect` 成员变量。
通过这行代码,我们可以看出,`FovInfo` 类型的变量中存储了视野范围和颜色信息,这些信息将在程序中用于绘制相机视野的图形。
相关问题
fi[nIndex].clrs = qMakePair(SSetting::GetInstance()->nvOddClr.at(0), SSetting::GetInstance()->nvEvenClr.at(0));是什么意思
这行代码中,`fi` 是一个 `QVector<FovInfo>` 类型的向量,`nIndex` 是一个整数类型的变量,表示向量中的一个索引。`clrs` 是 `FovInfo` 类的一个成员变量,是一个 `QPair<QColor, QColor>` 类型的变量,表示一组颜色信息。`qMakePair` 是 Qt 框架中的一个函数,用于创建一个 `QPair` 类型的变量。这一行代码的作用是将 `nvOddClr` 和 `nvEvenClr` 中的第一个元素分别赋值给 `clrs` 的两个成员变量。
具体来说,`SSetting::GetInstance()->nvOddClr.at(0)` 返回了 `SSetting` 类的唯一实例中的 `nvOddClr` 成员向量中的第一个元素,即奇数行的颜色值;`SSetting::GetInstance()->nvEvenClr.at(0)` 返回了 `SSetting` 类的唯一实例中的 `nvEvenClr` 成员向量中的第一个元素,即偶数行的颜色值。`qMakePair` 函数将这两个颜色值分别作为参数,创建了一个 `QPair<QColor, QColor>` 类型的变量,并将其赋值给 `fi[nIndex].clrs`,即 `fi` 向量中的第 `nIndex` 个元素的 `clrs` 成员变量。这样就完成了将一组颜色值赋值给 `FovInfo` 类型的变量的操作。
优化代码void QQuickPrint::CalcCleanSprayInk(int nCleanSprayTime, int nCleanSprayStartTime, int nCleanSprayEndTime) { if (nCleanSprayTime <= 0) return; _CLEANSPRAY_INKINFO *stuCleanSprayInkInfo = new _CLEANSPRAY_INKINFO; stuCleanSprayInkInfo->nCostTime = nCleanSprayTime; stuCleanSprayInkInfo->nStartTime = static_cast<uint>(nCleanSprayStartTime); stuCleanSprayInkInfo->nEndTime = static_cast<uint>(nCleanSprayEndTime); stuCleanSprayInkInfo->nType = CLEANSPRAY_INK_CALCULATE; int nCntOfChannel = m_qPrintParam->GetCntOfChannel(); int nFrameSize = m_qPrintParam->GetFrameSize(); //喷头孔数 int nCleanDropSize = m_qPrintParam->GetCleanFireDropSize(); double dDropSizeCost = CLEANSPRAYDROPSIZE[nCleanDropSize];//清喷小点、中点、大点对应的耗墨量 int nCleanFireTimes = m_qPrintParam->GetCleanFireTimes(); int nCleanFireInterval = m_qPrintParam->GetCleanFireInterval(); int nCleanTotalTimes = (nCleanSprayTime / nCleanFireInterval) + 1;//清喷动作执行次数 = (清喷时间 / 清喷间隔) + 1,+1的原因是开启清喷时会立即执行1次清喷动作 //单通道清喷动作耗墨量 = 喷头孔数 * 清喷大小 * 单次清喷动作的清喷次数 * 清喷动作执行次数 double dColorCost = PL2ML(nFrameSize * dDropSizeCost * nCleanFireTimes * nCleanTotalTimes); memset(stuCleanSprayInkInfo->dInkCost, 0.00, sizeof(double) * MAXCOLORS); //获取各通道对应的颜色,计算各通道清喷耗墨量 for (int iC = 0; iC != nCntOfChannel; ++iC) { int nColorsCnt = m_qPrintParam->GetCntOfColors(); int nColorIndex = m_qPrintParam->GetRIPDataOfPiece(iC); if (PRN_CMYKOrRBLk == nColorsCnt) //8色模式,通道依次接RIP图的第7 6 1 3 0 2 5 4个位置 { //判断清喷通道接的RIP图位置对应哪个颜色 for (int nIndex = 0; nIndex != PRN_CMYKOrRBLk; ++nIndex) { if (g_nColorIndexOfCMYKOrRBLk[nIndex] == nColorIndex) { stuCleanSprayInkInfo->dInkCost[nIndex] += dColorCost; } } } else //其它颜色模式 { stuCleanSprayInkInfo->dInkCost[nColorIndex] += dColorCost; } } //清喷信息上报到MES stuCleanSprayInfo *pCleanSprayInfo = new stuCleanSprayInfo; pCleanSprayInfo->nRunTime = nCleanSprayTime; pCleanSprayInfo->strStartTime = QDateTime::fromTime_t(stuCleanSprayInkInfo->nStartTime).toString("yyyy-MM-dd hh:mm:ss"); pCleanSprayInfo->strEndTime = QDateTime::fromTime_t(stuCleanSprayInkInfo->nEndTime).toString("yyyy-MM-dd hh:mm:ss"); memcpy((char*)pCleanSprayInfo->dInkCost, (char*)stuCleanSprayInkInfo->dInkCost, sizeof(double) * MAXCOLORS); emit(signal_SendMes(MES_MSG_CLEANSPRAY, pCleanSprayInfo)); emit(signal_AddInkInfo(CLEANSPRAY_INK_CALCULATE, stuCleanSprayInkInfo)); }
首先,可以使用智能指针来管理 `_CLEANSPRAY_INKINFO` 和 `stuCleanSprayInfo` 的内存,避免手动管理内存的问题。
其次,可以将一些重复的计算结果提前计算出来,避免重复计算。例如 `nCleanTotalTimes` 和 `dColorCost` 可以在循环之前计算出来。
最后,在循环中可以使用局部变量来存储一些重复计算的结果,避免多次调用函数。例如在循环中多次调用 `m_qPrintParam->GetCntOfColors()` 可以在循环之前将其计算出来并存储在变量中。
下面是优化后的代码示例:
```cpp
void QQuickPrint::CalcCleanSprayInk(int nCleanSprayTime, int nCleanSprayStartTime, int nCleanSprayEndTime) {
if (nCleanSprayTime <= 0)
return;
auto stuCleanSprayInkInfo = std::make_shared<_CLEANSPRAY_INKINFO>();
stuCleanSprayInkInfo->nCostTime = nCleanSprayTime;
stuCleanSprayInkInfo->nStartTime = static_cast<uint>(nCleanSprayStartTime);
stuCleanSprayInkInfo->nEndTime = static_cast<uint>(nCleanSprayEndTime);
stuCleanSprayInkInfo->nType = CLEANSPRAY_INK_CALCULATE;
const int nCntOfChannel = m_qPrintParam->GetCntOfChannel();
const int nFrameSize = m_qPrintParam->GetFrameSize();
const int nCleanDropSize = m_qPrintParam->GetCleanFireDropSize();
const double dDropSizeCost = CLEANSPRAYDROPSIZE[nCleanDropSize];
const int nCleanFireTimes = m_qPrintParam->GetCleanFireTimes();
const int nCleanFireInterval = m_qPrintParam->GetCleanFireInterval();
const int nCleanTotalTimes = (nCleanSprayTime / nCleanFireInterval) + 1;
const double dColorCost = PL2ML(nFrameSize * dDropSizeCost * nCleanFireTimes * nCleanTotalTimes);
std::vector<int> nChannelColors(nCntOfChannel);
for (int iC = 0; iC != nCntOfChannel; ++iC)
nChannelColors[iC] = m_qPrintParam->GetRIPDataOfPiece(iC);
for (int iC = 0; iC != nCntOfChannel; ++iC) {
const int nColorsCnt = m_qPrintParam->GetCntOfColors();
const int nColorIndex = nChannelColors[iC];
if (PRN_CMYKOrRBLk == nColorsCnt) {
for (int nIndex = 0; nIndex != PRN_CMYKOrRBLk; ++nIndex) {
if (g_nColorIndexOfCMYKOrRBLk[nIndex] == nColorIndex) {
stuCleanSprayInkInfo->dInkCost[nIndex] += dColorCost;
}
}
} else {
stuCleanSprayInkInfo->dInkCost[nColorIndex] += dColorCost;
}
}
auto pCleanSprayInfo = std::make_shared<stuCleanSprayInfo>();
pCleanSprayInfo->nRunTime = nCleanSprayTime;
pCleanSprayInfo->strStartTime = QDateTime::fromTime_t(stuCleanSprayInkInfo->nStartTime).toString("yyyy-MM-dd hh:mm:ss");
pCleanSprayInfo->strEndTime = QDateTime::fromTime_t(stuCleanSprayInkInfo->nEndTime).toString("yyyy-MM-dd hh:mm:ss");
memcpy((char*)pCleanSprayInfo->dInkCost, (char*)stuCleanSprayInkInfo->dInkCost, sizeof(double) * MAXCOLORS);
emit(signal_SendMes(MES_MSG_CLEANSPRAY, pCleanSprayInfo));
emit(signal_AddInkInfo(CLEANSPRAY_INK_CALCULATE, stuCleanSprayInkInfo));
}
```
阅读全文
相关推荐
















