Пример #1
0
    def __init__(self, track=lk_track.TrackLK):
        super(Position, self).__init__(track)
        self.rotation = Rotation.Rotation(track)
        self.translation = Translation.Translation(self.rotation.GetRad(),
                                                   track)

        self.rotationSum = 0
        self.pathLen = 0
        self.location = [0, 0]
        self.loc = []
        self.trackP = track
        self.heading = 0
        self.trans = 0.059

        self.flag = 1
        self.timer = QtCore.QTimer(QtCore.QThread())
Пример #2
0
    def interpretParameters(self):
        params = self.params

        # CHECK IF THE CELL CONTAINS A LATTICE
        self.hasLAT = False
        if (params.has_key('LAT')):
            # a cell containing a LAT also needs to have a FILL parameter
            if (params.has_key('FILL') or params.has_key('*FILL')):
                self.hasLAT = True
                self.typeLAT = int(params['LAT'])

                if ((self.typeLAT == 1) or (self.typeLAT == 2)):
                    # the cell describes a rectangular (square) lattice comprised of hexehedra
                    ranges = re.match(
                        '[ ]*[-]?[\d]+[:]{1}[\d]+[ ]+[-]?[\d]+[:]{1}[\d]+[ ]+[-]?[\d]+[:]{1}[\d]+[ ]+',
                        params['FILL'][:100])
                    if (ranges):
                        # parse the fully specified boundaries of the lattice
                        rangesItems = re.findall('[-]?[\d]+', ranges.group(0))
                        if (len(rangesItems) == 6):
                            self.minI = int(rangesItems[0])
                            self.maxI = int(rangesItems[1])
                            self.minJ = int(rangesItems[2])
                            self.maxJ = int(rangesItems[3])
                            self.minK = int(rangesItems[4])
                            self.maxK = int(rangesItems[5])
                        else:
                            raise (Exception(
                                "ERROR (Parse Cell " + str(self.number) +
                                "): Problem reading fill boundary parameters, too little args in cell "
                                + str(self.number)))

                        # parse the universes of the lattice
                        latUniverses = re.split(
                            '[\s]+', params['FILL'][len(ranges.group(0)):])
                        container.Container.remove_values_from_list(
                            latUniverses, '')
                        # check for parameters in lattice universes
                        # for example 200 10R (repeat 200 ten times)
                        latUniversesNew = []
                        for i in range(0, len(latUniverses)):
                            if (
                                    latUniverses[i][len(latUniverses[i]) - 1]
                                    == 'R'
                                    or latUniverses[i][len(latUniverses[i]) -
                                                       1] == 'r'
                            ):  #re.match('R$',latUniverses[i], flags=re.IGNORECASE)):
                                previousElement = latUniversesNew[
                                    len(latUniversesNew) - 1]
                                elements = int(
                                    latUniverses[i][:len(latUniverses[i]) - 1])
                                for x in range(0, elements):
                                    latUniversesNew.append(previousElement)
                            else:
                                latUniversesNew.append(latUniverses[i])
                        self.latUniverses = latUniversesNew
                    else:
                        #print "ERROR (Cell " + str(self.number) + "): no fully specified fill found in cell " + str(self.number) + " [CellCard::interpretParameters]"
                        raise (Exception(
                            "ERROR (Parse Cell " + str(self.number) +
                            "): No fully specified fill found in cell " +
                            str(self.number)))
                else:
                    raise (Exception("ERROR (Parse Cell " + str(self.number) +
                                     "): Cell " + str(self.number) +
                                     " contains a LAT with unknown type " +
                                     str(self.typeLAT)))
            else:
                raise (Exception("ERROR (Parse Cell " + str(self.number) +
                                 "): Cell " + str(self.number) +
                                 " contains LAT, but no FILL"))
                print
                return 0
        elif (params.has_key('FILL') or params.has_key('*FILL')):
            if (not self.hasLAT):
                if params.has_key('FILL'):
                    fill = params['FILL']
                else:
                    fill = params['*FILL']

                # get all the items between the brackets (these are the transform parameters)
                transformParams = re.findall('(?<=\()[\d,\D,\s]+(?=\))', fill)
                self.fillUniverse = int(re.split('[\(,\[]+', fill)[0])

                # if there is a transformation, parse the transformation data and put it in a Transformation object
                if (len(transformParams) >= 1):
                    # split the transform parameters and remove empty items
                    transformParamsItems = re.split('[\s]+',
                                                    transformParams[0])
                    container.Container.remove_values_from_list(
                        transformParamsItems, '')

                    # check if there is a translation defined on the fill parameters
                    if (len(transformParamsItems) >= 3):
                        self.universeTranslation = Translation.Translation(
                            transformParamsItems[0], transformParamsItems[1],
                            transformParamsItems[2])

                    # check if there is a rotation defined on the fill parameters
                    if (len(transformParamsItems) >= 12):
                        if (params.has_key('*FILL')):
                            for i in range(3, len(transformParamsItems)):
                                transformParamsItems[i] = math.cos(
                                    float(transformParamsItems[i]) * math.pi /
                                    180.0)
                        self.universeRotation = Rotation.Rotation(
                            transformParamsItems[3], transformParamsItems[4],
                            transformParamsItems[5], transformParamsItems[6],
                            transformParamsItems[7], transformParamsItems[8],
                            transformParamsItems[9], transformParamsItems[10],
                            transformParamsItems[11])

        if (params.has_key('TRCL')):
            trcl = params['TRCL']
            transformParams = re.findall('(?<=\()[\d,\D,\s]+(?=\))', trcl)
            if (len(transformParams) >= 1):
                transformParamsItems = re.split('[\s]+', transformParams[0])

                # check if there is a translation defined on the fill parameters
                if (len(transformParamsItems) >= 3):
                    self.translation = Translation.Translation(
                        transformParamsItems[0], transformParamsItems[1],
                        transformParamsItems[2])

                # check if there is a rotation defined on the fill parameters
                if (len(transformParamsItems) >= 12):
                    self.rotation = Rotation.Rotation(
                        transformParamsItems[3], transformParamsItems[4],
                        transformParamsItems[5], transformParamsItems[6],
                        transformParamsItems[7], transformParamsItems[8],
                        transformParamsItems[9], transformParamsItems[10],
                        transformParamsItems[11])

        elif (params.has_key('*TRCL')):
            trcl = params['*TRCL']
            transformParams = re.findall('(?<=\()[\d,\D,\s]+(?=\))', trcl)
            if (len(transformParams) >= 1):
                transformParamsItems = re.split('[\s]+', transformParams[0])

                # check if there is a translation defined on the fill parameters
                if (len(transformParamsItems) >= 3):
                    self.translation = Translation.Translation(
                        transformParamsItems[0], transformParamsItems[1],
                        transformParamsItems[2])

                # check if there is a rotation defined on the fill parameters
                if (len(transformParamsItems) >= 12):
                    for i in range(3, len(transformParamsItems)):
                        transformParamsItems[i] = math.cos(
                            float(transformParamsItems[i]) * math.pi / 180.0)
                    self.rotation = Rotation.Rotation(
                        transformParamsItems[3], transformParamsItems[4],
                        transformParamsItems[5], transformParamsItems[6],
                        transformParamsItems[7], transformParamsItems[8],
                        transformParamsItems[9], transformParamsItems[10],
                        transformParamsItems[11])
        return 1
