TEST_F(MatcherGTest, testPgaMatching) {
	count n = 50;
	Graph G(n);
	G.forNodePairs([&](node u, node v){
		G.addEdge(u,v);
	});
	PathGrowingMatcher pgaMatcher(G);

	DEBUG("Start PGA matching on 50-clique");

	pgaMatcher.run();
	Matching M = pgaMatcher.getMatching();

	count numExpEdges = n / 2;
	bool isProper = M.isProper(G);
	EXPECT_TRUE(isProper);
	EXPECT_EQ(M.size(G), numExpEdges);
	DEBUG("Finished PGA matching on 50-clique");


#if !defined _WIN32 && !defined _WIN64 && !defined WIN32 && !defined WIN64
	DibapGraphReader reader;
	Graph airfoil1 = reader.read("input/airfoil1.gi");
	PathGrowingMatcher pga2(airfoil1);
	pga2.run();
	M = pga2.getMatching();
	isProper = M.isProper(airfoil1);
	EXPECT_TRUE(isProper);
	DEBUG("PGA on airfoil1 produces matching of size: " , M.size(G));
#endif
}
void matchSurf(const Mat_f& kdesc0, const Mat_f& kdesc1, Matching& matches,
               float ratio) {

    assert(kdesc0.rows > 0);
    assert(kdesc0.cols == kdesc1.cols);
    int dimDesc = kdesc0.cols;

    matches.clear();
    matches.reserve(std::max(kdesc0.rows, kdesc1.rows));
    float dist, d1, d2;
    for (int i = 0; i < kdesc0.rows; i++) {
        d1 = d2 = FLT_MAX;
        int jMin = -1;
        for (int j = 0; j < kdesc1.rows; j++) {
            dist = computeSurfDescDist(kdesc0.data + i * dimDesc,
                                       kdesc1.data + j * dimDesc, dimDesc);
            if (dist < d1) // if this feature matches better than current best
            {
                d2 = d1;
                d1 = dist;
                jMin = j;

            } else if (dist < d2) // this feature matches better than second best
            {
                d2 = dist;
            }
        }
        // If match has a d1:d2 ratio < 0.65 ipoints are a match
        if (d1 / d2 < ratio) {
            matches.add(i, jMin, d1);
        }
    }
}
Example #3
0
void cvMatch2MyMatch(const DMatchVec& cvMatch , Matching& myMatch) {
	int numMatch = cvMatch.size();
	myMatch.reserve(numMatch);
	for (int i = 0; i < numMatch; i++) {
		myMatch.add(cvMatch[i].queryIdx, cvMatch[i].trainIdx, cvMatch[i].distance);
	}
}
void matchSurf(int dimDesc, std::vector<float>& desc0,
               std::vector<float>& desc1, Matching& matches, float ratio,
               float maxDist) {
    int len0 = (int) desc0.size();
    int len1 = (int) desc1.size();
    assert(len0 % dimDesc == 0 && len1 %dimDesc == 0);

    int npts0 = len0 / dimDesc;
    int npts1 = len1 / dimDesc;

    matches.clear();
    matches.reserve(npts0 > npts1 ? npts0 : npts1);

    float dist, d1, d2;
    for (int i = 0; i < npts0; i++) {
        d1 = d2 = FLT_MAX;
        int jMin = -1;
        for (int j = 0; j < npts1; j++) {
            dist = computeSurfDescDist(&desc0[0] + i * dimDesc,
                                       &desc1[0] + j * dimDesc, dimDesc);
            if (dist < d1) {
                d2 = d1;
                d1 = dist;
                jMin = j;
            } else if (dist < d2)
                d2 = dist;
        }
        if (d1 < maxDist && d1 / d2 < ratio) {
            matches.add(i, jMin, d1);
        }
    }
}
Matching GetAlignedMatching(size_t size) {
    Matching match;
    for (size_t i = 0; i < size; i++) {
        match.push_back(DMatch(i, i, 0));
    }
    return match;
}
Example #6
0
void RGFlow<Two_scale>::run_up()
{
   VERBOSE_MSG("> running tower up (iteration " << iteration << ") ...");
   const size_t number_of_models = models.size();
   for (size_t m = 0; m < number_of_models; ++m) {
      TModel* model = models[m];
      model->model->set_precision(get_precision());
      VERBOSE_MSG("> \tselecting model " << model->model->name());
      // apply all constraints
      const size_t n_upwards_constraints = model->upwards_constraints.size();
      for (size_t c = 0; c < n_upwards_constraints; ++c) {
         Constraint<Two_scale>* constraint = model->upwards_constraints[c];
         const double scale = constraint->get_scale();
         VERBOSE_MSG("> \t\tselecting constraint " << c << " at scale " << scale);
         VERBOSE_MSG("> \t\t\trunning model to scale " << scale);
         if (model->model->run_to(scale))
            throw NonPerturbativeRunningError(scale);
         VERBOSE_MSG("> \t\t\tapplying constraint");
         constraint->apply();
      }
      // apply matching condition if this is not the last model
      if (m != number_of_models - 1) {
         VERBOSE_MSG("> \tmatching to model " << models[m + 1]->model->name());
         Matching<Two_scale>* mc = model->matching_condition;
         mc->match_low_to_high_scale_model();
      }
   }
   VERBOSE_MSG("> running up finished");
}
TEST_F(MatcherGTest, testLocalMaxMatching) {
	count n = 50;
	Graph G(n);
	G.forNodePairs([&](node u, node v){
		G.addEdge(u,v);
	});

	LocalMaxMatcher localMaxMatcher(G);

	TRACE("Start localMax matching");
	localMaxMatcher.run();
	Matching M = localMaxMatcher.getMatching();
	TRACE("Finished localMax matching");

	count numExpEdges = n / 2;
	bool isProper = M.isProper(G);
	EXPECT_TRUE(isProper);
	EXPECT_EQ(M.size(G), numExpEdges);

#if !defined _WIN32 && !defined _WIN64 && !defined WIN32 && !defined WIN64
	DibapGraphReader reader;
	Graph airfoil1 = reader.read("input/airfoil1.gi");
	LocalMaxMatcher lmm(airfoil1);
	lmm.run();
	M = lmm.getMatching();
	isProper = M.isProper(airfoil1);
	EXPECT_TRUE(isProper);
	DEBUG("LocalMax on airfoil1 produces matching of size: " , M.size(G));
#endif
}
Example #8
0
int RGFlow<Two_scale>::run_to(double scale)
{
   // find model which is defined at `scale'
   model_at_this_scale = NULL;
   const size_t number_of_models = models.size();

   for (size_t m = 0; m < models.size(); ++m) {
      TModel* model = models[m];
      double highest_scale, lowest_scale;

      if (!model) {
         ERROR("RGFlow<Two_scale>::run_to: pointer to model " << m
               << " is zero");
         return 1;
      }

      if (m != number_of_models - 1) {
         // if this is not the last model, the matching condition is
         // the highest scale
         Matching<Two_scale>* mc = model->matching_condition;
         if (!mc) {
            ERROR("RGFlow<Two_scale>::run_to: pointer to matching condition"
                  " of model " << m << " is zero");
            return 1;
         }
         highest_scale = mc->get_scale();
      } else {
         // otherwise the last constraint is at the highest scale
         if (model->upwards_constraints.empty())
            highest_scale = std::numeric_limits<double>::max();
         else
            highest_scale = model->upwards_constraints.back()->get_scale();
      }

      if (m > 0) {
         // if this is not the first model, the previous matching
         // condition is the lowest scale
         lowest_scale = models[m-1]->matching_condition->get_scale();
      } else {
         // otherwise the first constraint is at the lowest scale
         if (model->upwards_constraints.empty())
            lowest_scale = 0.;
         else
            lowest_scale = model->upwards_constraints[0]->get_scale();
      }

      if (lowest_scale <= scale && scale <= highest_scale) {
         model_at_this_scale = model->model;
         break;
      }
   }

   if (model_at_this_scale)
      return model_at_this_scale->run_to(scale);

   return 1;
}
TEST_F(MatcherGTest, tryValidMatching) {
	METISGraphReader reader;
	Graph G = reader.read("coAuthorsDBLP.graph");

	LocalMaxMatcher pmatcher(G);
	pmatcher.run();
	Matching M = pmatcher.getMatching();

	bool isProper = M.isProper(G);
	EXPECT_TRUE(isProper);
}
int refineMatchedPoints(const Mat_d& pts1, const Mat_d& pts2, Matching& matches,
                        Matching& newMatches, double ratio) {
    double ud[2] = { 0, 0 };
    Mat_d d(matches.num, 2);

    int num = matches.num;
    for (int i = 0; i < num; i++) {
        int idx1 = matches[i].idx1;
        int idx2 = matches[i].idx2;

        d.data[2 * i] = pts2.data[2 * idx2] - pts1.data[2 * idx1];
        d.data[2 * i + 1] = pts2.data[2 * idx2 + 1] - pts1.data[2 * idx1 + 1];
        ud[0] += d.data[2 * i];
        ud[1] += d.data[2 * i + 1];
    }

    ud[0] /= num;
    ud[1] /= num;

    double cov[4] = { 0, 0, 0, 0 };
    for (int i = 0; i < num; i++) {
        double dx = d.data[2 * i] - ud[0];
        double dy = d.data[2 * i + 1] - ud[1];

        cov[0] += dx * dx;
        cov[1] += dx * dy;
        cov[3] += dy * dy;
    }

    double s = ratio * ratio;
    cov[0] /= num / s;
    cov[1] /= num / s;
    cov[3] /= num / s;
    cov[2] = cov[1];

    double icov[4];
    mat22Inv(cov, icov);

    newMatches.clear();
    newMatches.reserve(num);

    for (int i = 0; i < num; i++) {
        double dx = d.data[2 * i] - ud[0];
        double dy = d.data[2 * i + 1] - ud[1];
        double dist = dx * dx * icov[0] + 2 * dx * dy * icov[1]
                      + dy * dy * icov[2];
        if (dist < 1.0) {
            newMatches.add(matches[i].idx1, matches[i].idx2, 0);
        }
    }
    return newMatches.num;
}
Example #11
0
 void verifyMatching(BipartiteGraph g, unsigned expectedSize)
 {
     Matching matching = findMaximumMatching(g);
     typedef boost::unordered_set<unsigned> VertexSet;
     VertexSet first;
     VertexSet second;
     for (auto elem : matching)
     {
         ASSERT_TRUE(first.insert(elem.first).second);
         ASSERT_TRUE(second.insert(elem.second).second);
         ASSERT_TRUE(g.edgeExists(elem));
     }
     ASSERT_EQ(expectedSize, matching.size());
 }
