// DataSet_Modes::ReduceVectors() int DataSet_Modes::ReduceVectors() { if (evectors_ == 0) { mprintf("Warning: Cannot 'reduce', no eigenvectors present.\n"); return 0; } if ( Meta().ScalarType() == MetaData::COVAR || Meta().ScalarType() == MetaData::MWCOVAR ) return ReduceCovar(); else if ( Meta().ScalarType() == MetaData::DISTCOVAR ) return ReduceDistCovar(); else mprintf("Warning: 'reduce' not supported for matrix type %s\n", Meta().TypeString()); return 0; }
void CWidget::Init() { m_pNCursWin = derwin(GetParentWin(), Height(), Width(), Y(), X()); if (!m_pNCursWin) throw Exceptions::CExFrontend("Could not create derived window"); m_bSizeChanged = false; leaveok(m_pNCursWin, false); KeyPad(m_pNCursWin, true); Meta(m_pNCursWin, true); if (m_pParent) { if (!m_bSetFColors) { TColorPair colors = m_pParent->GetFColors(); SetFColors(colors); } if (!m_bSetDFColors) { TColorPair colors = m_pParent->GetDFColors(); SetDFColors(colors); } } CoreInit(); }
void CTUI::InitNCurses() { EndWin(); initscr(); NoEcho(); CBreak(); leaveok(GetRootWin(), false); KeyPad(GetRootWin(), true); Meta(GetRootWin(), true); if (has_colors()) StartColor(); m_pMainBox = new CBox(CBox::VERTICAL, false); m_pMainBox->SetParent(GetRootWin()); m_pMainBox->Init(); m_pMainBox->SetSize(0, 0, GetWWidth(GetRootWin()), GetWHeight(GetRootWin())); m_pMainBox->SetFocus(true); m_pButtonBar = new CButtonBar(GetWWidth(GetRootWin())); // Focused colors are used for keys, defocused colors for descriptions m_pButtonBar->SetFColors(COLOR_YELLOW, COLOR_RED); m_pButtonBar->SetDFColors(COLOR_WHITE, COLOR_RED); m_pMainBox->EndPack(m_pButtonBar, false, false, 0, 0); m_pWinManager = new CWindowManager; m_pMainBox->AddWidget(m_pWinManager); m_pWinManager->ReqFocus(); m_pMainBox->RequestQueuedDraw(); }
void FileImporter::getSubset(string metapath){ vector < std::pair<float,string> > tmpsubset(0); BaseFileLoader::attrSubset.clear(); ofFile Meta(metapath); if(Meta.exists()){ ofxJSONElement json; json.open(metapath); Json::Value val = json.get("InfoGain", ""); for( Json::Value::iterator iit = val.begin();iit != val.end(); ++iit){ tmpsubset.push_back(std::pair<float,string>((*iit).asFloat(),iit.memberName())); } std::sort(tmpsubset.begin(), tmpsubset.end()); vector< std::pair<float,string> >::iterator startiit = tmpsubset.begin(); if(tmpsubset.size()>numBest){ startiit = tmpsubset.end() - numBest; } ofLogWarning("FileImporter","getting subset :"); for( vector< std::pair<float,string> >::iterator iit = startiit ; iit < tmpsubset.end() ; ++iit ){ BaseFileLoader::attrSubset.push_back(iit->second); ofLogWarning("FileImporter", "\t" +iit->second ); } } }
void Stb::Read(SoyPixelsImpl& Pixels,const ArrayBridge<char>& ArrayBuffer,TReadFunction ReadFunction) { #if defined(USE_STB) const stbi_uc* Buffer = reinterpret_cast<const stbi_uc*>( ArrayBuffer.GetArray() ); auto BufferSize = size_cast<int>( ArrayBuffer.GetDataSize() ); int Width = 0; int Height = 0; int Channels = 0; int RequestedChannels = 4; auto* DecodedPixels = stbi_load_from_memory( Buffer, BufferSize, &Width, &Height, &Channels, RequestedChannels ); if ( !DecodedPixels ) { // gr: as this is not thread safe, it could come out mangled :( maybe add a lock around error popping before read (maybe have to lock around the whole thing) auto* StbError = stbi_failure_reason(); if ( !StbError ) StbError = "Unknown error"; std::stringstream Error; Error << "Failed to read image pixels; " << StbError; throw Soy::AssertException( Error.str() ); } // convert output into pixels // gr: have to assume size auto Format = SoyPixelsFormat::GetFormatFromChannelCount( Channels ); SoyPixelsMeta Meta( Width, Height, Format ); SoyPixelsRemote OutputPixels( DecodedPixels, Meta.GetDataSize(), Meta ); Pixels.Copy( OutputPixels ); #else throw Soy::AssertException("No STB support, no image reading"); #endif }
void Stb::Read(SoyPixelsImpl& Pixels,TStreamBuffer& Buffer,TReadFunction ReadFunction) { StbContext Context( Buffer, true ); int Width = 0; int Height = 0; int Channels = 0; // gr: use 0 for "defaults" int RequestedChannels = 0; auto* DecodedPixels = ReadFunction( &Context.mContext, &Width, &Height, &Channels, RequestedChannels ); if ( !DecodedPixels ) { throw Soy::AssertException( Context.GetError() ); } // convert output into pixels // gr: have to assume size auto Format = SoyPixelsFormat::GetFormatFromChannelCount( Channels ); SoyPixelsMeta Meta( Width, Height, Format ); SoyPixelsRemote OutputPixels( DecodedPixels, Meta.GetDataSize(), Meta ); Pixels.Copy( OutputPixels ); // success, don't let context unpop data Context.Flush(); }
PlaceHolder::Data * PlaceHolder::Data::create() { const std::string name = Shm::the().createObjectID(); Data *p = shm<Data>::construct(name)(name, "", Meta(), Object::UNKNOWN); publish(p); return p; }
/// Reads the header at the given file position. /// If the packet could not be read for any reason, the reason is printed. /// Reading the header means the file position is moved to after the header. void DTSC::File::readHeader(int pos) { fseek(F, pos, SEEK_SET); if (fread(buffer, 4, 1, F) != 1) { if (feof(F)) { DEBUG_MSG(DLVL_DEVEL, "End of file reached while reading header @ %d", pos); } else { DEBUG_MSG(DLVL_ERROR, "Could not read header @ %d", pos); } metadata = Meta(); return; } if (memcmp(buffer, DTSC::Magic_Header, 4) != 0) { DEBUG_MSG(DLVL_ERROR, "Invalid header - %.4s != %.4s @ %i", (char *)buffer, DTSC::Magic_Header, pos); metadata = Meta(); return; } if (fread(buffer, 4, 1, F) != 1) { DEBUG_MSG(DLVL_ERROR, "Could not read header size @ %i", pos); metadata = Meta(); return; } long packSize = ntohl(((unsigned long *)buffer)[0]) + 8; std::string strBuffer; strBuffer.resize(packSize); if (packSize) { fseek(F, pos, SEEK_SET); if (fread((void *)strBuffer.c_str(), packSize, 1, F) != 1) { DEBUG_MSG(DLVL_ERROR, "Could not read header packet @ %i", pos); metadata = Meta(); return; } metadata = Meta(DTSC::Packet(strBuffer.data(), strBuffer.size(),true)); } //if there is another header, read it and replace metadata with that one. if (metadata.moreheader) { if (metadata.moreheader < getBytePosEOF()) { readHeader(metadata.moreheader); return; } } if (!metadata.live){ metadata.vod = true; } }
bool DataSet_RemLog::ValidEnsemble() const { ReplicaEnsemble::const_iterator member = ensemble_.begin(); size_t first_size = (*member).size(); for (; member != ensemble_.end(); ++member) { if ((*member).size() != first_size) { mprinterr("Error: In remlog data set %s size of ensemble member %zu (%zu) !=" " size of first member (%zu)\n", Meta().Name().c_str(), // TODO: Change to legend member - ensemble_.begin() + 1, (*member).size(), first_size); return false; } } return true; }
#define Meta(x) ((x) | META) #define Marker(x) ((x) | MARKER) static struct mitem mitems[] = { { "Note_on_c", Event(NoteOn) }, { "Note_off_c", Event(NoteOff) }, { "Pitch_bend_c", Event(PitchBend) }, { "Control_c", Event(ControlChange) }, { "Program_c", Event(ProgramChange) }, { "Poly_aftertouch_c", Event(PolyphonicKeyPressure) }, { "Channel_aftertouch_c", Event(ChannelPressure) }, { "System_exclusive", Event(SystemExclusive) }, { "System_exclusive_packet", Event(SystemExclusivePacket) }, { "Sequence_number", Meta(SequenceNumberMetaEvent) }, { "Text_t", Meta(TextMetaEvent) }, { "Copyright_t", Meta(CopyrightMetaEvent) }, { "Title_t", Meta(TrackTitleMetaEvent) }, { "Instrument_name_t", Meta(TrackInstrumentNameMetaEvent) }, { "Lyric_t", Meta(LyricMetaEvent) }, { "Marker_t", Meta(MarkerMetaEvent) }, { "Cue_point_t", Meta(CuePointMetaEvent) }, { "Channel_prefix", Meta(ChannelPrefixMetaEvent) }, { "MIDI_port", Meta(PortMetaEvent) } , { "End_track", Meta(EndTrackMetaEvent) }, { "Tempo", Meta(SetTempoMetaEvent) }, { "SMPTE_offset", Meta(SMPTEOffsetMetaEvent) }, { "Time_signature", Meta(TimeSignatureMetaEvent) }, { "Key_signature", Meta(KeySignatureMetaEvent) }, { "Sequencer_specific", Meta(SequencerSpecificMetaEvent) },
void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver, gui::IGUIFont *font) const { // Do *not* use UNORDERED_MAP here as the order needs // to be the same for each call to prevent flickering std::map<std::string, Meta> m_meta; for (const Piece &piece : m_log) { for (const auto &i : piece.values) { const std::string &id = i.first; const float &value = i.second; std::map<std::string, Meta>::iterator j = m_meta.find(id); if (j == m_meta.end()) { m_meta[id] = Meta(value); continue; } if (value < j->second.min) j->second.min = value; if (value > j->second.max) j->second.max = value; } } // Assign colors static const video::SColor usable_colors[] = {video::SColor(255, 255, 100, 100), video::SColor(255, 90, 225, 90), video::SColor(255, 100, 100, 255), video::SColor(255, 255, 150, 50), video::SColor(255, 220, 220, 100)}; static const u32 usable_colors_count = sizeof(usable_colors) / sizeof(*usable_colors); u32 next_color_i = 0; for (auto &i : m_meta) { Meta &meta = i.second; video::SColor color(255, 200, 200, 200); if (next_color_i < usable_colors_count) color = usable_colors[next_color_i++]; meta.color = color; } s32 graphh = 50; s32 textx = x_left + m_log_max_size + 15; s32 textx2 = textx + 200 - 15; s32 meta_i = 0; for (const auto &p : m_meta) { const std::string &id = p.first; const Meta &meta = p.second; s32 x = x_left; s32 y = y_bottom - meta_i * 50; float show_min = meta.min; float show_max = meta.max; if (show_min >= -0.0001 && show_max >= -0.0001) { if (show_min <= show_max * 0.5) show_min = 0; } s32 texth = 15; char buf[10]; porting::mt_snprintf(buf, sizeof(buf), "%.3g", show_max); font->draw(utf8_to_wide(buf).c_str(), core::rect<s32>(textx, y - graphh, textx2, y - graphh + texth), meta.color); porting::mt_snprintf(buf, sizeof(buf), "%.3g", show_min); font->draw(utf8_to_wide(buf).c_str(), core::rect<s32>(textx, y - texth, textx2, y), meta.color); font->draw(utf8_to_wide(id).c_str(), core::rect<s32>(textx, y - graphh / 2 - texth / 2, textx2, y - graphh / 2 + texth / 2), meta.color); s32 graph1y = y; s32 graph1h = graphh; bool relativegraph = (show_min != 0 && show_min != show_max); float lastscaledvalue = 0.0; bool lastscaledvalue_exists = false; for (const Piece &piece : m_log) { float value = 0; bool value_exists = false; Profiler::GraphValues::const_iterator k = piece.values.find(id); if (k != piece.values.end()) { value = k->second; value_exists = true; } if (!value_exists) { x++; lastscaledvalue_exists = false; continue; } float scaledvalue = 1.0; if (show_max != show_min) scaledvalue = (value - show_min) / (show_max - show_min); if (scaledvalue == 1.0 && value == 0) { x++; lastscaledvalue_exists = false; continue; } if (relativegraph) { if (lastscaledvalue_exists) { s32 ivalue1 = lastscaledvalue * graph1h; s32 ivalue2 = scaledvalue * graph1h; driver->draw2DLine( v2s32(x - 1, graph1y - ivalue1), v2s32(x, graph1y - ivalue2), meta.color); } lastscaledvalue = scaledvalue; lastscaledvalue_exists = true; } else { s32 ivalue = scaledvalue * graph1h; driver->draw2DLine(v2s32(x, graph1y), v2s32(x, graph1y - ivalue), meta.color); } x++; } meta_i++; } }
void DocumentTemplate::addMeta(const std::string& sMetaName, const std::string& sFieldName) { m_metadata.push_back(Meta(sMetaName, sFieldName)); }
llvm::Expected<IndexFileIn> readRIFF(llvm::StringRef Data) { auto RIFF = riff::readFile(Data); if (!RIFF) return RIFF.takeError(); if (RIFF->Type != riff::fourCC("CdIx")) return makeError("wrong RIFF type"); llvm::StringMap<llvm::StringRef> Chunks; for (const auto &Chunk : RIFF->Chunks) Chunks.try_emplace(llvm::StringRef(Chunk.ID.data(), Chunk.ID.size()), Chunk.Data); for (llvm::StringRef RequiredChunk : {"meta", "stri"}) if (!Chunks.count(RequiredChunk)) return makeError("missing required chunk " + RequiredChunk); Reader Meta(Chunks.lookup("meta")); if (Meta.consume32() != Version) return makeError("wrong version"); auto Strings = readStringTable(Chunks.lookup("stri")); if (!Strings) return Strings.takeError(); IndexFileIn Result; if (Chunks.count("srcs")) { Reader SrcsReader(Chunks.lookup("srcs")); Result.Sources.emplace(); while (!SrcsReader.eof()) { auto IGN = readIncludeGraphNode(SrcsReader, Strings->Strings); auto Entry = Result.Sources->try_emplace(IGN.URI).first; Entry->getValue() = std::move(IGN); // We change all the strings inside the structure to point at the keys in // the map, since it is the only copy of the string that's going to live. Entry->getValue().URI = Entry->getKey(); for (auto &Include : Entry->getValue().DirectIncludes) Include = Result.Sources->try_emplace(Include).first->getKey(); } if (SrcsReader.err()) return makeError("malformed or truncated include uri"); } if (Chunks.count("symb")) { Reader SymbolReader(Chunks.lookup("symb")); SymbolSlab::Builder Symbols; while (!SymbolReader.eof()) Symbols.insert(readSymbol(SymbolReader, Strings->Strings)); if (SymbolReader.err()) return makeError("malformed or truncated symbol"); Result.Symbols = std::move(Symbols).build(); } if (Chunks.count("refs")) { Reader RefsReader(Chunks.lookup("refs")); RefSlab::Builder Refs; while (!RefsReader.eof()) { auto RefsBundle = readRefs(RefsReader, Strings->Strings); for (const auto &Ref : RefsBundle.second) // FIXME: bulk insert? Refs.insert(RefsBundle.first, Ref); } if (RefsReader.err()) return makeError("malformed or truncated refs"); Result.Refs = std::move(Refs).build(); } return std::move(Result); }
/// Attempts to parse a packet from the given std::string buffer. /// Returns true if successful, removing the parsed part from the buffer string. /// Returns false if invalid or not enough data is in the buffer. /// \arg buffer The std::string buffer to attempt to parse. bool DTSC::Stream::parsePacket(std::string & buffer) { uint32_t len; static bool syncing = false; if (buffer.length() > 8) { if (memcmp(buffer.c_str(), DTSC::Magic_Header, 4) == 0) { len = ntohl(((uint32_t *)buffer.c_str())[1]); if (buffer.length() < len + 8) { return false; } unsigned int i = 0; JSON::Value meta; JSON::fromDTMI((unsigned char *)buffer.c_str() + 8, len, i, meta); metadata = Meta(meta); buffer.erase(0, len + 8); if (buffer.length() <= 8) { return false; } } int version = 0; if (memcmp(buffer.c_str(), DTSC::Magic_Packet, 4) == 0) { version = 1; } if (memcmp(buffer.c_str(), DTSC::Magic_Packet2, 4) == 0) { version = 2; } if (version) { len = ntohl(((uint32_t *)buffer.c_str())[1]); if (buffer.length() < len + 8) { return false; } JSON::Value newPack; unsigned int i = 0; if (version == 1) { JSON::fromDTMI((unsigned char *)buffer.c_str() + 8, len, i, newPack); } if (version == 2) { JSON::fromDTMI2((unsigned char *)buffer.c_str() + 8, len, i, newPack); } buffer.erase(0, len + 8); addPacket(newPack); syncing = false; return true; } #if DEBUG >= DLVL_WARN if (!syncing) { DEBUG_MSG(DLVL_WARN, "Invalid DTMI data detected - re-syncing"); syncing = true; } #endif size_t magic_search = buffer.find(Magic_Packet); size_t magic_search2 = buffer.find(Magic_Packet2); if (magic_search2 == std::string::npos) { if (magic_search == std::string::npos) { buffer.clear(); } else { buffer.erase(0, magic_search); } } else { buffer.erase(0, magic_search2); } } return false; }
/// Adds a set of metadata to the steam. /// This is implemented by simply replacing the current metadata. /// This effectively resets the stream. void DTSC::Stream::addMeta(JSON::Value & newMeta) { metadata = Meta(newMeta); }