int main(void)
{
    polyn * pa, *pb, *padd, *psub;
    printf("please input polynomial pa(like 1,1 and 0,0 is over ):\n");
    pa = Creatpolyn();
    printf("please input polynomial pb(like 1,1 and 0,0 is over ):\n");
    pb = Creatpolyn();
    sort_link(pa);
    sort_link(pb);
    printf("pa=");
    print_polyn(pa);
    printf("pb=");
    print_polyn(pb);
    padd = add_polyn(pa, pb);
    psub = subtraction_polyn(pa, pb);
    printf("pa+pb=");
    print_polyn(padd);
    printf("pa-pb=");
    print_polyn(psub);
}
Exemplo n.º 2
0
void SurfaceEdgeCollapse::Reduce(int &red_tri, int &red_pnt)
{
    Edge current;
    Star star;
    int v1, v2;
    float cur_percent;
    int okay;
    char buf[100];
    float x_0, y_0, z_0;
    clock_t starttime, endtime;
    double time;
    pair link[MAXTRI];
    int num_link = 0;

    heap = new PQ<Edge>(num_triangles * 3);

    cur_percent = percent / 100.0;
    red_tri = num_triangles;
    red_pnt = num_points;

    starttime = clock();

    preprocess(red_tri);

    while ((heap->getSize() > TERMINATE) && (red_tri / (float)num_triangles > cur_percent))
    {
        current = heap->get_next();
        v1 = current.get_v1();
        v2 = current.get_v2();

        // valence test
        if (stars[v1].num_tri + stars[v2].num_tri > 5 && v1 >= 0 && v1 < num_points && v2 >= 0 && v2 < num_points)
        { // prevent too large stars
            if (stars[v1].num_tri + stars[v2].num_tri < MAXTRI)
            {
                merge_stars(v1, v2, star);
                make_link(v1, v2, star, link, num_link);
                if (check_link(v1, v2, star, link, num_link))
                {
                    okay = sort_link(link, num_link);

                    // topology preserving tests
                    if (okay && star.manifold && !((angle[v1] || angle[v2]) && star.boundary))
                    { // simplify edge

                        if (angle[v1] && angle[v2])
                            okay = straighten_edge(v1, v2, star, link, num_link, x_0, y_0, z_0);
                        else
                        {
                            if (stars[v1].boundary && stars[v2].boundary)
                            {

                                okay = straighten_boundary(v1, v2, star, link, num_link, x_0, y_0, z_0);
                            }
                            else
                            {
                                okay = compute_newpoint(v1, v2, star, link, num_link, x_0, y_0, z_0);
                            }
                        }
                        if (okay && (volume_bound >= fabs(compute_star_volume(v1, v2, star, link, num_link, x_0, y_0, z_0))))
                        {
                            update(red_tri, v1, v2, star, link, num_link, x_0, y_0, z_0);
                            red_pnt -= 1;
                        }
                        else
                            delete[] star.tri;
                    }
                    else
                        delete[] star.tri;
                }
                else
                    delete[] star.tri;
            }
        }
    }
    cur_percent = 100.0 * red_tri / (float)num_triangles;
    endtime = clock();
    time = (endtime - starttime) / (double)CLOCKS_PER_SEC;

    if (heap->getSize() == TERMINATE)
        sprintf(buf, "Reduction capacity exceeded: Removed %d triangles of %d, i.e. %.2f %% are left", num_triangles - red_tri, num_triangles, cur_percent);
    else
        sprintf(buf, "Removed %d triangles of %d, i.e. %.2f %% are left\n", num_triangles - red_tri, num_triangles, percent);
    Covise::sendInfo(buf);
    sprintf(buf, "Time: %.2f seconds\n", time);
    Covise::sendInfo(buf);

    delete heap;
}