예제 #1
0
  def transformation_matrix(self,cmd):
    '''
    transformation_matrix

    '''
    from PyRatBox import PyRatBox
    from PyRatClone import PyRatClone
    try:
      matrix = self.matrix
    except:
      matrix = np.matrix(np.eye(3))
    try:
      offset = self.offset
    except:
      offset = np.zeros(3)

    try:
      try:
        this = cmd.split[1:]
      except:
        this = cmd[1:]
      clone = PyRatClone(np.ones(3),np.ones(3))
      for i,n in enumerate(this):
        noGood = False
        if n == 'scale':
          scale = float(this[i+1])
          matrix2,offset2 = self.load_scaling_matrix4(scale)        
        elif n == 'transformation_matrix':
          matrix2,offset2 = np.matrix(np.array(this[i+1:i+1+9])\
                                      .reshape((3,3)).astype(float))
        elif n == 'scale_differential':
          fix_point = np.array(this[i+1:i+1+3]).astype(float)
          matrix2,offset2 = self.load_differential_scaling_matrix4(fix_point)  
        elif n == 'translate':
          offset3 = np.array(this[i+1:i+1+3]).astype(float)
          matrix2,offset2 = self.load_translation_matrix4(offset3)
        elif n == 'rotate_about_x_axis':
          rot = float(this[i+1])
          matrix2,offset2 = self.load_x_axis_rotation_matrix4(rot)
        elif n == 'rotate_about_y_axis':
          rot = float(this[i+1])
          matrix2,offset2 = self.load_y_axis_rotation_matrix4(rot)
        elif n == 'rotate_about_z_axis':
          rot = float(this[i+1])
          matrix2,offset2 = self.load_z_axis_rotation_matrix4(rot)
        elif n == 'rotate_about_arbitrary_axis':
          axis = np.array(this[i+1:i+1+3]).astype(float)
          rot = float(this[i+3])
          fix_point = np.array(this[i+4:i+4+3]).astype(float)
          matrix2,offset2 = self.rotate_about_arbitrary_axis(axis,rot,fix_point)
        elif n == 'scale_fix_point':
          scale = float(this[i+1])
          fix_point = np.array(this[i+2:i+2+3]).astype(float)
          matrix2,offset2 = self.load_scaling_fix_point_matrix4(scale,fix_point)
        elif n == 'scale_differential_fix_point':
          scale = np.array(this[i+1:i+1+3]).astype(float)
          fix_point = np.array(this[i+3:i+3+3]).astype(float)
          matrix2,offset2 = self.load_differential_scaling_fix_point_matrix4(\
                                    scale,fix_point)
        elif n == 'rotate_about_x_axis_fix_point':
          rot = float(this[i+1])
          fix_point = np.array(this[i+2:i+2+3]).astype(float)
          matrix2,offset2 = self.load_x_axis_rotation_fix_point_matrix4(\
                                     theta,fix_point)
        elif n == 'rotate_about_y_axis_fix_point':
          rot = float(this[i+1])
          fix_point = np.array(this[i+2:i+2+3]).astype(float)
          matrix2,offset2 = self.load_y_axis_rotation_fix_point_matrix4(\
                                     theta,fix_point)
        elif n == 'rotate_about_z_axis_fix_point':
          rot = float(this[i+1])
          fix_point = np.array(this[i+2:i+2+3]).astype(float)
          matrix2,offset2 = self.load_z_axis_rotation_fix_point_matrix4(\
                                     theta,fix_point)
        else:
          noGood = True
        if not noGood:
          clone.matrix = matrix2*matrix
          clone.matrixI = clone.matrix.I
          
      if (matrix != np.matrix(np.eye(3))).all():
        clone.matrix = matrix
      if np.abs(offset).sum() > 0:
        clone.offset = offset
      clone.contents = []

      self.top.contents.append(clone)
      self.verbose == 2 and sys.stderr.write('<M>')
    except:
      self.error('could not interpret clone line %d of %s: %s'%\
                (self.lineNumber,self.filename,' '.join(cmd)))
