bool ConnectedComponents::createPseudocolor(unsigned short maxLabel) const { if (isBatch() || mpView == NULL) { return true; } if (maxLabel > 50) { mProgress.report("More than 50 blobs exist, colors will be repeated.", 100, WARNING, true); } PseudocolorLayer* pOutLayer = static_cast<PseudocolorLayer*>( mpView->createLayer(PSEUDOCOLOR, mpLabels)); VERIFY(pOutLayer); pOutLayer->setXOffset(mXOffset); pOutLayer->setYOffset(mYOffset); if (pOutLayer != NULL) { std::vector<ColorType> colors; std::vector<ColorType> excluded; excluded.push_back(ColorType(0, 0, 0)); excluded.push_back(ColorType(255, 255, 255)); ColorType::getUniqueColors(std::min<unsigned short>(maxLabel, 50), colors, excluded); for (int cl = 1; cl <= maxLabel; ++cl) { pOutLayer->addInitializedClass(StringUtilities::toDisplayString(cl), cl, colors[(cl - 1) % 50]); } } return true; }
int getDiffColors(unsigned int count, std::vector<ColorType>& colors){ std::vector<ColorType> baseColors; baseColors.push_back(ColorType(0,0,255)); baseColors.push_back(ColorType(255,0,0)); baseColors.push_back(ColorType(0,255,0)); baseColors.push_back(ColorType(0,255,255)); baseColors.push_back(ColorType(255,255,0)); baseColors.push_back(ColorType(255,0,255)); baseColors.push_back(ColorType(255,255,255)); baseColors.push_back(ColorType(0,0,255)); if(count<=7){ for (int k = 0; k < count; k++){ ColorType colorToInsert; colorToInsert.mRed = baseColors[k].mRed; colorToInsert.mGreen = baseColors[k].mGreen; colorToInsert.mBlue = baseColors[k].mBlue; std::cout<<"colorToInsert.mRed:"<<colorToInsert.mRed<<" "<<"colorToInsert.mGreen:"<<colorToInsert.mGreen<<" "<<"colorToInsert.mBlue:"<<colorToInsert.mBlue<<std::endl; colors.push_back(colorToInsert); } } return 0; }
ThresholdLayerMemento::ThresholdLayerMemento(ThresholdLayer* pLayer) : mLowerThreshold(0.0), mUpperThreshold(0.0), mColor(ColorType()), mSymbol(SOLID) { if (pLayer != NULL) { mLowerThreshold = pLayer->getFirstThreshold(); mUpperThreshold = pLayer->getSecondThreshold(); mPassArea = pLayer->getPassArea(); mUnits = pLayer->getRegionUnits(); mColor = pLayer->getColor(); mSymbol = pLayer->getSymbol(); } }
/**************************************************************************//** * @file *****************************************************************************/ #include "globalVector.h" //instatiates the shape vector vector<Shape*>shapes; // initializes the tooltype to -1 float toolType = -1; //-1 = none, 0 = line, 1 = rectangle, 2 = FilledRectangle, 3 = ellipse, 4 = filled Ellipse //initializes the fill color to -1 ColorType fillColor = ColorType(-1); //initializes the fill color to -1 ColorType border = ColorType(-1);
/** * 产生一个或多个唯一的颜色 * @param count 要产生的颜色的个数 * @param colors 用于保存生成颜色的向量 * @param excludeColors 要排除的颜色 * @return 产生的颜色的个数 */ int getUniqueColors(unsigned int count, std::vector<ColorType>& colors, const std::vector<ColorType>& excludeColors) { unsigned int i, j, k, l; unsigned int numUnique = 0; double slValues[] = {0.0, 1.0, 0.5, 0.8, 0.3, 0.6, 0.9, 0.2, 0.7, 0.4, 0.1}; ColorType baseColors[] = { ColorType(0,0,255), ColorType(0,255,0), ColorType(255,0,0), ColorType(0,255,255), ColorType(255,255,0), ColorType(255,0,255), ColorType(255,255,255) }; for (i = 0; i < sizeof(slValues) / sizeof(slValues[0]); i++) { for (j = 0; j < sizeof(slValues) / sizeof(slValues[0]); j++) { for (k = 0; k < sizeof(baseColors) / sizeof(baseColors[0]); k++) { int newColor[3]; int maxValue; newColor[0] = (int) (baseColors[k].mRed * slValues[j] + 0.5); newColor[1] = (int) (baseColors[k].mGreen * slValues[j] + 0.5); newColor[2] = (int) (baseColors[k].mBlue * slValues[j] + 0.5); maxValue = 0; for (l = 0; l < 3; l++) { if (newColor[l] > maxValue) { maxValue = newColor[l]; } } maxValue = (int) (maxValue * slValues[i] + 0.5); for (l = 0; l < 3; l++) { if (newColor[l] < maxValue) { newColor[l] = maxValue; } } ColorType colorToInsert; colorToInsert.mRed = newColor[0]; colorToInsert.mGreen = newColor[1]; colorToInsert.mBlue = newColor[2]; for (l=0; l<excludeColors.size(); l++) { if (excludeColors[l].mRed == colorToInsert.mRed && excludeColors[l].mGreen == colorToInsert.mGreen && excludeColors[l].mBlue == colorToInsert.mBlue) { break; } } if (l == excludeColors.size()) { for (l = 0; l < colors.size(); l++) { if (colors[l].mRed == colorToInsert.mRed && colors[l].mGreen == colorToInsert.mGreen && colors[l].mBlue == colorToInsert.mBlue) { break; } } if (l == colors.size()) { colors.push_back (colorToInsert); ++numUnique; if (colors.size() == count) { return numUnique; } } } } } } return numUnique; }
const std::string QueryOptions::QUERY_NAME = "Query name"; const std::string QueryOptions::FORMAT_STRING = "Format string"; const std::string QueryOptions::QUERY_STRING = "Query string"; const std::string QueryOptions::SYMBOL_NAME = "Symbol name"; const std::string QueryOptions::SYMBOL_SIZE = "Symbol size"; const std::string QueryOptions::LINE_STATE = "Line state"; const std::string QueryOptions::LINE_STYLE = "Line style"; const std::string QueryOptions::LINE_WIDTH = "Line width"; const std::string QueryOptions::LINE_COLOR = "Line color"; const std::string QueryOptions::LINE_SCALED = "Line scaled"; const std::string QueryOptions::FILL_COLOR = "Fill color"; const std::string QueryOptions::FILL_STYLE = "Fill style"; const std::string QueryOptions::HATCH_STYLE = "Hatch style"; const ColorType QueryOptions::mDefaultColor = ColorType(255, 255, 0); const std::string QueryOptions::mDefaultName = "New Query"; QueryOptions::QueryOptions() : mQueryName(mDefaultName), mSymbolName(GraphicLayer::getSettingSymbolName()), mSymbolSize(GraphicLayer::getSettingSymbolSize()), mLineState(GraphicLayer::getSettingFill()), mLineStyle(GraphicLayer::getSettingLineStyle()), mLineWidth(GraphicLayer::getSettingLineWidth()), mLineColor(mDefaultColor), mLineScaled(GraphicLayer::getSettingLineScaled()), mFillColor(mDefaultColor), mFillStyle(EMPTY_FILL), mHatchStyle(GraphicLayer::getSettingHatchStyle()) {
bool _set(const StringName& p_name, const Variant& p_value) { String n = p_name; if (n=="extra_space/char") char_extra_spacing=p_value; else if (n=="extra_space/space") space_extra_spacing=p_value; else if (n=="extra_space/top") top_extra_spacing=p_value; else if (n=="extra_space/bottom") bottom_extra_spacing=p_value; else if (n=="character_set/mode") { character_set=CharacterSet(int(p_value)); _change_notify(); } else if (n=="character_set/custom") custom_file=p_value; else if (n=="shadow/enabled") { shadow=p_value; _change_notify(); }else if (n=="shadow/radius") shadow_radius=p_value; else if (n=="shadow/offset") shadow_offset=p_value; else if (n=="shadow/color") shadow_color=p_value; else if (n=="shadow/transition") shadow_transition=p_value; else if (n=="shadow2/enabled") { shadow2=p_value; _change_notify(); }else if (n=="shadow2/radius") shadow2_radius=p_value; else if (n=="shadow2/offset") shadow2_offset=p_value; else if (n=="shadow2/color") shadow2_color=p_value; else if (n=="shadow2/transition") shadow2_transition=p_value; else if (n=="color/mode") { color_type=ColorType(int(p_value)); _change_notify(); }else if (n=="color/color") color=p_value; else if (n=="color/begin") gradient_begin=p_value; else if (n=="color/end") gradient_end=p_value; else if (n=="color/image") gradient_image=p_value; else if (n=="advanced/round_advance") round_advance=p_value; else return false; emit_signal("changed"); return true; }
bool GraphMLImporter::import( ImporterContext& context ) { // context context_ = &context; // helpers graphOp_.reset( new GraphOperations( context_->getGraph() ) ); readNodes_.reset( new ReadNodesStore() ); // default types edgeType_ = NULL; nodeType_ = NULL; ( void )graphOp_->addDefaultTypes( edgeType_, nodeType_ ); // ziskame pristup ku nastaveniam Util::ApplicationConfig* appConf = Util::ApplicationConfig::get(); edgeTypeAttribute_ = appConf->getValue( "GraphMLParser.edgeTypeAttribute" ); nodeTypeAttribute_ = appConf->getValue( "GraphMLParser.nodeTypeAttribute" ); // pole farieb FIXME oddelit farby hran od farieb uzlov colors_.push_back( ColorType( 0, 1, 0, 1 ) ); colors_.push_back( ColorType( 0, 1, 1, 1 ) ); colors_.push_back( ColorType( 1, 0, 0, 1 ) ); colors_.push_back( ColorType( 1, 0, 1, 1 ) ); colors_.push_back( ColorType( 1, 1, 0, 1 ) ); colors_.push_back( ColorType( 1, 1, 1, 1 ) ); iColor_ = 0; bool ok = true; // ziskame graph element QDomElement graphElement; if ( ok ) { QDomNode graphNode; QDomDocument doc( "graphMLDocument" ); if ( doc.setContent( &( context_->getStream() ) ) ) { QDomElement docElem = doc.documentElement(); if ( !docElem.isNull() && docElem.nodeName() == "graphml" ) { QDomNodeList graphNodes = docElem.elementsByTagName( "graph" ); if ( graphNodes.length() > 0 ) { graphNode = graphNodes.item( 0 ); if ( !graphNode.isNull() && graphNode.parentNode() == docElem && graphNode.isElement() ) { graphElement = graphNode.toElement(); } } } } ok = !graphElement.isNull(); context_->getInfoHandler().reportError( ok, "Zvoleny subor nie je validny GraphML subor." ); } if ( ok ) { // for progress reporting entitiesProcessed_ = 0; entitiesCount_ = graphElement.elementsByTagName( "node" ).size() + graphElement.elementsByTagName( "edge" ).count(); } if ( ok ) { ok = processGraph( graphElement ); } return ok; }
void RangeProfilePlotManager::calculateDifferences() { // ensure we have only two objects selected VERIFYNRV(mpView); std::list<PlotObject*> selected; mpView->getSelectedObjects(selected, true); std::list<PlotObject*>::iterator selIt = selected.begin(); PointSet* pFirst = (selIt == selected.end()) ? NULL : dynamic_cast<PointSet*>(*(selIt++)); PointSet* pSecond = (selIt == selected.end()) ? NULL : dynamic_cast<PointSet*>(*(selIt++)); if (pFirst == NULL || pSecond == NULL) { return; } // locate the Difference point set std::list<PlotObject*> allObjects; mpView->getObjects(POINT_SET, allObjects); PointSet* pDiffSet = NULL; for (std::list<PlotObject*>::iterator obj = allObjects.begin(); obj != allObjects.end(); ++obj) { PointSet* pSet = static_cast<PointSet*>(*obj); std::string name; pSet->getObjectName(name); if (name == "Difference") { pDiffSet = pSet; pDiffSet->clear(true); break; } } if (pDiffSet == NULL) { pDiffSet = static_cast<PointSet*>(mpView->addObject(POINT_SET, true)); pDiffSet->setObjectName("Difference"); } // calculate the differences and errors std::vector<Point*> aPoints = pFirst->getPoints(); std::vector<Point*> bPoints = pSecond->getPoints(); if (aPoints.size() < 2 || bPoints.size() < 2) { return; } double mae = 0.0; double mse1 = 0.0; double mse2 = 0.0; for (size_t aIdx = 0; aIdx < aPoints.size(); ++aIdx) { Point* pA = aPoints[aIdx]; VERIFYNRV(pA); LocationType aVal = pA->getLocation(); LocationType newVal; // locate the associated spot in b for (size_t bIdx = 0; bIdx < bPoints.size(); ++bIdx) { Point* pB = bPoints[bIdx]; VERIFYNRV(pB); LocationType bVal = pB->getLocation(); double diff = aVal.mX - bVal.mX; if (fabs(diff) < 0.0000001) // a == b use the exact value { newVal.mX = aVal.mX; newVal.mY = bVal.mY - aVal.mY; break; } else if (diff < 0.0) // a < b found the upper point, interpolate { newVal.mX = aVal.mX; LocationType secondBVal; if (bIdx == 0) // we are at the start so continue the segment from the right { Point* pSecondB = bPoints[1]; VERIFYNRV(pSecondB); secondBVal = pSecondB->getLocation(); } else // grab the previous point for interpolation { Point* pSecondB = bPoints[bIdx-1]; VERIFYNRV(pSecondB); secondBVal = pSecondB->getLocation(); } // calculate slope-intercept double m = (bVal.mY - secondBVal.mY) / (bVal.mX - secondBVal.mX); double b = bVal.mY - m * bVal.mX; // find the y corresponding to the interpolated x newVal.mY = m * newVal.mX + b; newVal.mY -= aVal.mY; break; } } mae += fabs(newVal.mY); mse1 += newVal.mY * newVal.mY; mse2 += (newVal.mY * newVal.mY) / (aVal.mY * aVal.mY); pDiffSet->addPoint(newVal.mX, newVal.mY); } pDiffSet->setLineColor(ColorType(200, 0, 0)); mpView->refresh(); mae /= aPoints.size(); mse1 /= aPoints.size(); mse2 /= aPoints.size(); QMessageBox::information(mpView->getWidget(), "Comparison metrics", QString("Mean squared error (method 1): %1\n" "Mean squared error (method 2): %2\n" "Mean absolute error: %3").arg(mse1).arg(mse2).arg(mae), QMessageBox::Close); }
bool RangeProfilePlotManager::plotProfile(Signature* pSignature) { VERIFY(mpView && pSignature); std::string plotName = pSignature->getDisplayName(); if (plotName.empty()) { plotName = pSignature->getName(); } if (plotName == "Difference") { QMessageBox::warning(Service<DesktopServices>()->getMainWidget(), "Invalid signature", "Signatures can not be named 'Difference' as this is a reserved " "name for this plot. Please rename your signature and try again."); return false; } const Units* pXUnits = NULL; const Units* pYUnits = NULL; std::vector<double> xData; std::vector<double> yData; std::set<std::string> dataNames = pSignature->getDataNames(); for (std::set<std::string>::const_iterator dataName = dataNames.begin(); dataName != dataNames.end() && (pXUnits == NULL || pYUnits == NULL); ++dataName) { const Units* pUnits = pSignature->getUnits(*dataName); if (pUnits == NULL) { continue; } if (pUnits->getUnitType() == DISTANCE) { if (pXUnits == NULL) { pXUnits = pUnits; xData = dv_cast<std::vector<double> >(pSignature->getData(*dataName), std::vector<double>()); } } else if (pYUnits == NULL) { pYUnits = pUnits; yData = dv_cast<std::vector<double> >(pSignature->getData(*dataName), std::vector<double>()); } } if (xData.empty() || xData.size() != yData.size()) { QMessageBox::warning(Service<DesktopServices>()->getMainWidget(), "Invalid signature", QString("Signatures must have a distance axis. '%1' does not and will not be plotted.") .arg(QString::fromStdString(pSignature->getName()))); return false; } std::map<Signature*, std::string>::iterator oldPointSet = mSigPointSets.find(pSignature); PointSet* pSet = getPointSet(pSignature); if (pSet != NULL) { pSet->clear(true); } std::list<PlotObject*> curObjects; mpView->getObjects(POINT_SET, curObjects); if (pSet == NULL) { std::vector<ColorType> excluded; excluded.push_back(ColorType(255, 255, 255)); // background excluded.push_back(ColorType(200, 0, 0)); // color for the difference plot for (std::list<PlotObject*>::const_iterator cur = curObjects.begin(); cur != curObjects.end(); ++cur) { excluded.push_back(static_cast<PointSet*>(*cur)->getLineColor()); } pSet = static_cast<PointSet*>(mpView->addObject(POINT_SET, true)); mSigPointSets[pSignature] = plotName; pSignature->attach(SIGNAL_NAME(Subject, Deleted), Slot(this, &RangeProfilePlotManager::signatureDeleted)); pSignature->getDataDescriptor()->attach(SIGNAL_NAME(DataDescriptor, Renamed), Slot(this, &RangeProfilePlotManager::signatureRenamed)); std::vector<ColorType> colors; ColorType::getUniqueColors(1, colors, excluded); if (!colors.empty()) { pSet->setLineColor(colors.front()); } } pSet->setObjectName(plotName); for (size_t idx = 0; idx < xData.size(); ++idx) { pSet->addPoint(xData[idx], yData[idx]); } VERIFY(mpPlot); Axis* pBottom = mpPlot->getAxis(AXIS_BOTTOM); Axis* pLeft = mpPlot->getAxis(AXIS_LEFT); VERIFYRV(pBottom && pLeft, NULL); if (pBottom->getTitle().empty()) { pBottom->setTitle(pXUnits->getUnitName()); } if (pLeft->getTitle().empty()) { pLeft->setTitle(pYUnits->getUnitName()); } else if (pLeft->getTitle() != pYUnits->getUnitName()) { Axis* pRight = mpPlot->getAxis(AXIS_RIGHT); VERIFYRV(pRight, NULL); if (pRight->getTitle().empty()) { pRight->setTitle(pYUnits->getUnitName()); } } std::string classificationText = dv_cast<std::string>(pSignature->getMetadata()->getAttribute("Raw Classification"), mpPlot->getClassificationText()); if (classificationText.empty() == false) { FactoryResource<Classification> pClassification; if (pClassification->setClassification(classificationText) == true) { mpPlot->setClassification(pClassification.get()); } else { QMessageBox::warning(Service<DesktopServices>()->getMainWidget(), QString::fromStdString(getName()), "The plot could not be updated with the signature classification. Please ensure that the plot " "has the proper classification."); } } getDockWindow()->show(); mpView->zoomExtents(); mpView->refresh(); return true; }