// return raw(!) value of frontmost, active statistic item at given position ValuePairList StatisticsObject::getValuesAt(int x, int y) { ValuePairList valueList; for(int i=0; i<p_statsTypeList.count(); i++) { if (p_statsTypeList[i].render) // only show active values { int typeID = p_statsTypeList[i].typeID; StatisticsItemList statsList = getStatistics(p_lastIdx, typeID); if( statsList.size() == 0 && typeID == INT_INVALID ) // no active statistics continue; StatisticsType* aType = getStatisticsType(typeID); Q_ASSERT(aType->typeID != INT_INVALID && aType->typeID == typeID); // find item of this type at requested position StatisticsItemList::iterator it; bool foundStats = false; for (it = statsList.begin(); it != statsList.end(); it++) { StatisticsItem anItem = *it; QRect aRect = anItem.positionRect; int rawValue1 = anItem.rawValues[0]; int rawValue2 = anItem.rawValues[1]; float vectorValue1 = anItem.vector[0]; float vectorValue2 = anItem.vector[1]; if( aRect.contains(x,y) ) { if( anItem.type == blockType ) { valueList.append( ValuePair(aType->typeName, QString::number(rawValue1)) ); } else if( anItem.type == arrowType ) { // TODO: do we also want to show the raw values? valueList.append( ValuePair(QString("%1[x]").arg(aType->typeName), QString::number(vectorValue1)) ); valueList.append( ValuePair(QString("%1[y]").arg(aType->typeName), QString::number(vectorValue2)) ); } foundStats = true; } } if(!foundStats) valueList.append( ValuePair(aType->typeName, "-") ); } } return valueList; }
// we do not overwrite our statistics type, we just change their parameters foreach(StatisticsType aType, typeList) { StatisticsType* internalType = getStatisticsType( aType.typeID ); if( internalType->typeName != aType.typeName ) continue; internalType->render = aType.render; internalType->renderGrid = aType.renderGrid; internalType->alphaFactor = aType.alphaFactor; }
/* Set the statistics Type list. * we do not overwrite our statistics type, we just change their parameters * return if something has changed where a redraw would be necessary */ bool statisticSource::setStatisticsTypeList(StatisticsTypeList typeList) { bool bChanged = false; foreach(StatisticsType aType, typeList) { StatisticsType* internalType = getStatisticsType(aType.typeID); if (internalType->typeName != aType.typeName) continue; if (internalType->render != aType.render) { internalType->render = aType.render; bChanged = true; } if (internalType->renderGrid != aType.renderGrid) { internalType->renderGrid = aType.renderGrid; bChanged = true; } if (internalType->alphaFactor != aType.alphaFactor) { internalType->alphaFactor = aType.alphaFactor; bChanged = true; } }
void StatisticsObject::readStatisticsFromFile(int frameIdx, int typeID) { try { QFile inputFile(p_srcFilePath); if(inputFile.open(QIODevice::ReadOnly) == false) return; StatisticsItem anItem; QTextStream in(&inputFile); Q_ASSERT_X(p_pocTypeStartList.contains(frameIdx) && p_pocTypeStartList[frameIdx].contains(typeID), "StatisticsObject::readStatisticsFromFile", "POC/type not found in file. Do not call this function with POC/types that do not exist."); qint64 startPos = p_pocTypeStartList[frameIdx][typeID]; if (bFileSortedByPOC) { // If the statistics file is sorted by POC we have to start at the first entry of this POC and parse the // file until another POC is encountered. If this is not done, some information from a different typeID // could be ignored during parsing. // Get the position of the first line with the given frameIdx startPos = std::numeric_limits<qint64>::max(); QMap<int,qint64>::iterator it; for (it = p_pocTypeStartList[frameIdx].begin(); it != p_pocTypeStartList[frameIdx].end(); it++) if (it.value() < startPos) startPos = it.value(); } // fast forward in.seek(startPos); while (!in.atEnd()) { // read one line QString aLine = in.readLine(); // get components of this line QStringList rowItemList = parseCSVLine(aLine, ';'); if (rowItemList[0].isEmpty()) continue; int poc = rowItemList[0].toInt(); int type = rowItemList[5].toInt(); // if there is a new poc, we are done here! if( poc != frameIdx ) break; // if there is a new type and this is a non interleaved file, we are done here. if ( !bFileSortedByPOC && type != typeID ) break; int value1 = rowItemList[6].toInt(); int value2 = (rowItemList.count()>=8)?rowItemList[7].toInt():0; int posX = rowItemList[1].toInt(); int posY = rowItemList[2].toInt(); unsigned int width = rowItemList[3].toUInt(); unsigned int height = rowItemList[4].toUInt(); // Check if block is within the image range if (posX + width > p_width || posY + height > p_height) { // Block not in image throw("A block is outside of the specified image size in the statistics file."); } StatisticsType *statsType = getStatisticsType(type); Q_ASSERT_X(statsType != NULL, "StatisticsObject::readStatisticsFromFile", "Stat type not found."); anItem.type = ((statsType->visualizationType == colorMapType) || (statsType->visualizationType == colorRangeType)) ? blockType : arrowType; anItem.positionRect = QRect(posX, posY, width, height); anItem.rawValues[0] = value1; anItem.rawValues[1] = value2; anItem.color = QColor(); if (statsType->visualizationType == colorMapType) { ColorMap colorMap = statsType->colorMap; anItem.color = colorMap[value1]; } else if (statsType->visualizationType == colorRangeType) { if (statsType->scaleToBlockSize) anItem.color = statsType->colorRange->getColor((float)value1 / (float)(anItem.positionRect.width() * anItem.positionRect.height())); else anItem.color = statsType->colorRange->getColor((float)value1); } else if (statsType->visualizationType == vectorType) { // find color anItem.color = statsType->vectorColor; // calculate the vector size anItem.vector[0] = (float)value1 / statsType->vectorSampling; anItem.vector[1] = (float)value2 / statsType->vectorSampling; } // set grid color. if unset for this type, use color of type for grid, too if (statsType->gridColor.isValid()) { anItem.gridColor = statsType->gridColor; } else { anItem.gridColor = anItem.color; } p_statsCache[poc][type].append(anItem); } inputFile.close(); } // try catch ( const char * str ) { std::cerr << "Error while parsing: " << str << '\n'; setErrorState(QString("Error while parsing meta data: ") + QString(str)); return; } catch (...) { std::cerr << "Error while parsing."; setErrorState(QString("Error while parsing meta data.")); return; } return; }