Skip to content

Commit

Permalink
Fixed issues with files being read into specEditor with negative posi…
Browse files Browse the repository at this point in the history
…tions of regions.
  • Loading branch information
csalzberger committed May 7, 2012
1 parent 9758e70 commit 607f914
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 44 deletions.
86 changes: 63 additions & 23 deletions src/lib/calibrate.py
Expand Up @@ -205,27 +205,30 @@ def __init__(self, *args, **kwds):
# Keep track of which buttons are toggled
# Since we are using bitmap buttons and they can't toggle
# Also load all buttons' bitmaps and set appropriate ones
ltlmopRoot = self.GetLtlmopRoot(sys.argv[0])
if not ltlmopRoot:
print "Cannot find LTLMoP root directory. Exiting..."
self.toggleStates = {'vicon': False,
'addPoint': False,
'deletePoint': False,
'dimen': False}
self.buttonBitmaps = {'vicon': wx.Bitmap(os.path.join(os.getcwd(), \
"..\\images\\streamMarkersIcon.bmp"), wx.BITMAP_TYPE_ANY),
'viconSel': wx.Bitmap(os.path.join(os.getcwd(), \
"..\\images\\streamMarkersIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'image': wx.Bitmap(os.path.join(os.getcwd(), \
"..\\images\\importImageIcon.bmp"), wx.BITMAP_TYPE_ANY),
'addPoint': wx.Bitmap(os.path.join(os.getcwd(), \
"..\\images\\addCalibPointIcon.bmp"), wx.BITMAP_TYPE_ANY),
'addPointSel': wx.Bitmap(os.path.join(os.getcwd(), \
"..\\images\\addCalibPointIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'deletePoint': wx.Bitmap(os.path.join(os.getcwd(), \
"..\\images\\delCalibPointIcon.bmp"), wx.BITMAP_TYPE_ANY),
'deletePointSel': wx.Bitmap(os.path.join(os.getcwd(), \
"..\\images\\delCalibPointIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'dimen': wx.Bitmap(os.path.join(os.getcwd(), \
self.buttonBitmaps = {'vicon': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\streamMarkersIcon.bmp"), wx.BITMAP_TYPE_ANY),
'viconSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\streamMarkersIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'image': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\importImageIcon.bmp"), wx.BITMAP_TYPE_ANY),
'addPoint': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\addCalibPointIcon.bmp"), wx.BITMAP_TYPE_ANY),
'addPointSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\addCalibPointIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'deletePoint': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\delCalibPointIcon.bmp"), wx.BITMAP_TYPE_ANY),
'deletePointSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\delCalibPointIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'dimen': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\dimensionIcon.bmp"), wx.BITMAP_TYPE_ANY),
'dimSel': wx.Bitmap(os.path.join(os.getcwd(), \
'dimSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\dimensionIconSel.bmp"), wx.BITMAP_TYPE_ANY)}
self.toggleVicon.SetBitmapLabel(self.buttonBitmaps['vicon'])
self.buttonImage.SetBitmapLabel(self.buttonBitmaps['image'])
Expand Down Expand Up @@ -488,8 +491,10 @@ def OnToggleVicon(self, event): # wxGlade: CalibrationFrame.<event_handler>

# Switch Vicon streaming on or off based on state of toggle button
if self.toggleStates['vicon']:
self.toggleVicon.SetBitmapLabel(self.buttonBitmaps['vicon'])
self.viconListener.start()
else:
self.toggleVicon.SetBitmapLabel(self.buttonBitmaps['vicon'])
self.viconListener.stop()
# Reinitialize thread to enable restarting it
self.viconListener = ViconMarkerListener(self)
Expand All @@ -498,10 +503,23 @@ def OnButtonImage(self, event): # wxGlade: CalibrationFrame.<event_handler>
self.OnMenuLoadImage(None)

def OnToggleAddPoint(self, event): # wxGlade: CalibrationFrame.<event_handler>
self.toggleStates['addPoint'] = not self.toggleStates['addPoint']
if self.toggleStates['addPoint']:
self.toggleAddPoint.SetBitmapLabel( \
self.buttonBitmaps['addPointSel'])
else:
self.toggleAddPoint.SetBitmapLabel(self.buttonBitmaps['addPoint'])
self.ResetToggles(toggleKeep='addPoint')
# TODO: When menu items are added for add point, flip on here

def OnToggleDeletePoint(self, event): # wxGlade: CalibrationFrame.<event_handler>
self.toggleStates['deletePoint'] = not self.toggleStates['deletePoint']
if self.toggleStates['deletePoint']:
self.toggleDeletePoint.SetBitmapLabel( \
self.buttonBitmaps['deletePointSel'])
else:
self.toggleDeletePoint.SetBitmapLabel( \
self.buttonBitmaps['deletePoint'])
self.ResetToggles(toggleKeep='deletePoint')
# TODO: When menu items are added for delete point, flip on here

Expand All @@ -510,6 +528,12 @@ def OnButtonEnterPoint(self, event): # wxGlade: CalibrationFrame.<event_handler
event.Skip()

def OnToggleDimen(self, event): # wxGlade: CalibrationFrame.<event_handler>
self.toggleStates['dimen'] = not self.toggleStates['dimen']
self.menuDimen.Check(self.toggleStates['dimen'])
if self.toggleStates['dimen']:
self.toggleDimen.SetBitmapLabel(self.buttonBitmaps['dimen'])
else:
self.toggleDimen.SetBitmapLabel(self.buttonBitmaps['dimen'])
self.ResetToggles(toggleKeep='dimen')

def OnButtonSave(self, event): # wxGlade: CalibrationFrame.<event_handler>
Expand All @@ -527,7 +551,7 @@ def OnMapMouseLeftUp(self, event):
self.SnapPointMap(self.MapPix2M(ptPix))

# Creating a calibration point
if self.toggleAddPoint.GetValue() and iCalibPt == -1:
if self.toggleStates['addPoint'] and iCalibPt == -1:
# First point clicked for adding new point
if not self.newCalibPt[1]:
self.newCalibPt[0] = pt
Expand All @@ -540,7 +564,7 @@ def OnMapMouseLeftUp(self, event):
self.Redraw()

# Removing a calibration point
elif self.toggleDeletePoint.GetValue() and iCalibPt != -1:
elif self.toggleStates['deletePoint'] and iCalibPt != -1:
self.calibPoints.pop(iCalibPt)
self.Redraw()

Expand Down Expand Up @@ -588,7 +612,7 @@ def OnRefMouseLeftUp(self, event):
self.SnapPointRef(self.RefPix2M(ptPix))

# Creating a calibration point
if self.toggleAddPoint.GetValue() and iCalibPt == -1:
if self.toggleStates['addPoint'] and iCalibPt == -1:
# First point clicked for adding new point
if not self.newCalibPt[0]:
self.newCalibPt[1] = pt
Expand All @@ -601,12 +625,12 @@ def OnRefMouseLeftUp(self, event):
self.Redraw()

# Removing a calibration point
elif self.toggleDeletePoint.GetValue() and iCalibPt != -1:
elif self.toggleStates['deletePoint'] and iCalibPt != -1:
self.calibPoints.pop(iCalibPt)
self.Redraw()

# Setting scale on background image
elif self.toggleDimen.GetValue() and self.InsideBackgroundImage(pt):
elif self.toggleStates['dimen'] and self.InsideBackgroundImage(pt):
# First point on background image
if not self.dimenPoint:
self.dimenPoint = pt
Expand Down Expand Up @@ -651,8 +675,9 @@ def OnRefMouseLeftUp(self, event):
self.RedrawRef()

# Check if selecting or deselecting the background image
elif not self.toggleAddPoint.GetValue() and \
not self.toggleDeletePoint.GetValue():
elif not self.toggleStates['addPoint'] and \
not self.toggleStates['deletePoint'] and \
not self.toggleStates['dimen']:
isInImage = self.InsideBackgroundImage(pt)
# Selecting background image
if (not event.CmdDown() or not self.backgroundIsSelected) and \
Expand Down Expand Up @@ -1223,6 +1248,21 @@ def ProjPtOnLine(self, pt, p0, p1):
v = pt - p0 # Vector to point to project
u = (v.Dot(s) / s.Dot(s)) * s # Projected vector
return p0 + u # Map back to global coordinates

def GetLtlmopRoot(self, thisFile):
"""Return a string of the absolute path to the project root directory.
thisFile - String with the path to this file, should be found using
sys.argv[0]
"""
p = os.path.abspath(thisFile)
t = ""
while t != "src":
(p, t) = os.path.split(p)
if p == "":
return None

return os.path.join(p, "src")
# end of class CalibrationFrame


Expand Down
10 changes: 7 additions & 3 deletions src/lib/regions.py
Expand Up @@ -319,7 +319,9 @@ def recalcAdjacency(self):
def getBoundingBox(self):
if self.regions == []:
return None


p = self.regions[0]

leftMargin = min([pt.x for region in self.regions for pt in region.getPoints()])
topMargin = min([pt.y for region in self.regions for pt in region.getPoints()])
rightExtent = max([pt.x for region in self.regions for pt in region.getPoints()]) - leftMargin
Expand Down Expand Up @@ -455,8 +457,8 @@ def readFile(self, filename):
for i in range(2, len(transData), 2):
ip1 = int(transData[i])
ip2 = int(transData[i % len(self.regions[region1].pointArray)])
p1 = self.regions[region1].pointArray(ip1)
p2 = self.regions[region1].pointArray(ip2)
p1 = self.regions[region1].pointArray[ip1]
p2 = self.regions[region1].pointArray[ip2]
faces.append(tuple(sorted((p1, p2))))

# Don't assume bidirectional transitions
Expand Down Expand Up @@ -531,6 +533,8 @@ def convertRegionDataNewToOld(self, rd, offsets):
rdnew['points'] = points
rdnew['holeList'] = holeList
xOff, yOff = offsets
xOff = int(xOff * 1000)
yOff = int(yOff * 1000)
rdnew['position'] = (leftMargin + xOff, topMargin + yOff)
rdnew['size'] = (rightExtent, downExtent)

Expand Down
55 changes: 37 additions & 18 deletions src/regionEditor.py
Expand Up @@ -152,36 +152,39 @@ def __init__(self, *args, **kwds):
# Keep track of which buttons are toggled
# Since we are using bitmap buttons and they can't toggle
# Also load all buttons' bitmaps and set appropriate ones
ltlmopRoot = self.GetLtlmopRoot(sys.argv[0])
if not ltlmopRoot:
print "Cannot find LTLMoP root directory. Exiting..."
self.toggleStates = {'vicon': False,
'square': False,
'poly': False,
'dim': False,
'feedback': False}
self.buttonBitmaps = {'vicon': wx.Bitmap(os.path.join(os.getcwd(), \
self.buttonBitmaps = {'vicon': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\streamMarkersIcon.bmp"), wx.BITMAP_TYPE_ANY),
'viconSel': wx.Bitmap(os.path.join(os.getcwd(), \
'viconSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\streamMarkersIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'image': wx.Bitmap(os.path.join(os.getcwd(), \
'image': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\importImageIcon.bmp"), wx.BITMAP_TYPE_ANY),
'square': wx.Bitmap(os.path.join(os.getcwd(), \
'square': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\rectIcon.bmp"), wx.BITMAP_TYPE_ANY),
'squareSel': wx.Bitmap(os.path.join(os.getcwd(), \
'squareSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\rectIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'poly': wx.Bitmap(os.path.join(os.getcwd(), \
'poly': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\polyIcon.bmp"), wx.BITMAP_TYPE_ANY),
'polySel': wx.Bitmap(os.path.join(os.getcwd(), \
'polySel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\polyIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'dim': wx.Bitmap(os.path.join(os.getcwd(), \
'dim': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\dimensionIcon.bmp"), wx.BITMAP_TYPE_ANY),
'dimSel': wx.Bitmap(os.path.join(os.getcwd(), \
'dimSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\dimensionIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'autobound': wx.Bitmap(os.path.join(os.getcwd(), \
'autobound': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\autoboundaryIcon.bmp"), wx.BITMAP_TYPE_ANY),
'feedback': wx.Bitmap(os.path.join(os.getcwd(), \
'feedback': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\audioFeedbackIcon.bmp"), wx.BITMAP_TYPE_ANY),
'feedbackSel': wx.Bitmap(os.path.join(os.getcwd(), \
'feedbackSel': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\audioFeedbackIconSel.bmp"), wx.BITMAP_TYPE_ANY),
'cal': wx.Bitmap(os.path.join(os.getcwd(), \
'cal': wx.Bitmap(os.path.join(ltlmopRoot, \
"images\\calibPointIcon.bmp"), wx.BITMAP_TYPE_ANY)}
self.toggleVicon.SetBitmapLabel(self.buttonBitmaps['vicon'])
self.buttonImage.SetBitmapLabel(self.buttonBitmaps['image'])
Expand Down Expand Up @@ -267,7 +270,7 @@ def __init__(self, *args, **kwds):
self.Bind(wx.EVT_CLOSE, self.OnClose)

# Display the GUI window and set up the map canvas
if self.fileName:
if self.fileName and os.path.exists(self.fileName):
self.ReadFile(self.fileName)
self.Show()
self.RedrawCanvas()
Expand Down Expand Up @@ -490,6 +493,7 @@ def OnMenuSave(self, event): # wxGlade: regionEditor.<event_handler>
for face in faces:
singleTrans += "(" + str(face[0]) + "\t" + \
str(face[1]) + ")"
singleTrans += "]"
transitionData.append(singleTrans)

obstacleRegions = [r.name for r in self.regions if r.isObstacle]
Expand Down Expand Up @@ -1452,10 +1456,10 @@ def ReadFile(self, filePath):
for tData in data["Transitions"]:
tData = re.sub('[\[\]\(\)]', '', tData)
tData = tData.split(); # Separate on any whitespace
iReg1 = self.indexOfRegionWithName(tData[0])
iReg2 = self.indexOfRegionWithName(tData[1])
iReg1 = self.IndexOfRegionWithName(tData[0])
iReg2 = self.IndexOfRegionWithName(tData[1])
# All transitions between regions
for i in range(2, len(transData), 2):
for i in range(2, len(tData), 2):
iFaceReg1 = int(tData[i])
iFaceReg2 = int(tData[i+1])
self.adjacent[iReg1][iReg2].append((iFaceReg1, iFaceReg2))
Expand Down Expand Up @@ -2035,7 +2039,22 @@ def ProjPtOnLine(self, pt, p0, p1):
v = pt - p0 # Vector to point to project
u = (v.Dot(s) / s.Dot(s)) * s # Projected vector
return p0 + u # Map back to global coordinates
# end of class RegionEditor

def GetLtlmopRoot(self, thisFile):
"""Return a string of the absolute path to the project root directory.
thisFile - String with the path to this file, should be found using
sys.argv[0]
"""
p = os.path.abspath(thisFile)
t = ""
while t != "src":
(p, t) = os.path.split(p)
if p == "":
return None

return os.path.join(p, "src")
# end of class RegionEditor


class FeedbackDialog(wx.Dialog):
Expand Down

0 comments on commit 607f914

Please sign in to comment.