bool
DependencySplitter::parse(const char * reldepStr)
{
    enum { NAME = 1, CMP_TYPE = 2, EVR = 3, _LAST_ };
    auto matchResult = RELDEP_REGEX.match(reldepStr, false, _LAST_);
    if (!matchResult.isMatched() || matchResult.getMatchedLen(NAME) == 0) {
        return false;
    }
    name = matchResult.getMatchedString(NAME);
    evr = matchResult.getMatchedString(EVR);
    cmpType = 0;
    int evrLen = matchResult.getMatchedLen(EVR);
    int cmpTypeLen = matchResult.getMatchedLen(CMP_TYPE);
    if (cmpTypeLen < 1) {
        if (evrLen > 0) {
            // name contains the space char, e.g. filename like "hello world.jpg"
            evr.clear();
            name = reldepStr;
        }
        return true;
    }
    if (evrLen < 1)
        return false;

    return getCmpFlags(&cmpType, matchResult.getMatchedString(CMP_TYPE));
}
Ejemplo n.º 2
0
void SelectorMatcher::startElement(const XMLElementDecl& elemDecl,
                                   const unsigned int urlId,
                                   const XMLCh* const elemPrefix,
                                   const RefVectorOf<XMLAttr>& attrList,
                                   const unsigned int attrCount) {

    XPathMatcher::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount);
    fElementDepth++;

    // activate the fields, if selector is matched
    int matched = isMatched();
    if ((fMatchedDepth == -1 && ((matched & XP_MATCHED) == XP_MATCHED))
            || ((matched & XP_MATCHED_D) == XP_MATCHED_D)) {

        IdentityConstraint* ic = fSelector->getIdentityConstraint();
        int count = ic->getFieldCount();

        fMatchedDepth = fElementDepth;
        fFieldActivator->startValueScopeFor(ic, fInitialDepth);

        for (int i = 0; i < count; i++) {

            XPathMatcher* matcher = fFieldActivator->activateField(ic->getFieldAt(i), fInitialDepth);
            matcher->startElement(elemDecl, urlId, elemPrefix, attrList, attrCount);
        }
    }
}
Ejemplo n.º 3
0
bool MyMoneySplit::hasReferenceTo(const QString& id) const
{
  bool rc = false;
  if (isMatched()) {
    rc = matchedTransaction().hasReferenceTo(id);
  }
  for (int i = 0; i < m_tagList.size(); i++)
    if (id == m_tagList[i])
      return true;
  return rc || (id == m_account) || (id == m_payee);
}
Ejemplo n.º 4
0
void MyMoneySplit::addMatch(const MyMoneyTransaction& _t)
{
  //  now we allow matching of two manual transactions
  if (!isMatched()) {
    MyMoneyTransaction t(_t);
    t.clearId();
    QDomDocument doc("MATCH");
    QDomElement el = doc.createElement("CONTAINER");
    doc.appendChild(el);
    t.writeXML(doc, el);
    QString xml = doc.toString();
    xml.replace('<', "&lt;");
    setValue("kmm-matched-tx", xml);
  }
}
Ejemplo n.º 5
0
 bool isValid(string s) {
     stack<char> openBrackets;
     for(int pos = 0; pos < s.length(); pos++)
     {
         if (openBrackets.size() > 0)
         {
             if (isOpenBrackets(s[pos]))
             {
                 openBrackets.push(s[pos]);
             }
             else
             {
                 if (!isMatched(openBrackets.top(), s[pos]))
                 {
                     return false;
                 }
                 else
                 {
                     openBrackets.pop();
                 }
             }
         }
         else
         {
             if (isOpenBrackets(s[pos]))
             {
                 openBrackets.push(s[pos]);
             }
             else
             {
                 return false;
             }
         }
     }
     if (openBrackets.size() != 0)
     {
         return false;
     }
     else
     {
         return true;
     }
     
 }
Ejemplo n.º 6
0
bool MyMoneySplit::replaceId(const QString& newId, const QString& oldId)
{
  bool changed = false;

  if (m_payee == oldId) {
    m_payee = newId;
    changed = true;
  } else if (m_account == oldId) {
    m_account = newId;
    changed = true;
  }

  if (isMatched()) {
    MyMoneyTransaction t = matchedTransaction();
    if (t.replaceId(newId, oldId)) {
      removeMatch();
      addMatch(t);
      changed = true;
    }
  }

  return changed;
}
Ejemplo n.º 7
0
/* u and v are the number of vertices in sets U, and V, respectively,
 * filling up bipgraph[0..u-1][0..v-1].
 * result:
 *  matching[u0]==v0 iff u0 and v0 are in the matching, 
 * otherwise matching[u0] = -1 */
