예제 #1
0
파일: Reg.cpp 프로젝트: awarematics/SECONDO
vector<Reg> Reg::Concavities() {
    vector<Reg> ret = vector<Reg>();
    vector<Seg> ch = convexhull;
    unsigned int j = 0;

    cerr << "Calculating Concavities Start " << depth++ << "\n";
    cerr << "Hull\n";
    for (unsigned int a = 0; a < ch.size(); a++) {
        cerr << ch[a].ToString() << "\n";
    }
    cerr << "Pol\n";
    for (unsigned int a = 0; a < v.size(); a++) {
        cerr << v[a].ToString() << "\n";
    }

    for (j = 0; j < v.size(); j++) {
        if ((ch[0].x1 == v[j].x1) && (ch[0].y1 == v[j].y1)) {
            break;
        }
    }

    for (unsigned int i = 0; i < ch.size(); i++) {
        if (!(ch[i] == v[j])) {
            cerr << "Found new Concavity: " << depth << "\n";
            Reg r = Reg(this, i);
            unsigned int hpidx;
            if (j == 0) {
                hpidx = v.size() - 1;
            } else {
                hpidx = j - 1;
            }
            r.hullPoint = new Pt(v[hpidx].x1, v[hpidx].x2);
            cerr << "End: " << ch[i].x2 << "/" << ch[i].y2 << "\n";
            do {
                Seg s = Seg(v[j].x2, v[j].y2, v[j].x1, v[j].y1);
                r.AddSeg(s);
                j = (j + 1) % v.size();
            } while ((ch[i].x2 != v[j].x1) || (ch[i].y2 != v[j].y1));
            std::reverse(r.v.begin(), r.v.end());
            r.Close();
            //            r.Print();
            cerr << "End Found new Concavity: " << depth << "\n";
            ret.push_back(r);
        } else {
            j = (j + 1) % v.size();
        }
    }

    cvs = ret;

    cerr << "Found " << cvs.size() << " Concavities\n";

    cerr << "Calculating Concavities End " << --depth << "\n";

    return ret;
}
예제 #2
0
파일: Reg.cpp 프로젝트: awarematics/SECONDO
vector<Reg> Reg::Concavities2(Reg *reg2) {
    vector<Reg> ret;
    Reg *reg1 = this;

    reg1->Begin();
    reg2->Begin();

    Reg r1 = Reg(reg1->convexhull);
    Reg r2 = Reg(reg2->convexhull);
    cerr << "\n\nConcavities2: START\n";

    do {
        double a1 = r1.Cur().angle();
        double a2 = r2.Cur().angle();
        int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0,
                dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;

        if (((a1 <= a2) && !r1.End()) || r2.End()) {
            cerr << "Concavities2/r1: Comparing " << r1.Cur().ToString()
                    << " (hull) / " << reg1->Cur().ToString() << " (region)\n";
            if (r1.Cur() == reg1->Cur()) {
                r1.Next();
                reg1->Next();
            } else {

                // We found a concavity in the source region

                cerr << "Concavities2: Found concavity\n";
                Reg ccv; // The concavity
                while (r1.Cur().x2 != reg1->Cur().x1 ||
                        r1.Cur().y2 != reg1->Cur().y1) {
                    sx1 = reg1->Cur().x1;
                    sy1 = reg1->Cur().y1;
                    sx2 = reg1->Cur().x2;
                    sy2 = reg1->Cur().y2;
                    dx1 = dx2 = r2.Cur().x1;
                    dy1 = dy2 = r2.Cur().y1;
                    reg1->Next();
                    //    msegs.AddMSeg(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
                    Seg s(sx1, sy1, sx2, sy2);
                    ccv.AddSeg(s);
                    cerr << "Concavities2: Adding segment " << s.ToString()
                            << "\n";
                }
                ccv.hullPoint = new Pt(reg1->Cur().x1, reg1->Cur().y1);
                ccv.peerPoint = new Pt(r2.Cur().x1, r2.Cur().y1);
                cerr << "HP" << ccv.hullPoint->ToString()
                        << " PP " << ccv.peerPoint->ToString() << "\n\n";
                cerr << "Concavities2: Found concavity end\n\n";
                ccv.Close();
                ret.push_back(ccv);
                r1.Next();
            }
        } else if ((a1 >= a2) || r1.End()) {
            cerr << "Concavities2/r2: Comparing " << r2.Cur().ToString()
                    << " (hull) / " << reg2->Cur().ToString() << " (region)\n";
            if (r2.Cur() == reg2->Cur()) {
                reg2->Next();
                r2.Next();
            } else {
                while (r2.Cur().x2 != reg2->Cur().x1 ||
                        r2.Cur().y2 != reg2->Cur().y1) {
                    reg2->Next();
                }
                r2.Next();
            }
        }

        if (r1.End() && r2.End())
            break;

    } while (1);
    cerr << "\nConcavities2: END\n\n";

    return ret;
}