Example #1
0
void OCC_Connect::MergeVertices(TopoDS_Shape &shape1,TopoDS_Shape &shape2) const
{
    TopTools_IndexedMapOfShape imap, omap;
    TopExp::MapShapes(shape1,TopAbs_VERTEX,imap);
    TopExp::MapShapes(shape2,TopAbs_VERTEX,imap);
    BRepTools_ReShape replacer;
    for(int i=0;i<imap.Extent();i++) {
        for(int j=0;j<omap.Extent();j++) {
            TopoDS_Vertex orig=TopoDS::Vertex(imap(i+1));
            TopoDS_Vertex repl=TopoDS::Vertex(omap(j+1));
            if(BRepTools::Compare(orig,repl)) {
                repl.Orientation(orig.Orientation());
                replacer.Replace(orig,repl);
                // FIXME, tolerance and point should be updated
                goto skip;
            }
        }
        omap.Add(imap(i+1));
    skip:;
    }
    TopoDS_Shape t=shape1;
    shape1=replacer.Apply(t);
    t=shape2;
    shape2=replacer.Apply(t);
}
void HaarDetector::run_classifiers()
{
        float oval = 0.0f;
        for (unsigned int i = 0; i < (unsigned int)m_object_maps.size(); i++) {
                const ObjectMap* pom = m_object_maps[i];
                unsigned int dx = pom->get_object_width() / 2;
                unsigned int dy = pom->get_object_height() / 2;
                vec2D& omap = pom->get_object_map();
                omap.set(0.0f);
                for (unsigned int y = dy; y < omap.height() - dy; y++) {
                        for (unsigned int x = dx; x < omap.width() - dx; x++) {
                                //negotiate with motion & skin detector out
                                if ((*m_search_mask)(y, x) == 0)
                                        continue;

                                for (unsigned int j = 0; j < (unsigned int)m_ai_classifiers.size(); j++) {                                        
                                        const AiClassifier* pprev_ai = 0;     //previous stage ai classifier
                                        if (j > 0)
                                                pprev_ai = m_ai_classifiers[j - 1];
                                        AiClassifier* pai = m_ai_classifiers[j];                                        
                                        int cls = pai->classify(*m_integral_image, i, x - dx, y - dy, &oval, pprev_ai);
                                        if (j != (unsigned int)m_ai_classifiers.size() - 1) {   //first stages classifiers
                                                if (cls < 0) {
                                                        omap(y, x) = 0.07f;
                                                        break;
                                                }                                        
                                        }
                                        else    //last classification stage: ANN with sigmoid out layer
                                                omap(y, x) = oval;                                                                                
                                }
                        }
                }
                //debug
                //omap.print(L"object_map.txt");
        }
}
Example #3
0
void OCC_Connect::MergeEdges(TopoDS_Shape &shape1, TopoDS_Shape &shape2) const
{
    TopTools_IndexedMapOfShape imap, omap;
    TopExp::MapShapes(shape1,TopAbs_EDGE,imap);
    TopExp::MapShapes(shape2,TopAbs_EDGE,imap);
    BRepTools_ReShape replacer;
    for(int i=0;i<imap.Extent();i++) {
        for(int j=0;j<omap.Extent();j++) {
            TopoDS_Edge orig=TopoDS::Edge(imap(i+1));
            TopoDS_Edge repl=TopoDS::Edge(omap(j+1));

            TopoDS_Vertex o1, o2, r1, r2;
            TopExp::Vertices(orig,o1,o2,true);
            TopExp::Vertices(repl,r1,r2,true);

            if(o1.IsSame(o2)) {
                if(!BRep_Tool::Degenerated(orig)) {
                    if(verbose&Cutting) {
                        cout << "Same vertex in edge\n";
                        BRepTools::Dump(orig,cout);
                    }
                    replacer.Remove(orig);
                    goto skip;
                } else if(o1.IsSame(r1) && o1.IsSame(r2)
                    && CanMergeCurve(orig,repl)
                ) {
                    if(verbose&Cutting) {
                        cout << "Degenerated edge, replace " << i+1
                            << " with " << j+1 << '\n';
                        BRepTools::Dump(orig,cout);
                        BRepTools::Dump(repl,cout);
                    }
                    // FIXME, update tolerance
                    BRepTools::Dump(repl.Complemented(),cout);
                    replacer.Replace(orig,repl.Complemented());
                    goto skip;
                }
                cout << i+1 << " Degenerated\n";
            }
            if(o1.IsSame(r1) && o2.IsSame(r2) && CanMergeCurve(orig,repl))  {
                if(verbose&Cutting) {
                    cout << "Same order of vertices, replace " << i+1
                        << " with " << j+1 << '\n';
                    BRepTools::Dump(orig,cout);
                    BRepTools::Dump(repl,cout);
                }
                // FIXME, update tolerance
                replacer.Replace(orig,repl);
                goto skip;
            }
            if(o1.IsSame(r2) && o2.IsSame(r1) && CanMergeCurve(orig,repl)) {
                if(verbose&Cutting) {
                    cout << "Reversed order of vertices, replace " << i+1
                        << " with " << j+1 << '\n';
                    BRepTools::Dump(orig,cout);
                    BRepTools::Dump(repl,cout);
                }
                // FIXME, update tolerance
                replacer.Replace(orig,repl.Complemented());
                goto skip;
            }
        }
        if(verbose&Cutting)
            cout << "Adding " << i+1 << " as " << omap.Extent()+1<<" to keep map\n";
        omap.Add(imap(i+1));
    skip:;
    }
    TopoDS_Shape t=shape1;
    shape1=replacer.Apply(t);
    t=shape2;
    shape2=replacer.Apply(t);
}