void
match(int u, int v) {
  int i,j, head,tail, bad, last, increased;

  for( i = 0; i < u; i++ ) {
    matching[i] = -1;
    flagUmatched[i] = 0;
  }
  for( i = 0; i < v; i++ ) flagVmatched[i] = 0;

  do { /* find alternating paths by repeated bfs. */
    for( i = 0; i < MAXU+MAXV; i++ ) predecessor[i] = -1;
    for( i = 0; i < MAXU; i++ ) flagUused[i] = flagUvisited[i] = 0;
    for( i = 0; i < MAXV; i++ ) flagVused[i] = flagVvisited[i] = 0;
  
    head = tail = 0;

    /* put all the unmatched u's on the queue. They start the 
     * alternating path. */
    for( i = 0; i < u; i++ ) {
      if( ! isMatched(U(i))) {
	queue[tail++] = U(i);
	predecessor[i] = -1; /* redundant statement */
	setVisited(U(i));
      }
    }

    /* flag that at least one path was found by the bfs.
     * when the bfs does not find an alternating path we are done. */
    increased = 0;

    while( head != tail ) {
      i = queue[head++];

      /* this node appeared on some previously found alternating path. */
      if( isUsed(i) ) continue;
    
      if( isV(i) && !isMatched(i) ) {
	/* we got to the end of an alternating path. see if
	 * it is disjoint with other paths found so far. only
	 * then can we mess it up a bit. */
	bad = 0;
	for( j = i; j != -1; j = predecessor[j]) {
	  if( isUsed(j)) {
	    bad = 1;
	    break;
	  }
	}
	
	if( ! bad ) {
	  /* this path is pristine. switch "polarity" of edges
	   * in the matching on this path. */

	  /* flag and instrumention - whether (not) to quit,
	   * and how many paths we found this bfs. */
	  increased++; 
	  for( j = i; j != -1; last = j, j = predecessor[j] ) {
	    if( isV(j) && !isMatched(j)) {
	      /* the only unmatched v - actually this means we
	       * are on the first iteration of this loop. */
	      setMatched(j);

	    } else if( isU(j) ) {
	      if( isMatched(j) ) {
		/* the node we saw in the previous iteration of
		 * this loop must be a V. We will match with it
		 * instead of the one we used to match with, which
		 * must be the next node visited in this loop. */
		assert(isV(last));
		matching[j] = last - MAXU;
	      } else {
		/* we are the very first u, one of the ones the
		 * bfs queue was "seeded" with. We should have ...*/
		assert(predecessor[j] == -1);
		setMatched(j);
		assert(isV(last));
		matching[j] = last - MAXU;
	      }
	    }
	    setUsed(j); /* this node cannot be used for other
			 * paths we might run across in the future
			 * on this bfs. */
	  } /* for */
	} /* if ! bad */
      } /* isV and !isMatched */

      else if( isV(i) ) {
	/* this must be a matched V - find the matching U and put it on 
	 * the queue if it is not visited or used. */

	bad = 1;

	for( j = 0; j < u; j++ ) {
	  if( isMatched(U(j)) && matching[j] == i - MAXU ) {
	    /* this is the one. */
	    if( ! isVisited(U(j)) && !isUsed(U(j))) {
	      setVisited(U(j));
	      queue[tail++] = U(j); 
	      predecessor[U(j)] = i;
	    }
	    bad = 0;
	    break;
	  }
	}
	assert(!bad);
      } /* isV */
      else if( isU(i) ) {
	/* we are at U. whether it is unmatched (a "seed"),
	 * or matched, we do the same thing - put on the queue
	 * all V's which it is connected to in the graph but
	 * which it is _not_ paired to in the current matching. */

	for( j = 0; j < v; j++ ) {
	  if( bipgraph[i][j] &&
	      !isVisited(V(j)) && 
	      !isUsed(V(j)) && 
	      matching[i] != j ) {
	    /* we can put this one on the queue. */
	    queue[tail++] = V(j);
	    predecessor[V(j)] = i;
	    setVisited(V(j));
	  }
	}
      } else {
	assert(0); /* should be no other cases. */
      }
      /* this is the end of the bfs. */
    } 
  } while( increased );

  return;
}
Ejemplo n.º 8
0
void Codebook::processFrame(uint8_t* frameBytes, uint16_t t){

    int rawPixel = 0;
	// Get height and weight from frame
	for(int r=0; r<height; r++) {			// Run the algorithm for each pixel
		for(int c=0; c<width; c++) {

			// Get codebook of current pixel
			Codebook *cb;
			cb = codebooks+rawPixel;

			// Get rgb value of current pixel into rgb[3] array
			float rgb[3];
			int rawChannel = 3*rawPixel;
			rgb[0] = frameBytes[rawChannel+2];
			rgb[1] = frameBytes[rawChannel+1];
			rgb[2] = frameBytes[rawChannel+0];


            // Calculate the brightness
            //float I = sqrt(rgb[0]*rgb[0] + rgb[1]*rgb[1] + rgb[2]*rgb[2]);
            float I = (rgb[0] + rgb[1] + rgb[2]);

			// Seek matched codewords
			int matched = -1;
			for( uint16_t i=0; i<cb->cwlist.size(); i++ ) {
				if( isMatched(cb->cwlist.at(i), rgb, I) ) {
					matched = i;
					break;
				}
			}

			if (mode == PLAY){
                // Background substraction
                if (matched == -1) {
                    outputFrameBytes[rawPixel] = 0;
                }
                else {
                    outputFrameBytes[rawPixel] = 255;
                }

			}
            else if (mode == TRAIN) {
                if (matched == -1) {		// There is no match or codebookSize == 0, add new codeword
                    Codeword *cw = new Codeword;

                    cw->rgb[0]  = rgb[0];
                    cw->rgb[1]  = rgb[1];
                    cw->rgb[2]  = rgb[2];
                    cw->minI    = I;
                    cw->maxI    = I;
                    cw->f       = 1;
                    cw->l       = t-1;
                    cw->p       = t;
                    cw->q       = t;

                    cw->col = c;
                    cw->row = r;
                    cb->cwlist.push_back(cw);
                    cwCount++;
                }
                else {						// Update matched codeword
                    Codeword *cw = cb->cwlist.at(matched);
                    int f = cw->f;
                    int fn = f+1;
                    cw->rgb[0] = (f*cw->rgb[0]+rgb[0])/fn;
                    cw->rgb[1] = (f*cw->rgb[1]+rgb[1])/fn;
                    cw->rgb[2] = (f*cw->rgb[2]+rgb[2])/fn;
                    cw->minI = min(cw->minI, I);
                    cw->maxI = min(cw->maxI, I);
                    cw->f = fn;
                    uint16_t temp = t-cw->q;
                    cw->l = max(cw->l, temp);
                    //cw->p = cw->p;	// Redundant
                    cw->q = t;
                }
            }

            rawPixel++; // rawPixel = r*width+c + 1;
		}
	}

}
Ejemplo n.º 9
0
//处理无匹配区域
void FindRegionCorrespondence(const Mat& srcImg, const Mat& refImg, const vector<Point2i>& srcFeatures, const vector<Point2i>& refFeatures, const Mat& srcVisibility, const Mat& refVisibility,
	const vector<int>& srcLabels, const int& regionum, vector<int>& refLabels, string resultFolder)
{
	vector<vector<Point2f>> srcFeaturesTab(regionum);
	vector<vector<Point2f>> refFeaturesTab(regionum);
	int sz = srcFeatures.size();
	int width = srcImg.size().width;
	int height = srcImg.size().height;
	for (int i = 0; i < sz; ++i)
	{
		int index = srcFeatures[i].y * width + srcFeatures[i].x;
		int l = srcLabels[index];

		srcFeaturesTab[l].push_back(srcFeatures[i]);
		refFeaturesTab[l].push_back(refFeatures[i]);	
	}

	//保存无匹配区域
	vector<int> unmatchedIdx(0);
	for (int i = 0; i < regionum; ++i)
		if (srcFeaturesTab[i].size() == 0)
		{
			unmatchedIdx.push_back(i);
		}
	vector<vector<Point2f>> d_srcPointsTab(regionum);
	calPointsTab(srcLabels, width, height, d_srcPointsTab);
	
	string fn;
	Mat unmatchedMsk = Mat::zeros(height, width, CV_8UC1), unmatched;
	cout << "unmatched regions: " << endl;
	for (int i = 0; i < unmatchedIdx.size(); ++i)
	{
		int idx = unmatchedIdx[i];
		cout << idx << ' ';
		pointsToMask(d_srcPointsTab[idx], unmatchedMsk);
	}
	cout << endl;
	fn = resultFolder + "/unmatched_regions_mask.png";
	imwrite(fn, unmatchedMsk);
	srcImg.copyTo(unmatched, unmatchedMsk);
	fn = resultFolder + "/unmatched_regions.png";
	imwrite(fn, unmatched);
	

	//每个区域的像素点
	vector<vector<Point2f>> srcPointsTab(regionum);  //已知
	vector<vector<Point2f>> refPointsTab(regionum);  //未知
	calPointsTab(srcLabels, srcVisibility, srcPointsTab);   //每个区域只保留可见性为1的像素
	//calPointsTab(srcLabels, width, height, srcPointsTab);

	vector<Mat> transforms(regionum);
	vector<int> isMatched(regionum);
	computeTransforms(srcFeaturesTab, refFeaturesTab, transforms, isMatched);

	//deal with unmatched region
	//cout << endl << "copy with no-matched region." << endl;
	dealUnMatchedRegion(isMatched, transforms);
	//dealUnMatchedRegion(srcImg, srcPointsTab, srcFeaturesTab, srcLabels, isMatched, transforms);
	
	//apply transform to each region
	applyTransforms(srcPointsTab, transforms, isMatched, refPointsTab);

	//求解refLabels
	computeRefLabels(refPointsTab, width, height, refVisibility, refLabels);	
}