int DiagramList::readList(const SensorData* data, std::vector<DiagramList*> &lists) { const std::vector<SensorDataType::type> time_series_names (data->getTimeSeriesNames()); int nLists(time_series_names.size()); std::vector<size_t> time_steps; if (data->getStepSize()>0) { const size_t start = data->getStartTime(); const size_t end = data->getEndTime(); const size_t stepsize = data->getStepSize(); for (size_t i = start; i <= end; i+=stepsize) time_steps.push_back(i); } else time_steps = data->getTimeSteps(); bool is_date (false); if (!(BaseLib::int2date(time_steps[0])).empty()) is_date = true; size_t nValues (time_steps.size()); for (int i = 0; i < nLists; i++) { DiagramList* l = new DiagramList; l->setName(QString::fromStdString(SensorData::convertSensorDataType2String(time_series_names[i]))); l->setXLabel("Time"); lists.push_back(l); const std::vector<float> *time_series = data->getTimeSeries(time_series_names[i]); if (is_date) { l->setXUnit("day"); QDateTime startDate(getDateTime(QString::fromStdString(BaseLib::int2date(time_steps[0])))); lists[i]->setStartDate(startDate); int numberOfSecs(0); for (size_t j = 0; j < nValues; j++) { numberOfSecs = startDate.secsTo(getDateTime(QString::fromStdString(BaseLib::int2date(time_steps[j])))); lists[i]->addNextPoint(numberOfSecs, (*time_series)[j]); } } else { l->setXUnit("time step"); for (size_t j = 0; j < nValues; j++) lists[i]->addNextPoint(time_steps[j], (*time_series)[j]); } lists[i]->update(); } return nLists; }
NValue eval(const TableTuple *tuple1, const TableTuple *tuple2) const { //TODO: Could make this vector a member, if the memory management implications // (of the NValue internal state) were clear -- is there a penalty for longer-lived // NValues that outweighs the current per-eval allocation penalty? std::vector<NValue> nValues(m_args.size()); for (int i = 0; i < m_args.size(); ++i) { nValues[i] = m_args[i]->eval(tuple1, tuple2); } m_inList.setArrayElements(nValues); return m_inList; }
void LinearEditDialog::setupDialog(const std::vector<size_t> &dis_nodes, const std::vector<double> &dis_values) { size_t nPoints(_line.getNumberOfPoints()); this->tableWidget->setRowCount(nPoints); QList<QString> indexlist; for (size_t i=0; i<nPoints; i++) { indexlist.push_back(QString::number(i)); QTableWidgetItem *newItem = new QTableWidgetItem(""); tableWidget->setItem(i, 0, newItem); } QStringList vHeaders(indexlist); tableWidget->setVerticalHeaderLabels(vHeaders); size_t nValues (dis_values.size()); for (size_t i=0; i<nValues; i++) tableWidget->item(dis_nodes[i],0)->setText(QString::number(dis_values[i])); }
// ---------------------------------------------------------------------------- // TextLanguage::readLanguageDefinition // // Reads in a text definition of a language. See slade.pk3 for // formatting examples // ---------------------------------------------------------------------------- bool TextLanguage::readLanguageDefinition(MemChunk& mc, string source) { Tokenizer tz; // Open the given text data if (!tz.openMem(mc, source)) { Log::warning(1, S_FMT("Warning: Unable to open %s", source)); return false; } // Parse the definition text ParseTreeNode root; if (!root.parse(tz)) return false; // Get parsed data for (unsigned a = 0; a < root.nChildren(); a++) { auto node = root.getChildPTN(a); // Create language TextLanguage* lang = new TextLanguage(node->getName()); // Check for inheritance if (!node->inherit().IsEmpty()) { TextLanguage* inherit = fromId(node->inherit()); if (inherit) inherit->copyTo(lang); else Log::warning( 1, S_FMT("Warning: Language %s inherits from undefined language %s", node->getName(), node->inherit()) ); } // Parse language info for (unsigned c = 0; c < node->nChildren(); c++) { auto child = node->getChildPTN(c); // Language name if (S_CMPNOCASE(child->getName(), "name")) lang->setName(child->stringValue()); // Comment begin else if (S_CMPNOCASE(child->getName(), "comment_begin")) { lang->setCommentBeginList(child->stringValues()); } // Comment end else if (S_CMPNOCASE(child->getName(), "comment_end")) { lang->setCommentEndList(child->stringValues()); } // Line comment else if (S_CMPNOCASE(child->getName(), "comment_line")) { lang->setLineCommentList(child->stringValues()); } // Preprocessor else if (S_CMPNOCASE(child->getName(), "preprocessor")) lang->setPreprocessor(child->stringValue()); // Case sensitive else if (S_CMPNOCASE(child->getName(), "case_sensitive")) lang->setCaseSensitive(child->boolValue()); // Doc comment else if (S_CMPNOCASE(child->getName(), "comment_doc")) lang->setDocComment(child->stringValue()); // Keyword lookup link else if (S_CMPNOCASE(child->getName(), "keyword_link")) lang->word_lists_[WordType::Keyword].lookup_url = child->stringValue(); // Constant lookup link else if (S_CMPNOCASE(child->getName(), "constant_link")) lang->word_lists_[WordType::Constant].lookup_url = child->stringValue(); // Function lookup link else if (S_CMPNOCASE(child->getName(), "function_link")) lang->f_lookup_url_ = child->stringValue(); // Jump blocks else if (S_CMPNOCASE(child->getName(), "blocks")) { for (unsigned v = 0; v < child->nValues(); v++) lang->jump_blocks_.push_back(child->stringValue(v)); } else if (S_CMPNOCASE(child->getName(), "blocks_ignore")) { for (unsigned v = 0; v < child->nValues(); v++) lang->jb_ignore_.push_back(child->stringValue(v)); } // Block begin else if (S_CMPNOCASE(child->getName(), "block_begin")) lang->block_begin_ = child->stringValue(); // Block end else if (S_CMPNOCASE(child->getName(), "block_end")) lang->block_end_ = child->stringValue(); // Preprocessor block begin else if (S_CMPNOCASE(child->getName(), "pp_block_begin")) { for (unsigned v = 0; v < child->nValues(); v++) lang->pp_block_begin_.push_back(child->stringValue(v)); } // Preprocessor block end else if (S_CMPNOCASE(child->getName(), "pp_block_end")) { for (unsigned v = 0; v < child->nValues(); v++) lang->pp_block_end_.push_back(child->stringValue(v)); } // Word block begin else if (S_CMPNOCASE(child->getName(), "word_block_begin")) { for (unsigned v = 0; v < child->nValues(); v++) lang->word_block_begin_.push_back(child->stringValue(v)); } // Word block end else if (S_CMPNOCASE(child->getName(), "word_block_end")) { for (unsigned v = 0; v < child->nValues(); v++) lang->word_block_end_.push_back(child->stringValue(v)); } // Keywords else if (S_CMPNOCASE(child->getName(), "keywords")) { // Go through values for (unsigned v = 0; v < child->nValues(); v++) { string val = child->stringValue(v); // Check for '$override' if (S_CMPNOCASE(val, "$override")) { // Clear any inherited keywords lang->clearWordList(WordType::Keyword); } // Not a special symbol, add as keyword else lang->addWord(WordType::Keyword, val); } } // Constants else if (S_CMPNOCASE(child->getName(), "constants")) { // Go through values for (unsigned v = 0; v < child->nValues(); v++) { string val = child->stringValue(v); // Check for '$override' if (S_CMPNOCASE(val, "$override")) { // Clear any inherited constants lang->clearWordList(WordType::Constant); } // Not a special symbol, add as constant else lang->addWord(WordType::Constant, val); } } // Types else if (S_CMPNOCASE(child->getName(), "types")) { // Go through values for (unsigned v = 0; v < child->nValues(); v++) { string val = child->stringValue(v); // Check for '$override' if (S_CMPNOCASE(val, "$override")) { // Clear any inherited constants lang->clearWordList(WordType::Type); } // Not a special symbol, add as constant else lang->addWord(WordType::Type, val); } } // Properties else if (S_CMPNOCASE(child->getName(), "properties")) { // Go through values for (unsigned v = 0; v < child->nValues(); v++) { string val = child->stringValue(v); // Check for '$override' if (S_CMPNOCASE(val, "$override")) { // Clear any inherited constants lang->clearWordList(WordType::Property); } // Not a special symbol, add as constant else lang->addWord(WordType::Property, val); } } // Functions else if (S_CMPNOCASE(child->getName(), "functions")) { bool lang_has_void = lang->isWord(Keyword, "void") || lang->isWord(Type, "void"); if (lang->id_ != "zscript") { // Go through children (functions) for (unsigned f = 0; f < child->nChildren(); f++) { auto child_func = child->getChildPTN(f); string params; // Simple definition if (child_func->nChildren() == 0) { if (child_func->stringValue(0).empty()) { if (lang_has_void) params = "void"; else params = ""; } else { params = child_func->stringValue(0); } // Add function lang->addFunction( child_func->getName(), params, "", "", !child_func->getName().Contains("."), child_func->type()); // Add args for (unsigned v = 1; v < child_func->nValues(); v++) lang->addFunction(child_func->getName(), child_func->stringValue(v)); } // Full definition else { string name = child_func->getName(); vector<string> args; string desc = ""; string deprecated = ""; for (unsigned p = 0; p < child_func->nChildren(); p++) { auto child_prop = child_func->getChildPTN(p); if (child_prop->getName() == "args") { for (unsigned v = 0; v < child_prop->nValues(); v++) args.push_back(child_prop->stringValue(v)); } else if (child_prop->getName() == "description") desc = child_prop->stringValue(); else if (child_prop->getName() == "deprecated") deprecated = child_prop->stringValue(); } if (args.empty() && lang_has_void) args.push_back("void"); for (unsigned as = 0; as < args.size(); as++) lang->addFunction(name, args[as], desc, deprecated, as == 0, child_func->type()); } } } // ZScript function info which cannot be parsed from (g)zdoom.pk3 else { zfunc_ex_prop ex_prop; for (unsigned f = 0; f < child->nChildren(); f++) { auto child_func = child->getChildPTN(f); for (unsigned p = 0; p < child_func->nChildren(); ++p) { auto child_prop = child_func->getChildPTN(p); if (child_prop->getName() == "description") ex_prop.description = child_prop->stringValue(); else if (child_prop->getName() == "deprecated_f") ex_prop.deprecated_f = child_prop->stringValue(); } lang->zfuncs_ex_props_.emplace(child_func->getName(), ex_prop); } } } } } return true; }
bool DictionaryBased::getInnerCode(const cv::Mat& thres_img, int total_nbits, std::vector<uint64_t>& ids) { int bits_noborder = static_cast<int>(std::sqrt(total_nbits)); int bits_withborder = bits_noborder + 2; // Markers are divided in (bits_a+2)x(bits_a+2) regions, of which the inner bits_axbits_a belongs to marker // info // the external border shoould be entirely black cv::Mat nonZeros(bits_withborder,bits_withborder,CV_32SC1); cv::Mat nValues(bits_withborder,bits_withborder,CV_32SC1); nonZeros.setTo(cv::Scalar::all(0)); nValues.setTo(cv::Scalar::all(0)); for (int y = 0; y < thres_img.rows; y++) { const uchar *ptr=thres_img.ptr<uchar>(y); int my= float(bits_withborder)*float(y)/ float(thres_img.rows); for (int x = 0; x < thres_img.cols; x++) { int mx= float(bits_withborder)*float(x)/ float(thres_img.cols); if( ptr[x]>125) nonZeros.at<int>(my,mx)++; nValues.at<int>(my,mx)++; } } cv::Mat binaryCode(bits_withborder,bits_withborder,CV_8UC1); //now, make the theshold for(int y=0;y<bits_withborder;y++) for(int x=0;x<bits_withborder;x++){ if(nonZeros.at<int>(y,x)>nValues.at<int>(y,x)/2) binaryCode.at<uchar>(y,x)=1; else binaryCode.at<uchar>(y,x)=0; } //check if border is completely black for (int y = 0; y < bits_withborder; y++) { int inc = bits_withborder - 1; if (y == 0 || y == bits_withborder - 1) inc = 1; // for first and last row, check the whole border for (int x = 0; x < bits_withborder; x += inc) if (binaryCode.at<uchar>(y,x)!=0 ) return false; } //take the inner code cv::Mat _bits(bits_noborder,bits_noborder,CV_8UC1); for(int y=0;y<bits_noborder;y++) for(int x=0;x<bits_noborder;x++) _bits.at<uchar>(y,x)=binaryCode.at<uchar>(y+1,x+1); // now, get the 64bits ids int nr = 0; do { ids.push_back(touulong(_bits)); _bits = rotate(_bits); nr++; } while (nr < 4); return true; }
// ----------------------------------------------------------------------------- // Reads a UDMF property definition from a parsed tree [node] // ----------------------------------------------------------------------------- void UDMFProperty::parse(ParseTreeNode* node, std::string_view group) { // Set group and property name group_ = group; property_ = node->name(); // Check for basic definition if (node->nChildren() == 0) { name_ = node->stringValue(); return; } // Otherwise, read node data for (unsigned a = 0; a < node->nChildren(); a++) { auto prop = node->childPTN(a); auto pn_lower = StrUtil::lower(prop->name()); // Property type if (pn_lower == "type") { auto val_lower = StrUtil::lower(prop->stringValue()); if (val_lower == "bool") type_ = Type::Boolean; else if (val_lower == "int") type_ = Type::Int; else if (val_lower == "float") type_ = Type::Float; else if (val_lower == "string") type_ = Type::String; else if (val_lower == "colour") type_ = Type::Colour; else if (val_lower == "actionspecial") type_ = Type::ActionSpecial; else if (val_lower == "sectorspecial") type_ = Type::SectorSpecial; else if (val_lower == "thingtype") type_ = Type::ThingType; else if (val_lower == "angle") type_ = Type::Angle; else if (val_lower == "texture_wall") type_ = Type::TextureWall; else if (val_lower == "texture_flat") type_ = Type::TextureFlat; else if (val_lower == "id") type_ = Type::ID; } // Property name else if (pn_lower == "name") name_ = prop->stringValue(); // Default value else if (pn_lower == "default") { switch (type_) { case Type::Boolean: default_value_ = prop->boolValue(); break; case Type::Int: default_value_ = prop->intValue(); break; case Type::Float: default_value_ = prop->floatValue(); break; case Type::String: default_value_ = prop->stringValue(); break; case Type::ActionSpecial: default_value_ = prop->intValue(); break; case Type::SectorSpecial: default_value_ = prop->intValue(); break; case Type::ThingType: default_value_ = prop->intValue(); break; case Type::Angle: default_value_ = prop->intValue(); break; case Type::TextureWall: default_value_ = prop->stringValue(); break; case Type::TextureFlat: default_value_ = prop->stringValue(); break; case Type::ID: default_value_ = prop->intValue(); break; default: default_value_ = prop->stringValue(); break; } // Not sure why I have to do this here, but for whatever reason prop->getIntValue() doesn't work // if the value parsed was hex (or it could be to do with the colour type? who knows) if (type_ == Type::Colour) default_value_ = StrUtil::asInt(prop->stringValue()); has_default_ = true; } // Property is a flag else if (pn_lower == "flag") flag_ = true; // Property is a SPAC trigger else if (pn_lower == "trigger") trigger_ = true; // Possible values else if (pn_lower == "values") { switch (type_) { case Type::Boolean: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->boolValue(b)); break; case Type::Int: case Type::ActionSpecial: case Type::SectorSpecial: case Type::ThingType: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->intValue(b)); break; case Type::Float: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->floatValue(b)); break; default: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->stringValue(b)); break; } } // Show always else if (pn_lower == "show_always") show_always_ = prop->boolValue(); } }