Changeset 29787
- Timestamp:
- 2015-03-17T00:27:22+13:00 (9 years ago)
- Location:
- other-projects/nz-flag-design/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/nz-flag-design/trunk/INSTALL.sh
r29785 r29787 21 21 echo "* 2. Making 'similarity-2d' world-writable so web server can save JSON data there" 22 22 echo "* => chmod a+rwx similarity-2d" 23 echo "* => chmod a+rwx similarity-2d/json-data" 23 24 echo "****" 24 25 chmod a+rwx similarity-2d 26 chmod a+rwx similarity-2d/json-data 25 27 26 28 echo "****" -
other-projects/nz-flag-design/trunk/design-2d/image-data-to-file.jsp
r29608 r29787 1 <%@ page contentType="text/html; charset=UTF-8" %> 1 2 <!DOCTYPE html> 2 3 <html> -
other-projects/nz-flag-design/trunk/main-form/choose-canvas.html
r29781 r29787 74 74 $.getJSON( "../similarity-2d/flag-aspect-ratios-json.jsp", function( data ) { 75 75 76 var scale_to_y_dim = 130; 76 77 //var scale_to_y_dim = 130; 78 79 // express scale_to_y_dim to use relative to height of window 80 81 var la_y_dim = $(window).height() - $('#aspect-ratio-div').position().top; 82 var scale_to_y_dim = la_y_dim/4; 83 84 //alert("scale_to_y_dim = " + scale_to_y_dim); 77 85 78 86 var items = []; … … 131 139 p--; 132 140 } 133 /*134 var nz_prioritized_flags = ratio_table.flags.sort( function (a, b) {135 var a_title = a.replace(/^.*\//,"").replace(/\.(.*?)$/,"");136 if (a_title == "nz") {137 return -1;138 }139 else {140 return 0;141 }142 });143 */144 141 145 142 $.each(nz_prioritized_flags, function(index, flag_filename) { … … 174 171 175 172 $('#aspect-ratio-div').append("<div class='centredDiv' style='width: 100%'>"+items.join("\n")+"</div>"); 173 174 175 // now change the flag tooltip labels into their country names 176 $.getJSON( "../similarity-2d/iso-3166-keyed-by-alpha-2-countrycodes.json", function( data ) { 177 178 }); 179 176 180 }); 177 181 }); … … 202 206 <h2>Canvas Size</h2> 203 207 204 <div class="dialog" id="dialog" title=" Ratio Select Dialog" width="800px">208 <div class="dialog" id="dialog" title="Flat Aspect Ratio Selection Panel" widthXX="800px"> 205 209 <br><br> 206 210 <h2>Please choose from the following aspect ratios.</h2> … … 257 261 } 258 262 } 263 264 259 265 </script> 260 266 … … 264 270 265 271 </div><!-- /content --> 272 273 <!-- make persistent? 274 <div data-role="footer" style="width:100%;"> 275 COSI: Centre of Open Source Innovation @ The University of Waikato. 276 </div> 277 --> 266 278 267 279 </div><!-- /page --> -
other-projects/nz-flag-design/trunk/main-form/choose-palette.html
r29781 r29787 35 35 <span class="left story-icon research" ></span> 36 36 <h2>Choose Colour Palette</h2> 37 <div> 38 <h3 style="font-size: large; position: relative; display: inline-block;"> 37 38 <div class="dialog" id="dialog" title="Colour Palette Selection Panel" widthXX="800px"> 39 <h2 style="position: relative; display: inline-block;"> 39 40 Click on a palette circle to select it, and change its colour using the colour picker to the right 40 </h3> 41 41 </h2> 42 42 <a style="font-size: medium; padding-left: 10px;" 43 43 href="http://www.netstate.com/states/symb/flags/flag_design_principles.htm" target="_blank"> … … 98 98 99 99 console.log("ActivateColourPalette()"); 100 101 // Page not shown yet, so the y-position of <svg> is still 0 102 // => make height purely a percentage of height 103 var la_y_dim = $(window).height(); 104 var svg_y_dim = 0.5 * la_y_dim; 105 $('#svg-palette').css("height",svg_y_dim+"px"); 100 106 101 107 // init state-keeping variables … … 227 233 return false; 228 234 } 235 236 237 $(window).resize(function() { 238 console.log("choose-palette resize()"); 239 console.log("position top = " + $('#svg-palette').position().top); 240 console.log("offset top = " + $('#svg-palette').offset().top); 241 242 var la_y_dim = $(window).height() - $('#svg-palette').offset().top; 243 var svg_y_dim = 0.65 * la_y_dim; 244 $('#svg-palette').css("height",svg_y_dim+"px"); 245 }); 229 246 230 247 -
other-projects/nz-flag-design/trunk/main-form/enter-name.html
r29781 r29787 25 25 </div> 26 26 27 <a target="_parent" href="../index.html" class="back-button back-left"></a> 27 <!-- 28 <a target="_parent" href="../index.html" class="back-button back-left"></a> 29 --> 28 30 29 31 <div class="story-page"> … … 31 33 <!-- put custom content here --> 32 34 <div class="story-title"> 33 <h1 id="enter-name-header" class="center"> Enter Name</h1>35 <h1 id="enter-name-header" class="center">Contact Details</h1> 34 36 <!-- 35 37 <p class="center">- - xx </p> 36 38 --> 37 <p> 38 Your Name: 39 </p> 40 <form> 41 <input type="text" autofocus="autofocus" style="color: white;" /> 39 <style> 40 input { 41 color: white; 42 } 43 </style> 44 <form style="width: 400px; margin-left:auto; margin-right:auto;"> 45 <p> 46 Your Name: 47 </p> 48 <input type="text" autofocus="autofocus" style="color: white;" name="name" /> 49 50 <p> 51 Contact email: 52 </p> 53 <input type="text" name="email" /> 54 55 56 <div style="padding-top: 120px; padding-left: 100px; padding-right: 100px"> 57 <input type="submit" value="Submit Flag Design" /> 58 </div> 42 59 </form> 43 60 </div> -
other-projects/nz-flag-design/trunk/similarity-2d/flag-processing.js
r29757 r29787 5 5 var show_progress = 5; 6 6 7 var start_hist_delay = 4000;7 var start_hist_delay = 1000; // used to be 4000 8 8 var mini_delay = 300; 9 9 10 10 11 var hasLocalStorage = false; 12 var needToComputeHistograms = true; 11 var hasLocalStorage = (typeof(Storage) !== "undefined"); // **** 12 //var hasLocalStorage = false; 13 13 14 var quantHSLHistogramArray; 15 16 //var saveOnServer=true; 17 var saveOnServer=false; 18 var retrieveFromServer=true; 19 20 21 function runlength_encode(int_array) { 22 23 var array_len = int_array.length; 24 25 if (array_len<2) { 26 console.warn("runlength_encode(): unable to run-length encode array of length " + array_len); 27 console.warn("returning null"); 28 return null; 29 } 30 31 var int_array_rle = new Array(); 32 33 34 var lock_val=int_array[0]; 35 var next_val=int_array[1]; 36 var i = 1; 37 38 while (i<array_len) { 39 var c=1; 40 while (next_val==lock_val) { 41 c++; 42 var next_pos = i+c-1; 43 if (next_pos<array_len) { 44 next_val = int_array[next_pos]; 45 } 46 else { 47 // hit end of array 48 break; 49 } 50 } 51 // come out of a run-length sequence of same val 52 // next_val is one past the run-length sequence 53 54 int_array_rle.push(c); 55 int_array_rle.push(lock_val); 56 57 i+=c; 58 59 if (i<array_len) { 60 lock_val = next_val; 61 next_val = int_array[i]; 62 } 63 else { 64 break; 65 } 66 } 67 68 return int_array_rle; 69 } 70 71 72 73 function runlength_decode(int_array_rle) { 74 75 var array_rle_len = int_array_rle.length; 76 77 if (array_rle_len<2) { 78 console.warn("runlength_decode(): unable to run-length decode array of length " + array_rle_len); 79 console.warn("returning null"); 80 return null; 81 } 82 83 var int_array = new Array(); 84 for (var i=0; i<array_rle_len; i+=2){ 85 var rep = int_array_rle[i]; 86 var val = int_array_rle[i+1]; 87 for (var r=0; r<rep; r++) { 88 int_array.push(val); 89 } 90 } 91 92 return int_array; 93 } 94 95 96 97 function arrays_identical(int_array1, int_array2) { 98 99 var array_len1 = int_array1.length; 100 var array_len2 = int_array2.length; 101 102 if (array_len1 != array_len2) { 103 console.warn("arrays_identical(): array lengths differ, array1("+array_len1+") vs array2(" + array_len2 + ")"); 104 return false; 105 } 106 107 var all_ident = true; 108 109 for (var i=0; i<array_len1; i++){ 110 if (int_array1[i] != int_array2[i]) { 111 all_ident = false; 112 break; 113 } 114 } 115 116 return all_ident; 117 } 14 118 15 119 … … 61 165 var y,p; 62 166 for (y=0,p=0; y<imageObj.height; y++) { 63 // setTimeout(function() {64 167 var x; 65 168 for (x=0; x<imageObj.width; x++,p+=4) { … … 87 190 outputArray[result] += count; 88 191 } 89 // },4);90 192 } 91 193 … … 94 196 outputArray[i] = outputArray[i] / total; 95 197 } 198 199 /* 200 if (saveOnServer) { 201 console.log("Saving HSV quantized histogram on server: " + imageObj.title) 202 //console.log("outputArray = " + JSON.stringify(outputArray)); 203 204 var jsonFilename = imageObj.title + ".json"; 205 var data = { jsonFilename: jsonFilename, jsonData: JSON.stringify(outputArray)}; 206 207 console.log("Saving colour histogram data for " + imageObj.title); 208 $.ajax({ 209 type: "POST", 210 url: "../similarity-2d/save-json-data.jsp", 211 data: data 212 }); 213 } 214 */ 96 215 97 216 return outputArray; … … 182 301 */ 183 302 184 185 186 303 imageObj.onclick = function(e) { 187 304 // Store result of HSL quantization in the image object/tag … … 231 348 // Only need to compute this if it is not 232 349 // already stored in the object/tag 233 imageObj.quantHSLHist = createHSLHistogram(imageObj,16); 234 //console.log(imageObj.quantHSLHist); 350 351 if (retrieveFromServer) { 352 // see if it is stored on the server 353 console.log("Retrieving stored colour histogram for " + imageObj.title + " ..."); 354 $.ajax({ 355 async: false, 356 dataType: "json", 357 url: "../similarity-2d/json-data/" + imageObj.title + ".json", 358 success: function(data) { 359 console.log("... success"); 360 // 'data' is the array of integer vals we want 361 imageObj.quantHSLHist = data; 362 }, 363 error: function() { 364 console.log("... not stored on server"); 365 // not stored on the server (currently) 366 // => need to compute it 367 imageObj.quantHSLHist = createHSLHistogram(imageObj,16); 368 //console.log(imageObj.quantHSLHist); 369 370 } 371 }); 372 } 373 else { 374 imageObj.quantHSLHist = createHSLHistogram(imageObj,16); 375 } 376 235 377 } 236 378 … … 294 436 function doneComputingHistograms(img_list_len) 295 437 { 438 quantHSLHistogramArray = new Array(img_list_len); 439 for (var i=0; i<img_list_len; i++) { 440 var flag_id = "flag-img-" + i; 441 var imageObj = document.getElementById(flag_id); 442 quantHSLHistogramArray[i] = imageObj.quantHSLHist; 443 } 444 var json_hist_data = JSON.stringify(quantHSLHistogramArray); 445 296 446 if (hasLocalStorage) { 297 447 // build up quantHSLHistogramArray from all the images 298 448 299 quantHSLHistogramArray = new Array(img_list_len);300 var i;301 for (i=0; i<img_list_len; i++) {302 var flag_id = "flag-img-" + i;303 var imageObj = document.getElementById(flag_id);304 quantHSLHistogramArray[i] = imageObj.quantHSLHist;305 }306 307 449 console.log("Storing computed HSL histograms in localStorage"); 308 localStorage.quantHSLHistogramArray = JSON.stringify(quantHSLHistogramArray); 450 localStorage.quantHSLHistogramArray = json_hist_data; 451 } 452 453 if (saveOnServer) { 454 // run-length encode data, so less to send 455 var quantHSLHistogramArrayRLE = new Array(img_list_len); 456 for (var i=0; i<img_list_len; i++) { 457 //console.log("rle encoding ... i = " + i); 458 quantHSLHistogramArrayRLE[i] = runlength_encode(quantHSLHistogramArray[i]) 459 460 //var test_decode_array = runlength_decode(quantHSLHistogramArrayRLE[i]); 461 //console.log("Checking decoded array: " + arrays_identical(test_decode_array,quantHSLHistogramArray[i])); 462 } 463 464 465 var json_hist_data_rle = JSON.stringify(quantHSLHistogramArrayRLE); 466 467 var json_filename = "all-hsv-histograms-rle.json"; 468 var data = { jsonFilename: json_filename, jsonData: json_hist_data_rle}; 469 470 console.log("Saving colour histogram data for all flags"); 471 $.ajax({ 472 type: "POST", 473 url: "../similarity-2d/save-json-data.jsp", 474 data: data 475 }); 309 476 } 310 477 } … … 312 479 function doneDisplayFlags(img_list,$progressArea,$progressBar) 313 480 { 314 hasLocalStorage = false;315 needToComputeHistograms = true; 316 317 if (typeof(Storage) !== "undefined") { 318 hasLocalStorage = true; 481 console.log("doneDisplayFlags()"); 482 483 var needToComputeHistograms = true; 484 485 if (hasLocalStorage) { 319 486 320 487 if (localStorage.quantHSLHistogramArray) { 321 488 322 console.log("Retrieving quantized HSL histograms ");489 console.log("Retrieving quantized HSL histograms from local storage"); 323 490 324 491 var stored_hist_array = JSON.parse(localStorage["quantHSLHistogramArray"]); … … 336 503 } 337 504 338 339 505 needToComputeHistograms = false; 340 506 } … … 345 511 } 346 512 347 348 513 if (needToComputeHistograms) { 349 computeFlagHistograms(img_list,$progressArea,$progressBar); 514 515 if (retrieveFromServer) { 516 // before computing histograms from scratch, see if resulting data stored on server 517 518 console.log("Retrieving stored colour histgram data for all flags ..."); 519 $.ajax({ 520 async: true, 521 dataType: "json", 522 url: "../similarity-2d/json-data/all-hsv-histograms-rle.json", 523 success: function(rle_data) { 524 console.log("... success"); 525 if (rle_data.length != img_list.length) { 526 console.log("Stored histogram data out of date with flag list."); 527 // what is stored on the sever differed to the number of images displayed 528 computeFlagHistograms(img_list,$progressArea,$progressBar); 529 } 530 else { 531 var img_list_len = img_list.length; 532 quantHSLHistogramArray = new Array(img_list_len); 533 534 // Need to rle decode each entry in this array 535 for (var i=0; i<img_list_len; i++) { 536 quantHSLHistogramArray[i] = runlength_decode(rle_data[i]); 537 var flag_id = "flag-img-" + i; 538 var imageObj = document.getElementById(flag_id); 539 imageObj.quantHSLHist = quantHSLHistogramArray[i]; 540 541 } 542 543 needToComputeHistograms = false; 544 545 $progressArea.slideUp(); 546 doneComputingHistograms(img_list.length); 547 548 } 549 }, 550 error: function() { 551 console.log("... not stored on server"); 552 computeFlagHistograms(img_list,$progressArea,$progressBar); 553 } 554 }); 555 556 557 } 558 else { 559 computeFlagHistograms(img_list,$progressArea,$progressBar); 560 } 350 561 } 351 562 else { -
other-projects/nz-flag-design/trunk/similarity-2d/list-flags.jsp
r29621 r29787 2 2 String docBase = getServletContext().getRealPath("/"); 3 3 File similarityDir = new File(docBase,"similarity-2d"); 4 File imagesDir = new File(similarityDir,"Images"); 4 5 String imagesStr = (request.getParameter("imagesDir")!=null) ? request.getParameter("imagesDir") : "import"; 6 File imagesDir = new File(similarityDir,imagesStr); 5 7 6 8 ArrayList<File> imageFileList = listFilesForFolder(imagesDir,".gif"); 7 9 8 File imageUrlBase = new File( "Images");10 File imageUrlBase = new File(imagesStr); 9 11 10 String action = request.getParameter("action");12 //String action = request.getParameter("action"); 11 13 12 14 out.println("<script>");
Note:
See TracChangeset
for help on using the changeset viewer.