|
1 | 1 | <!doctype html> |
2 | 2 | <html> |
3 | 3 | <head> |
4 | | -<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> |
| 4 | +<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> |
5 | 5 | <script type="text/javascript" src="js/jsc3d.js"></script> |
6 | 6 |
|
7 | 7 | <script> |
8 | | - function image_for_object(object_id, mesh_id) { |
9 | | - // Get the name of the object |
10 | | - var object_name = ''; |
11 | | - $.getJSON("/object_recognition/" + object_id, function(data) { |
12 | | - object_name = data.object_name; |
13 | | - }); |
14 | | - |
| 8 | + // Creates the icon of an object |
| 9 | + function iconForObject(object_id, mesh_id) { |
15 | 10 | $.getJSON("/object_recognition/_design/observations/_view/by_object_id?key=\"" |
16 | 11 | + object_id + "\"&limit=1", |
17 | 12 | function(data) { |
18 | 13 | if (data.rows.length == 0) { |
19 | | - $("<a>").attr("href", "?mesh=" + mesh_id).text( |
20 | | - object_name + ' (' + object_id + ')').appendTo("#links"); |
| 14 | + $.getJSON("/object_recognition/" + object_id, function(data) { |
| 15 | + $("<a>").attr("href", "?mesh=" + mesh_id).text( |
| 16 | + data.object_name + ' (' + object_id + ')').appendTo("#links"); |
| 17 | + }); |
21 | 18 | } else { |
22 | 19 | var observation_id = data.rows[0].id |
23 | 20 | var a = $("<a>").attr("href", "?mesh=" + mesh_id).appendTo("#links"); |
|
26 | 23 | } |
27 | 24 | }); |
28 | 25 | } |
29 | | - function get_list_of_urls() { |
| 26 | + |
| 27 | + // Create the icons for the objects |
| 28 | + function createObjectIcons() { |
30 | 29 | $.getJSON("/object_recognition/_design/models/_view/by_object_id_and_mesh", |
31 | 30 | function(data) { |
| 31 | + var is_first = false; |
| 32 | + var vars = getUrlVars(); |
| 33 | + if (!(vars.hasOwnProperty("mesh"))) |
| 34 | + is_first = true; |
| 35 | + |
32 | 36 | $.each(data.rows, function(key, val) { |
33 | | - image_for_object(val.value.object_id, val.id); |
| 37 | + if (is_first) { |
| 38 | + is_first = false; |
| 39 | + createViewer(val.id); |
| 40 | + } |
| 41 | + iconForObject(val.value.object_id, val.id); |
| 42 | + } |
| 43 | + ); |
34 | 44 | }); |
35 | | - }); |
36 | 45 | } |
37 | 46 |
|
| 47 | + // Get the information embedded in the url |
38 | 48 | function getUrlVars() { |
39 | 49 | var vars = {}, hash; |
40 | 50 | var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); |
|
44 | 54 | } |
45 | 55 | return vars; |
46 | 56 | } |
47 | | - window.onload = function() { |
48 | | - get_list_of_urls(); |
49 | | - var vars = getUrlVars(); |
50 | 57 |
|
51 | | - // Load the mesh |
52 | | - $.getJSON("/object_recognition/" + vars.mesh, function(data) { |
| 58 | + // Create a 3d viewer for a given mesh_id |
| 59 | + function createViewer(mesh_id) { |
| 60 | + $.getJSON("/object_recognition/" + mesh_id, function(data) { |
53 | 61 | if (!("_attachments" in data)) |
54 | 62 | return; |
55 | 63 | // Find interesting names of the meshes |
|
67 | 75 | str_stl = name; |
68 | 76 | } |
69 | 77 |
|
70 | | - var viewer = new JSC3D.Viewer(document.getElementById('mesh')); |
| 78 | + var viewer = new JSC3D.Viewer(document.getElementById('mesh')); |
71 | 79 | if (str_original) |
72 | | - viewer.setParameter('SceneUrl', "/object_recognition/" + vars.mesh + "/" + str_original); |
73 | | - else if (str_original) |
74 | | - viewer.setParameter('SceneUrl', "/object_recognition/" + vars.mesh + "/" + str_obj); |
75 | | - else if (str_original) |
76 | | - viewer.setParameter('SceneUrl', "/object_recognition/" + vars.mesh + "/" + str_stl); |
| 80 | + viewer.setParameter('SceneUrl', "/object_recognition/" + mesh_id + "/" + str_original); |
| 81 | + else if (str_obj) |
| 82 | + viewer.setParameter('SceneUrl', "/object_recognition/" + mesh_id + "/" + str_obj); |
| 83 | + else if (str_stl) |
| 84 | + viewer.setParameter('SceneUrl', "/object_recognition/" + mesh_id + "/" + str_stl); |
77 | 85 |
|
78 | 86 | viewer.setParameter('BackgroundColor1', '#E5D7BA'); |
79 | 87 | viewer.setParameter('BackgroundColor2', '#383840'); |
|
85 | 93 | viewer.update(); |
86 | 94 | }); |
87 | 95 | } |
| 96 | + |
| 97 | + window.onload = function() { |
| 98 | + createObjectIcons(); |
| 99 | + var vars = getUrlVars(); |
| 100 | + |
| 101 | + // Load the mesh |
| 102 | + if (vars.hasOwnProperty("mesh")) |
| 103 | + createViewer(vars.mesh); |
| 104 | + } |
88 | 105 | </script> |
89 | 106 | </head> |
90 | 107 | <body> |
|
0 commit comments