Exemplo n.º 1
0
def main(argv):
    """
    Try to be as similar to the original C source code as possible. There's a
    lot of python sugar and python magic that isn't being invoked here.
    """
    # TODO: support native python lists
    p1 = (ctypes.c_double * 3)()
    p2 = (ctypes.c_double * 3)()
    rgb = (ctypes.c_double * 3)()

    # TODO: wdb_fopen wasn't in wdb.h
    db_fp = wdb.wdb_fopen(argv[1])

    # create the database header record
    wdb.mk_id(db_fp, "My Database")

    # All units in the database file are stored in millimeters. This constrains
    # the arguments to the mk_* routines to also be in millimeters.

    # make a sphere centered at 1.0, 2.0, 3.0 with radius 0.75
    p1[:] = [1.0, 2.0, 3.0]
    wdb.mk_sph(db_fp, "ball.s", p1, 0.75)

    # Make an rpp under the sphere (partly overlapping). NOte that this realy
    # makes an arb8, but gives us a shortcut for specifying the parameters.
    p1[:] = [0, 0, 0]
    p2[:] = [2, 4, 2.5]
    wdb.mk_rpp(db_fp, "box.s", p1, p2)

    # Make a region that is the union of these two objectsion. To accomplish
    # this, we need to create a linked list of the items that make up the
    # combination. The wm_hd structure serves as the head of the list of items.

    wm_hd = wdb.wmember()

    somelistp = wdb.bu_list_new()
    wdb.mk_pipe_init(somelistp) # calls BU_LIST_INIT(headp)
    somelistp.contents.magic = 0x01016580 # BU_LIST_HEAD_MAGIC

    # Create a wmember structure for each of the items that we want in the
    # combination. The return from mk_addmember is a pointer to the wmember
    # structure.
    some_wmember = wdb._libs['/usr/brlcad/lib/libwdb.so'].mk_addmember("box.s", somelistp, wdb.NULL, ord("u"))

    # Add the second member to the database.
    #
    # Note that there is nothing which checks to make sure that "ball.s" exists
    # in the database when you create the wmember structure OR when you create
    # the combination. So mis-typing the name of a sub-element for a
    # region/combination can be a problem.
    another_wmember = wdb._libs['/usr/brlcad/lib/libwdb.so'].mk_addmember("ball.s", somelistp, wdb.NULL, ord("u"))

    # Create the combination
    #
    # In this case we are going to make it a region (hence the is_region flag
    # is set), and we provide shader parameter information.
    #
    # When making a combination that is NOT a region, the region flag argument
    # is 0, and the strings for optical shader, and shader parameters should
    # (in general) be null pointers.
    is_region = 1

    rgb[:] = [64, 180, 96] # a nice green

    wdb.mk_comb(
        db_fp,
        "box_n_ball.r", # name of the db element created
        somelistp, # list of elements and boolean operations
        is_region, # flag: this is a region
        "plastic", # optical shader
        "di=.8 sp=.2", # shader parameters
        rgb, # item color
        0, 0, 0,
        0, 0, 0,
        0)

    wdb.make_hole(db_fp, p1, p2, 0.75, 0, 0)

    # TDOO: fix this one, wdb_close wasn't in wdb.h
    wdb._libs["/usr/brlcad/lib/libwdb.so"].wdb_close(db_fp)
