Element* Breath::prevElement() { return segment()->lastInPrevSegments(staffIdx()); }
STDMETHODIMP CKeySegment::put_Flags(IFlags* Value) { Value->All(&segment()->flags.all); return S_OK; }
void ccGraphicalSegmentationTool::segmentIn() { segment(true); }
String ParsedURL::fragment() const { return segment(m_segments.fragment); }
STDMETHODIMP CKeySegment::get_FieldNum(unsigned char* Value) { *Value = segment()->fieldNum; return S_OK; }
String ParsedURL::host() const { return segment(m_segments.host); }
String ParsedURL::path() const { return segment(m_segments.path); }
int main(int argc, char** argv) { try { // init command line parser util::ProgramOptions::init(argc, argv); int stack_id = optionStackId.as<int>(); std::string comp_dir = optionComponentDir.as<std::string>(); std::string pg_host = optionPGHost.as<std::string>(); std::string pg_user = optionPGUser.as<std::string>(); std::string pg_pass = optionPGPassword.as<std::string>(); std::string pg_dbase = optionPGDatabase.as<std::string>(); std::cout << "Testing PostgreSQL stores with stack ID " << stack_id << std::endl; // init logger logger::LogManager::init(); logger::LogManager::setGlobalLogLevel(logger::Debug); // create new project configuration ProjectConfiguration pc; pc.setBackendType(ProjectConfiguration::PostgreSql); StackDescription stack; stack.id = stack_id; pc.setCatmaidStack(Raw, stack); pc.setComponentDirectory(comp_dir); pc.setPostgreSqlHost(pg_host); pc.setPostgreSqlUser(pg_user); pc.setPostgreSqlPassword(pg_pass); pc.setPostgreSqlDatabase(pg_dbase); PostgreSqlSliceStore sliceStore(pc, Membrane); // Add first set of slices boost::shared_ptr<Slice> slice1 = createSlice(10, 0); boost::shared_ptr<Slice> slice2 = createSlice(10, 1); boost::shared_ptr<Slice> slice3 = createSlice(10, 2); Slices slices = Slices(); slices.add(slice1); slices.add(slice2); slices.add(slice3); Block block(0, 0, 0); sliceStore.associateSlicesToBlock(slices, block); Blocks blocks; blocks.add(block); Blocks missingBlocks; boost::shared_ptr<Slices> retrievedSlices = sliceStore.getSlicesByBlocks(blocks, missingBlocks); // Create conflict set where each slice ConflictSet conflictSet1; conflictSet1.addSlice(slice1->hashValue()); conflictSet1.addSlice(slice2->hashValue()); conflictSet1.addSlice(slice3->hashValue()); ConflictSets conflictSets; conflictSets.add(conflictSet1); sliceStore.associateConflictSetsToBlock(conflictSets, block); boost::shared_ptr<ConflictSets> retrievedConflictSets = sliceStore.getConflictSetsByBlocks(blocks, missingBlocks); for (const ConflictSet& cs : *retrievedConflictSets) { std::cout << "ConflictSet hash: " << hash_value(cs); for (const SliceHash& sh : cs.getSlices()) { std::cout << " Slice hash: " << sh; } std::cout << std::endl; } PostgreSqlSegmentStore segmentStore(pc, Membrane); util::box<unsigned int, 2> segmentBounds(0, 0, 0, 0); std::vector<double> segmentFeatures; segmentFeatures.push_back(0.0); segmentFeatures.push_back(1.0); segmentFeatures.push_back(2.0); SegmentDescription segment(0, segmentBounds); segment.addLeftSlice(slice1->hashValue()); segment.addRightSlice(slice2->hashValue()); segment.setFeatures(segmentFeatures); boost::shared_ptr<SegmentDescriptions> segments = boost::make_shared<SegmentDescriptions>(); segments->add(segment); segmentStore.associateSegmentsToBlock(*segments, block); boost::shared_ptr<SegmentDescriptions> retrievedSegments = segmentStore.getSegmentsByBlocks(blocks, missingBlocks, false); } catch (boost::exception& e) { handleException(e, std::cerr); } }
status_t tcp_receive_data(net_buffer* buffer) { TRACE(("TCP: Received buffer %p\n", buffer)); if (buffer->interface_address == NULL || buffer->interface_address->domain == NULL) return B_ERROR; net_domain* domain = buffer->interface_address->domain; net_address_module_info* addressModule = domain->address_module; NetBufferHeaderReader<tcp_header> bufferHeader(buffer); if (bufferHeader.Status() < B_OK) return bufferHeader.Status(); tcp_header& header = bufferHeader.Data(); uint16 headerLength = header.HeaderLength(); if (headerLength < sizeof(tcp_header)) return B_BAD_DATA; if (Checksum::PseudoHeader(addressModule, gBufferModule, buffer, IPPROTO_TCP) != 0) return B_BAD_DATA; addressModule->set_port(buffer->source, header.source_port); addressModule->set_port(buffer->destination, header.destination_port); TRACE((" Looking for: peer %s, local %s\n", AddressString(domain, buffer->source, true).Data(), AddressString(domain, buffer->destination, true).Data())); //dump_tcp_header(header); //gBufferModule->dump(buffer); tcp_segment_header segment(header.flags); segment.sequence = header.Sequence(); segment.acknowledge = header.Acknowledge(); segment.advertised_window = header.AdvertisedWindow(); segment.urgent_offset = header.UrgentOffset(); process_options(segment, buffer, headerLength - sizeof(tcp_header)); bufferHeader.Remove(headerLength); // we no longer need to keep the header around EndpointManager* endpointManager = endpoint_manager_for(domain); if (endpointManager == NULL) { TRACE((" No endpoint manager!\n")); return B_ERROR; } int32 segmentAction = DROP; TCPEndpoint* endpoint = endpointManager->FindConnection( buffer->destination, buffer->source); if (endpoint != NULL) { segmentAction = endpoint->SegmentReceived(segment, buffer); gSocketModule->release_socket(endpoint->socket); } else if ((segment.flags & TCP_FLAG_RESET) == 0) segmentAction = DROP | RESET; if ((segmentAction & RESET) != 0) { // send reset endpointManager->ReplyWithReset(segment, buffer); } if ((segmentAction & DROP) != 0) gBufferModule->free(buffer); return B_OK; }
void KeySig::layout() { qreal _spatium = spatium(); setbbox(QRectF()); if (isCustom() && !isAtonal()) { for (KeySym& ks: _sig.keySymbols()) { ks.pos = ks.spos * _spatium; addbbox(symBbox(ks.sym).translated(ks.pos)); } return; } _sig.keySymbols().clear(); if (staff() && !staff()->genKeySig()) // no key sigs on TAB staves return; // determine current clef for this staff ClefType clef = ClefType::G; if (staff()) clef = staff()->clef(segment()->tick()); int accidentals = 0, naturals = 0; int t1 = int(_sig.key()); switch (qAbs(t1)) { case 7: accidentals = 0x7f; break; case 6: accidentals = 0x3f; break; case 5: accidentals = 0x1f; break; case 4: accidentals = 0xf; break; case 3: accidentals = 0x7; break; case 2: accidentals = 0x3; break; case 1: accidentals = 0x1; break; case 0: accidentals = 0; break; default: qDebug("illegal t1 key %d", t1); break; } // manage display of naturals: // naturals are shown if there is some natural AND prev. measure has no section break // AND style says they are not off // OR key sig is CMaj/Amin (in which case they are always shown) bool naturalsOn = false; Measure* prevMeasure = measure() ? measure()->prevMeasure() : 0; // If we're not force hiding naturals (Continuous panel), use score style settings if (!_hideNaturals) naturalsOn = (prevMeasure && !prevMeasure->sectionBreak() && (score()->styleI(StyleIdx::keySigNaturals) != int(KeySigNatural::NONE))) || (t1 == 0); // Don't repeat naturals if shown in courtesy if (prevMeasure && prevMeasure->findSegment(Segment::Type::KeySigAnnounce, segment()->tick()) && !segment()->isKeySigAnnounceType()) naturalsOn = false; if (track() == -1) naturalsOn = false; int coffset = 0; Key t2 = Key::C; if (naturalsOn) { t2 = staff()->key(segment()->tick() - 1); if (t2 == Key::C) naturalsOn = false; else { switch (qAbs(int(t2))) { case 7: naturals = 0x7f; break; case 6: naturals = 0x3f; break; case 5: naturals = 0x1f; break; case 4: naturals = 0xf; break; case 3: naturals = 0x7; break; case 2: naturals = 0x3; break; case 1: naturals = 0x1; break; case 0: naturals = 0; break; default: qDebug("illegal t2 key %d", int(t2)); break; } // remove redundant naturals if (!((t1 > 0) ^ (t2 > 0))) naturals &= ~accidentals; if (t2 < 0) coffset = 7; } } // naturals should go BEFORE accidentals if style says so // OR going from sharps to flats or vice versa (i.e. t1 & t2 have opposite signs) bool prefixNaturals = naturalsOn && (score()->styleI(StyleIdx::keySigNaturals) == int(KeySigNatural::BEFORE) || t1 * int(t2) < 0); // naturals should go AFTER accidentals if they should not go before! bool suffixNaturals = naturalsOn && !prefixNaturals; const signed char* lines = ClefInfo::lines(clef); // add prefixed naturals, if any qreal xo = 0.0; if (prefixNaturals) { for (int i = 0; i < 7; ++i) { if (naturals & (1 << i)) { addLayout(SymId::accidentalNatural, xo, lines[i + coffset]); xo += 1.0; } } } // add accidentals static const qreal sspread = 1.0; static const qreal fspread = 1.0; switch(t1) { case 7: addLayout(SymId::accidentalSharp, xo + 6.0 * sspread, lines[6]); case 6: addLayout(SymId::accidentalSharp, xo + 5.0 * sspread, lines[5]); case 5: addLayout(SymId::accidentalSharp, xo + 4.0 * sspread, lines[4]); case 4: addLayout(SymId::accidentalSharp, xo + 3.0 * sspread, lines[3]); case 3: addLayout(SymId::accidentalSharp, xo + 2.0 * sspread, lines[2]); case 2: addLayout(SymId::accidentalSharp, xo + 1.0 * sspread, lines[1]); case 1: addLayout(SymId::accidentalSharp, xo, lines[0]); break; case -7: addLayout(SymId::accidentalFlat, xo + 6.0 * fspread, lines[13]); case -6: addLayout(SymId::accidentalFlat, xo + 5.0 * fspread, lines[12]); case -5: addLayout(SymId::accidentalFlat, xo + 4.0 * fspread, lines[11]); case -4: addLayout(SymId::accidentalFlat, xo + 3.0 * fspread, lines[10]); case -3: addLayout(SymId::accidentalFlat, xo + 2.0 * fspread, lines[9]); case -2: addLayout(SymId::accidentalFlat, xo + 1.0 * fspread, lines[8]); case -1: addLayout(SymId::accidentalFlat, xo, lines[7]); case 0: break; default: qDebug("illegal t1 key %d", t1); break; } // add suffixed naturals, if any if (suffixNaturals) { xo += qAbs(t1); // skip accidentals if (t1 > 0) { // after sharps, add a little more space xo += 0.15; // if last sharp (t1) is above next natural (t1+1)... if (lines[t1] < lines[t1+1]) xo += 0.2; // ... add more space } for (int i = 0; i < 7; ++i) { if (naturals & (1 << i)) { addLayout(SymId::accidentalNatural, xo, lines[i + coffset]); xo += 1.0; } } } // compute bbox for (KeySym& ks : _sig.keySymbols()) { ks.pos = ks.spos * _spatium; addbbox(symBbox(ks.sym).translated(ks.pos)); } }
int vector_test() { typedef std::vector<int> MyStdVector; typedef typename MyShmVector::value_type IntType; std::string process_name; test::get_process_id_name(process_name); const int Memsize = 65536; const char *const shMemName = process_name.c_str(); const int max = 100; { //Compare several shared memory vector operations with std::vector //Create shared memory shared_memory_object::remove(shMemName); try{ ManagedSharedMemory segment(create_only, shMemName, Memsize); segment.reserve_named_objects(100); //Shared memory allocator must be always be initialized //since it has no default constructor MyShmVector *shmvector = segment.template construct<MyShmVector>("MyShmVector") (segment.get_segment_manager()); MyStdVector *stdvector = new MyStdVector; shmvector->resize(100); stdvector->resize(100); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(200); stdvector->resize(200); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType new_int(i); shmvector->insert(shmvector->end(), boost::move(new_int)); stdvector->insert(stdvector->end(), i); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; typename MyShmVector::iterator shmit(shmvector->begin()); typename MyStdVector::iterator stdit(stdvector->begin()); typename MyShmVector::const_iterator cshmit = shmit; (void)cshmit; ++shmit; ++stdit; shmvector->erase(shmit); stdvector->erase(stdit); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->erase(shmvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; { //Initialize values IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); //BOOST_STATIC_ASSERT((::boost::move_ipcdetail::is_copy_constructible<boost::interprocess::test::movable_int>::value == false)); aux_vect[i] = boost::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmvector->insert(shmvector->end() ,::boost::make_move_iterator(&aux_vect[0]) ,::boost::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->end(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; for(int i = 0, j = static_cast<int>(shmvector->size()); i < j; ++i){ shmvector->erase(shmvector->begin()); stdvector->erase(stdvector->begin()); } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType new_int(-1); aux_vect[i] = boost::move(new_int); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmvector->insert(shmvector->begin() ,::boost::make_move_iterator(&aux_vect[0]) ,::boost::make_move_iterator(aux_vect + 50)); stdvector->insert(stdvector->begin(), aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } shmvector->reserve(shmvector->size()*2); stdvector->reserve(stdvector->size()*2); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; IntType push_back_this(1); shmvector->push_back(boost::move(push_back_this)); stdvector->push_back(int(1)); shmvector->push_back(IntType(1)); stdvector->push_back(int(1)); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; if(!copyable_only(shmvector, stdvector ,ipcdetail::bool_<!ipcdetail::is_same<IntType, test::movable_int>::value>())){ return 1; } shmvector->erase(shmvector->begin()); stdvector->erase(stdvector->begin()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; for(int i = 0; i < max; ++i){ IntType insert_this(i); shmvector->insert(shmvector->begin(), boost::move(insert_this)); stdvector->insert(stdvector->begin(), i); shmvector->insert(shmvector->begin(), IntType(i)); stdvector->insert(stdvector->begin(), int(i)); } if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; //Test insertion from list { std::list<int> l(50, int(1)); shmvector->insert(shmvector->begin(), l.begin(), l.end()); stdvector->insert(stdvector->begin(), l.begin(), l.end()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->assign(l.begin(), l.end()); stdvector->assign(l.begin(), l.end()); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; } /* std::size_t cap = shmvector->capacity(); shmvector->reserve(cap*2); stdvector->reserve(cap*2); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(0); stdvector->resize(0); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; shmvector->resize(cap*2); stdvector->resize(cap*2); if(!test::CheckEqualContainers(shmvector, stdvector)) return 1; */ delete stdvector; segment.template destroy<MyShmVector>("MyShmVector"); segment.shrink_to_fit_indexes(); if(!segment.all_memory_deallocated()) return 1; } catch(std::exception &ex){ shared_memory_object::remove(shMemName); std::cout << ex.what() << std::endl; return 1; } } shared_memory_object::remove(shMemName); std::cout << std::endl << "Test OK!" << std::endl; return 0; }
Element* KeySig::prevElement() { return segment()->lastInPrevSegments(staffIdx()); }
Element* KeySig::nextElement() { return segment()->firstInNextSegments(staffIdx()); }
int KeySig::tick() const { return segment() ? segment()->tick() : 0; }
String ParsedURL::username() const { return segment(m_segments.username); }
int list_test (bool copied_allocators_equal = true) { typedef std::list<int> MyStdList; typedef typename MyShmList::value_type IntType; const int memsize = 65536; const char *const shMemName = test::get_process_id_name(); const int max = 100; typedef push_data_function<DoublyLinked> push_data_t; try{ //Named new capable shared mem allocator //Create shared memory shared_memory_object::remove(shMemName); ManagedSharedMemory segment(create_only, shMemName, memsize); segment.reserve_named_objects(100); //Shared memory allocator must be always be initialized //since it has no default constructor MyShmList *shmlist = segment.template construct<MyShmList>("MyList") (segment.get_segment_manager()); MyStdList *stdlist = new MyStdList; if(push_data_t::execute(max/2, shmlist, stdlist)){ return 1; } shmlist->erase(shmlist->begin()++); stdlist->erase(stdlist->begin()++); if(!CheckEqualContainers(shmlist, stdlist)) return 1; if(pop_back_function<DoublyLinked>::execute(shmlist, stdlist)){ return 1; } shmlist->pop_front(); stdlist->pop_front(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmlist->assign(::boost::make_move_iterator(&aux_vect[0]) ,::boost::make_move_iterator(&aux_vect[50])); stdlist->assign(&aux_vect2[0], &aux_vect2[50]); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } if(copied_allocators_equal){ shmlist->sort(); stdlist->sort(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } shmlist->reverse(); stdlist->reverse(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; shmlist->reverse(); stdlist->reverse(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; { IntType aux_vect[50]; for(int i = 0; i < 50; ++i){ IntType move_me(-1); aux_vect[i] = boost::move(move_me); } int aux_vect2[50]; for(int i = 0; i < 50; ++i){ aux_vect2[i] = -1; } shmlist->insert(shmlist->begin() ,::boost::make_move_iterator(&aux_vect[0]) ,::boost::make_move_iterator(&aux_vect[50])); stdlist->insert(stdlist->begin(), &aux_vect2[0], &aux_vect2[50]); } shmlist->unique(); stdlist->unique(); if(!CheckEqualContainers(shmlist, stdlist)) return 1; if(copied_allocators_equal){ shmlist->sort(std::greater<IntType>()); stdlist->sort(std::greater<int>()); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } shmlist->resize(25); stdlist->resize(25); shmlist->resize(50); stdlist->resize(50); shmlist->resize(0); stdlist->resize(0); if(!CheckEqualContainers(shmlist, stdlist)) return 1; if(push_data_t::execute(max/2, shmlist, stdlist)){ return 1; } { MyShmList othershmlist(shmlist->get_allocator()); MyStdList otherstdlist; int listsize = (int)shmlist->size(); if(push_data_t::execute(listsize/2, shmlist, stdlist)){ return 1; } if(copied_allocators_equal){ shmlist->splice(shmlist->begin(), othershmlist); stdlist->splice(stdlist->begin(), otherstdlist); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } listsize = (int)shmlist->size(); if(push_data_t::execute(listsize/2, shmlist, stdlist)){ return 1; } if(push_data_t::execute(listsize/2, &othershmlist, &otherstdlist)){ return 1; } if(copied_allocators_equal){ shmlist->sort(std::greater<IntType>()); stdlist->sort(std::greater<int>()); if(!CheckEqualContainers(shmlist, stdlist)) return 1; othershmlist.sort(std::greater<IntType>()); otherstdlist.sort(std::greater<int>()); if(!CheckEqualContainers(&othershmlist, &otherstdlist)) return 1; shmlist->merge(othershmlist, std::greater<IntType>()); stdlist->merge(otherstdlist, std::greater<int>()); if(!CheckEqualContainers(shmlist, stdlist)) return 1; } for(int i = 0; i < max; ++i){ shmlist->insert(shmlist->begin(), IntType(i)); stdlist->insert(stdlist->begin(), int(i)); } if(!CheckEqualContainers(shmlist, stdlist)) return 1; } segment.template destroy<MyShmList>("MyList"); delete stdlist; segment.shrink_to_fit_indexes(); if(!segment.all_memory_deallocated()) return 1; } catch(...){ shared_memory_object::remove(shMemName); throw; } shared_memory_object::remove(shMemName); return 0; }
String ParsedURL::password() const { return segment(m_segments.password); }
void Snake::AddSegment(unsigned x, unsigned y) { SnakeSegment segment(x, y); segments.push_back(segment); }
String ParsedURL::port() const { return segment(m_segments.port); }
SkOpContour* SkOpSpanBase::contour() const { return segment()->contour(); }
String ParsedURL::query() const { return segment(m_segments.query); }
SkOpContour* SkOpPtT::contour() const { return segment()->contour(); }
void MediaEngineWebRTCAudioSource::Process(int channel, webrtc::ProcessingTypes type, sample* audio10ms, int length, int samplingFreq, bool isStereo) { // On initial capture, throw away all far-end data except the most recent sample // since it's already irrelevant and we want to keep avoid confusing the AEC far-end // input code with "old" audio. if (!mStarted) { mStarted = true; while (gFarendObserver->Size() > 1) { free(gFarendObserver->Pop()); // only call if size() > 0 } } while (gFarendObserver->Size() > 0) { FarEndAudioChunk *buffer = gFarendObserver->Pop(); // only call if size() > 0 if (buffer) { int length = buffer->mSamples; int res = mVoERender->ExternalPlayoutData(buffer->mData, gFarendObserver->PlayoutFrequency(), gFarendObserver->PlayoutChannels(), mPlayoutDelay, length); free(buffer); if (res == -1) { return; } } } MonitorAutoLock lock(mMonitor); if (mState != kStarted) return; uint32_t len = mSources.Length(); for (uint32_t i = 0; i < len; i++) { nsRefPtr<SharedBuffer> buffer = SharedBuffer::Create(length * sizeof(sample)); sample* dest = static_cast<sample*>(buffer->Data()); memcpy(dest, audio10ms, length * sizeof(sample)); nsAutoPtr<AudioSegment> segment(new AudioSegment()); nsAutoTArray<const sample*,1> channels; channels.AppendElement(dest); segment->AppendFrames(buffer.forget(), channels, length); TimeStamp insertTime; segment->GetStartTime(insertTime); if (mSources[i]) { // Make sure we include the stream and the track. // The 0:1 is a flag to note when we've done the final insert for a given input block. LogTime(AsyncLatencyLogger::AudioTrackInsertion, LATENCY_STREAM_ID(mSources[i].get(), mTrackID), (i+1 < len) ? 0 : 1, insertTime); // This is safe from any thread, and is safe if the track is Finished // or Destroyed. // Note: due to evil magic, the nsAutoPtr<AudioSegment>'s ownership transfers to // the Runnable (AutoPtr<> = AutoPtr<>) RUN_ON_THREAD(mThread, WrapRunnable(mSources[i], &SourceMediaStream::AppendToTrack, mTrackID, segment, (AudioSegment *) nullptr), NS_DISPATCH_NORMAL); } } return; }
int Clef::tick() const { return segment() ? segment()->tick() : 0; }
STDMETHODIMP CKeySegment::put_FieldNum(unsigned char Value) { segment()->fieldNum = Value; return S_OK; }
SOrientedBoundingBox * SOrientedBoundingBox::buildOBB(std::vector<SPoint3> &vertices) { #if defined(HAVE_MESH) int num_vertices = vertices.size(); // First organize the data std::set<SPoint3> unique; unique.insert(vertices.begin(), vertices.end()); num_vertices = unique.size(); fullMatrix<double> data(3, num_vertices); fullVector<double> mean(3); fullVector<double> vmins(3); fullVector<double> vmaxs(3); mean.setAll(0); vmins.setAll(DBL_MAX); vmaxs.setAll(-DBL_MAX); size_t idx = 0; for(std::set<SPoint3>::iterator uIter = unique.begin(); uIter != unique.end(); ++uIter) { const SPoint3 &pp = *uIter; for(int d = 0; d < 3; d++) { data(d, idx) = pp[d]; vmins(d) = std::min(vmins(d), pp[d]); vmaxs(d) = std::max(vmaxs(d), pp[d]); mean(d) += pp[d]; } idx++; } for(int i = 0; i < 3; i++) { mean(i) /= num_vertices; } // Get the deviation from the mean fullMatrix<double> B(3, num_vertices); for(int i = 0; i < 3; i++) { for(int j = 0; j < num_vertices; j++) { B(i, j) = data(i, j) - mean(i); } } // Compute the covariance matrix fullMatrix<double> covariance(3, 3); B.mult(B.transpose(), covariance); covariance.scale(1. / (num_vertices - 1)); /* Msg::Debug("Covariance matrix"); Msg::Debug("%f %f %f", covariance(0,0),covariance(0,1),covariance(0,2) ); Msg::Debug("%f %f %f", covariance(1,0),covariance(1,1),covariance(1,2) ); Msg::Debug("%f %f %f", covariance(2,0),covariance(2,1),covariance(2,2) ); */ for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { if(std::abs(covariance(i, j)) < 10e-16) covariance(i, j) = 0; } } fullMatrix<double> left_eigv(3, 3); fullMatrix<double> right_eigv(3, 3); fullVector<double> real_eig(3); fullVector<double> img_eig(3); covariance.eig(real_eig, img_eig, left_eigv, right_eigv, true); // Now, project the data in the new basis. fullMatrix<double> projected(3, num_vertices); left_eigv.transpose().mult(data, projected); // Get the size of the box in the new direction fullVector<double> mins(3); fullVector<double> maxs(3); for(int i = 0; i < 3; i++) { mins(i) = DBL_MAX; maxs(i) = -DBL_MAX; for(int j = 0; j < num_vertices; j++) { maxs(i) = std::max(maxs(i), projected(i, j)); mins(i) = std::min(mins(i), projected(i, j)); } } // double means[3]; double sizes[3]; // Note: the size is computed in the box's coordinates! for(int i = 0; i < 3; i++) { sizes[i] = maxs(i) - mins(i); // means[i] = (maxs(i) - mins(i)) / 2.; } if(sizes[0] == 0 && sizes[1] == 0) { // Entity is a straight line... SVector3 center; SVector3 Axis1; SVector3 Axis2; SVector3 Axis3; Axis1[0] = left_eigv(0, 0); Axis1[1] = left_eigv(1, 0); Axis1[2] = left_eigv(2, 0); Axis2[0] = left_eigv(0, 1); Axis2[1] = left_eigv(1, 1); Axis2[2] = left_eigv(2, 1); Axis3[0] = left_eigv(0, 2); Axis3[1] = left_eigv(1, 2); Axis3[2] = left_eigv(2, 2); center[0] = (vmaxs(0) + vmins(0)) / 2.0; center[1] = (vmaxs(1) + vmins(1)) / 2.0; center[2] = (vmaxs(2) + vmins(2)) / 2.0; return new SOrientedBoundingBox(center, sizes[0], sizes[1], sizes[2], Axis1, Axis2, Axis3); } // We take the smallest component, then project the data on the plane defined // by the other twos int smallest_comp = 0; if(sizes[0] <= sizes[1] && sizes[0] <= sizes[2]) smallest_comp = 0; else if(sizes[1] <= sizes[0] && sizes[1] <= sizes[2]) smallest_comp = 1; else if(sizes[2] <= sizes[0] && sizes[2] <= sizes[1]) smallest_comp = 2; // The projection has been done circa line 161. // We just ignore the coordinate corresponding to smallest_comp. std::vector<SPoint2 *> points; for(int i = 0; i < num_vertices; i++) { SPoint2 *p = new SPoint2(projected(smallest_comp == 0 ? 1 : 0, i), projected(smallest_comp == 2 ? 1 : 2, i)); bool keep = true; for(std::vector<SPoint2 *>::iterator point = points.begin(); point != points.end(); point++) { if(std::abs((*p)[0] - (**point)[0]) < 10e-10 && std::abs((*p)[1] - (**point)[1]) < 10e-10) { keep = false; break; } } if(keep) { points.push_back(p); } else { delete p; } } // Find the convex hull from a delaunay triangulation of the points DocRecord record(points.size()); record.numPoints = points.size(); srand((unsigned)time(0)); for(std::size_t i = 0; i < points.size(); i++) { record.points[i].where.h = points[i]->x() + (10e-6) * sizes[smallest_comp == 0 ? 1 : 0] * (-0.5 + ((double)rand()) / RAND_MAX); record.points[i].where.v = points[i]->y() + (10e-6) * sizes[smallest_comp == 2 ? 1 : 0] * (-0.5 + ((double)rand()) / RAND_MAX); record.points[i].adjacent = NULL; } try { record.MakeMeshWithPoints(); } catch(const char *err) { Msg::Error("%s", err); } std::vector<Segment> convex_hull; for(int i = 0; i < record.numTriangles; i++) { Segment segs[3]; segs[0].from = record.triangles[i].a; segs[0].to = record.triangles[i].b; segs[1].from = record.triangles[i].b; segs[1].to = record.triangles[i].c; segs[2].from = record.triangles[i].c; segs[2].to = record.triangles[i].a; for(int j = 0; j < 3; j++) { bool okay = true; for(std::vector<Segment>::iterator seg = convex_hull.begin(); seg != convex_hull.end(); seg++) { if(((*seg).from == segs[j].from && (*seg).from == segs[j].to) // FIXME: // || ((*seg).from == segs[j].to && (*seg).from == segs[j].from) ) { convex_hull.erase(seg); okay = false; break; } } if(okay) { convex_hull.push_back(segs[j]); } } } // Now, examinate all the directions given by the edges of the convex hull // to find the one that lets us build the least-area bounding rectangle for // then points. fullVector<double> axis(2); axis(0) = 1; axis(1) = 0; fullVector<double> axis2(2); axis2(0) = 0; axis2(1) = 1; SOrientedBoundingRectangle least_rectangle; least_rectangle.center[0] = 0.0; least_rectangle.center[1] = 0.0; least_rectangle.size[0] = -1.0; least_rectangle.size[1] = 1.0; fullVector<double> segment(2); fullMatrix<double> rotation(2, 2); for(std::vector<Segment>::iterator seg = convex_hull.begin(); seg != convex_hull.end(); seg++) { // segment(0) = record.points[(*seg).from].where.h - // record.points[(*seg).to].where.h; segment(1) = // record.points[(*seg).from].where.v - record.points[(*seg).to].where.v; segment(0) = points[(*seg).from]->x() - points[(*seg).to]->x(); segment(1) = points[(*seg).from]->y() - points[(*seg).to]->y(); segment.scale(1.0 / segment.norm()); double cosine = axis(0) * segment(0) + segment(1) * axis(1); double sine = axis(1) * segment(0) - segment(1) * axis(0); // double sine = axis(0)*segment(1) - segment(0)*axis(1); rotation(0, 0) = cosine; rotation(0, 1) = sine; rotation(1, 0) = -sine; rotation(1, 1) = cosine; // TODO C++11 std::numeric_limits<double> double max_x = -DBL_MAX; double min_x = DBL_MAX; double max_y = -DBL_MAX; double min_y = DBL_MAX; for(int i = 0; i < record.numPoints; i++) { fullVector<double> pnt(2); // pnt(0) = record.points[i].where.h; // pnt(1) = record.points[i].where.v; pnt(0) = points[i]->x(); pnt(1) = points[i]->y(); fullVector<double> rot_pnt(2); rotation.mult(pnt, rot_pnt); if(rot_pnt(0) < min_x) min_x = rot_pnt(0); if(rot_pnt(0) > max_x) max_x = rot_pnt(0); if(rot_pnt(1) < min_y) min_y = rot_pnt(1); if(rot_pnt(1) > max_y) max_y = rot_pnt(1); } /**/ fullVector<double> center_rot(2); fullVector<double> center_before_rot(2); center_before_rot(0) = (max_x + min_x) / 2.0; center_before_rot(1) = (max_y + min_y) / 2.0; fullMatrix<double> rotation_inv(2, 2); rotation_inv(0, 0) = cosine; rotation_inv(0, 1) = -sine; rotation_inv(1, 0) = sine; rotation_inv(1, 1) = cosine; rotation_inv.mult(center_before_rot, center_rot); fullVector<double> axis_rot1(2); fullVector<double> axis_rot2(2); rotation_inv.mult(axis, axis_rot1); rotation_inv.mult(axis2, axis_rot2); if((least_rectangle.area() == -1) || (max_x - min_x) * (max_y - min_y) < least_rectangle.area()) { least_rectangle.size[0] = max_x - min_x; least_rectangle.size[1] = max_y - min_y; least_rectangle.center[0] = (max_x + min_x) / 2.0; least_rectangle.center[1] = (max_y + min_y) / 2.0; least_rectangle.center[0] = center_rot(0); least_rectangle.center[1] = center_rot(1); least_rectangle.axisX[0] = axis_rot1(0); least_rectangle.axisX[1] = axis_rot1(1); // least_rectangle.axisX[0] = segment(0); // least_rectangle.axisX[1] = segment(1); least_rectangle.axisY[0] = axis_rot2(0); least_rectangle.axisY[1] = axis_rot2(1); } } // TODO C++11 std::numeric_limits<double>::min() / max() double min_pca = DBL_MAX; double max_pca = -DBL_MAX; for(int i = 0; i < num_vertices; i++) { min_pca = std::min(min_pca, projected(smallest_comp, i)); max_pca = std::max(max_pca, projected(smallest_comp, i)); } double center_pca = (max_pca + min_pca) / 2.0; double size_pca = (max_pca - min_pca); double raw_data[3][5]; raw_data[0][0] = size_pca; raw_data[1][0] = least_rectangle.size[0]; raw_data[2][0] = least_rectangle.size[1]; raw_data[0][1] = center_pca; raw_data[1][1] = least_rectangle.center[0]; raw_data[2][1] = least_rectangle.center[1]; for(int i = 0; i < 3; i++) { raw_data[0][2 + i] = left_eigv(i, smallest_comp); raw_data[1][2 + i] = least_rectangle.axisX[0] * left_eigv(i, smallest_comp == 0 ? 1 : 0) + least_rectangle.axisX[1] * left_eigv(i, smallest_comp == 2 ? 1 : 2); raw_data[2][2 + i] = least_rectangle.axisY[0] * left_eigv(i, smallest_comp == 0 ? 1 : 0) + least_rectangle.axisY[1] * left_eigv(i, smallest_comp == 2 ? 1 : 2); } // Msg::Info("Test 1 : %f // %f",least_rectangle.center[0],least_rectangle.center[1]); // Msg::Info("Test 2 : %f // %f",least_rectangle.axisY[0],least_rectangle.axisY[1]); int tri[3]; if(size_pca > least_rectangle.size[0]) { // P > R0 if(size_pca > least_rectangle.size[1]) { // P > R1 tri[0] = 0; if(least_rectangle.size[0] > least_rectangle.size[1]) { // R0 > R1 tri[1] = 1; tri[2] = 2; } else { // R1 > R0 tri[1] = 2; tri[2] = 1; } } else { // P < R1 tri[0] = 2; tri[1] = 0; tri[2] = 1; } } else { // P < R0 if(size_pca < least_rectangle.size[1]) { // P < R1 tri[2] = 0; if(least_rectangle.size[0] > least_rectangle.size[1]) { tri[0] = 1; tri[1] = 2; } else { tri[0] = 2; tri[1] = 1; } } else { tri[0] = 1; tri[1] = 0; tri[2] = 2; } } SVector3 size; SVector3 center; SVector3 Axis1; SVector3 Axis2; SVector3 Axis3; for(int i = 0; i < 3; i++) { size[i] = raw_data[tri[i]][0]; center[i] = raw_data[tri[i]][1]; Axis1[i] = raw_data[tri[0]][2 + i]; Axis2[i] = raw_data[tri[1]][2 + i]; Axis3[i] = raw_data[tri[2]][2 + i]; } SVector3 aux1; SVector3 aux2; SVector3 aux3; for(int i = 0; i < 3; i++) { aux1(i) = left_eigv(i, smallest_comp); aux2(i) = left_eigv(i, smallest_comp == 0 ? 1 : 0); aux3(i) = left_eigv(i, smallest_comp == 2 ? 1 : 2); } center = aux1 * center_pca + aux2 * least_rectangle.center[0] + aux3 * least_rectangle.center[1]; // center[1] = -center[1]; /* Msg::Info("Box center : %f %f %f",center[0],center[1],center[2]); Msg::Info("Box size : %f %f %f",size[0],size[1],size[2]); Msg::Info("Box axis 1 : %f %f %f",Axis1[0],Axis1[1],Axis1[2]); Msg::Info("Box axis 2 : %f %f %f",Axis2[0],Axis2[1],Axis2[2]); Msg::Info("Box axis 3 : %f %f %f",Axis3[0],Axis3[1],Axis3[2]); Msg::Info("Volume : %f", size[0]*size[1]*size[2]); */ return new SOrientedBoundingBox(center, size[0], size[1], size[2], Axis1, Axis2, Axis3); #else Msg::Error("SOrientedBoundingBox requires mesh module"); return 0; #endif }
void Rest::layout() { int lines = staff()->lines(); switch(durationType().type()) { case TDuration::V_64TH: case TDuration::V_32ND: dotline = -3; break; case TDuration::V_256TH: case TDuration::V_128TH: dotline = -5; break; default: dotline = -1; break; } qreal _spatium = spatium(); int stepOffset = 0; if (staff()) { stepOffset = staff()->staffType()->stepOffset(); } int line = lrint(userOff().y() / _spatium); // + ((staff()->lines()-1) * 2); int lineOffset = 0; if (segment() && measure() && measure()->mstaff(staffIdx())->hasVoices) { // move rests in a multi voice context bool up = (voice() == 0) || (voice() == 2); // TODO: use style values switch(durationType().type()) { case TDuration::V_LONG: lineOffset = up ? -3 : 5; break; case TDuration::V_BREVE: lineOffset = up ? -3 : 5; break; case TDuration::V_MEASURE: if (duration() >= Fraction(2, 1)) // breve symbol lineOffset = up ? -3 : 5; // fall through case TDuration::V_WHOLE: lineOffset = up ? -4 : 6; break; case TDuration::V_HALF: lineOffset = up ? -4 : 4; break; case TDuration::V_QUARTER: lineOffset = up ? -4 : 4; break; case TDuration::V_EIGHT: lineOffset = up ? -4 : 4; break; case TDuration::V_16TH: lineOffset = up ? -6 : 4; break; case TDuration::V_32ND: lineOffset = up ? -6 : 6; break; case TDuration::V_64TH: lineOffset = up ? -8 : 6; break; case TDuration::V_128TH: lineOffset = up ? -8 : 8; break; case TDuration::V_256TH: // not available lineOffset = up ? -10 : 6; break; default: break; } } else { switch(durationType().type()) { case TDuration::V_LONG: case TDuration::V_BREVE: case TDuration::V_MEASURE: case TDuration::V_WHOLE: if (lines == 1) lineOffset = -2; break; case TDuration::V_HALF: case TDuration::V_QUARTER: case TDuration::V_EIGHT: case TDuration::V_16TH: case TDuration::V_32ND: case TDuration::V_64TH: case TDuration::V_128TH: case TDuration::V_256TH: // not available if (lines == 1) lineOffset = -4; break; default: break; } } int yo; _sym = getSymbol(durationType().type(), line + lineOffset/2, lines, &yo); layoutArticulations(); rypos() = (qreal(yo) + qreal(lineOffset + stepOffset) * .5) * _spatium; Spatium rs; if (dots()) { rs = Spatium(score()->styleS(ST_dotNoteDistance) + dots() * score()->styleS(ST_dotDotDistance)); } Segment* s = segment(); if (s && s->measure() && s->measure()->multiMeasure()) { qreal _spatium = spatium(); qreal h = _spatium * 6.5; qreal w = point(score()->styleS(ST_minMMRestWidth)); setbbox(QRectF(-w * .5, -h + 2 * _spatium, w, h)); } else { if (dots()) { rs = Spatium(score()->styleS(ST_dotNoteDistance) + dots() * score()->styleS(ST_dotDotDistance)); } setbbox(symbols[score()->symIdx()][_sym].bbox(magS())); } _space.setLw(0.0); _space.setRw(width() + point(rs)); }
String ParsedURL::scheme() const { return segment(m_segments.scheme); }
void ccGraphicalSegmentationTool::segmentOut() { segment(false); }
Element* Breath::nextElement() { return segment()->firstInNextSegments(staffIdx()); }