Пример #3
0
    def processContent(self):
        if self.filetype == "ON":
            # Kick the useless first entry
            for a in range(1,len(self.rawcontent)):
                # Kick useless empty lines
                if self.rawcontent[a] != "" and "#begin" not in self.rawcontent[a] and "#end" not in self.rawcontent[a]:
                    splitLine = self.rawcontent[a].split()
                    # Pick out the juicy bits
                    dummy_lemma = Lemma.Lemma(int(splitLine[1]), int(splitLine[2]), str(splitLine[3]).lower(), str(splitLine[4]), str(splitLine[6]).lower(), str(splitLine[8]))
                    self.procontent.append(dummy_lemma)
        if self.filetype == "IN":
            # Kick the useless first 29 entries
            for a in range(29,len(self.rawcontent)):
                # Kick useless empty lines
                if self.rawcontent[a] != "":
                    splitLine = self.rawcontent[a].split()
                    # Pick out the juicy bits
                    dummy_list_of_senses = []
                    # Check for multiple senses
                    for b in range(6,len(splitLine)):
                        if len(splitLine[b]) > 3:
                            dummy_list_of_senses.append(splitLine[b])
                    # Putting juicy bits together
                    dummy_translation = Translation.Translation(str(splitLine[0]), str(splitLine[1]), dummy_list_of_senses)
                    self.procontent.append(dummy_translation)
        if self.filetype == "FW":
            # Kick the useless first 25 entries
            for a in range(25,len(self.rawcontent)):
                # Kick useless empty lines
                if self.rawcontent[a] != "" and "//" not in self.rawcontent[a]:
                    # Check for multiple examples
                    splitLine = self.rawcontent[a].split(", ")
                    dummy_functionWords = []
                    # Take all examples
                    for b in range(len(splitLine)):
                        # Kick constructions of multiple words
                        if " " not in splitLine[b]:
                            self.procontent.append(splitLine[b])
        if self.filetype == "TL":
            dummy_senselists = []
            dummy_switch = False
            # Get the info from filename back
            dir = os.path.realpath(__file__)
            dummy_string = self.filename.replace("\\".join(dir.split("\\")[:-1])+"\\Translation\\","").replace(".xml","")
            dummy_word_and_type = dummy_string.split("-")

            for a in range(0,len(self.rawcontent)):
                # Look out for juicy bits
                #
                # The following part is NSFW
                #
                # This is a dummy in case the file just wanted to put info in a new line
                
                if dummy_switch == True:
                    
                    dummy_string = self.rawcontent[a]
                    # This is in case the file wanted to add an additional empty line
                    if dummy_string != "":
                        # Yes, there are files with additional info instead
                        if "<wn lemma" not in dummy_string and dummy_string != "-" and "<omega" not in dummy_string:
                            splitLine = dummy_string.split(" ")
                            dummy_list = []
                            for b in range(len(splitLine)):
                                try:
                                    dummy_list.append(int(splitLine[b]))
                                # It is 3am , now I stop to care and start to botch
                                except ValueError:
                                    dummy_splitLine = splitLine[0].split(",")
                                    dummy_list.append(int(dummy_splitLine[b]))
                            dummy_senselists.append(dummy_list)
                            #print dummy_senselists
                        elif dummy_string != "-":
                            dummy_senselists.append([0])
                            #print dummy_senselists
                        # This is not the normal format either    
                        else:
                            # Kick useless stuff
                            dummy_splitLine1 = dummy_string.split("version=\"3.0\">")
                            dummy_splitLine2 = dummy_splitLine1[-1].split("</wn>")
                            splitLine = dummy_splitLine2[0].split(",")
                            if splitLine[0] != "" and splitLine[0] != "-":
                                dummy_list = []
                                for b in range(len(splitLine)):
                                        dummy_list.append(int(splitLine[b]))
                                dummy_senselists.append(dummy_list)
                                #print dummy_senselists
                        ###    elif splitLine[0] == "-":
                        ###        dummy_senselists.append([0])
                            else: 
                                dummy_senselists.append([0])
                                #print dummy_senselists
                        dummy_switch = False
                # That is the normal format I would say. Not sure though.
                if "<wn version=\"3.0\">" in self.rawcontent[a]:
                    # Kick the useless stuff around juicy bit
                    dummy_string = self.rawcontent[a].replace("<wn version=\"3.0\">","").replace("</wn>","").replace("<omega/>","")
                    splitLine = dummy_string.split(",")
                    if splitLine[0] != "" and splitLine[0] != "NM":
                        dummy_list = []
                        for b in range(len(splitLine)):
                            if "." in splitLine[b]:
                                dummy_list.append(int(splitLine[b].split(".")[0]))
                            else:
                                dummy_list.append(int(splitLine[b]))
                        dummy_senselists.append(dummy_list)
                        #print dummy_senselists
                    elif splitLine[0] == "NM":
                        dummy_senselists.append([0])
                        #print dummy_senselists
                    else:
                        dummy_switch = True
                if "<wn version=\"1.7\">" in self.rawcontent[a]:
                    # Blub
                    dummy_string = self.rawcontent[a].replace("<wn version=\"1.7\">","").replace("</wn>","").replace("<omega/>","")
                    splitLine = dummy_string.split(",")
                    if splitLine[0] != "" and splitLine[0] != "NM" and splitLine[0] != "?":
                        dummy_list = []
                        for b in range(len(splitLine)):
                            if "." in splitLine[b]:
                                dummy_list.append(int(splitLine[b].split(".")[0]))
                            else:
                                dummy_list.append(int(splitLine[b]))
                        dummy_senselists.append(dummy_list)
                        #print dummy_senselists
                    elif splitLine[0] == "NM" or splitLine[0] == "?" or splitLine[0] == "-":
                        dummy_senselists.append([0])
                        #print dummy_senselists
                    else:
                        dummy_switch = True
                # By now, anything could happen in these lines
                if "<wn version=\"2.0\">" in self.rawcontent[a] and "</wn>" in self.rawcontent[a]:
                    dummy_list = []
                    dummy_string = self.rawcontent[a]
                    dummy_splitLine1 = dummy_string.split("version=\"2.0\">")
                    dummy_splitLine2 = dummy_splitLine1[-1].split("</wn>")
                    dummy_splitLine3 = dummy_splitLine2[0].split(",")
                    splitLine = dummy_splitLine3[0].split(" ")
                    if splitLine[0] != "" and splitLine[0] != "-" and splitLine[0] != "Placeholder":
                        dummy_list = []
                        for b in range(len(splitLine)):
                            try:
                                dummy_list.append(int(splitLine[b]))
                            except ValueError:
                                print self.rawcontent[a]
                                print self.filename
                        dummy_senselists.append(dummy_list)
                        #print dummy_senselists
                    else: 
                        dummy_senselists.append([0])
                        #print dummy_senselists
                if "<wn version=\"2.0\">" in self.rawcontent[a] and "</wn>" not in self.rawcontent[a]:
                    dummy_switch = True
            dummy_translator = Translator.Translator(dummy_word_and_type[0],dummy_word_and_type[1],dummy_senselists)
            self.procontent.append(dummy_translator)
Пример #4
0
from Hamilton import *
from Rotation import *
from Translation import *

H = Hamilton()
R = Rotation()
T = Translation()


class Desired:
    @staticmethod
    def quaternion(p, o, a):
        z = np.array([1, 0, 0, 0, 0, 0.5 * p[0], 0.5 * p[1], 0.5 * p[2]])
        if a == 'X' or a == 'x' or a == 88 or a == 120:
            z = H.left(z).dot(R.x(o))
        elif a == 'Y' or a == 'y' or a == 89 or a == 121:
            z = H.left(z).dot(R.y(o))
        elif a == 'Z' or a == 'z' or a == 90 or a == 122:
            z = H.left(z).dot(R.z(o))
        return z