void drawMatching(const ImgG& img1, const Mat_d& keyPts1, const ImgG& img2,
		const Mat_d& keyPts2, ImgRGB& outImg, double scale,
		unsigned char* flag) {

	int numPts = keyPts1.rows;
	Matching matches;
	matches.reserve(numPts);

	cv::RNG rng;

	for (int i = 0; i < numPts; i++) {
		matches.add(i, i, 0);
	}
	drawMatching(img1, keyPts1, img2, keyPts2, matches, outImg, scale, flag);
}
Example #13
0
void GetAlignedPointsFromMatch(const Features& leftFeatures,
                               const Features& rightFeatures,
                               const Matching& matches,
                               Features& alignedLeft,
                               Features& alignedRight,
                               vector<int>& leftBackReference,
                               vector<int>& rightBackReference)
{
    alignedLeft .keyPoints.clear();
    alignedRight.keyPoints.clear();
    alignedLeft .descriptors = cv::Mat();
    alignedRight.descriptors = cv::Mat();

    for (unsigned int i=0; i<matches.size(); i++) {
        alignedLeft .keyPoints  .push_back(leftFeatures.keyPoints       [matches[i].queryIdx]);
        alignedLeft .descriptors.push_back(leftFeatures.descriptors.row (matches[i].queryIdx));
        alignedRight.keyPoints  .push_back(rightFeatures.keyPoints      [matches[i].trainIdx]);
        alignedRight.descriptors.push_back(rightFeatures.descriptors.row(matches[i].trainIdx));
        leftBackReference .push_back(matches[i].queryIdx);
        rightBackReference.push_back(matches[i].trainIdx);
    }

    KeyPointsToPoints(alignedLeft.keyPoints,  alignedLeft.points);
    KeyPointsToPoints(alignedRight.keyPoints, alignedRight.points);
}
Example #14
0
		IDIS() {

			fileLeft = "/apps/workspaces/kiste_data/stereo/2/left.png";
			fileRight = "/apps/workspaces/kiste_data/stereo/2/right.png";
			imgLeft = ImageFactory::readPNG(fileLeft);
			imgRight = ImageFactory::readPNG(fileRight);

			MatchingSAD sad(imgLeft, imgRight, 15);
			Matching matcher;

			Point2i pl1(257,369);	Point2i pr1(98,367);		pr1 = matcher.refine(sad, pl1, pr1);
			Point2i pl2(261,579);	Point2i pr2(101,589);		pr2 = matcher.refine(sad, pl2, pr2);
			Point2i pl3(282,692);	Point2i pr3(121,708);		pr3 = matcher.refine(sad, pl3, pr3);
			Point2i pl4(657,673);	Point2i pr4(520,678);		pr4 = matcher.refine(sad, pl4, pr4);
			Point2i pl5(704,247);	Point2i pr5(569,247);		pr5 = matcher.refine(sad, pl5, pr5);
			Point2i pl6(816,641);	Point2i pr6(679,641);		pr6 = matcher.refine(sad, pl6, pr6);
			Point2i pl7(1113,503);	Point2i pr7(964,501);		pr7 = matcher.refine(sad, pl7, pr7);
			Point2i pl8(1025,472);	Point2i pr8(882,472);		pr8 = matcher.refine(sad, pl8, pr8);
			Point2i pl9(1096,345);	Point2i pr9(948,348);		pr9 = matcher.refine(sad, pl9, pr9);

			fm.addCorrespondence(pl1,	pr1);
			fm.addCorrespondence(pl2,	pr2);
			fm.addCorrespondence(pl3,	pr3);
			fm.addCorrespondence(pl4,	pr4);
			fm.addCorrespondence(pl5,	pr5);
			fm.addCorrespondence(pl6,	pr6);
			fm.addCorrespondence(pl7,	pr7);
			fm.addCorrespondence(pl8,	pr8);
			//fm.addCorrespondence(pl9,	pr9);

			fm.estimate();

		}
