Permalink
Browse files

better focalplacing

  • Loading branch information...
1 parent 8038da9 commit 7f5a441c1ec2e45e7c49c9b996eafe149570f98e @casparwylie committed May 15, 2017
@@ -301,7 +301,7 @@
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
- enabled = 1;
+ enabled = 0;
};
};
};
View
@@ -35,10 +35,6 @@
<string>So we know where to locate you in the virtual world.</string>
<key>NSMotionUsageDescription</key>
<string>So that your reality is augmented!</string>
- <key>UIBackgroundModes</key>
- <array>
- <string>audio</string>
- </array>
<key>UILaunchStoryboardName</key>
<string>Launch Screen.storyboard</string>
<key>UIMainStoryboardFile</key>
View
@@ -76,7 +76,7 @@ class ViewController: UIViewController, LocationDelegate, UIActionDelegate, mapA
self.map.getMapAsIMG({(image) in
- let toHideAsSTR = OpenCVWrapper.buildingDetect( &focalValsPX, image: image, currPoint: &currPointPX, pxLength: Int32(pxVals.pxLength),forTapLimit: false, forBuildingTap: false);
+ let toHideAsSTR = OpenCVWrapper.buildingDetect( &focalValsPX, image: image, currPoint: &currPointPX, pxLength: Int32(pxVals.pxLength), forBuildingTap: false);
self.scene.renderFocals(self.mapPoints, currMapPoint: self.currMapPoint,
render: newRender, currentHeading: self.currentHeading, toHide: toHideAsSTR!, comments: self.focalFirstComments, tempFocalMapPoint: self.tempFocalMapPoint);
@@ -117,7 +117,6 @@ class ViewController: UIViewController, LocationDelegate, UIActionDelegate, mapA
count += 1;
}
-
/* var focalsToNotify: [Int] = [];
if(userKnownFocals != nil){
for focalID in focalsClose{
@@ -192,95 +191,81 @@ class ViewController: UIViewController, LocationDelegate, UIActionDelegate, mapA
var addTempFirst = true;
var phonePitch = 0;
var latestDesiredFocalLocation: CLLocation!;
+
func renderTempFocalFromMap(_ mapTapCoord: CLLocationCoordinate2D){
let focalLocation = CLLocation(latitude: mapTapCoord.latitude, longitude: mapTapCoord.longitude);
- self.map.getMapAsIMG({(image) in
-
- let pxVals = self.map.collectPXfromMapPoints([MKMapPointForCoordinate(focalLocation.coordinate)], currMapPoint: MKMapPointForCoordinate(self.currentLocation.coordinate));
-
- var currentPointPX = pxVals.currPointPX;
- var focalDesValPX = pxVals.focalValsPX;
-
- let distNoBuilding = Int(OpenCVWrapper.buildingDetect(&focalDesValPX, image: image, currPoint: &currentPointPX, pxLength: Int32(pxVals.pxLength), forTapLimit: true, forBuildingTap: true)!)!;
-
- if(distNoBuilding > 5 || distNoBuilding == -1){
- self.addFocalTemp(focalLocation);
- }else{
- self.userInterface.updateInfoLabel("You cannot place a focal on a building.", show: true, hideAfter: 3);
- }
- });
+
+ self.latestDesiredFocalLocation = focalLocation;
+ self.tempFocalMapPoint = MKMapPointForCoordinate(focalLocation.coordinate);
+ chooseLatestTempPos(vec: SCNVector3Zero);
+
}
+
func renderTempFocalFromUI(_ tapX: Int, tapY: Int){
- var newFocalDistMetres: Double = 0.0;
- var bearingDegreesTap: Double = 0.0;
- newFocalDistMetres = self.location.getDistFromVerticalTap(Double(tapX), tapY: Double(tapY), phonePitch: Double(self.phonePitch));
- if(newFocalDistMetres < 0){
- newFocalDistMetres = 3;
- }
-
- bearingDegreesTap = self.location.getBearingFromHorizontalTap(Double(tapX));
- var focalLocation = location.getPolarCoords(newFocalDistMetres, bearingDegrees: bearingDegreesTap);
-
-
+
let positionsFound = scene.sceneView.hitTest(CGPoint(x: tapX, y: tapY), options: nil);
- /* let pxVals = self.map.collectPXfromMapPoints([MKMapPointForCoordinate(focalLocation.coordinate)], currMapPoint: MKMapPointForCoordinate(currentLocation.coordinate));
-
- var currentPointPX = pxVals.currPointPX;
- var focalDesValPX = pxVals.focalValsPX;
-
- self.map.getMapAsIMG({(image) in
-
- let distLimitPX = Int(OpenCVWrapper.buildingDetect(&focalDesValPX, image: image, currPoint: &currentPointPX, pxLength: Int32(pxVals.pxLength), forTapLimit: true, forBuildingTap: false)!)!;
-
- if(distLimitPX > -1){
- let distLimitMetres = (distLimitPX / 2)-4;
- focalLocation = self.location.getPolarCoords(Double(distLimitMetres), bearingDegrees: bearingDegreesTap);
- }
-
- self.addFocalTemp(focalLocation);
-
- });*/
-
if(positionsFound.count>0){
if(positionsFound.first?.node.name == "floor"){
+
let vecFound = positionsFound.first?.worldCoordinates;
- self.scene.renderSingleFocal(0, mapPoint: tempFocalMapPoint, currMapPoint: currMapPoint, focalDisplayInfo: (" ", " "), render: self.addTempFirst, tempFocal: true, vec: vecFound!);
- self.addTempFirst = false;
+ var vecRotate = (x: Double((vecFound?.x)!), y: Double((vecFound?.z)!));
+ vecRotate = misc.rotateAroundPoint(vecRotate, angle: 90);
+ let mapPointT = (x: vecRotate.x + currMapPoint.x, y: vecRotate.y + currMapPoint.y);
+ let mapPoint = MKMapPoint(x: mapPointT.x, y: mapPointT.y);
+ self.tempFocalMapPoint = mapPoint;
+ let coordPoint2d = MKCoordinateForMapPoint(mapPoint);
+ let coordLocation = CLLocation(latitude: coordPoint2d.latitude, longitude: coordPoint2d.longitude);
+ self.latestDesiredFocalLocation = coordLocation;
+ chooseLatestTempPos(vec: vecFound!);
}
}
-
}
- func addFocalTemp(_ focalLocation: CLLocation){
-
- self.latestDesiredFocalLocation = focalLocation;
+
+
+ //render temp focal visually
+ func chooseLatestTempPos(vec: SCNVector3){
+ self.map.updateSinglePin(self.latestDesiredFocalLocation, temp: true);
self.userInterface.showTapFinishedOptions();
- tempFocalMapPoint = MKMapPointForCoordinate(focalLocation.coordinate);
- let currentMapPoint = MKMapPointForCoordinate(currentLocation.coordinate);
-
- map.updateSinglePin(focalLocation, temp: true);
- self.scene.renderSingleFocal(0, mapPoint: tempFocalMapPoint, currMapPoint: currentMapPoint, focalDisplayInfo: (" ", " "), render: self.addTempFirst, tempFocal: true, vec: SCNVector3Zero);
+ self.scene.renderSingleFocal(0, mapPoint: tempFocalMapPoint, currMapPoint: currMapPoint, focalDisplayInfo: (" ", " "), render: self.addTempFirst, tempFocal: true, vec: vec);
self.addTempFirst = false;
-
}
-
+
func addFocalReady(_ comment: String){
- self.addTempFirst = true;
- tempFocalMapPoint = MKMapPoint();
- self.scene.removeTempFocal();
- CLGeocoder().reverseGeocodeLocation(self.latestDesiredFocalLocation, completionHandler: {(placemarks,err) in
- var areaName = "N/A";
- if((placemarks?.count)!>0){
- let placemark = (placemarks?[0])! as CLPlacemark;
- areaName = placemark.thoroughfare! + ", " + placemark.locality!;
- }
-
- let focalInfo = (comment: comment, author: self.loggedinUserData.username, userID: self.loggedinUserData.id, areaName: areaName);
- self.networkRequest.addFocal(self.networkWebSocket, focalLocation: self.latestDesiredFocalLocation,focalDisplayInfo: focalInfo);
- });
+ self.map.getMapAsIMG({(image) in
+
+ let pxVals = self.map.collectPXfromMapPoints([self.tempFocalMapPoint], currMapPoint: self.currMapPoint);
+
+ var currentPointPX = pxVals.currPointPX;
+ var focalDesValPX = pxVals.focalValsPX;
+
+ let distNoBuilding = Int(OpenCVWrapper.buildingDetect(&focalDesValPX, image: image, currPoint: &currentPointPX, pxLength: Int32(pxVals.pxLength), forBuildingTap: true)!)!;
+
+ if(distNoBuilding > 5 || distNoBuilding == -1){
+
+ self.addTempFirst = true;
+ self.tempFocalMapPoint = MKMapPoint();
+ self.scene.removeTempFocal();
+ CLGeocoder().reverseGeocodeLocation(self.latestDesiredFocalLocation, completionHandler: {(placemarks,err) in
+ var areaName = "N/A";
+ if((placemarks?.count)!>0){
+ let placemark = (placemarks?[0])! as CLPlacemark;
+ areaName = placemark.thoroughfare! + ", " + placemark.locality!;
+ }
+
+ let focalInfo = (comment: comment, author: self.loggedinUserData.username, userID: self.loggedinUserData.id, areaName: areaName);
+ self.networkRequest.addFocal(self.networkWebSocket, focalLocation: self.latestDesiredFocalLocation,focalDisplayInfo: focalInfo);
+ });
+
+ }else{
+ self.userInterface.updateInfoLabel("You cannot post a focal within a building. Try again.", show: true, hideAfter: 4);
+ }
+
+ });
+
}
func addedFocalResponse(_ responseStr: String) {
@@ -473,6 +458,7 @@ class ViewController: UIViewController, LocationDelegate, UIActionDelegate, mapA
//Initilize Map component
map.renderMap(self.view);
map.mapActionDelegate = self;
+ map.scene = scene;
self.view.viewWithTag(3)?.isHidden = true;
appDelegate.viewController = self;
View
@@ -34,10 +34,10 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
- <constraint firstItem="j1f-IJ-CXz" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="Nfy-z8-WYr"/>
- <constraint firstItem="j1f-IJ-CXz" firstAttribute="bottom" secondItem="xb3-aO-Qok" secondAttribute="top" id="ZUf-Bj-CEC"/>
- <constraint firstItem="j1f-IJ-CXz" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="a27-N4-2OE"/>
- <constraint firstAttribute="trailing" secondItem="j1f-IJ-CXz" secondAttribute="trailing" id="kx4-02-As0"/>
+ <constraint firstAttribute="trailing" secondItem="j1f-IJ-CXz" secondAttribute="trailing" id="3ux-D2-BhV"/>
+ <constraint firstItem="j1f-IJ-CXz" firstAttribute="bottom" secondItem="xb3-aO-Qok" secondAttribute="top" id="53C-9H-vxQ"/>
+ <constraint firstItem="j1f-IJ-CXz" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="hgT-eQ-Der"/>
+ <constraint firstItem="j1f-IJ-CXz" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="l8Z-Md-Ssm"/>
</constraints>
</view>
</viewController>
View
@@ -67,7 +67,6 @@ class Location: NSObject, CLLocationManagerDelegate{
cos(distanceByER)-sin(latitude)*sin(newLatitude));
return CLLocation(latitude: newLatitude * (180 / M_PI), longitude: newLongitude * (180 / M_PI));
-
}
func getBearingFromTwoCoords(_ location1: CLLocation, location2: CLLocation) -> Int{
@@ -82,7 +81,6 @@ class Location: NSObject, CLLocationManagerDelegate{
let pointY = cos(latitude1) * sin(latitude2)-sin(latitude1) * cos(latitude2) * cos(diff);
let bearing = atan2(pointX, pointY)*(180.0 / M_PI);
return Int(bearing);
-
}
func getBearingFromTwo2dPoints(_ point1X: Double, point1Y: Double, point2X: Double, point2Y: Double) -> Int{
@@ -93,7 +91,6 @@ class Location: NSObject, CLLocationManagerDelegate{
}
let bearing = (180 / M_PI) * theta;
return Int(bearing);
-
}
func getDistanceBetweenTwo2dPoints(_ point1X: Double, point1Y: Double, point2X: Double, point2Y: Double) -> Int{
@@ -105,30 +102,6 @@ class Location: NSObject, CLLocationManagerDelegate{
return distance;
}
- func getBearingFromHorizontalTap(_ tapX: Double) -> Double{
- let pxMidDiff = 160.0 - Double(tapX);
- let step = 320.0/54.0;
- let degDiff = pxMidDiff/step;
- let bearingDegrees: Double = ((currentHeading?.trueHeading)! + 5) - degDiff/2.0;
- return bearingDegrees;
- }
-
- func getDistFromVerticalTap(_ tapX: Double, tapY: Double, phonePitch: Double) -> Double{
-
- let hozPx: Double = 230;
- var yPos = tapY;
- if(tapY < hozPx){
- yPos = hozPx;
- }
-
- let acc1 = 500.0;
- let acc2 = 15.0;
- let acc3 = acc1/acc2 - Double(phonePitch-10);
-
- let distMetres: Double = (acc2-(Double(yPos)/acc3))*3;
- return distMetres;
- }
-
func collectFocalToUserData(_ point1X: Double, point1Y: Double, point2X: Double, point2Y: Double) -> (distance: Int, bearing: Int){
let lineBetweenBearing = getBearingFromTwo2dPoints(point1X, point1Y: point1Y, point2X: point2X, point2Y: point2Y);
View
@@ -9,6 +9,7 @@
import Foundation
import MapKit
import Darwin
+import SceneKit
/*
@@ -28,7 +29,8 @@ class Map: NSObject, MKMapViewDelegate{
var tapMapToPost = false;
var tempPin: MKPointAnnotation!;
var tapRec: UITapGestureRecognizer!;
-
+ var misc = Misc();
+ var scene: Scene!;
//MARK: setup map
func renderMap(_ view: UIView){
mapView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height);
@@ -159,8 +161,7 @@ class Map: NSObject, MKMapViewDelegate{
return (focalValsPX: pixelsXY, currPointPX: resultsCurrPointXY, pxLength: mapPoints.count);
}
-
-
+
//MARK: convert coordinate data to 2D map points
func getCoordsAsMapPoints(_ coords: [CLLocation]) -> [MKMapPoint]{
var mapPoints: [MKMapPoint] = [];
View
@@ -20,7 +20,34 @@ class Misc{
}
}
- func sha512(string: String){
+ func objcStringToArray(string: String) ->[[(Int,Int)]] {
+ var vectors: [[(Int,Int)]] = [];
+ let sepGroups = string.components(separatedBy: " ");
+ for group in sepGroups{
+ var finalGroupVec: [(Int,Int)] = [];
+ let groupVec: [String] = group.components(separatedBy: "/");
+ for item in groupVec{
+ var finalItem: (Int,Int) = (0,0);
+ var itemVec = item.components(separatedBy: ",");
+ if(itemVec[0] != ""){
+ let i1 = Int(itemVec[0]);
+ let i2 = Int(itemVec[1]);
+ finalItem.0 = i1!;
+ finalItem.1 = i2!;
+ finalGroupVec.append(finalItem);
+ }
+ }
+ vectors.append(finalGroupVec);
+ }
+ print(vectors);
+ return vectors;
+ }
+
+ func rotateAroundPoint(_ pointXY: (x: Double,y: Double),angle: Double) -> (x: Double, y: Double){
+ let angle = angle * 0.0174533;
+ let pX = (pointXY.x * cos(angle)) + (pointXY.y * sin(angle));
+ let pY = -(pointXY.x * sin(angle)) + (pointXY.y * cos(angle));
+ return (x: pX, y: pY);
}
}
View
@@ -18,8 +18,9 @@
@interface OpenCVWrapper : NSObject
-+(NSString*) buildingDetect: (double[][2])pxVals image:(UIImage*)UIMap currPoint:(double[2])currPointPX pxLength:(int) pxLength forTapLimit:(bool)forTapLimit forBuildingTap:(bool)forBuildingTap;
++(NSString*) buildingDetect: (double[][2])pxVals image:(UIImage*)UIMap currPoint:(double[2])currPointPX pxLength:(int) pxLength forBuildingTap:(bool)forBuildingTap;
++(NSString*) prepVirtualStreet: (UIImage*)UIMap;
//+(NSString*) limitNewFocalDist: (double[2])currPoint image:(UIImage*)UIMap desPoint:(double[2])desPoint;
@end
Oops, something went wrong.

0 comments on commit 7f5a441

Please sign in to comment.