예제 #2
0
    def transformation_matrix(self, cmd):
        '''
    transformation_matrix

    '''
        from PyRatBox import PyRatBox
        from PyRatClone import PyRatClone
        try:
            matrix = self.matrix
        except:
            matrix = np.matrix(np.eye(3))
        try:
            offset = self.offset
        except:
            offset = np.zeros(3)

        try:
            try:
                this = cmd.split[1:]
            except:
                this = cmd[1:]
            clone = PyRatClone(np.ones(3), np.ones(3))
            for i, n in enumerate(this):
                noGood = False
                if n == 'scale':
                    scale = float(this[i + 1])
                    matrix2, offset2 = self.load_scaling_matrix4(scale)
                elif n == 'transformation_matrix':
                    matrix2,offset2 = np.matrix(np.array(this[i+1:i+1+9])\
                                                .reshape((3,3)).astype(float))
                elif n == 'scale_differential':
                    fix_point = np.array(this[i + 1:i + 1 + 3]).astype(float)
                    matrix2, offset2 = self.load_differential_scaling_matrix4(
                        fix_point)
                elif n == 'translate':
                    offset3 = np.array(this[i + 1:i + 1 + 3]).astype(float)
                    matrix2, offset2 = self.load_translation_matrix4(offset3)
                elif n == 'rotate_about_x_axis':
                    rot = float(this[i + 1])
                    matrix2, offset2 = self.load_x_axis_rotation_matrix4(rot)
                elif n == 'rotate_about_y_axis':
                    rot = float(this[i + 1])
                    matrix2, offset2 = self.load_y_axis_rotation_matrix4(rot)
                elif n == 'rotate_about_z_axis':
                    rot = float(this[i + 1])
                    matrix2, offset2 = self.load_z_axis_rotation_matrix4(rot)
                elif n == 'rotate_about_arbitrary_axis':
                    axis = np.array(this[i + 1:i + 1 + 3]).astype(float)
                    rot = float(this[i + 3])
                    fix_point = np.array(this[i + 4:i + 4 + 3]).astype(float)
                    matrix2, offset2 = self.rotate_about_arbitrary_axis(
                        axis, rot, fix_point)
                elif n == 'scale_fix_point':
                    scale = float(this[i + 1])
                    fix_point = np.array(this[i + 2:i + 2 + 3]).astype(float)
                    matrix2, offset2 = self.load_scaling_fix_point_matrix4(
                        scale, fix_point)
                elif n == 'scale_differential_fix_point':
                    scale = np.array(this[i + 1:i + 1 + 3]).astype(float)
                    fix_point = np.array(this[i + 3:i + 3 + 3]).astype(float)
                    matrix2,offset2 = self.load_differential_scaling_fix_point_matrix4(\
                                              scale,fix_point)
                elif n == 'rotate_about_x_axis_fix_point':
                    rot = float(this[i + 1])
                    fix_point = np.array(this[i + 2:i + 2 + 3]).astype(float)
                    matrix2,offset2 = self.load_x_axis_rotation_fix_point_matrix4(\
                                               theta,fix_point)
                elif n == 'rotate_about_y_axis_fix_point':
                    rot = float(this[i + 1])
                    fix_point = np.array(this[i + 2:i + 2 + 3]).astype(float)
                    matrix2,offset2 = self.load_y_axis_rotation_fix_point_matrix4(\
                                               theta,fix_point)
                elif n == 'rotate_about_z_axis_fix_point':
                    rot = float(this[i + 1])
                    fix_point = np.array(this[i + 2:i + 2 + 3]).astype(float)
                    matrix2,offset2 = self.load_z_axis_rotation_fix_point_matrix4(\
                                               theta,fix_point)
                else:
                    noGood = True
                if not noGood:
                    clone.matrix = matrix2 * matrix
                    clone.matrixI = clone.matrix.I

            if (matrix != np.matrix(np.eye(3))).all():
                clone.matrix = matrix
            if np.abs(offset).sum() > 0:
                clone.offset = offset
            clone.contents = []

            self.top.contents.append(clone)
            self.verbose == 2 and sys.stderr.write('<M>')
        except:
            self.error('could not interpret clone line %d of %s: %s'%\
                      (self.lineNumber,self.filename,' '.join(cmd)))
예제 #3
0
  def clone(self,cmd):
    '''
    clone

    clone dx dy dz [Rz] name
    '''
    from PyRatBox import PyRatBox
    from PyRatClone import PyRatClone
    try:
      try:
        this = cmd.split[1:]
      except:
        this = cmd[1:]
      # look up groups
      try:
        offset = np.array(this[:3]).astype(float)
        this = cmd[4:]
      except:
        offset = np.zeros(3)
        
      thisGroup = None
      thisGroupName = None
      matrix = np.matrix(np.eye(3))
      done = np.zeros_like(np.array(this)).astype(bool)
      for i in xrange(len(this)):
        if not done[i]:
          if this[i] == 'Rx':
            theta = float(this[i+1])*np.pi/180.
            done[i:i+2] = True
            if theta != 0:
              c = np.cos(theta)
              s = np.sin(theta)
              m = np.eye(3)
              m[1,1] = m[2,2] = c
              m[2,1] = s
              m[1,2] = -s
              matrix = matrix * np.matrix(m)
          elif this[i] == 'Ry':
            theta = float(this[i+1])*np.pi/180.
            done[i:i+2] = True
            if theta != 0:
              c = np.cos(theta)
              s = np.sin(theta)
              m = np.eye(3)
              m[2,2] = m[0,0] = c
              m[0,2] = s
              m[2,0] = -s
              matrix = matrix * np.matrix(m)
          elif this[i] == 'Rz':
            theta = float(this[i+1])*np.pi/180.
            done[i:i+2] = True
            if theta != 0:
              c = np.cos(theta)
              s = np.sin(theta)
              m = np.eye(3)
              m[0,0] = m[1,1] = c
              m[0,1] = -s
              m[1,0] = s
              matrix = matrix * np.matrix(m)
          elif this[i] == 'Transform':
          # arbitrary 3 x 3 rotation
            m = \
               np.matrix(np.array(this[i+1:i+9+1]).astype(float).reshape((3,3)))
            done[i+1:i+9+1] = True  
            matrix = matrix * np.matrix(m)
          else:
            # maybe its a grp name
            possible = ' '.join(this[i:])
            try:
              thisGroup = self.group[possible] 
              thisGroupName = possible
              done[:] = True
            except:
              # maybe its a z rotation
              try:
                theta = float(this[i])*np.pi/180.
                done[i] = True
                if theta != 0:
                  c = np.cos(theta)
                  s = np.sin(theta)
                  m = np.eye(3)
                  m[0,0] = m[1,1] = c
                  m[0,1] = -s
                  m[1,0] = s
                  matrix = matrix * np.matrix(m)
              except:
                pass
      # NB dummy extent at this point        
      clone = PyRatClone(np.zeros(3),None)
      clone.empty = False
      clone.invisible = True
      if (matrix != np.matrix(np.eye(3))).any():
        clone.matrix = matrix
      clone.thisGroup = thisGroup
      clone.thisGroupName = thisGroupName
      if np.abs(offset).sum() > 0:
        clone.offset = offset
      clone.contents = [clone.thisGroup]
      self.top.contents.append(clone)
      self.verbose == 2 and sys.stderr.write('<Clone %s>'%thisGroupName)      
    except:
      self.error('could not interpret clone line %d of %s: %s'%\
                (self.lineNumber,self.filename,' '.join(cmd)))
