ravens/tasks/defs_bags.py
def understand_bag_top_ring(self, env, base_pos):
        """By our circular bag design, there exists a top ring file.

        Reading it gives us several important pieces of information. We assign to:

            _top_ring_idxs: indices of the vertices (out of entire bag).
            _top_ring_posi: their starting xyz positions (BEFORE simulation
                or applying pose transformations). This way we can get the
                area of the circle. We can't take the rotated bag and map
                vertices to the xy plane, because any rotation will make the
                area artificially smaller.

        The .txt file saves in (x,y,z) order but the .obj files put z second.
        Make sure vertex indices are MONOTONICALLY INCREASING since I use
        that assumption to 'assign' vertex indices in order to targets.

        Input: base_pos, the center of the bag's sphere.
        """
        self._top_ring_f = (self._f_bag).replace('.obj', '_top_ring.txt')
        self._top_ring_f = os.path.join('ravens', self._top_ring_f)
        self._top_ring_idxs = [] # is this the same as p.getMeshData?
        self._top_ring_posi = [] # for raw, non-scaled bag
        with open(self._top_ring_f, 'r') as fh:
            for line in fh:
                ls = (line.rstrip()).split()
                vidx = int(ls[0])
                vx, vy, vz = float(ls[1]), float(ls[2]), float(ls[3])
                if len(self._top_ring_idxs) >= 1:
                    assert vidx > self._top_ring_idxs[-1], \
                            f'Wrong: {vidx} vs {self._top_ring_idxs}'
                self._top_ring_idxs.append(vidx)
                self._top_ring_posi.append((vx,vy,vz))

        # Next, define a target zone. This makes a bunch of plus signs in a
        # circular fashion from the xy projection of the ring.
        self._target_positions = []
        for item in self._top_ring_posi:
            sx, sy, _ = item
            sx = sx * self._bag_scale + base_pos[0]
            sy = sy * self._bag_scale + base_pos[1]
            self._target_positions.append( (sx,sy,0) )
            if self._targets_visible:
                square_pose = ((sx,sy,0.001), (0,0,0,1))
                square_template = 'assets/square/square-template-allsides-green.urdf'
                replace = {'DIM': (0.004,), 'HALF': (0.004 / 2,)}
                urdf = self.fill_template(square_template, replace)
                env.add_object(urdf, square_pose, fixed=True)
                os.remove(urdf)

        if self._name in ['bag-color-goal']:
            return

        # Fit a circle and print some statistics, can be used by demonstrator.
        # We should be careful to consider nonplanar cases, etc.
        xc, yc, rad, _ = U.fit_circle(self._top_ring_posi, self._bag_scale, debug=False)
        self._circle_area = np.pi * (rad ** 2)
        self._circle_center = (xc * self._bag_scale + base_pos[0],
                               yc * self._bag_scale + base_pos[1])
By our circular bag design, there exists a top ring file.

        Reading it gives us several important pieces of information. We assign to:

            _top_ring_idxs: indices of the vertices (out of entire bag).
            _top_ring_posi: their starting xyz positions (BEFORE simulation
                or applying pose transformations). This way we can get the
                area of the circle. We can't take the rotated bag and map
                vertices to the xy plane, because any rotation will make the
                area artificially smaller.

        The .txt file saves in (x,y,z) order but the .obj files put z second.
        Make sure vertex indices are MONOTONICALLY INCREASING since I use
        that assumption to 'assign' vertex indices in order to targets.

        Input: base_pos, the center of the bag's sphere.
        
By our circular bag design, there exists a top ring file.
Reading it gives us several important pieces of information. We assign to.

indices of the vertices (out of entire bag).
_top_ring_posi: their starting xyz positions (BEFORE simulation
or applying pose transformations). This way we can get the
area of the circle. We can't take the rotated bag and map
vertices to the xy plane, because any rotation will make the
area artificially smaller.

The .txt file saves in (x,y,z) order but the .obj files put z second.
Make sure vertex indices are MONOTONICALLY INCREASING since I use
that assumption to 'assign' vertex indices in order to targets.

