Example #1
0
def _get_inputs():
    # PlanarRectangle
    ll = {'x': 0, 'y': 0, 'z': 0}
    lr = {'x': 1, 'y': 0, 'z': 0}
    ul = {'x': 0, 'y': 1, 'z': 0}

    # Cylinder
    base = {'x': 0, 'y': 0, 'z': 0}
    axis = {'x': 0, 'y': 0, 'z': 1}
    radius = 1

    # Sphere
    center = {'x': 1.23, 'y': 4.56, 'z': 7.89}
    radius = 1

    # ArbitraryGeometry
    filename = rosmsg2json.fixup_path('$(find freemoovr)/data/pyramid.osg')

    inputs = [
        (simple_geom.PlanarRectangle,
         dict(lowerleft=ll, upperleft=ul, lowerright=lr)),
        (simple_geom.Cylinder, dict(base=base, axis=axis, radius=radius)),
        (simple_geom.Sphere, dict(center=center, radius=radius)),
        (pdsag.ArbitraryGeometry, dict(filename=filename, precision=1e-5)),
    ]
    return inputs
Example #2
0
    def __init__(self, filename=None, geom_dict=None):
        if filename and not geom_dict:
            geom_dict = json.loads(open(filename).read())
        elif geom_dict and not filename:
            pass
        else:
            raise Exception(
                "must supply filename OR geometry dict (but not both)")

        if geom_dict['model'] == 'cylinder':
            self.model = Cylinder(base=geom_dict['base'],
                                  axis=geom_dict['axis'],
                                  radius=geom_dict['radius'])
        elif geom_dict['model'] == 'sphere':
            self.model = Sphere(center=geom_dict['center'],
                                radius=geom_dict['radius'])
        elif geom_dict['model'] == 'planar_rectangle':
            kwargs = geom_dict.copy()
            del kwargs['model']
            self.model = PlanarRectangle(**kwargs)
        elif geom_dict['model'] == 'from_file':
            import PyDisplaySurfaceArbitraryGeometry as pdsag
            import freemoovr.rosmsg2json as rosmsg2json
            self.model = pdsag.ArbitraryGeometry(
                filename=rosmsg2json.fixup_path(geom_dict['filename']),
                precision=geom_dict.get('precision', 1e-6))
        else:
            raise ValueError("unknown model type: %s" % geom_dict['model'])
Example #3
0
    def __init__(self, filename=None, geom_dict=None):
        if filename and not geom_dict:
            geom_dict = json.loads( open(filename).read() )
        elif geom_dict and not filename:
            pass
        else:
            raise Exception("must supply filename OR geometry dict (but not both)")

        if geom_dict['model']=='cylinder':
            self.model = Cylinder(base=geom_dict['base'],
                                  axis=geom_dict['axis'],
                                  radius=geom_dict['radius'])
        elif geom_dict['model']=='sphere':
            self.model = Sphere(center=geom_dict['center'],
                                radius=geom_dict['radius'])
        elif geom_dict['model']=='planar_rectangle':
            kwargs = geom_dict.copy()
            del kwargs['model']
            self.model = PlanarRectangle(**kwargs)
        elif geom_dict['model']=='from_file':
            import PyDisplaySurfaceArbitraryGeometry as pdsag
            import freemoovr.rosmsg2json as rosmsg2json
            self.model = pdsag.ArbitraryGeometry(
                filename=rosmsg2json.fixup_path( geom_dict['filename'] ),
                precision=geom_dict.get('precision',1e-6))
        else:
            raise ValueError("unknown model type: %s"%geom_dict['model'])
Example #4
0
def test_arbitrary_geom():
    filename = rosmsg2json.fixup_path( '$(find freemoovr)/data/pyramid.osg' )
    model = PyDisplaySurfaceArbitraryGeometry.ArbitraryGeometry(filename=filename,precision=1e-6)

    # Use a few special texcoords because not all in range [0,1] are
    # valid for arbitrary geometries.

    eps = 1e-5;
    tc1 = np.array( [[eps,eps],
                     [0.1, 0.1],
                     [0.2, 0.1],
                     [0.4, 0.2],
                     ] )
    wc1 = model.texcoord2worldcoord(tc1)
    tc2 = model.worldcoord2texcoord(wc1)
    wc2 = model.texcoord2worldcoord(tc2)
    assert nan_shape_allclose( tc1, tc2)
    assert nan_shape_allclose( wc1, wc2 )
Example #5
0
def test_arbitrary_geom():
    filename = rosmsg2json.fixup_path('$(find freemoovr)/data/pyramid.osg')
    model = PyDisplaySurfaceArbitraryGeometry.ArbitraryGeometry(
        filename=filename, precision=1e-6)

    # Use a few special texcoords because not all in range [0,1] are
    # valid for arbitrary geometries.

    eps = 1e-5
    tc1 = np.array([
        [eps, eps],
        [0.1, 0.1],
        [0.2, 0.1],
        [0.4, 0.2],
    ])
    wc1 = model.texcoord2worldcoord(tc1)
    tc2 = model.worldcoord2texcoord(wc1)
    wc2 = model.texcoord2worldcoord(tc2)
    assert nan_shape_allclose(tc1, tc2)
    assert nan_shape_allclose(wc1, wc2)
Example #6
0
def _get_inputs():
    # PlanarRectangle
    ll = {'x':0, 'y':0, 'z':0}
    lr = {'x':1, 'y':0, 'z':0}
    ul = {'x':0, 'y':1, 'z':0}

    # Cylinder
    base = {'x':0, 'y':0, 'z':0}
    axis = {'x':0, 'y':0, 'z':1}
    radius = 1

    # Sphere
    center = {'x':1.23, 'y':4.56, 'z':7.89}
    radius = 1

    # ArbitraryGeometry
    filename = rosmsg2json.fixup_path( '$(find freemoovr)/data/pyramid.osg' )

    inputs = [ (simple_geom.PlanarRectangle, dict(lowerleft=ll, upperleft=ul, lowerright=lr)),
               (simple_geom.Cylinder, dict(base=base, axis=axis, radius=radius)),
               (simple_geom.Sphere, dict(center=center, radius=radius)),
               (pdsag.ArbitraryGeometry, dict(filename=filename, precision=1e-5)),
               ]
    return inputs