Exemplo n.º 2
0
def main(argv):
    """
    Try to be as similar to the original C source code as possible. There's a
    lot of python sugar and python magic that isn't being invoked here.
    """
    # TODO: support native python lists
    p1 = (ctypes.c_double * 3)()
    p2 = (ctypes.c_double * 3)()
    rgb = (ctypes.c_double * 3)()

    # TODO: wdb_fopen wasn't in wdb.h
    db_fp = wdb._libs[wdb._libs.keys()[0]].wdb_fopen(argv[1])
    #db_fp = wdb.wdb_fopen(argv[1])

    # create the database header record
    wdb.mk_id(db_fp, "My Database")

    # All units in the database file are stored in millimeters. This constrains
    # the arguments to the mk_* routines to also be in millimeters.

    # make a sphere centered at 1.0, 2.0, 3.0 with radius 0.75
    p1[:] = [1.0, 2.0, 3.0]
    wdb.mk_sph(db_fp, "ball.s", p1, 0.75)

    # Make an rpp under the sphere (partly overlapping). NOte that this realy
    # makes an arb8, but gives us a shortcut for specifying the parameters.
    p1[:] = [0, 0, 0]
    p2[:] = [2, 4, 2.5]
    wdb.mk_rpp(db_fp, "box.s", p1, p2)

    # Make a region that is the union of these two objectsion. To accomplish
    # this, we need to create a linked list of the items that make up the
    # combination. The wm_hd structure serves as the head of the list of items.

    wm_hd = wdb.wmember()

    somelistp = wdb.bu_list_new()
    wdb.mk_pipe_init(somelistp) # calls BU_LIST_INIT(headp)
    somelistp.contents.magic = 0x01016580 # BU_LIST_HEAD_MAGIC

    # Create a wmember structure for each of the items that we want in the
    # combination. The return from mk_addmember is a pointer to the wmember
    # structure.
    some_wmember = wdb._libs['/usr/brlcad/lib/libwdb.so'].mk_addmember("box.s", somelistp, wdb.NULL, ord("u"))

    # Add the second member to the database.
    #
    # Note that there is nothing which checks to make sure that "ball.s" exists
    # in the database when you create the wmember structure OR when you create
    # the combination. So mis-typing the name of a sub-element for a
    # region/combination can be a problem.
    another_wmember = wdb._libs['/usr/brlcad/lib/libwdb.so'].mk_addmember("ball.s", somelistp, wdb.NULL, ord("u"))

    # Create the combination
    #
    # In this case we are going to make it a region (hence the is_region flag
    # is set), and we provide shader parameter information.
    #
    # When making a combination that is NOT a region, the region flag argument
    # is 0, and the strings for optical shader, and shader parameters should
    # (in general) be null pointers.
    is_region = 1

    rgb[:] = [64, 180, 96] # a nice green

    wdb.mk_comb(
        db_fp,
        "box_n_ball.r", # name of the db element created
        somelistp, # list of elements and boolean operations
        is_region, # flag: this is a region
        "plastic", # optical shader
        "di=.8 sp=.2", # shader parameters
        rgb, # item color
        0, 0, 0,
        0, 0, 0,
        0)

    wdb.make_hole(db_fp, p1, p2, 0.75, 0, 0)

    # TODO fix this one, wdb_close wasn't in wdb.h
    wdb._libs[wdb._libs.keys()[0]].wdb_close(db_fp)