Example #15
0
/** match SURF feature points between two views*/
int NewMapPtsSURF::matchBetween(int iCam, int jCam, Matching& matches) {

	std::vector<float>& desc1 = surfDescs[iCam];
	std::vector<float>& desc2 = surfDescs[jCam];

	int dim = m_descDim;

	std::vector<cv::DMatch> matches1, matches2;

	cv::Mat matDesc1(desc1.size() / dim, dim, CV_32F, &desc1[0]);
	cv::Mat matDesc2(desc2.size() / dim, dim, CV_32F, &desc2[0]);
	cv::BruteForceMatcher<cv::L2<float> > matcher;
	matcher.match(matDesc1, matDesc2, matches1);
	matcher.match(matDesc2, matDesc1, matches2);

	//test
	cv::Mat img1(m_img[iCam].rows, m_img[iCam].cols, CV_8UC1, m_img[iCam].data);
	cv::Mat img2(m_img[jCam].rows, m_img[jCam].cols, CV_8UC1, m_img[jCam].data);

	cv::Mat outImg;
	cv::drawMatches(img1, surfPoints[iCam], img2, surfPoints[jCam], matches1, outImg);
	cv::imwrite("/home/tsou/test.bmp", outImg);

	//cross validation
	std::vector<int> ind1;
	ind1.assign(surfPoints[iCam].size(), -1);

	for (size_t j = 0; j < matches1.size(); j++) {
		int idx1 = matches1[j].queryIdx;
		int idx2 = matches1[j].trainIdx;
		ind1[idx1] = idx2;
	}

	matches.clear();
	matches.reserve(matches2.size());
	for (size_t j = 0; j < matches2.size(); j++) {
		int idx2 = matches2[j].queryIdx;
		int idx1 = matches2[j].trainIdx;
		if (ind1[idx1] == idx2) {
			matches.add(idx1, idx2, matches2[j].distance);
		}
	}
	return matches.num;
}
Example #16
0
//-------------------------------------
// Fire()
//-------------------------------------
void Bullet::Fire(OBJECT_PARAMETER_DESC &parameter)
{
	parameter_ = parameter;

	speed_ = { BULLET_DEF_SPEED_XZ, BULLET_DEF_SPEED_Y, BULLET_DEF_SPEED_XZ };

	// 回転値を少し調整
	parameter_.rotation_.x_ += BULLET_OFFSET_ROT;
	// 回転値を参照して速度を改良
	speed_.y += sinf(parameter_.rotation_.x_) * BULLET_ADD_SPEED_Y;

	if (collision_ == nullptr)
	{
		Scene *scene = SceneManager::GetCurrentScene();
		std::string str = SceneManager::GetCurrentSceneName();
		if (str != "Game" && str != "Matching"){
			ASSERT_ERROR("弾が生成されるべきシーンではありません");
			return;
		}
		COLLISION_PARAMETER_DESC param;
		param.position_ = {
			parameter_.position_.x_,
			parameter_.position_.y_,
			parameter_.position_.z_ };
		param.range_ = 0.5f;
		param.offset_ = { 0.0f, 0.0f, 0.0f };

		if (str == "Game"){
			Game *game = dynamic_cast<Game*>(scene);
			collision_ = game->collision_manager()->Create(this, param);
		}
		if (str == "Matching"){
			Matching *matching = dynamic_cast<Matching*>(scene);
			collision_ = matching->collision_manager()->Create(this, param);
		}
	}

	// 使用フラグOFF
	use_ = true;
	collision_->SetUse(true);
}
Example #17
0
int main() {
    int n, d;
    int x[MAXN], y[MAXN];

    while (scanf("%d", &n) != EOF) {
        for (int i = 0; i < n; ++i) {
            scanf("%d%d", &x[i], &y[i]);
        }
        scanf("%d", &d);
        m.init(n);
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (abs(x[i] - x[j]) + abs(y[i] - y[j]) <= d) {
                    m.addEdge(i, j);
                }
            }
        }
        puts(m.gao() * 2 == n ? "YES" : "NO");
    }

    return 0;
}
Example #18
0
void RGFlow<Two_scale>::run_down()
{
   assert(models.size() > 0 && "model size must not be zero");
   VERBOSE_MSG("< running tower down ...");
   const size_t number_of_models = models.size();
   for (long m = number_of_models - 1; m >= 0; --m) {
      TModel* model = models[m];
      VERBOSE_MSG("< \tselecting model " << model->model->name());
      // apply all constraints:
      // If m is the last model, do not apply the highest constraint,
      // because it was already appied when we ran up.
      const size_t c_begin = (m + 1 == (long)number_of_models ? 1 : 0);
      const size_t c_end = model->downwards_constraints.size();
      for (size_t c = c_begin; c < c_end; ++c) {
         Constraint<Two_scale>* constraint = model->downwards_constraints[c];
         const double scale = constraint->get_scale();
         VERBOSE_MSG("< \t\tselecting constraint " << c << " at scale " << scale);
         VERBOSE_MSG("< \t\t\trunning model to scale " << scale);
         if (model->model->run_to(scale))
            throw NonPerturbativeRunningError(scale);
         // If m is the lowest energy model, do not apply the lowest
         // constraint, because it will be applied when we run up next
         // time.
         if (m != 0 || c + 1 != c_end) {
            VERBOSE_MSG("< \t\t\tapplying constraint");
            constraint->apply();
         }
      }
      // apply matching condition if this is not the first model
      if (m > 0) {
         Matching<Two_scale>* mc = models[m - 1]->matching_condition;
         VERBOSE_MSG("< \tmatching to model " << models[m - 1]->model->name());
         mc->match_high_to_low_scale_model();
      }
   }
   VERBOSE_MSG("< running down finished");
}
Example #19
0
		Garden() {

			fileLeft = getDataFile("stereo1.jpg");		// left image
			fileRight = getDataFile("stereo2.jpg");		// right image
			imgLeft = ImageFactory::readJPEG(fileLeft);
			imgRight = ImageFactory::readJPEG(fileRight);

			MatchingSAD sad(imgLeft, imgRight, 15);
			Matching matcher;

			// image1				// image2 (left of image1)	// refine the approximate matching positions
			Point2i pl1(85,53);		Point2i pr1(29,57);			pr1 = matcher.refine(sad, pl1, pr1);
			Point2i pl2(264,34);	Point2i pr2(209,36);		pr2 = matcher.refine(sad, pl2, pr2);
			Point2i pl3(362,32);	Point2i pr3(306,32);		pr3 = matcher.refine(sad, pl3, pr3);

			Point2i pl4(213,155);	Point2i pr4(155,159);		pr4 = matcher.refine(sad, pl4, pr4);

			Point2i pl5(96,209);	Point2i pr5(36,210);		pr5 = matcher.refine(sad, pl5, pr5);
			Point2i pl6(330,212);	Point2i pr6(269,211);		pr6 = matcher.refine(sad, pl6, pr6);
			Point2i pl7(276,241);	Point2i pr7(216,242);		pr7 = matcher.refine(sad, pl7, pr7);

			Point2i pl8(385,332);	Point2i pr8(321,328);		pr8 = matcher.refine(sad, pl8, pr8);
			Point2i pl9(180,389);	Point2i pr9(114,388);		pr9 = matcher.refine(sad, pl9, pr9);
			Point2i pl10(136,500);	Point2i pr10(67,500);		pr10 = matcher.refine(sad, pl10, pr10);

			fm.addCorrespondence(pl1,	pr1);
			fm.addCorrespondence(pl2,	pr2);
			fm.addCorrespondence(pl3,	pr3);

			fm.addCorrespondence(pl4,	pr4);

			fm.addCorrespondence(pl5,	pr5);
			fm.addCorrespondence(pl6,	pr6);
			fm.addCorrespondence(pl7,	pr7);
			fm.addCorrespondence(pl8,	pr8);
//			fm.addCorrespondence(pl9,	pr9);
//			fm.addCorrespondence(pl10,	pr10);

			fm.estimate();

		}
