void AbstractLexer::printQueue(const QQueue<TOKEN>& q) const { QStringList res; foreach(const TOKEN& t, q) { if(m_longOperators.values().contains(t.type)) res += m_longOperators.key(t.type); else if(m_operators.values().contains(t.type)) res += m_operators.key(t.type); else res+= (t.val + ';' + QString::number(t.type) + error()); } qDebug() << q.count() << ":::" << "(" << res.join(QStringLiteral("|")) << ")"; }
bool SBusController::isBusy( const QString & bus ) { const QStringList & keys = active_buses->keys(); if( keys.contains(bus) ) return true; if( !queued_buses->contains(bus) ) return false; QQueue<SBusController*> *list = queued_buses->value(bus); for( int i=0 ; i<list->count() ; i++ ) if( !list->at(i)->passUpAndWait() ) return true; return false; }
void SBusController::finish( const QString & bus ) { if( bus.isEmpty() ) return; SBusController *core = (*active_buses)[bus]; if( core != this ) { qCritical() << QString("SBusController::finish : This SBusController Object can't remove \"%1\" from SBusController.").arg(bus); return ; } active_buses->remove(bus); /*! ---------- Dequeue first not pass up process ------------ */ SBusController *item = 0; if( !queued_buses->contains(bus) ) return; QQueue<SBusController*> *queue = queued_buses->value(bus); if( queue == 0 ) return; for( int i=0 ; i<queue->count() ; i++ ) { if( !queue->at(i)->passUpAndWait() ) { item = queue->takeAt( i ); break; } } if( item == 0 ) return; /*! --------------------------------------------------------- */ if( queued_buses->value(bus)->isEmpty() ) delete queued_buses->take( bus ); active_buses->insert( bus , item ); emit item->go(); }
void SBusController::finish() { QStringList keys; keys = queued_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( !queued_buses->contains(bus) ) continue; QQueue<SBusController*> *queue = queued_buses->value(bus); if( queue == 0 ) continue; for( int j=0 ; j<queue->count() ; j++ ) if( queue->at(j) == this ) { queue->removeAt( j ); j--; } if( queued_buses->value(bus)->isEmpty() ) delete queued_buses->take( bus ); } keys = active_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( !active_buses->contains(bus) ) continue; if( active_buses->value(bus) == this ) finish( bus ); } }
void VolumeOperations::dilateConnected(int dr, int wr, int hr, Vec bmin, Vec bmax, int tag, int nDilate, int& minD, int& maxD, int& minW, int& maxW, int& minH, int& maxH, bool allVisible) { if (dr < 0 || wr < 0 || hr < 0 || dr > m_depth-1 || wr > m_width-1 || hr > m_height-1) { QMessageBox::information(0, "", QString("No visible region found at %1 %2 %3").\ arg(hr).arg(wr).arg(dr)); return; } uchar *lut = Global::lut(); { qint64 idx = (qint64)dr*m_width*m_height + (qint64)wr*m_height + (qint64)hr; int val = m_volData[idx]; if (m_volDataUS) val = m_volDataUS[idx]; if (lut[4*val+3] == 0 || m_maskData[idx] != tag) { QMessageBox::information(0, "Dilate", QString("Cannot dilate.\nYou are on voxel with tag %1, was expecting tag %2").arg(m_maskData[idx]).arg(tag)); return; } } QProgressDialog progress("Updating voxel structure", QString(), 0, 100, 0); progress.setMinimumDuration(0); int ds = qMax(0, (int)bmin.z); int ws = qMax(0, (int)bmin.y); int hs = qMax(0, (int)bmin.x); int de = qMin((int)bmax.z, m_depth-1); int we = qMin((int)bmax.y, m_width-1); int he = qMin((int)bmax.x, m_height-1); qint64 mx = he-hs+1; qint64 my = we-ws+1; qint64 mz = de-ds+1; MyBitArray bitmask; bitmask.resize(mx*my*mz); bitmask.fill(false); MyBitArray cbitmask; cbitmask.resize(mx*my*mz); cbitmask.fill(false); int indices[] = {-1, 0, 0, 1, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0,-1, 0, 0, 1}; // find connected region before dilation QQueue<Vec> que; que.enqueue(Vec(dr,wr,hr)); qint64 bidx = (dr-ds)*mx*my+(wr-ws)*mx+(hr-hs); bitmask.setBit(bidx, true); cbitmask.setBit(bidx, true); minD = maxD = dr; minW = maxW = wr; minH = maxH = hr; int pgstep = 10*m_width*m_height; int prevpgv = 0; int ip=0; while(!que.isEmpty()) { ip = (ip+1)%pgstep; int pgval = 99*(float)ip/(float)pgstep; progress.setValue(pgval); if (pgval != prevpgv) { progress.setLabelText(QString("Updating voxel structure %1").arg(que.count())); qApp->processEvents(); } prevpgv = pgval; Vec dwh = que.dequeue(); int dx = qBound(ds, qCeil(dwh.x), de); int wx = qBound(ws, qCeil(dwh.y), we); int hx = qBound(hs, qCeil(dwh.z), he); for(int i=0; i<6; i++) { int da = indices[3*i+0]; int wa = indices[3*i+1]; int ha = indices[3*i+2]; qint64 d2 = qBound(ds, dx+da, de); qint64 w2 = qBound(ws, wx+wa, we); qint64 h2 = qBound(hs, hx+ha, he); qint64 bidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); if (!cbitmask.testBit(bidx)) { cbitmask.setBit(bidx, true); bool clipped = false; for(int i=0; i<m_cPos.count(); i++) { Vec p = Vec(h2, w2, d2) - m_cPos[i]; if (m_cNorm[i]*p > 0) { clipped = true; break; } } if (!clipped) { qint64 idx = d2*m_width*m_height + w2*m_height + h2; int val = m_volData[idx]; if (m_volDataUS) val = m_volDataUS[idx]; uchar mtag = m_maskData[idx]; bool opaque = (lut[4*val+3]*Global::tagColors()[4*mtag+3] > 0); opaque &= mtag == tag; if (opaque) { bitmask.setBit(bidx, true); que.enqueue(Vec(d2,w2,h2)); } } } } } progress.setLabelText("Dilate"); qApp->processEvents(); QList<QList<Vec> > edges; edges.clear(); qint64 MAXEDGES = 100000000; int ce = 0; QList<Vec> ege; edges << ege; // find inner boundary for(int d=ds; d<=de; d++) { progress.setValue(90*(d-ds)/(mz)); if (d%10 == 0) { progress.setLabelText(QString("Finding boundary to dilate %1").arg(edges[ce].count())); qApp->processEvents(); } for(int w=ws; w<=we; w++) for(int h=hs; h<=he; h++) { qint64 bidx = (d-ds)*mx*my+(w-ws)*mx+(h-hs); if (bitmask.testBit(bidx)) { bool inside = true; for(int i=0; i<6; i++) { int da = indices[3*i+0]; int wa = indices[3*i+1]; int ha = indices[3*i+2]; qint64 d2 = qBound(ds, d+da, de); qint64 w2 = qBound(ws, w+wa, we); qint64 h2 = qBound(hs, h+ha, he); qint64 tidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); inside &= bitmask.testBit(tidx); } if (!inside) { if (edges[ce].count() >= MAXEDGES) { QList<Vec> ege; edges << ege; ce++; } edges[ce] << Vec(d,w,h); } } } } for(int ne=0; ne<nDilate; ne++) { progress.setValue(90*(float)ne/(float)nDilate); qApp->processEvents(); if (ne < nDilate-1) { QList<QList<Vec> > tedges; tedges.clear(); QList<Vec> ege; tedges << ege; cbitmask.fill(false); int ce = 0; // find outer boundary to fill for(int tce=0; tce<edges.count(); tce++) { progress.setLabelText(QString("Dilating boundary %1").arg(edges[tce].count())); qApp->processEvents(); for(int e=0; e<edges[tce].count(); e++) { int dx = edges[tce][e].x; int wx = edges[tce][e].y; int hx = edges[tce][e].z; for(int i=0; i<6; i++) { int da = indices[3*i+0]; int wa = indices[3*i+1]; int ha = indices[3*i+2]; qint64 d2 = qBound(ds, dx+da, de); qint64 w2 = qBound(ws, wx+wa, we); qint64 h2 = qBound(hs, hx+ha, he); bool clipped = false; for(int i=0; i<m_cPos.count(); i++) { Vec p = Vec(h2, w2, d2) - m_cPos[i]; if (m_cNorm[i]*p > 0) { clipped = true; break; } } if (!clipped) { qint64 bidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); qint64 idx = d2*m_width*m_height + w2*m_height + h2; int val = m_volData[idx]; if (m_volDataUS) val = m_volDataUS[idx]; uchar mtag = m_maskData[idx]; bool opaque = (lut[4*val+3]*Global::tagColors()[4*mtag+3] > 0); opaque &= (mtag == 0 || allVisible); //if (lut[4*val+3] > 0 && // dilate only in connected region //m_maskData[idx] == 0 && // dilate only in zero mask or allVisible region if (opaque && // dilate only in connected opaque region !bitmask.testBit(bidx) && !cbitmask.testBit(bidx)) { cbitmask.setBit(bidx); //tedges << Vec(d2,w2,h2); if (tedges[ce].count() >= MAXEDGES) { QList<Vec> ege; tedges << ege; ce++; } tedges[ce] << Vec(d2,w2,h2); minD = qMin(minD, (int)d2); maxD = qMax(maxD, (int)d2); minW = qMin(minW, (int)w2); maxW = qMax(maxW, (int)w2); minH = qMin(minH, (int)h2); maxH = qMax(maxH, (int)h2); } } // not clipped } } } // fill boundary for(int tce=0; tce<tedges.count(); tce++) for(int e=0; e<tedges[tce].count(); e++) { qint64 d2 = tedges[tce][e].x; qint64 w2 = tedges[tce][e].y; qint64 h2 = tedges[tce][e].z; qint64 idx = d2*m_width*m_height + w2*m_height + h2; m_maskData[idx] = tag; qint64 bidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); bitmask.setBit(bidx, true); } //edges = tedges; for(int tce=0; tce<edges.count(); tce++) edges[tce].clear(); edges.clear(); for(int tce=0; tce<tedges.count(); tce++) edges << tedges[tce]; } } for(int tce=0; tce<edges.count(); tce++) edges[tce].clear(); edges.clear(); }
void VolumeOperations::erodeConnected(int dr, int wr, int hr, Vec bmin, Vec bmax, int tag, int nErode, int& minD, int& maxD, int& minW, int& maxW, int& minH, int& maxH) { if (dr < 0 || wr < 0 || hr < 0 || dr > m_depth-1 || wr > m_width-1 || hr > m_height-1) { QMessageBox::information(0, "", QString("No visible region found at %1 %2 %3").\ arg(hr).arg(wr).arg(dr)); return; } uchar *lut = Global::lut(); { qint64 idx = (qint64)dr*m_width*m_height + (qint64)wr*m_height + (qint64)hr; int val = m_volData[idx]; if (m_volDataUS) val = m_volDataUS[idx]; if (lut[4*val+3] == 0 || m_maskData[idx] != tag) { QMessageBox::information(0, "Erode", QString("Cannot erode.\nYou are on voxel with tag %1, was expecting tag %2").arg(m_maskData[idx]).arg(tag)); return; } } QProgressDialog progress("Updating voxel structure", QString(), 0, 100, 0); progress.setMinimumDuration(0); int ds = bmin.z; int ws = bmin.y; int hs = bmin.x; int de = bmax.z; int we = bmax.y; int he = bmax.x; qint64 mx = he-hs+1; qint64 my = we-ws+1; qint64 mz = de-ds+1; MyBitArray bitmask; bitmask.resize(mx*my*mz); bitmask.fill(false); MyBitArray cbitmask; cbitmask.resize(mx*my*mz); cbitmask.fill(false); int indices[] = {-1, 0, 0, 1, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0,-1, 0, 0, 1}; // find connected region before erosion QQueue<Vec> que; que.enqueue(Vec(dr,wr,hr)); qint64 bidx = (dr-ds)*mx*my+(wr-ws)*mx+(hr-hs); bitmask.setBit(bidx, true); cbitmask.setBit(bidx, true); minD = maxD = dr; minW = maxW = wr; minH = maxH = hr; int pgstep = 10*m_width*m_height; int prevpgv = 0; int ip=0; while(!que.isEmpty()) { ip = (ip+1)%pgstep; int pgval = 99*(float)ip/(float)pgstep; progress.setValue(pgval); if (pgval != prevpgv) { progress.setLabelText(QString("Updating voxel structure %1").arg(que.count())); qApp->processEvents(); } prevpgv = pgval; Vec dwh = que.dequeue(); int dx = qCeil(dwh.x); int wx = qCeil(dwh.y); int hx = qCeil(dwh.z); for(int i=0; i<6; i++) { int da = indices[3*i+0]; int wa = indices[3*i+1]; int ha = indices[3*i+2]; qint64 d2 = qBound(ds, dx+da, de); qint64 w2 = qBound(ws, wx+wa, we); qint64 h2 = qBound(hs, hx+ha, he); qint64 bidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); if (!cbitmask.testBit(bidx)) { cbitmask.setBit(bidx, true); qint64 idx = d2*m_width*m_height + w2*m_height + h2; int val = m_volData[idx]; if (m_volDataUS) val = m_volDataUS[idx]; if (lut[4*val+3] > 0 && m_maskData[idx] == tag) { bitmask.setBit(bidx, true); que.enqueue(Vec(d2,w2,h2)); minD = qMin(minD, (int)d2); maxD = qMax(maxD, (int)d2); minW = qMin(minW, (int)w2); maxW = qMax(maxW, (int)w2); minH = qMin(minH, (int)h2); maxH = qMax(maxH, (int)h2); } } } } progress.setLabelText("Erode"); qApp->processEvents(); QList<Vec> edges; edges.clear(); // find inner boundary for(int d=ds; d<=de; d++) { progress.setValue(90*(d-ds)/(mz)); if (d%10 == 0) qApp->processEvents(); for(int w=ws; w<=we; w++) for(int h=hs; h<=he; h++) { qint64 bidx = (d-ds)*mx*my+(w-ws)*mx+(h-hs); if (bitmask.testBit(bidx)) { bool inside = true; for(int i=0; i<6; i++) { int da = indices[3*i+0]; int wa = indices[3*i+1]; int ha = indices[3*i+2]; qint64 d2 = qBound(ds, d+da, de); qint64 w2 = qBound(ws, w+wa, we); qint64 h2 = qBound(hs, h+ha, he); qint64 tidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); inside &= bitmask.testBit(tidx); } if (!inside) edges << Vec(d,w,h); } } } for(int ne=0; ne<nErode; ne++) { progress.setValue(90*(float)ne/(float)nErode); qApp->processEvents(); // fill boundary for(int e=0; e<edges.count(); e++) { qint64 d2 = edges[e].x; qint64 w2 = edges[e].y; qint64 h2 = edges[e].z; qint64 idx = d2*m_width*m_height + w2*m_height + h2; m_maskData[idx] = 0; qint64 bidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); bitmask.setBit(bidx, false); } if (ne < nErode-1) { QList<Vec> tedges; tedges.clear(); cbitmask.fill(false); // find next inner boundary to fill for(int e=0; e<edges.count(); e++) { int dx = edges[e].x; int wx = edges[e].y; int hx = edges[e].z; for(int i=0; i<6; i++) { int da = indices[3*i+0]; int wa = indices[3*i+1]; int ha = indices[3*i+2]; qint64 d2 = qBound(ds, dx+da, de); qint64 w2 = qBound(ws, wx+wa, we); qint64 h2 = qBound(hs, hx+ha, he); qint64 bidx = (d2-ds)*mx*my+(w2-ws)*mx+(h2-hs); if (bitmask.testBit(bidx) && !cbitmask.testBit(bidx)) { cbitmask.setBit(bidx); tedges << Vec(d2,w2,h2); } } } edges = tedges; } } }
bool TreeSearch::operator()() { QQueue<letter_node *> queue; QQueue<letter_node *> queue_emptyCharacters; queue.clear(); filled_details = false; queue.enqueue((letter_node *)Tree->getFirstNode()); bool stop = false; int nodes_per_level = 1; bool wait_for_dequeue = false; position = info.start; while ((!queue.isEmpty() || !queue_emptyCharacters.isEmpty()) && !stop) { node *current_node = NULL; if (wait_for_dequeue) { if (!queue_emptyCharacters.isEmpty()) { current_node = queue_emptyCharacters.dequeue(); } else { wait_for_dequeue = false; position++; } } if (current_node == NULL) { current_node = queue.dequeue(); nodes_per_level--; if (nodes_per_level == 0) { wait_for_dequeue = true; nodes_per_level = queue.count(); } } QChar future_letter; if (position == info.text->length()) { future_letter = '\0'; } else if (position > info.text->length()) { future_letter = '\0'; position = info.text->length(); //break; } else { future_letter = info.text->at(position); while (position < info.text->length() && isDiacritic(future_letter)) { position++; if (position == info.text->length()) { future_letter = '\0'; } else { future_letter = info.text->at(position); } } } bool added_to_main_queue = addLetterToQueue(queue, queue_emptyCharacters, current_node, future_letter); if (added_to_main_queue && wait_for_dequeue) { nodes_per_level++; } QList<result_node *> *current_result_children = current_node->getResultChildren(); int num_children = current_result_children->count(); for (int j = 0; j < num_children; j++) { result_node *current_child = current_result_children->at(j); reached_node = current_child; resulting_category_idOFCurrentMatch = ((result_node *)current_child)->get_resulting_category_id(); bool isAccept = ((result_node *)current_child)->is_accept_state(); if (isAccept && shouldcall_onmatch_ex(position) && !(on_match_helper())) { stop = true; break; } else { bool added_to_main_queue = addLetterToQueue(queue, queue_emptyCharacters, current_child, future_letter); if (added_to_main_queue && wait_for_dequeue) { nodes_per_level++; } } } } return (!stop); }
/*Write paskage to TOO*/ void ftdiChip::on_Machine() { static QQueue<QByteArray> templistCMD; static quint16 retAnswer; static int CurrentValue,ValueMax; switch(stat) { case stOpen: if(!listCMD.isEmpty()){ if(Open()==retOk){ stat=stCounter; disconnect(this,SIGNAL(signalStart()),this,SIGNAL(signalStep())); setParametersUSB(parameter.retSpeed(),parameter.retDataBit(),parameter.retStopBit(),parameter.retParity()); timerRead->setInterval(parameter.retTimeDelay()); templistCMD = listCMD; CurrentValue = 0; ValueMax = 3*templistCMD.count(); emit signalProgressRange(0,ValueMax); emit signalStep(); }else { emit signalMessageError(tr("<CENTER><b>Not found KIT USN_RS485!</CENTER></b>")); emit signalStop(); } } listCMD.clear(); return; case stCounter: if(!templistCMD.isEmpty()){ emit signalProgressValue(++CurrentValue,true); stat=stWrite; }else{ stat=stClose; } emit signalStep(); return; case stWrite: { QByteArray cmd(templistCMD.dequeue());//long Time; quint16 result = Bit8Write(cmd,1); emit signalSendMessage(false,cmd,Qt::green); if(result!=retOk){ templistCMD.clear();stat=stCounter;emit signalStep();} stat=stRead; timerRead->start(); emit signalProgressValue(++CurrentValue,true); } return; case stRead: { QByteArray resBuff; quint16 retRead =Read(resBuff); emit signalSendMessage(true,resBuff,Qt::darkBlue); retAnswer = CheckingReceivedPacket(resBuff); if(retAnswer&ANWR_PROTOCOL::retGet){ return; // next package } if((retAnswer&(~(ANWR_PROTOCOL::retOK))) && (retRead&(ftdiChip::retErr|ftdiChip::retBusyDevice))){// stop sending templistCMD.clear(); } stat=stCounter; timerRead->stop(); emit signalProgressValue(++CurrentValue,true); emit signalStep(); } return; case stClose: Close(); connect(this,SIGNAL(signalStart()),this,SIGNAL(signalStep()),Qt::DirectConnection); default: emit signalEnd(true); stat = stOpen; timerRead->stop(); emit signalProgressValue(0,false); if(retAnswer&(ANWR_PROTOCOL::retOK)) // it is not error emit signalStatusOk(tr("Data is written successfully!")); if(retAnswer&ANWR_PROTOCOL::retError) // it is error emit signalStatusError(tr("Error response!"),false); if(retAnswer&ANWR_PROTOCOL::retNoAnsError) // it is error emit signalStatusError(tr("Device does not answer!"),false); if(retAnswer&ANWR_PROTOCOL::retIncorData) emit signalStatusError(tr("Data is incorrect!"),false); emit signalStep(); return; } }
void SBusController::setPassUpAndWait( bool state ) { if( p->pass_up_and_wait == state ) return; p->pass_up_and_wait = state; if( state ) { /*! ----------------- Find Active Buses ---------------- */ QStringList keys = active_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( !active_buses->contains(bus) ) continue; SBusController *controller = active_buses->value( bus ); if( controller == this ) { finish( bus ); getAccess( bus ); } } } else { /*! ----------------- Find Disabled Buses ---------------- */ QStringList keys = queued_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( active_buses->contains(bus) ) continue; /*! ---------- Find First Deactived Processes to Active --------- */ if( !queued_buses->contains(bus) ) continue; QQueue<SBusController*> *queue = queued_buses->value(bus); if( queue == 0 ) continue; for( int j=0 ; j<queue->count() ; j++ ) { if( queue->at(j) != this ) continue; queue->removeAt( j ); if( queue->isEmpty() ) delete queued_buses->take( bus ); active_buses->insert( bus , this ); emit go(); break; } } } }