Exemplo n.º 3
0
def main(argv):
    p1 = (ctypes.c_double * 3)()
    rgb = (ctypes.c_double * 3)()

    initialSize = 900.0
    finalSize = 1000.0
    stepSize = 10.0
    currentSize = 0.0
    counter = 0
    name = ""
    solidName = ""
    prevSolid = ""
    shaderparams = ""

    wm_hd = wdb.wmember()  # These are probably not necessary.
    bigList = wdb.wmember()

    db_fp = wdb.wdb_fopen(argv[1])

    wdb.mk_id(db_fp, "Globe Database")  # Create the database header record

    # Make a region that is the union of these two objectsion. To accomplish
    # this, we need to create a linked list of the items that make up the
    # combination. The wm_hd structure serves as the head of the list of items.
    somelistp = wdb.bu_list_new()
    biglistp = wdb.bu_list_new()

    # make the CORE of the globe with a given color
    p1[:] = [0, 0, 0]
    rgb[:] = [130, 253, 194]  # some green
    is_region = 1
    # make a sphere centered at 1.0, 2.0, 3.0 with radius .75
    wdb.mk_sph(db_fp, "land.s", p1, initialSize)
    wdb._libs.values()[0].mk_addmember("land.s", somelistp, wdb.NULL, ord("u"))
    wdb.mk_comb(db_fp,
                "land.c",
                somelistp,
                is_region,
                "",
                "",
                rgb,
                0, 0, 0,
                0, 0, 0,
                0)
    wdb._libs.values()[0].mk_addmember("land.s", somelistp, wdb.NULL, ord("u"))
    wdb.mk_comb(db_fp,
                "land.r",
                somelistp,
                is_region,
                "plastic",
                "di=.8 sp=.2",
                rgb,
                0, 0, 0,
                0, 0, 0,
                0)

    # make the AIR of the globe with a given color
    rgb[:] = [130, 194, 253]  # a light blue

    prevSolid = "land.s"
    counter = 0
    currentSize = initialSize + stepSize
    while currentSize < finalSize:
        somelistp = wdb.bu_list_new()

        solidName = "air.%d.s" % counter
        wdb.mk_sph(db_fp, solidName, p1, currentSize)
        wdb.mk_addmember(solidName, somelistp, wdb.NULL, ord("u"))
        wdb.mk_addmember(prevSolid, somelistp, wdb.NULL, ord("-"))

        # make the spatial combination
        name = "air.%d.c" % counter
        wdb.mk_comb(db_fp,
                    name,
                    somelistp,
                    0,
                    wdb.NULL,
                    wdb.NULL,
                    wdb.NULL,
                    0, 0, 0,
                    0, 0, 0,
                    0)
        wdb.mk_addmember(name, somelistp, wdb.NULL, ord("u"))

        # make the spatial region
        name = "air.%d.r" % counter
        shaderparams = "{tr %f}" % float(currentSize/finalSize)
        wdb.mk_comb(db_fp,
                    name,
                    somelistp,
                    is_region,
                    "plastic",
                    shaderparams,
                    rgb,
                    0, 0, 0,
                    0, 0, 0,
                    0)

        # add the region to a master region list
        wdb.mk_addmember(name, biglistp, wdb.NULL, ord("u"))

        # keep track of the last combination we made for the next iteration
        prevSolid = solidName

        counter += 1
        currentSize += stepSize

    # make one final air region that comprises all the air regions
    wdb.mk_comb(db_fp,
                "air.c",
                biglistp,
                0,
                wdb.NULL,
                wdb.NULL,
                wdb.NULL,
                0, 0, 0,
                0, 0, 0,
                0)

    # Create the master globe region
    #
    # In this case we are going to make it a region (hence the
    # is_region flag is set, and we provide shader parameter information.
    #
    # When making a combination that is NOT a region, the region flag
    # argument is 0, and the strings for optical shader, and shader
    # parameters should (in general) be null pointers.
    #
    # add the land to the main globe object that gets created at the end 
    somelistp = wdb.bu_list_new()
    wdb.mk_addmember("land.r", somelistp, wdb.NULL, ord("u"))
    wdb.mk_addmember("air.c", somelistp, wdb.NULL, ord("u"))

    wdb.mk_comb(db_fp,
                "globe.r",
                somelistp,
                is_region,
                wdb.NULL,
                wdb.NULL,
                wdb.NULL,
                0, 0, 0,
                0, 0, 0,
                0)

    wdb._libs.values()[0].wdb_close(db_fp)
    return 0
