Commit 1556347c authored by bernie wang's avatar bernie wang
Browse files

implemented evaluation using the binary files in /test/velodyne/data as test data

parent 2795f718
var maxSize = 2;
var SettingsControls = function() {
this.size = pointSize / maxSize;
};
var gui = new dat.GUI();
var settingsControls = new SettingsControls();
var settingsFolder = gui.addFolder('settings');
settingsFolder.add(settingsControls, 'size').min(0.0).max(1.0).step(0.05).onChange(function() {
pointcloud.material.size = settingsControls.size * maxSize;
pointMaterial.size = 4 * settingsControls.size * maxSize;
});
settingsFolder.open();
function next_frame(event) {
if (evaluation.is_done()) {
alert("You have completed the evaluation! Thank you for participating!");
evaluation.add_evaluator(evaluator);
evaluation.write_output();
return;
}
var response = confirm('Do you want to move on to the next frame? You cannot go back to edit previous frames.');
if (response == true) {
$("#next_frame").text("Next Frame (" + (evaluation.get_frame_number() + 1) +
"/" + evaluation.num_frames() + ")");
evaluation.add_evaluator(evaluator);
evaluation.next_frame();
reset();
data = evaluation.get_data();
show();
animate();
if (isRecording) {
toggleRecord(event);
}
select2DMode();
}
}
function toggleRecord(event) {
// pause recording
if (isRecording) {
$("#record").text("Click to resume recording");
evaluator.pause_recording();
move2DMode(event);
isRecording = false;
} else {
// resume recording
isRecording = true;
$("#record").text("Click to pause recording");
evaluator.resume_recording();
}
}
// controller for pressing hotkeys
function onKeyDown(event) {
if (isRecording) {
if (event.ctrlKey) {
toggleControl(false);
}
var KeyID = event.keyCode;
switch(KeyID)
{
case 8: // backspace
deleteSelectedBox();
break;
case 46: // delete
deleteSelectedBox();
break;
case 68:
default:
break;
}
}
}
// controller for releasing hotkeys
function onKeyUp(event) {
if(isRecording) {
var KeyID = event.keyCode;
switch(KeyID)
{
default:
toggleControl(true);
break;
}
}
}
// toggles between move2D and move3D
function toggleControl(b) {
if (b) {
controls.enabled = b;
controls.update();
} else {
if (move2D) {
controls.enabled = b;
controls.update();
}
}
}
\ No newline at end of file
function Evaluation() {
// this.test_filenames = [
// "0000000001.bin",
// "0000000013.bin",
// "0000000022.bin",
// "0000000049.bin",
// "0000000128.bin",
// "0000000003.bin",
// "0000000019.bin",
// "0000000023.bin",
// "0000000060.bin",
// "0000000133.bin"
// ];
this.test_data = [];
this.filenames = [];
this.index = 0;
this.evaluators = [];
this.get_filename = function() {
return this.filenames[this.index];
}
this.get_data = function() {
return this.test_data[this.index];
}
this.next_frame = function() {
this.index += 1;
}
this.is_done = function() {
return this.index == this.filenames.length - 1;
}
this.add_data = function(data) {
this.test_data.push(data);
}
this.add_filename = function(filename) {
this.filenames.push(filename);
}
this.get_frame_number = function() {
return this.index + 1;
}
this.num_frames = function() {
return this.test_data.length;
}
this.add_evaluator = function(evaluator) {
this.evaluators.push(evaluator);
}
this.write_output = function() {
// output_bounding_boxes = save(this.)
var output_evaluators = [];
for (var i = 0; i < this.evaluators.length; i++) {
// output_evaluators[this.filenames[i]] = this.evaluators[i].output();
console.log(this.evaluators[i].output());
output_evaluators.push(this.evaluators[i].output());
}
var output = {"frames": output_evaluators};
var stringifiedOutput = JSON.stringify(output);
var file = new File([stringifiedOutput], "test.json", {type: "/json;charset=utf-8"});
saveAs(file);
}
}
function Evaluator(angle, bounding_boxes) {
function Evaluator(angle, bounding_boxes, filename) {
this.add_box_count = 0;
this.resize_count = 0;
this.translate_count = 0;
......@@ -9,7 +9,7 @@ function Evaluator(angle, bounding_boxes) {
this._3D_timer = new Timer();
this.timer = new Timer();
this.bounding_boxes = bounding_boxes;
this.filename = filename;
this.camera_angle = angle;
this.increment_add_box_count = function() {
......@@ -82,6 +82,26 @@ function Evaluator(angle, bounding_boxes) {
}
}
this.output = function() {
return new OutputEvaluator(this);
}
}
function OutputEvaluator(eval) {
this.add_box_count = eval.add_box_count;
this.resize_count = eval.resize_count;
this.translate_count = eval.translate_count;
this.rotate_count = eval.rotate_count;
this.delete_count = eval.delete_count;
this.label_count = eval.label_count;
this.rotate_camera_count = eval.rotate_camera_count;
this.filename = eval.filename;
this.bounding_boxes = [];
for (var i = 0; i < eval.bounding_boxes.length; i++) {
this.bounding_boxes.push(eval.bounding_boxes[i].output());
}
this.camera_angle = eval.camera_angle;
}
function Timer() {
......
......@@ -21,7 +21,7 @@ $("#object-table").on('mousedown', 'tbody tr', function() {
var boxId = $(this).find('.id').text();
var box = getBoxById(boxId);
selectRow(boxId);
selectBox(box, null);
box.select(null);
selectedBox = null;
});
......
function Box(anchor, cursor, angle, boundingBox, boxHelper) {
this.id = id; // id (int) of Box
this.object_id = null; // object id (string)
this.object_id = 'car'; // object id (string)
this.color = new THREE.Color( 1,0,0 ); // color of corner points
this.angle = angle; // orientation of bounding box
this.anchor = anchor; // point where bounding box was created
......@@ -29,100 +29,172 @@ function Box(anchor, cursor, angle, boundingBox, boxHelper) {
this.geometry.vertices.push(anchor.clone());
this.geometry.vertices.push(cursor.clone());
this.geometry.vertices.push(getCenter(anchor.clone(), cursor.clone()));
}
// method for resizing bounding box given cursor coordinates
//
// since BoxHelper3 draws a box in the same orientation as that of the point cloud,
// we take the anchor and cursor, rotate them by the angle of the camera, draw the box,
// then rotate the box back
function resize(box, cursor) {
// checks and executes only if anchor does not overlap with cursor to avoid 0 determinant
if (cursor.x != box.anchor.x && cursor.y != box.anchor.y && cursor.z != box.anchor.z) {
// method for resizing bounding box given cursor coordinates
//
// since BoxHelper3 draws a box in the same orientation as that of the point cloud,
// we take the anchor and cursor, rotate them by the angle of the camera, draw the box,
// then rotate the box back
this.resize = function(cursor) {
// checks and executes only if anchor does not overlap with cursor to avoid 0 determinant
if (cursor.x != this.anchor.x && cursor.y != this.anchor.y && cursor.z != this.anchor.z) {
var v1 = cursor.clone();
var v2 = this.anchor.clone();
v1.y = 0;
v2.y = 0;
// rotate cursor and anchor
rotate(v1, v2, this.angle);
// calculating corner points and rotating point
var minVector = getMin(v1, v2);
var maxVector = getMax(v1, v2);
var topLeft = getTopLeft(v1, v2);
var bottomRight = getBottomRight(v1, v2);
var topCenter = getCenter(topLeft, maxVector);
var bottomCenter = getCenter(minVector, bottomRight);
// need to do this to make matrix invertible
maxVector.y = 0.00001;
// setting bounding box limits
this.boundingBox.set(minVector.clone(), maxVector.clone());
// rotate BoxHelper back
this.boxHelper.rotation.y = this.angle;
// setting y coordinate back to zero since we are done with drawing
maxVector.y = 0;
// rotate back the corner points
rotate(minVector, maxVector, -this.angle);
rotate(topLeft, bottomRight, -this.angle);
rotate(topCenter, bottomCenter, -this.angle);
// set updated corner points used to resize box
this.geometry.vertices[0] = maxVector.clone();
this.geometry.vertices[1] = minVector.clone();
this.geometry.vertices[2] = topLeft.clone();
this.geometry.vertices[3] = bottomRight.clone();
this.geometry.vertices[4] = bottomCenter.clone();
// tell scene to update corner points
this.geometry.verticesNeedUpdate = true;
}
}
var v1 = cursor.clone();
var v2 = box.anchor.clone();
// method to rotate bounding box by clicking and dragging rotate point,
// which is the top center point on the bounding box
this.rotate = function(cursor) {
// get corner points
var maxVector = this.geometry.vertices[0].clone();
var minVector = this.geometry.vertices[1].clone();
var topLeft = this.geometry.vertices[2].clone();
var bottomRight = this.geometry.vertices[3].clone();
var topCenter = getCenter(maxVector, topLeft);
var bottomCenter = this.geometry.vertices[4].clone();
// get relative angle of cursor with respect to
var center = getCenter(maxVector, minVector);
var angle = getAngle(center, bottomCenter, cursor, topCenter);
// update angle of Box and bounding box
this.angle = this.angle + angle;
this.boxHelper.rotation.y = this.angle;
// rotate and update corner points
rotate(minVector, maxVector, -angle);
rotate(topLeft, bottomRight, -angle);
rotate(topCenter, bottomCenter, -angle);
this.geometry.vertices[0] = maxVector.clone();
this.geometry.vertices[1] = minVector.clone();
this.geometry.vertices[2] = topLeft.clone();
this.geometry.vertices[3] = bottomRight.clone();
this.geometry.vertices[4] = bottomCenter.clone();
v1.y = 0;
v2.y = 0;
// tell scene to update corner points
this.geometry.verticesNeedUpdate = true;
// rotate cursor and anchor
rotate(v1, v2, box.angle);
}
// method to translate bounding box given a reference point
this.translate = function(v) {
// get difference in x and z coordinates between cursor when
// box was selected and current cursor position
var dx = v.x - this.cursor.x;
var dz = v.z - this.cursor.z;
// update all points related to box by dx and dz
this.anchor.x += dx;
this.anchor.z += dz;
this.cursor = v.clone();
for (var i = 0; i < this.geometry.vertices.length; i++) {
var p = this.geometry.vertices[i];
p.x += dx;
p.z += dz;
}
// calculating corner points and rotating point
var minVector = getMin(v1, v2);
var maxVector = getMax(v1, v2);
var topLeft = getTopLeft(v1, v2);
var bottomRight = getBottomRight(v1, v2);
var topCenter = getCenter(topLeft, maxVector);
var bottomCenter = getCenter(minVector, bottomRight);
// shift bounding box given new corner points
var maxVector = this.geometry.vertices[0].clone();
var minVector = this.geometry.vertices[1].clone();
var topLeft = this.geometry.vertices[2].clone();
var bottomRight = this.geometry.vertices[3].clone();
var topCenter = getCenter(maxVector, topLeft);
var bottomCenter = this.geometry.vertices[4].clone();
rotate(maxVector, minVector, this.angle);
rotate(topLeft, bottomRight, this.angle);
rotate(topCenter, bottomCenter, this.angle);
// need to do this to make matrix invertible
maxVector.y = 0.00001;
maxVector.y += 0.0000001;
// setting bounding box limits
box.boundingBox.set(minVector.clone(), maxVector.clone());
this.boundingBox.set(minVector, maxVector);
// rotate BoxHelper back
box.boxHelper.rotation.y = box.angle;
// tell scene to update corner points
this.geometry.verticesNeedUpdate = true;
}
// setting y coordinate back to zero since we are done with drawing
maxVector.y = 0;
// method to highlight box given cursor
this.select = function(cursor) {
selectedBox = this;
if (this && cursor) {
selectedBox.cursor = cursor;
}
updateHoverBoxes(cursor);
this.changeBoundingBoxColor(new THREE.Color( 0,0,7 ) );
}
// rotate back the corner points
rotate(minVector, maxVector, -box.angle);
rotate(topLeft, bottomRight, -box.angle);
rotate(topCenter, bottomCenter, -box.angle);
// set updated corner points used to resize box
box.geometry.vertices[0] = maxVector.clone();
box.geometry.vertices[1] = minVector.clone();
box.geometry.vertices[2] = topLeft.clone();
box.geometry.vertices[3] = bottomRight.clone();
box.geometry.vertices[4] = bottomCenter.clone();
// changes and updates a box's point's color given point index and color
this.changePointColor = function(idx, color) {
this.colors[idx] = color;
this.geometry.colorsNeedUpdate = true;
}
// method to change color of bounding box
this.changeBoundingBoxColor = function(color) {
var boxHelperCopy = new THREE.Box3Helper( this.boundingBox, color );
scene.add(boxHelperCopy);
scene.remove(this.boxHelper);
this.boxHelper = boxHelperCopy;
boxHelperCopy.rotation.y = this.angle;
}
// tell scene to update corner points
box.geometry.verticesNeedUpdate = true;
this.output = function() {
return new OutputBox(this);
}
}
// method to rotate bounding box by clicking and dragging rotate point,
// which is the top center point on the bounding box
function rotateBox(box, cursor) {
// get corner points
var maxVector = box.geometry.vertices[0].clone();
var minVector = box.geometry.vertices[1].clone();
var topLeft = box.geometry.vertices[2].clone();
var bottomRight = box.geometry.vertices[3].clone();
var topCenter = getCenter(maxVector, topLeft);
var bottomCenter = box.geometry.vertices[4].clone();
// get relative angle of cursor with respect to
var center = getCenter(maxVector, minVector);
var angle = getAngle(center, bottomCenter, cursor, topCenter);
// update angle of Box and bounding box
box.angle = box.angle + angle;
box.boxHelper.rotation.y = box.angle;
// rotate and update corner points
rotate(minVector, maxVector, -angle);
rotate(topLeft, bottomRight, -angle);
rotate(topCenter, bottomCenter, -angle);
box.geometry.vertices[0] = maxVector.clone();
box.geometry.vertices[1] = minVector.clone();
box.geometry.vertices[2] = topLeft.clone();
box.geometry.vertices[3] = bottomRight.clone();
box.geometry.vertices[4] = bottomCenter.clone();
// tell scene to update corner points
box.geometry.verticesNeedUpdate = true;
}
// gets angle between v1 and v2 with respect to origin
//
......@@ -181,19 +253,19 @@ function highlightCorners() {
// if there was a previously hovered box, change its color back to red
if (hoverBox) {
changePointColor(hoverBox, hoverIdx, new THREE.Color(7, 0, 0));
hoverBox.changePointColor(hoverIdx, new THREE.Color(7, 0, 0));
}
// update hover box
hoverBox = box;
hoverIdx = closestIdx;
changePointColor(hoverBox, hoverIdx, new THREE.Color(0, 0, 7));
hoverBox.changePointColor(hoverIdx, new THREE.Color(0, 0, 7));
} else {
// change color of previously hovered box back to red
if (hoverBox) {
changePointColor(hoverBox, hoverIdx, new THREE.Color(7, 0, 0));
hoverBox.changePointColor(hoverIdx, new THREE.Color(7, 0, 0));
}
// set hover box to null since there is no intersection
......@@ -202,59 +274,10 @@ function highlightCorners() {
}
// changes and updates a box's point's color given point index and color
function changePointColor(box, idx, color) {
box.colors[idx] = color;
box.geometry.colorsNeedUpdate = true;
}
// method to translate bounding box given a reference point
function moveBox(box, v) {
// get difference in x and z coordinates between cursor when
// box was selected and current cursor position
var dx = v.x - box.cursor.x;
var dz = v.z - box.cursor.z;
// update all points related to box by dx and dz
box.anchor.x += dx;
box.anchor.z += dz;
box.cursor = v.clone();
for (var i = 0; i < box.geometry.vertices.length; i++) {
var p = box.geometry.vertices[i];
p.x += dx;
p.z += dz;
}
// shift bounding box given new corner points
var maxVector = box.geometry.vertices[0].clone();
var minVector = box.geometry.vertices[1].clone();
var topLeft = box.geometry.vertices[2].clone();
var bottomRight = box.geometry.vertices[3].clone();
var topCenter = getCenter(maxVector, topLeft);
var bottomCenter = box.geometry.vertices[4].clone();
rotate(maxVector, minVector, box.angle);
rotate(topLeft, bottomRight, box.angle);
rotate(topCenter, bottomCenter, box.angle);
// need to do this to make matrix invertible
maxVector.y += 0.0000001;
box.boundingBox.set(minVector, maxVector);
// tell scene to update corner points
box.geometry.verticesNeedUpdate = true;
}
// method to change color of bounding box
function changeBoundingBoxColor(box, color) {
var boxHelperCopy = new THREE.Box3Helper( box.boundingBox, color );
scene.add(boxHelperCopy);
scene.remove(box.boxHelper);
box.boxHelper = boxHelperCopy;
boxHelperCopy.rotation.y = box.angle;
}
// method to add box to boundingBoxes and object id table
function addBox(box) {
......@@ -264,12 +287,15 @@ function addBox(box) {
}
// method to highlight box given cursor
function selectBox(box, cursor) {
selectedBox = box;
if (box && cursor) {
selectedBox.cursor = cursor;
}
updateHoverBoxes(cursor);
changeBoundingBoxColor(box, new THREE.Color( 0,0,7 ) );
function OutputBox(box) {
var v1 = box.geometry.vertices[0];
var v2 = box.geometry.vertices[1];
var v3 = box.geometry.vertices[2];
var center = getCenter(v1, v2);
this.center = new THREE.Vector2(-center.z, center.x);
this.width = distance2D(v1, v3);
this.length = distance2D(v2, v3);
this.angle = box.angle;
this.object_id = box.object_id;
}
\ No newline at end of file
......@@ -45,6 +45,8 @@ var pointMaterial = new THREE.PointsMaterial( { size: pointSize * 4, sizeAttenua
var evaluator;
var yCoords = [];
var isRecording = false;
var evaluators;
var evaluation;
init();
var id = 0;
......@@ -103,7 +105,6 @@ function generatePointCloud( vertices, color ) {
var k = 0;
var stride = 4;
for ( var i = 0, l = vertices.length / 4; i < l; i ++ ) {
// creates new vector from a cluster and adds to geometry
var v = new THREE.Vector3( vertices[ stride * k + 1 ],
......@@ -163,22 +164,50 @@ function init() {
//