base_pos, the center of the bag's sphere.
By our circular bag design there exists a top ring file . Reading it gives us several important pieces of information . We assign to . indices of the vertices ( out of entire bag ) . _top_ring_posi : their starting xyz positions ( BEFORE simulation or applying pose transformations ) . This way we can get the area of the circle . We can ' t take the rotated bag and map vertices to the xy plane because any rotation will make the area artificially smaller . The . txt file saves in ( x y z ) order but the . obj files put z second . Make sure vertex indices are MONOTONICALLY INCREASING since I use that assumption to ' assign ' vertex indices in order to targets . base_pos the center of the bag ' s sphere .
def understand_bag_top_ring(self, env, base_pos):
        self._top_ring_f = (self._f_bag).replace('.obj', '_top_ring.txt')
        self._top_ring_f = os.path.join('ravens', self._top_ring_f)
        self._top_ring_idxs = [] 
        self._top_ring_posi = [] 
        with open(self._top_ring_f, 'r') as fh:
            for line in fh:
                ls = (line.rstrip()).split()
                vidx = int(ls[0])
                vx, vy, vz = float(ls[1]), float(ls[2]), float(ls[3])
                if len(self._top_ring_idxs) >= 1:
                    assert vidx > self._top_ring_idxs[-1], \
                            f'Wrong: {vidx} vs {self._top_ring_idxs}'
                self._top_ring_idxs.append(vidx)
                self._top_ring_posi.append((vx,vy,vz))
        self._target_positions = []
        for item in self._top_ring_posi:
            sx, sy, _ = item
            sx = sx * self._bag_scale + base_pos[0]
            sy = sy * self._bag_scale + base_pos[1]
            self._target_positions.append( (sx,sy,0) )
            if self._targets_visible:
                square_pose = ((sx,sy,0.001), (0,0,0,1))
                square_template = 'assets/square/square-template-allsides-green.urdf'
                replace = {'DIM': (0.004,), 'HALF': (0.004 / 2,)}
                urdf = self.fill_template(square_template, replace)
                env.add_object(urdf, square_pose, fixed=True)
                os.remove(urdf)
        if self._name in ['bag-color-goal']:
            return
        xc, yc, rad, _ = U.fit_circle(self._top_ring_posi, self._bag_scale, debug=False)
        self._circle_area = np.pi * (rad ** 2)
        self._circle_center = (xc * self._bag_scale + base_pos[0],
                               yc * self._bag_scale + base_pos[1])
def understand_bag_top_ring ( self , env , base_pos ) : self . _top_ring_f = ( self . _f_bag ) . replace ( '.obj' , '_top_ring.txt' ) self . _top_ring_f = os . path . join ( 'ravens' , self . _top_ring_f ) self . _top_ring_idxs = [ ] self . _top_ring_posi = [ ] with open ( self . _top_ring_f , 'r' ) as fh : for line in fh : ls = ( line . rstrip ( ) ) . split ( ) vidx = int ( ls [ 0 ] ) vx , vy , vz = float ( ls [ 1 ] ) , float ( ls [ 2 ] ) , float ( ls [ 3 ] ) if len ( self . _top_ring_idxs ) >= 1 : assert vidx > self . _top_ring_idxs [ - 1 ] , f'Wrong: {vidx} vs {self._top_ring_idxs}' self . _top_ring_idxs . append ( vidx ) self . _top_ring_posi . append ( ( vx , vy , vz ) ) self . _target_positions = [ ] for item in self . _top_ring_posi : sx , sy , _ = item sx = sx * self . _bag_scale + base_pos [ 0 ] sy = sy * self . _bag_scale + base_pos [ 1 ] self . _target_positions . append ( ( sx , sy , 0 ) ) if self . _targets_visible : square_pose = ( ( sx , sy , 0.001 ) , ( 0 , 0 , 0 , 1 ) ) square_template = 'assets/square/square-template-allsides-green.urdf' replace = { 'DIM' : ( 0.004 , ) , 'HALF' : ( 0.004 / 2 , ) } urdf = self . fill_template ( square_template , replace ) env . add_object ( urdf , square_pose , fixed = True ) os . remove ( urdf ) if self . _name in [ 'bag-color-goal' ] : return xc , yc , rad , _ = U . fit_circle ( self . _top_ring_posi , self . _bag_scale , debug = False ) self . _circle_area = np . pi * ( rad ** 2 ) self . _circle_center = ( xc * self . _bag_scale + base_pos [ 0 ] , yc * self . _bag_scale + base_pos [ 1 ] )
By our circular bag design, there exists a top ring file.
By our circular bag design there exists a top ring file .
"""By our circular bag design, there exists a top ring file.

        Reading it gives us several important pieces of information. We assign to:

            _top_ring_idxs: indices of the vertices (out of entire bag).
            _top_ring_posi: their starting xyz positions (BEFORE simulation
                or applying pose transformations). This way we can get the
                area of the circle. We can't take the rotated bag and map
                vertices to the xy plane, because any rotation will make the
                area artificially smaller.

        The .txt file saves in (x,y,z) order but the .obj files put z second.
        Make sure vertex indices are MONOTONICALLY INCREASING since I use
        that assumption to 'assign' vertex indices in order to targets.

        Input: base_pos, the center of the bag's sphere.
        """ # is this the same as p.getMeshData? # for raw, non-scaled bag # Next, define a target zone. This makes a bunch of plus signs in a # circular fashion from the xy projection of the ring. # Fit a circle and print some statistics, can be used by demonstrator. # We should be careful to consider nonplanar cases, etc.
self
env
base_pos