Example #20
0
bool GramError::Evaluate() {
  ensure(scrutinizer); ensure(matchingSet);
  ensure(matching);
  Matching *m = matching;
  matching = NULL;
  ruleTerm = m->GetRuleTerm();
  const AbstractSentence *s = sentence = m->GetSentence();
  bool falseAlarm = false;

  // create alt sentences:
  m->SetAltSentence(NULL);
  for (Expr* c = ruleTerm->GetCorr(); c; c = c->Next()) {
    DynamicSentence *ds = new DynamicSentence(s);
    DynamicSentence *prevAlt = m->GetAltSentence();
    m->SetAltSentence(ds);
    if (!m->GetRuleTerm()->EvaluateCorr(m, c))
      Message(MSG_WARNING, "evaluation of corr failed", m->GetRule()->Name());     
    if (prevAlt) m->AddAltSentences(prevAlt);
  }

  // set status info:
  DynamicSentence *d;
  for (d = m->GetAltSentence(); d; d = d->Next()) {
    if (d->Status() == FORM_NOT_FOUND)
      continue;
    if (s->IsEqual(d)) {
      d->status = SAME_AS_ORIGINAL;
      if (xSuggestionSameAsOriginalMeansFalseAlarm) {
	falseAlarm = true;
	break;
      }
    }
    for (DynamicSentence *d2 = m->GetAltSentence(); d2 && d2 != d; d2 = d2->Next())
      if (d2->Status() != FORM_NOT_FOUND && d->IsEqual(d2)) {
	d->status = SAME_AS_ANOTHER;
	break;
      }
  }

  if (!falseAlarm) {
    // extract info:
    info = stringBuf.NewString(ruleTerm->EvaluateInfo(m));
    if (*info == '\0')
      Message(MSG_WARNING, "no info from", ruleTerm->GetRule()->Name());
    
    // extract mark:
    std::ostringstream out2;
    if (ruleTerm->GetMark())
      ruleTerm->EvaluateMark(m);
    else
      for (int i=m->Start(); i<= m->End(); i++)
	s->GetWordToken(i)->SetMarked();
    out2 << xRed;
    bool gap = false, anyMark = false;
    nMarkedSections = 0;
    start[0] = stop[0] = -1;
    int firstWTpos = (m->Start() >= 2) ? m->Start() : 2;
    int lastWTpos = (m->End() >= s->NTokens()-2) ? s->NTokens()-3 : m->End();
    for (int i=2; i<s->NTokens()-2; i++)
	if (s->GetWordToken(i)->IsMarked()) {
	    if (!anyMark) firstWTpos = i;
	    lastWTpos = i;
	    anyMark = true;
	    s->GetWordToken(i)->SetMarked(0);
	    s->GetWordToken(i)->SetMarked2();
	    if (gap) { out2 << " ... "; gap = false; }
	    out2 << s->GetWordToken(i);
	    if (start[nMarkedSections] < 0)
		start[nMarkedSections] = i;
	    stop[nMarkedSections] = i;
	} else {
	    gap = anyMark;
	    if (start[nMarkedSections] >= 0) {
		if (nMarkedSections >= MAX_MARKED_SECTIONS-1)
		    Message(MSG_WARNING, "too many marked sections");
		nMarkedSections++;
		start[nMarkedSections] = stop[nMarkedSections] = -1;
	    }
	}
    // jbfix: if the marked area ended in the last position
    // nMarkedSections was not incremented
    if(start[nMarkedSections] != -1)
    {
	if(nMarkedSections >= MAX_MARKED_SECTIONS-1)
	    Message(MSG_WARNING, "too many marked sections");
	nMarkedSections++;
    }

    if (!anyMark) {
      Message(MSG_WARNING, "nothing marked with", ruleTerm->GetRule()->Name());
      start[0] = firstWTpos;
      stop[0] = lastWTpos;
      nMarkedSections = 1;
    } else if (firstWTpos <= 2 && lastWTpos >= s->NTokens()-3) {
      allMarked = true;
      markedArea = "";
      start[0] = firstWTpos;
      stop[0] = lastWTpos;
      nMarkedSections = 1;
    } else {
      out2 << xNoColor << '\0';
      markedArea = stringBuf.NewString(out2.str().c_str());
    }

    // jb: mem is now handled by std::string
    //if (str) delete str; else delete out2.str();
    
    // create suggestions:
    for (d = m->GetAltSentence(); d; d = d->Next()) {
      if (nSuggestions >= MAX_SUGGESTIONS) {
	Message(MSG_WARNING, "too many suggestions");
	break;
      }
      switch (d->Status()) {
      case FORM_NOT_FOUND:
	nErrors[nSuggestions] = 0;
	suggestion[nSuggestions++] = stringBuf.NewString("FORM NOT FOUND");
	continue;
      case SAME_AS_ANOTHER:
	if (xAcceptRepeatedSuggestions) break;
	continue;
      case NOT_IMPROVING: ensure(0);
      case SAME_AS_ORIGINAL:
      case SEEMS_OK:
	break;
      }
      d->TagMe();
      matchingSet->SetCheckMode(true);
      scrutinizer->Scrutinize(d);
      nErrors[nSuggestions] = (char) matchingSet->NCheckModeFound();
      matchingSet->SetCheckMode(false);
      if (nErrors[nSuggestions] >= sentence->NGramErrors())
	d->status = NOT_IMPROVING;
      if (xPrintMatchings) {
	std::cout << tab;
	switch(d->Status()) {
	case SEEMS_OK: std::cout << "(OK)"; break;
	case SAME_AS_ORIGINAL: std::cout << "(NO CHANGES)"; break;
	case SAME_AS_ANOTHER: std::cout << "(REPEATED)"; break;
	case NOT_IMPROVING: std::cout << "(NOT IMPROVING)"; break;
	case FORM_NOT_FOUND: std::cout << "(FORM NOT FOUND)"; break;
	}
	std::cout << std::endl;
      }
      if (!xAcceptNonImprovingCorrections && d->Status() == NOT_IMPROVING)
	continue;
      std::ostringstream out;
      d->PrintOrgRange(firstWTpos, lastWTpos, out);  
      switch(d->Status()) {
      case SEEMS_OK: break;
      case SAME_AS_ORIGINAL: out << " (NO CHANGES)"; break;
      case SAME_AS_ANOTHER: out << " (REPEATED)"; break;
      case NOT_IMPROVING: out << " (NOT IMPROVING, gives " << (int)nErrors[nSuggestions]
			      << " errors, " << sentence->NGramErrors() << " before)"; break;
      case FORM_NOT_FOUND: ensure(0); break;
      }
      out << '\0';

      //      suggestion[nSuggestions++] = stringBuf.NewString(out.str().c_str());
      suggestion[nSuggestions++] = stringBuf.NewString(move_xmltag_and_space(out.str()).c_str());
    }
  }
  // delete alt sentences:
  DynamicSentence *nxt = NULL;
  for (d = m->GetAltSentence(); d; d = nxt) {  
    nxt = d->Next();
    delete d;
  }
  m->SetAltSentence(NULL);
  //  std::cout << this << std::endl;

  return !falseAlarm;
}
Example #21
0
//-------------------------------------
// Update()
//-------------------------------------
void Bullet::Update()
{
	if (!use_)
	{
		return;
	}

	parameter_.position_.x_ += sinf(parameter_.rotation_.y_) * speed_.x;
	parameter_.position_.y_ += speed_.y;
	parameter_.position_.z_ += cosf(parameter_.rotation_.y_) * speed_.z;
	speed_.y -= BULLET_GRAVITY;

	Scene *scene = SceneManager::GetCurrentScene();
	std::string str = SceneManager::GetCurrentSceneName();
	if (str == "Game"){
		Game *game = dynamic_cast<Game*>(scene);
		Object *obj = game->object_manager()->Get("field");
		Field *field = dynamic_cast<Field*>(obj);
		float height = field->GetHeight(
			D3DXVECTOR3(
			parameter_.position_.x_,
			parameter_.position_.y_,
			parameter_.position_.z_));
		if (parameter_.position_.y_ < height){
			use_ = false;
			collision_->SetUse(false);

			//-------------------------------------
			// シーンからエフェクト取得
			EFFECT_PARAMETER_DESC effect_param;
			MyEffect *effect = game->effect_manager()->Get("fieldhit");
			effect_param = effect->parameter();
			effect_param.position_ = parameter_.position_;
			effect_param.position_.y_ = height;
			effect_param.rotation_ = { 0.0f, parameter_.rotation_.y_, 0.0f };
			effect->SetParameter(effect_param);

			//-------------------------------------
			// エフェクト再生
			game->effect_manager()->Play("fieldhit");

			parameter_.position_.y_ = 10000.0f;
		}



	}

	if (str == "Matching"){
		Matching *matching = dynamic_cast<Matching*>(scene);
		Object *obj = matching->object_manager()->Get("field");
		Field *field = dynamic_cast<Field*>(obj);
		float height = field->GetHeight(
			D3DXVECTOR3(
			parameter_.position_.x_,
			parameter_.position_.y_,
			parameter_.position_.z_));
		if (parameter_.position_.y_ < height){
			use_ = false;
			collision_->SetUse(false);
			parameter_.position_.y_ = 10000.0f;

			//-------------------------------------
			// シーンからエフェクト取得
			EFFECT_PARAMETER_DESC effect_param;
			MyEffect *effect = matching->effect_manager()->Get("fieldhit");
			effect_param = effect->parameter();
			effect_param.position_ = parameter_.position_;
			effect_param.position_.y_ = height;
			effect_param.rotation_ = { 0.0f, parameter_.rotation_.y_, 0.0f };
			effect->SetParameter(effect_param);

			//-------------------------------------
			// エフェクト再生
			matching->effect_manager()->Play("fieldhit");
		}
	}

	// ワールド計算
	D3DXMATRIX translate, rotate, scaling;
	D3DXMatrixIdentity(&translate);
	D3DXMatrixIdentity(&rotate);
	D3DXMatrixIdentity(&scaling);
	D3DXMatrixIdentity(&world_);

	D3DXMatrixScaling(
		&scaling, parameter_.scaling_.x_, parameter_.scaling_.y_, parameter_.scaling_.z_);
	D3DXMatrixMultiply(
		&world_, &world_, &scaling);
	D3DXMatrixRotationYawPitchRoll(
		&rotate, parameter_.rotation_.y_, parameter_.rotation_.x_, parameter_.rotation_.z_);
	D3DXMatrixMultiply(
		&world_, &world_, &rotate);
	D3DXMatrixTranslation(
		&translate, parameter_.position_.x_, parameter_.position_.y_, parameter_.position_.z_);
	D3DXMatrixMultiply(
		&world_, &world_, &translate);
}