Esempio n. 1
0
/* returns -1 on error, zero on success */
int Cdraw3d_from_text (const char *ident, const char *text)
{
    char *p = (char *) text;
    int line = 1;
    double x, y, z, a, b, c, r, r2;
    Vec *v;
    int w, h, i, k;

    do {
        p += strspn(p, " \t\r");
        if(!*p)
            break;
        if (*p == '#' || *p == '\n') {
            /* comment, do nothing */ ;
        } else if (!strncmp (p, "scale ", 6)) {
            if (sscanf (p, "scale %lf", &x) == 1)
                Cdraw3d_scale (ident, x);
            else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "offset ", 7)) {
            if (sscanf (p, "offset %lf %lf %lf", &x, &y, &z) == 3)
                Cdraw3d_offset (ident, x, y, z);
            else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "density ", 7)) {
            if (sscanf (p, "density %lf", &x) == 1)
                Cdraw3d_density (ident, x);
            else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "cylinder ", 8)) {
            if (sscanf (p, "cylinder %lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &b, &c, &r) == 7)
                Cdraw3d_cylinder (ident, x, y, z, a, b, c, r);
            else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "roundplate ", 11)) {
            if (sscanf (p, "roundplate %lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &b, &c, &r) == 7) {
                Cdraw3d_roundplate (ident, x, y, z, a, b, c, r);
                Cdraw3d_roundplate (ident, -x, -y, -z, a, b, c, r);
            } else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "cone ", 5)) {
            if (sscanf (p, "cone %lf %lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &b, &c, &r, &r2) == 8)
                Cdraw3d_cone (ident, x, y, z, a, b, c, r, r2);
            else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "cappedcone ", 11)) {
            if (sscanf (p, "cappedcone %lf %lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &b, &c, &r, &r2) == 8)
                Cdraw3d_cappedcone (ident, x, y, z, a, b, c, r, r2);
            else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "cappedcylinder ", 15)) {
            if (sscanf (p, "cappedcylinder %lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &b, &c, &r) == 7) {
                Cdraw3d_cappedcylinder (ident, x, y, z, a, b, c, r);
            } else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "ellipsoid ", 10)) {
            if (sscanf (p, "ellipsoid %lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &b, &c, &r) == 7) {
                Cdraw3d_ellipsoid (ident, x, y, z, a, b, c, r);
            } else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "rectangle ", 10)) {
            if (sscanf (p, "rectangle %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &b, &c) == 6) {
                Cdraw3d_rectangle (ident, x, y, z, a, b, c);
            } else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "sphere ", 7)) {
            if (sscanf (p, "sphere %lf %lf %lf %lf ", &x, &y, &z, &r) == 4) {
                Cdraw3d_sphere (ident, x, y, z, r);
            } else {
                textformaterror (line, ident);
                return -1;
            }
        } else if (!strncmp (p, "surface ", 8)) {
            if (sscanf (p, "surface %d %d %n", &w, &h, &i) == 2) {
                v = Cmalloc(w * h * sizeof(Vec));
                for(k = 0; k < w * h; k++) {
                    p += i;
                    if(sscanf(p, "%lf %lf %lf %n", &(v[k].x), &(v[k].y), &(v[k].z), &i) != 3) {
                        textformaterror (line, ident);
                        free(v);
                        return -1;
                    }
                }
                draw3d_surface(ident, w, h, v);
                free(v);
            } else {
                textformaterror (line, ident);
                return -1;
            }
        } else {
            textformaterror (line, ident);
            return -1;
        }

        while (*p != '\n' && *p)
            p++;
        line++;
    } while (*(p++));

    Credraw3dobject(ident, 1);
    return 0;
}
Esempio n. 2
0
void main (int argc, char **argv)
{
    int menuopen = 0;
    int x, y, x1;
    CEvent cwevent;
    XEvent xevent;
    Window choicewin, editorwin, win3d;

    init_desktop (&desktop);

    stereo_init (argv[0]);

    choicewin = Cdrawwindow ("choicewin", CMain, 0, 0, 10, 10, "");
    Cgethintpos (&x, &y);
    x1 = x;
    Cdrawbutton ("load", choicewin, x, y, AUTO_SIZE,
		 " Load Image ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("loadcal", choicewin, x, y, AUTO_SIZE,
		 " Load Calibration File ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("showcal", choicewin, x, y, AUTO_SIZE,
		 " Display Calibration Points ");
    Cgethintpos (0, &y);  x = x1;
    Cdrawbutton ("loadd", choicewin, x, y, AUTO_SIZE,
		 " Load Previous Desktop ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("saved", choicewin, x, y, AUTO_SIZE,
		 " Save Previous Desktop ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("finish", choicewin, x, y, AUTO_SIZE,
		 " Quit ");
    Cgethintpos (0, &y);  x = x1;
    Cdrawbutton ("getpnt", choicewin, x, y, AUTO_SIZE,
		 " Triangulate Point        ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("getsurf", choicewin, x, y, AUTO_SIZE,
		 " Triangulate Multiple Points (Surface)   ");
    Cgethintpos (0, &y);  x = x1;
    Cdrawbutton ("getline", choicewin, x, y, AUTO_SIZE,
		 " Fit Line from Points     ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("getlineedge", choicewin, x, y, AUTO_SIZE,
		 " Fit Line from two Line Projections      ");
    Cgethintpos (0, &y);  x = x1;
    Cdrawbutton ("getcyl", choicewin, x, y, AUTO_SIZE,
		 " Fit Cylinder from Points ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("getcyle", choicewin, x, y, AUTO_SIZE,
		 " Fit Cylinder from four Line Projections ");
    Cgethintpos (0, &y);  x = x1;
    Cdrawbutton ("getcirc", choicewin, x, y, AUTO_SIZE,
		 " Fit Circle from Points   ");
    Cgethintpos (&x, 0);
    Cdrawbutton ("getcircedge", choicewin, x, y, AUTO_SIZE,
		 " Fit Circle from Ellipses Projections    ");
    Cgethintpos (0, &y);  x = x1;
    Cdrawbutton ("getellipse", choicewin, x, y, AUTO_SIZE,
		 " Fit Ellipse from Points  ");
    Cgethintpos (&x, 0);

    Csetsizehintpos ("choicewin");

    editorwin = Cdrawwindow ("editorwin", CMain, 200, 100, 640 + 18, \
			     450 + 40 + 18 + TEXT_PIX_PER_LINE + 11, "");
    Cdraweditor ("editor", editorwin, 6, 6 + 40,
	       640, 450, "", 0, "/home/terry/stereo-0.2b/tmp/");

    CDrawEditMenuButtons ("em", editorwin, Cwidget ("editor")->winid, 10, 10);

    Caddcallback ("editor", cb_editor);


    Cdraw3dobject ("3dview", win3d = Cdrawwindow ("3dplanewin",
		CMain, 150, 150, WIDTH3D + 100, 16 + HEIGHT3D, ""), 6, 6,
		   WIDTH3D, HEIGHT3D, 1, 256);

    Cdrawbutton ("plshr", win3d, WIDTH3D + 20, 10, 70, 20, "Shrink");
    Cdrawbutton ("plenl", win3d, WIDTH3D + 20, 40, 70, 20, "Enlarge");
    Cdrawbutton ("newrender", win3d, WIDTH3D + 20, 70, 70, 20, "New render");
    Cdrawbutton ("density", win3d, WIDTH3D + 20, 100, 70, 20, "Density");
    Cdrawbutton ("flattri", win3d, WIDTH3D + 20, 130, 70, 20, "Flat Triangle");
    Cdrawbutton ("savewin", win3d, WIDTH3D + 20, 160, 70, 20, "Save Window");


    Caddcallback ("getpnt", cb_getpoint);
    Caddcallback ("getellipse", cb_getellipse);
    Caddcallback ("getcircedge", cb_getcircleedge);

    Caddcallback ("load", cb_newimage);

    Caddcallback ("3dview", cb_3dplane);
    Caddcallback ("newrender", cb_newrender);


    Caddcallback ("getsurf", cb_getsurface);
    Caddcallback ("getline", cb_getline);
    Caddcallback ("getcirc", cb_getcircle);
    Caddcallback ("getcyle", cb_getcylinderedge);
    Caddcallback ("getcyl", cb_getcylinder);
    Caddcallback ("getlineedge", cb_getlineedge);

    Caddcallback ("loadcal", cb_loadcal);
    Caddcallback ("showcal", cb_showcal);
    Caddcallback ("saved", cb_save_desktop);
    Caddcallback ("loadd", cb_load_desktop);

    Caddcallback ("savewin", cb_save_window);

    if (argc > 1)
	if (*argv[1] != '-')
	    do_load_desktop (&desktop, argv[1]);

    do {
	CNextEvent (&xevent, &cwevent);

	if (!strcmp (cwevent.ident, "plshr")) {
	    Cwidget ("3dview")->solid->distance += 2400;
	    Cwidget ("3dview")->solid->y_cam += 2400;
	    Credraw3dobject ("3dview", 0);
	}
	if (!strcmp (cwevent.ident, "plenl")) {
	    Cwidget ("3dview")->solid->distance -= 2400;
	    Cwidget ("3dview")->solid->y_cam -= 2400;
	    Credraw3dobject ("3dview", 0);
	}
	if (!strcmp (cwevent.ident, "flattri")) {
	    CWidget *w = Cwidget ("3dview");
	    if (w->solid->option_flags & TDOPTION_FLAT_TRIANGLE) {
		w->solid->option_flags &= 0xFFFFFFFF - TDOPTION_FLAT_TRIANGLE;
	    } else {
		w->solid->option_flags |= TDOPTION_FLAT_TRIANGLE;
	    }
	    Credraw3dobject ("3dview", 0);
	}
	if (!strcmp (cwevent.ident, "kill")) {
	    menuopen = 0;
	    Cundrawwidget ("win1");
	}
    } while (strcmp (cwevent.ident, "finish"));

    Cundrawall ();
    mad_finalize (__FILE__, __LINE__);

}