Exemplo n.º 4
0
def main(argv):
    p1 = (ctypes.c_double * 3)()
    rgb = (ctypes.c_double * 3)()

    initialSize = 900.0
    finalSize = 1000.0
    stepSize = 10.0
    currentSize = 0.0
    counter = 0
    name = ""
    solidName = ""
    prevSolid = ""
    shaderparams = ""

    wm_hd = wdb.wmember()  # These are probably not necessary.
    bigList = wdb.wmember()

    db_fp = wdb.wdb_fopen(argv[1])

    wdb.mk_id(db_fp, "Globe Database")  # Create the database header record

    # Make a region that is the union of these two objectsion. To accomplish
    # this, we need to create a linked list of the items that make up the
    # combination. The wm_hd structure serves as the head of the list of items.
    somelistp = wdb.bu_list_new()
    biglistp = wdb.bu_list_new()

    # make the CORE of the globe with a given color
    p1[:] = [0, 0, 0]
    rgb[:] = [130, 253, 194]  # some green
    is_region = 1
    # make a sphere centered at 1.0, 2.0, 3.0 with radius .75
    wdb.mk_sph(db_fp, "land.s", p1, initialSize)
    wdb._libs.values()[0].mk_addmember("land.s", somelistp, wdb.NULL, ord("u"))
    wdb.mk_comb(db_fp, "land.c", somelistp, is_region, "", "", rgb, 0, 0, 0, 0,
                0, 0, 0)
    wdb._libs.values()[0].mk_addmember("land.s", somelistp, wdb.NULL, ord("u"))
    wdb.mk_comb(db_fp, "land.r", somelistp, is_region, "plastic",
                "di=.8 sp=.2", rgb, 0, 0, 0, 0, 0, 0, 0)

    # make the AIR of the globe with a given color
    rgb[:] = [130, 194, 253]  # a light blue

    prevSolid = "land.s"
    counter = 0
    currentSize = initialSize + stepSize
    while currentSize < finalSize:
        somelistp = wdb.bu_list_new()

        solidName = "air.%d.s" % counter
        wdb.mk_sph(db_fp, solidName, p1, currentSize)
        wdb.mk_addmember(solidName, somelistp, wdb.NULL, ord("u"))
        wdb.mk_addmember(prevSolid, somelistp, wdb.NULL, ord("-"))

        # make the spatial combination
        name = "air.%d.c" % counter
        wdb.mk_comb(db_fp, name, somelistp, 0, wdb.NULL, wdb.NULL, wdb.NULL, 0,
                    0, 0, 0, 0, 0, 0)
        wdb.mk_addmember(name, somelistp, wdb.NULL, ord("u"))

        # make the spatial region
        name = "air.%d.r" % counter
        shaderparams = "{tr %f}" % float(currentSize / finalSize)
        wdb.mk_comb(db_fp, name, somelistp, is_region, "plastic", shaderparams,
                    rgb, 0, 0, 0, 0, 0, 0, 0)

        # add the region to a master region list
        wdb.mk_addmember(name, biglistp, wdb.NULL, ord("u"))

        # keep track of the last combination we made for the next iteration
        prevSolid = solidName

        counter += 1
        currentSize += stepSize

    # make one final air region that comprises all the air regions
    wdb.mk_comb(db_fp, "air.c", biglistp, 0, wdb.NULL, wdb.NULL, wdb.NULL, 0,
                0, 0, 0, 0, 0, 0)

    # Create the master globe region
    #
    # In this case we are going to make it a region (hence the
    # is_region flag is set, and we provide shader parameter information.
    #
    # When making a combination that is NOT a region, the region flag
    # argument is 0, and the strings for optical shader, and shader
    # parameters should (in general) be null pointers.
    #
    # add the land to the main globe object that gets created at the end
    somelistp = wdb.bu_list_new()
    wdb.mk_addmember("land.r", somelistp, wdb.NULL, ord("u"))
    wdb.mk_addmember("air.c", somelistp, wdb.NULL, ord("u"))

    wdb.mk_comb(db_fp, "globe.r", somelistp, is_region, wdb.NULL, wdb.NULL,
                wdb.NULL, 0, 0, 0, 0, 0, 0, 0)

    wdb._libs.values()[0].wdb_close(db_fp)
    return 0