1 /**
  2  * potree.js 
  3  * http://potree.org
  4  *
  5  * Copyright 2012, Markus Sch�tz
  6  * Licensed under the GPL Version 2 or later.
  7  * - http://potree.org/wp/?page_id=7
  8  * - http://www.gnu.org/licenses/gpl-3.0.html
  9  *
 10  */
 11 
 12 /**
 13  * Used for some evil javascript inheritance magic.
 14  * Get rid of it as soon as javascript classes are available.
 15  * 
 16  * @see http://livingmachines.net/2009/03/creating-javascript-classes-part-4-method-overrides/
 17  */
 18 var inheriting = { };
 19 
 20 
 21 
 22 /**
 23  * load a binary resource from the given url.
 24  * 
 25  * @see https://developer.mozilla.org/En/Using_XMLHttpRequest 
 26  * 
 27  */
 28 function load_binary_resource(url) {
 29 	var req = new XMLHttpRequest();
 30 	req.open('GET', url, false);
 31 	// The following line says we want to receive data as Binary and not as Unicode
 32 	req.overrideMimeType('text/plain; charset=x-user-defined');
 33 	req.send(null);
 34 	// when accessing local files, req.status will be 0
 35 	if (req.status != 200 && req.status != 0) {
 36 		console.log("req.status: '" + req.status + "'");
 37 		console.log("req.readyState: '" + req.readyState + "'");
 38 		return '';
 39 	}
 40 	return req.responseText;
 41 }
 42 
 43 /**
 44  * load a binary resource directly into an an ArrayBuffer
 45  * 
 46  * @param url
 47  * @returns an arraybuffer with data from url
 48  */
 49 function loadBinaryResourceIntoArrayBuffer(url) {
 50 	var xhr = new XMLHttpRequest();
 51 	xhr.open('GET', url, false);
 52 	xhr.responseType = 'arraybuffer';
 53 	xhr.overrideMimeType('text/plain; charset=x-user-defined');
 54 	xhr.send(null);
 55 	if (xhr.readyState == 4) {
 56 		// when accessing local files, req.status will be 0
 57 		if (xhr.status == 200 || xhr.status == 0) {
 58 			var buffer = xhr.response;
 59 			return buffer;
 60 		} else {
 61 			alert('Failed to load file! HTTP status: ' + xhr.status);
 62 		}
 63 	}
 64 
 65 	return null;
 66 }
 67 
 68 /**
 69  * returns a list of get-parameters in the open url
 70  * 
 71  * @returns {___anonymous1456_1457}
 72  */
 73 function getUrlVars() {
 74     var vars = {};
 75     var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
 76         vars[key] = value;
 77     });
 78     return vars;
 79 };
 80 
 81 /**
 82  * add separators to large numbers
 83  * 
 84  * @param nStr
 85  * @returns
 86  */
 87 function addCommas(nStr)
 88 {
 89 	nStr += '';
 90 	x = nStr.split('.');
 91 	x1 = x[0];
 92 	x2 = x.length > 1 ? '.' + x[1] : '';
 93 	var rgx = /(\d+)(\d{3})/;
 94 	while (rgx.test(x1)) {
 95 		x1 = x1.replace(rgx, '$1' + ',' + '$2');
 96 	}
 97 	return x1 + x2;
 98 }
 99 
100 //function logLRU(){
101 //	var lru = PointcloudOctreeNode.lruNodes;
102 //	
103 //	var string = "{ ";
104 //	var curr = lru.first;
105 //	var i = 0; 
106 //	while(curr != null){
107 //		string += curr.node.id;
108 //		if(curr.next != null){
109 //			string += ", ";
110 //		}
111 //		if( i > 20){
112 //			Logger.info(string);
113 //			string = "";
114 //			i = 0;
115 //		}
116 //		
117 //		curr = curr.next;
118 //		i++;
119 //	}
120 //	string += "}";
121 //	string += "(" + lru.size() + ")";
122 //	Logger.info(string);
123 //}
124