Skip to content

Commit

Permalink
idc
Browse files Browse the repository at this point in the history
  • Loading branch information
acodexm committed Jun 6, 2019
1 parent 702461b commit 24a79ed
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 88 deletions.
4 changes: 3 additions & 1 deletion android/src/main/java/study/acodexm/CameraSurface.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private int setCameraDisplayOrientation(Context context) {
android.hardware.Camera.getCameraInfo(0, info); // Use the first rear-facing camera
int rotation = getDeviceCurrentOrientation(context);

int degrees = 0;
int degrees;
switch (rotation) {
case Surface.ROTATION_0:
degrees = 0;
Expand All @@ -155,6 +155,8 @@ private int setCameraDisplayOrientation(Context context) {
case Surface.ROTATION_270:
degrees = 270;
break;
default:
degrees = 0;
}

int result;
Expand Down
4 changes: 3 additions & 1 deletion android/src/main/java/study/acodexm/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public synchronized void run() {
LOG.s(TAG, "image handler call");
while (mRunning) {
try {
Thread.sleep(500);
wait(500);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Expand Down Expand Up @@ -234,6 +234,8 @@ public synchronized boolean handleMessage(Message msg) {
MainActivity.this.showToastRunnable(MainActivity.this.getString(R.string.part_msg_is_saved) + (msg.arg1 == 1));
break;
}
default:
break;
}
return true;
}
Expand Down
10 changes: 8 additions & 2 deletions android/src/main/java/study/acodexm/WelcomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import butterknife.OnClick;

public class WelcomeActivity extends Activity implements ActivityCompat.OnRequestPermissionsResultCallback {
public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;
private static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;
private static final String TAG = WelcomeActivity.class.getSimpleName();
private final String CAMERA = Manifest.permission.CAMERA;
private final String STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE;
Expand Down Expand Up @@ -70,6 +70,7 @@ private void openMainActivity() {
Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(intent);
}

/**
* method checks if permissions are granted, if they are not then it request them to be granted
*
Expand Down Expand Up @@ -101,7 +102,7 @@ private boolean checkAndRequestPermissions() {
* @param grantResults
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
LOG.d(TAG, "Permission callback called-------");
switch (requestCode) {
case REQUEST_ID_MULTIPLE_PERMISSIONS: {
Expand All @@ -126,14 +127,19 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String permissi
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
default:
break;
}
});
} else {
Toast.makeText(this, R.string.msg_go_to_settings, Toast.LENGTH_LONG).show();
}
}
}
break;
}
default:
break;
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package study.acodexm.control;

import java.util.List;

import study.acodexm.SphereControl;

public class AndroidSphereControl implements SphereControl {
private byte[] mPicture;
private List<Integer> ids;
private CameraControl mCameraControl;
private int position;

public AndroidSphereControl(CameraControl cameraControl) {
mCameraControl = cameraControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void onCropClickListener() {
mat.release();
result.release();
recreate();
}).run();
}).start();
}

@Override
Expand Down
10 changes: 0 additions & 10 deletions android/src/main/java/study/acodexm/representation/Quaternion.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ public void multiplyByQuat(Quaternion input, Quaternion output) {
}


/**
* Multiplies this Quaternion with a scalar
*
* @param scalar the value that the vector should be multiplied with
*/
public void multiplyByScalar(float scalar) {
multiplyByScalar(scalar);
}


/**
* Sets the quaternion to an identity quaternion of 0,0,0,1.
*/
Expand Down
111 changes: 45 additions & 66 deletions android/src/main/java/study/acodexm/utils/MaximumHistogram.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static Set<Integer> maxArea(PicturePosition position) {
}

private static void removeUnusedAreas(int[][] grid, Set<Integer> tempPictures, Set<Integer> points, PicturePosition position) {
for (int x = 0; x < Math.round(Math.abs(grid.length / 2)); x++) {
for (int x = 0; x < Math.round(grid.length / 2); x++) {
for (int y = 0; y < grid[0].length; y++) {
if (points.contains(y))
continue;
Expand Down Expand Up @@ -57,45 +57,34 @@ public static Set<Integer> maxLength(PicturePosition position) {

private static void gridExtractor(PicturePosition position, int[][] grid, int[] temp, Set<Integer> tempPictures, int x) {
for (int y = 0; y < grid[0].length; y++) {
int offset = Math.round(Math.abs(grid.length / 2));
int offset = Math.round(grid.length / 2);
if (x >= offset) {// edge check
int xo = x - offset;
int newItem = position.calculatePosition(xo, y);
if (grid[xo][y] == 0) {
temp[y] = 0;
for (int rmX = 0; rmX < offset; rmX++)
tempPictures.remove(position.calculatePosition(rmX, y));

} else if (// pictures taken closer to middle of grid has higher weight value
y == Math.round(Math.abs(grid[0].length / 2)) &&
!tempPictures.contains(newItem)
) {
temp[y] += 2 * grid[xo][y];
tempPictures.add(newItem);
} else if (!tempPictures.contains(newItem)) {
temp[y] += grid[xo][y];
tempPictures.add(newItem);
}
processGrid(position, grid, temp, tempPictures, xo, y, offset);
} else {
int newItem = position.calculatePosition(x, y);
if (grid[x][y] == 0) {
temp[y] = 0;
for (int rmX = 0; rmX < offset; rmX++)
tempPictures.remove(position.calculatePosition(rmX, y));
} else if (// pictures taken closer to middle of grid has higher weight value
y == Math.round(Math.abs(grid[0].length / 2)) &&
!tempPictures.contains(newItem)
) {
temp[y] += 2 * grid[x][y];
tempPictures.add(newItem);
} else if (!tempPictures.contains(newItem)) {
temp[y] += grid[x][y];
tempPictures.add(newItem);
}
processGrid(position, grid, temp, tempPictures, x, y, offset);
}
}
}

private static void processGrid(PicturePosition position, int[][] grid, int[] temp, Set<Integer> tempPictures, int x, int y, int offset) {
int newItem = position.calculatePosition(x, y);
if (grid[x][y] == 0) {
temp[y] = 0;
for (int rmX = 0; rmX < offset; rmX++)
tempPictures.remove(position.calculatePosition(rmX, y));
} else if (// pictures taken closer to middle of grid has higher weight value
y == Math.round(grid[0].length / 2) &&
!tempPictures.contains(newItem)
) {
temp[y] += 2 * grid[x][y];
tempPictures.add(newItem);
} else if (!tempPictures.contains(newItem)) {
temp[y] += grid[x][y];
tempPictures.add(newItem);
}
}

/**
* Extend main grid for edge cases
*
Expand All @@ -110,7 +99,7 @@ private static int[][] extendGrid(int[][] grid) {
}


public int maxHistogram(int input[]) {
public int maxHistogram(int[] input) {
Deque<Integer> stack = new LinkedList<>();
int maxArea = 0;
int area = 0;
Expand All @@ -119,41 +108,31 @@ public int maxHistogram(int input[]) {
if (stack.isEmpty() || input[stack.peekFirst()] <= input[i]) {
stack.offerFirst(i++);
} else {
int top = stack.pollFirst();
//if stack is empty means everything till i has to be
//greater or equal to input[top] so get area by
//input[top] * i;
if (stack.isEmpty()) {
area = input[top] * i;
}
//if stack is not empty then everything from i-1 to input.peek() + 1
//has to be greater or equal to input[top]
//so area = input[top]*(i - stack.peek() - 1);
else {
area = input[top] * (i - stack.peekFirst() - 1);
}
if (area > maxArea) {
maxArea = area;
}
maxArea = getMaxArea(input, stack, maxArea, i, area);
}
}
while (!stack.isEmpty()) {
int top = stack.pollFirst();
//if stack is empty means everything till i has to be
//greater or equal to input[top] so get area by
//input[top] * i;
if (stack.isEmpty()) {
area = input[top] * i;
}
//if stack is not empty then everything from i-1 to input.peek() + 1
//has to be greater or equal to input[top]
//so area = input[top]*(i - stack.peek() - 1);
else {
area = input[top] * (i - stack.peekFirst() - 1);
}
if (area > maxArea) {
maxArea = area;
}
maxArea = getMaxArea(input, stack, maxArea, i, area);
}
return maxArea;
}

private int getMaxArea(int[] input, Deque<Integer> stack, int maxArea, int i, int area) {
int top = stack.pollFirst();
//if stack is empty means everything till i has to be
//greater or equal to input[top] so get area by
//input[top] * i;
if (stack.isEmpty()) {
area = input[top] * i;
}
//if stack is not empty then everything from i-1 to input.peek() + 1
//has to be greater or equal to input[top]
//so area = input[top]*(i - stack.peek() - 1);
else {
area = input[top] * (i - stack.peekFirst() - 1);
}
if (area > maxArea) {
maxArea = area;
}
return maxArea;
}
Expand Down
6 changes: 3 additions & 3 deletions android/src/test/java/study/acodexm/JustTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public void justTest() throws Exception {
Date date = new Date();
SimpleDateFormat simple = new SimpleDateFormat("ddMMyyyyHHmmss");
System.out.println(simple.format(date));
StringBuilder sb = new StringBuilder(simple.format(date));
sb.append(".png");
sb.insert(0, "panorama_");
// StringBuilder sb = new StringBuilder(simple.format(date));
// sb.append(".png");
// sb.insert(0, "panorama_");
// String file=sb.toString();
String file = "/storage/emulated/0/PanoramaApp/panorama_15012018215307.png";
file = file.substring(file.indexOf("panorama_"));
Expand Down

0 comments on commit 24a79ed

Please sign in to comment.