예제 #4
0
    def clone(self, cmd):
        '''
    clone

    clone dx dy dz [Rz] name
    '''
        from PyRatBox import PyRatBox
        from PyRatClone import PyRatClone
        try:
            try:
                this = cmd.split[1:]
            except:
                this = cmd[1:]
            # look up groups
            try:
                offset = np.array(this[:3]).astype(float)
                this = cmd[4:]
            except:
                offset = np.zeros(3)

            thisGroup = None
            thisGroupName = None
            matrix = np.matrix(np.eye(3))
            done = np.zeros_like(np.array(this)).astype(bool)
            for i in xrange(len(this)):
                if not done[i]:
                    if this[i] == 'Rx':
                        theta = float(this[i + 1]) * np.pi / 180.
                        done[i:i + 2] = True
                        if theta != 0:
                            c = np.cos(theta)
                            s = np.sin(theta)
                            m = np.eye(3)
                            m[1, 1] = m[2, 2] = c
                            m[2, 1] = s
                            m[1, 2] = -s
                            matrix = matrix * np.matrix(m)
                    elif this[i] == 'Ry':
                        theta = float(this[i + 1]) * np.pi / 180.
                        done[i:i + 2] = True
                        if theta != 0:
                            c = np.cos(theta)
                            s = np.sin(theta)
                            m = np.eye(3)
                            m[2, 2] = m[0, 0] = c
                            m[0, 2] = s
                            m[2, 0] = -s
                            matrix = matrix * np.matrix(m)
                    elif this[i] == 'Rz':
                        theta = float(this[i + 1]) * np.pi / 180.
                        done[i:i + 2] = True
                        if theta != 0:
                            c = np.cos(theta)
                            s = np.sin(theta)
                            m = np.eye(3)
                            m[0, 0] = m[1, 1] = c
                            m[0, 1] = -s
                            m[1, 0] = s
                            matrix = matrix * np.matrix(m)
                    elif this[i] == 'Transform':
                        # arbitrary 3 x 3 rotation
                        m = \
                           np.matrix(np.array(this[i+1:i+9+1]).astype(float).reshape((3,3)))
                        done[i + 1:i + 9 + 1] = True
                        matrix = matrix * np.matrix(m)
                    else:
                        # maybe its a grp name
                        possible = ' '.join(this[i:])
                        try:
                            thisGroup = self.group[possible]
                            thisGroupName = possible
                            done[:] = True
                        except:
                            # maybe its a z rotation
                            try:
                                theta = float(this[i]) * np.pi / 180.
                                done[i] = True
                                if theta != 0:
                                    c = np.cos(theta)
                                    s = np.sin(theta)
                                    m = np.eye(3)
                                    m[0, 0] = m[1, 1] = c
                                    m[0, 1] = -s
                                    m[1, 0] = s
                                    matrix = matrix * np.matrix(m)
                            except:
                                pass
            # NB dummy extent at this point
            clone = PyRatClone(np.zeros(3), None)
            clone.empty = False
            clone.invisible = True
            if (matrix != np.matrix(np.eye(3))).any():
                clone.matrix = matrix
            clone.thisGroup = thisGroup
            clone.thisGroupName = thisGroupName
            if np.abs(offset).sum() > 0:
                clone.offset = offset
            clone.contents = [clone.thisGroup]
            self.top.contents.append(clone)
            self.verbose == 2 and sys.stderr.write(
                '<Clone %s>' % thisGroupName)
        except:
            self.error('could not interpret clone line %d of %s: %s'%\
                      (self.lineNumber,self.filename,' '.join(cmd)))