Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved debugging; fixed errors in warped quad tree tile generation

  • Loading branch information...
commit 35821fbf23b84ee2fa4b48c6d6706962c29a6b86 1 parent f11eb2a
Trey Smith trey0 authored
20 geocamTiePoint/models.py
View
@@ -9,6 +9,7 @@
from django.db import models
from django.core.files.storage import FileSystemStorage
+from django.core.urlresolvers import reverse
from geocamUtil.models import UuidField
from geocamUtil import anyjson as json
@@ -21,6 +22,9 @@ def getNewImageFileName(instance, filename):
return 'geocamTiePoint/overlay_images/'+filename
+def dumps(obj):
+ return json.dumps(obj, sort_keys=True, indent=4)
+
class QuadTree(models.Model):
overlay = models.ForeignKey('Overlay', null=True, db_index=True,
on_delete=models.SET_NULL # avoid circular FK constraints making deletes impossible
@@ -34,11 +38,20 @@ def getBasePath(self):
def getGenerator(self):
if self.transform:
- return quadtree.WarpedQuadTreeGenerator(self.overlay.image.path, self.transform)
+ return quadtree.WarpedQuadTreeGenerator(self.overlay.image.path,
+ json.loads(self.transform))
else:
return quadtree.SimpleQuadTreeGenerator(self.overlay.image.path)
+# FIX: may want to pull out Overlay.image field into a separate model to
+# support versioning:
+
+# class OverlayImage(models.Model):
+# image = models.ImageField(upload_to=getNewImageFileName,
+# storage=dataStorage)
+
+
class Overlay(models.Model):
data = models.TextField()
image = models.ImageField(upload_to=getNewImageFileName,
@@ -80,7 +93,8 @@ def generateUnalignedQuadTree(self):
def generateAlignedQuadTree(self):
data = json.loads(self.data)
- qt = QuadTree(overlay=self, transform=data['transform'])
+
+ qt = QuadTree(overlay=self, transform=dumps(data['transform']))
qt.save()
if settings.GEOCAM_TIE_POINT_PRE_GENERATE_TILES:
@@ -88,6 +102,8 @@ def generateAlignedQuadTree(self):
gen.writeQuadTree(qt.getBasePath())
self.alignedQuadtree = qt
+ data['alignedTilesUrl'] = reverse('geocamTiePoint_tileRoot', args=[qt.id])
+ self.data = dumps(data)
self.save()
if 0:
21 geocamTiePoint/quadtree.py
View
@@ -363,36 +363,37 @@ def __init__(self, imagePath, transformDict):
self.transform = makeTransform(transformDict)
self.baseMask = Image.new('L', self.image.size, 255)
- def writeQuadTree(self, basePath):
corners = getImageCorners(self.image)
- mercatorCorners = [self.transform.forward(corner)
+ self.mercatorCorners = [self.transform.forward(corner)
for corner in corners]
if 1:
# debug getProjectiveInverse
- print >> sys.stderr, 'mercatorCorners:', mercatorCorners
+ print >> sys.stderr, 'mercatorCorners:', self.mercatorCorners
corners2 = [self.transform.reverse(corner)
- for corner in mercatorCorners]
+ for corner in self.mercatorCorners]
print >> sys.stderr, 'zip:', zip(corners, corners2)
for i, pair in enumerate(zip(corners, corners2)):
c1, c2 = pair
print >> sys.stderr, i, numpy.array(c1) - numpy.array(c2)
bounds = Bounds()
- for corner in mercatorCorners:
+ for corner in self.mercatorCorners:
bounds.extend(corner)
self.maxZoom = calculateMaxZoom(bounds, self.image)
+
+ def writeQuadTree(self, basePath):
print >> sys.stderr, 'warping...'
totalTiles = 0
startTime = time.time()
for zoom in xrange(int(self.maxZoom), -1, -1):
- bounds = Bounds()
- for corner in mercatorCorners:
+ tileBounds = Bounds()
+ for corner in self.mercatorCorners:
tileCoords = tileIndex(zoom, corner)
- bounds.extend(tileCoords)
- xmin, ymin = (bounds.bounds[0], bounds.bounds[1])
- xmax, ymax = (bounds.bounds[2], bounds.bounds[3])
+ tileBounds.extend(tileCoords)
+ xmin, ymin = (tileBounds.bounds[0], tileBounds.bounds[1])
+ xmax, ymax = (tileBounds.bounds[2], tileBounds.bounds[3])
maxNumTiles = (xmax - xmin + 1) * (ymax - ymin + 1)
totalTiles += maxNumTiles
sys.stderr.write('zoom %d: generating %d tiles' % (zoom, maxNumTiles))
7 geocamTiePoint/static/geocamTiePoint/overlay-preview.js
View
@@ -18,8 +18,11 @@ function getTransformedImageTileUrl(coord,zoom) {
if(!normalizedCoord)
return null;
var bounds = Math.pow(2,zoom);
- return data_url+"geocamTiePoint/registeredTiles/"+overlay['key']+
- '/'+zoom+'/'+normalizedCoord.x+'/'+normalizedCoord.y+'.png';
+ return overlay.alignedTilesUrl
+ + zoom
+ + '/' + normalizedCoord.x
+ + '/' + normalizedCoord.y
+ + '.png';
}
var transformedImageMapTypeOptions = {
2  geocamTiePoint/urls.py
View
@@ -35,7 +35,7 @@
{}, 'geocamTiePoint_overlayIdImageFileName'),
url(r'^tile/(?P<quadTreeId>\d+)/$',
- 'helloQuadTree',
+ 'dummyView',
{}, 'geocamTiePoint_tileRoot'),
url(r'^tile/(?P<quadTreeId>\d+)/(?P<zoom>\d+)/(?P<x>\d+)/(?P<y>\d+)\.(\w+)$',
20 geocamTiePoint/views.py
View
@@ -45,7 +45,11 @@
def transparentPngResponse():
- return HttpResponse(TRANSPARENT_PNG_BINARY, mimetype='image/png')
+ return HttpResponse(TRANSPARENT_PNG_BINARY, content_type='image/png')
+
+
+def dumps(obj):
+ return json.dumps(obj, sort_keys=True, indent=4)
def overlayIndex(request):
@@ -79,7 +83,7 @@ def overlayNew(request):
overlay = models.Overlay(image=image,
imageType=image.content_type,
name=os.path.basename(image.name),
- data=json.dumps(preData))
+ data=dumps(preData))
overlay.save()
qt = overlay.generateQuadTree()
image = Image.open(models.dataStorage.path(overlay.image))
@@ -89,7 +93,7 @@ def overlayNew(request):
preData['tilesUrl'] = reverse('geocamTiePoint_tileRoot', args=[qt.id])
preData['imageSize'] = (overlay.image.width, overlay.image.height)
preData['key'] = overlay.key
- overlay.data = json.dumps(preData)
+ overlay.data = dumps(preData)
overlay.save()
return render_to_response('geocamTiePoint/new-overlay-result.html',
{'status':'success',
@@ -136,7 +140,7 @@ def overlayIdJson(request, key):
"name": overlay.name,
"imageType": overlay.imageType
}
- return HttpResponse(json.dumps(data))
+ return HttpResponse(dumps(data), content_type='application/json')
elif request.method == 'POST':
overlay = get_object_or_404(Overlay, key=key)
if 'data' in request.POST:
@@ -151,7 +155,7 @@ def overlayIdJson(request, key):
"name": overlay.name,
"imageType": overlay.imageType
}
- return HttpResponse(json.dumps(data))
+ return HttpResponse(dumps(data), content_type='application/json')
else:
return HttpResponseNotAllowed(['GET','POST'])
@@ -167,7 +171,7 @@ def overlayIdWarp(request, key):
transformType = data['transform']['type']
transformMatrix = data['transform']['matrix']
overlay.generateAlignedQuadTree()
- return HttpResponse("{}")
+ return HttpResponse("{}", content_type='application/json')
else:
return HttpResponseNotAllowed(['GET','POST'])
@@ -199,5 +203,5 @@ def getTile(request, quadTreeId, zoom, x, y):
return transparentPngResponse()
-def helloQuadTree(request, quadTreeId):
- return HttpResponse('hello')
+def dummyView(*args, **kwargs):
+ return HttpResponseNotFound()
Please sign in to comment.
Something went wrong with that request. Please try again.