DecoderWorker.js 7.6 KB

1
  1. function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_unsupportedIterableToArray(t,e)||_nonIterableRest()}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArrayLimit(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,a=[],o=!0,A=!1;try{for(r=r.call(t);!(o=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);o=!0);}catch(t){A=!0,i=t}finally{try{o||null==r.return||r.return()}finally{if(A)throw i}}return a}}function _unsupportedIterableToArray(t,e){if(t){if("string"==typeof t)return _arrayLikeToArray(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(r="Object"===r&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(t,e):void 0}}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _createForOfIteratorHelper(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=_unsupportedIterableToArray(t))||e&&t&&"number"==typeof t.length){r&&(t=r);function n(){}var i=0;return{s:n,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,A=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){A=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(A)throw a}}}}var obj,PointAttributeTypes={DATA_TYPE_DOUBLE:{ordinal:0,name:"double",size:8},DATA_TYPE_FLOAT:{ordinal:1,name:"float",size:4},DATA_TYPE_INT8:{ordinal:2,name:"int8",size:1},DATA_TYPE_UINT8:{ordinal:3,name:"uint8",size:1},DATA_TYPE_INT16:{ordinal:4,name:"int16",size:2},DATA_TYPE_UINT16:{ordinal:5,name:"uint16",size:2},DATA_TYPE_INT32:{ordinal:6,name:"int32",size:4},DATA_TYPE_UINT32:{ordinal:7,name:"uint32",size:4},DATA_TYPE_INT64:{ordinal:8,name:"int64",size:8},DATA_TYPE_UINT64:{ordinal:9,name:"uint64",size:8}},i=0;for(obj in PointAttributeTypes)PointAttributeTypes[i]=PointAttributeTypes[obj],i++;var PointAttribute=_createClass(function t(e,r,n){_classCallCheck(this,t),this.name=e,this.type=r,this.numElements=n,this.byteSize=this.numElements*this.type.size,this.description="",this.range=[1/0,-1/0]}),replacements={COLOR_PACKED:"rgba",RGBA:"rgba",INTENSITY:"intensity",CLASSIFICATION:"classification",GPS_TIME:"gps-time"},replaceOldNames=function(t){return replacements[t]||t};PointAttribute.POSITION_CARTESIAN=new PointAttribute("POSITION_CARTESIAN",PointAttributeTypes.DATA_TYPE_FLOAT,3),PointAttribute.RGBA_PACKED=new PointAttribute(replaceOldNames("COLOR_PACKED"),PointAttributeTypes.DATA_TYPE_INT8,4),PointAttribute.COLOR_PACKED=PointAttribute.RGBA_PACKED,PointAttribute.RGB_PACKED=new PointAttribute("COLOR_PACKED",PointAttributeTypes.DATA_TYPE_INT8,3),PointAttribute.NORMAL_FLOATS=new PointAttribute("NORMAL_FLOATS",PointAttributeTypes.DATA_TYPE_FLOAT,3),PointAttribute.INTENSITY=new PointAttribute(replaceOldNames("INTENSITY"),PointAttributeTypes.DATA_TYPE_UINT16,1),PointAttribute.CLASSIFICATION=new PointAttribute(replaceOldNames("CLASSIFICATION"),PointAttributeTypes.DATA_TYPE_UINT8,1),PointAttribute.NORMAL_SPHEREMAPPED=new PointAttribute("NORMAL_SPHEREMAPPED",PointAttributeTypes.DATA_TYPE_UINT8,2),PointAttribute.NORMAL_OCT16=new PointAttribute("NORMAL_OCT16",PointAttributeTypes.DATA_TYPE_UINT8,2),PointAttribute.NORMAL=new PointAttribute("NORMAL",PointAttributeTypes.DATA_TYPE_FLOAT,3),PointAttribute.RETURN_NUMBER=new PointAttribute("RETURN_NUMBER",PointAttributeTypes.DATA_TYPE_UINT8,1),PointAttribute.NUMBER_OF_RETURNS=new PointAttribute("NUMBER_OF_RETURNS",PointAttributeTypes.DATA_TYPE_UINT8,1),PointAttribute.SOURCE_ID=new PointAttribute("SOURCE_ID",PointAttributeTypes.DATA_TYPE_UINT16,1),PointAttribute.INDICES=new PointAttribute("INDICES",PointAttributeTypes.DATA_TYPE_UINT32,1),PointAttribute.SPACING=new PointAttribute("SPACING",PointAttributeTypes.DATA_TYPE_FLOAT,1),PointAttribute.GPS_TIME=new PointAttribute(replaceOldNames("GPS_TIME"),PointAttributeTypes.DATA_TYPE_DOUBLE,1);var typedArrayMapping={int8:Int8Array,int16:Int16Array,int32:Int32Array,int64:Float64Array,uint8:Uint8Array,uint16:Uint16Array,uint32:Uint32Array,uint64:Float64Array,float:Float32Array,double:Float64Array};Potree={},onmessage=function(t){var e,r=t.data,n=r.buffer,i=r.pointAttributes,a=r.scale,o=(r.name,r.min),A=(r.max,r.size),u=r.offset,l=r.numPoints,s=(performance.now(),new DataView(n)),T={},f=0,b=0,y=_createForOfIteratorHelper(i.attributes);try{for(y.s();!(e=y.n()).done;)b+=e.value.byteSize}catch(t){y.e(t)}finally{y.f()}var P,_=new Uint32Array(Math.pow(32,3)),p=0,c=_createForOfIteratorHelper(i.attributes);try{for(c.s();!(P=c.n()).done;){var I=P.value;if(["POSITION_CARTESIAN","position"].includes(I.name)){for(var E=new ArrayBuffer(4*l*3),m=new Float32Array(E),N=0;N<l;N++){var d=N*b,O=s.getInt32(d+f+0,!0)*a[0]+u[0]-o.x,w=s.getInt32(d+f+4,!0)*a[1]+u[1]-o.y,D=s.getInt32(d+f+8,!0)*a[2]+u[2]-o.z;0==_[function(t,e,r){t=32*t/A.x,e=32*e/A.y,r=32*r/A.z;return Math.min(parseInt(t),31)+32*Math.min(parseInt(e),31)+32*Math.min(parseInt(r),31)*32}(O,w,D)]++&&p++,m[3*N+0]=O,m[3*N+1]=w,m[3*N+2]=D}T[I.name]={buffer:E,attribute:I}}else if(["RGBA","rgba"].includes(I.name)){for(var v=new ArrayBuffer(4*l),S=new Uint8Array(v),h=0;h<l;h++){var C=h*b,R=s.getUint16(C+f+0,!0),U=s.getUint16(C+f+2,!0),g=s.getUint16(C+f+4,!0);S[4*h+0]=255<R?R/256:R,S[4*h+1]=255<U?U/256:U,S[4*h+2]=255<g?g/256:g}T[I.name]={buffer:v,attribute:I}}else{var L=new ArrayBuffer(4*l),Y=new Float32Array(L),F=typedArrayMapping[I.type.name];preciseBuffer=new F(l);var M,B,z=0,G=1,j={int8:s.getInt8,int16:s.getInt16,int32:s.getInt32,uint8:s.getUint8,uint16:s.getUint16,uint32:s.getUint32,float:s.getFloat32,double:s.getFloat64}[I.type.name].bind(s);4<I.type.size&&(B=(M=_slicedToArray(I.range,2))[0],G=1/(M[1]-(z=B)));for(var H=0;H<l;H++){var K=j(H*b+f,!0);Y[H]=(K-z)*G,preciseBuffer[H]=K}T[I.name]={buffer:L,preciseBuffer:preciseBuffer,attribute:I,offset:z,scale:G}}f+=I.byteSize}}catch(t){c.e(t)}finally{c.f()}for(var t=parseInt(l/p),r=new ArrayBuffer(4*l),k=new Uint32Array(r),x=0;x<l;x++)k[x]=x;T.INDICES={buffer:r,attribute:PointAttribute.INDICES};var V,W=_createForOfIteratorHelper(i.vectors);try{for(W.s();!(V=W.n()).done;){var $,q=V.value,J=q.name,Q=q.attributes,X=Q.length,Z=new ArrayBuffer(X*l*4),tt=new Float32Array(Z),et=0,rt=_createForOfIteratorHelper(Q);try{for(rt.s();!($=rt.n()).done;){for(var nt=T[$.value],it=nt.offset,at=nt.scale,ot=new DataView(nt.buffer),At=ot.getFloat32.bind(ot),ut=0;ut<l;ut++){var lt=At(4*ut,!0);tt[ut*X+et]=lt/at+it}et++}}catch(t){rt.e(t)}finally{rt.f()}var st=new PointAttribute(J,PointAttributeTypes.DATA_TYPE_FLOAT,3);T[J]={buffer:Z,attribute:st}}}catch(t){W.e(t)}finally{W.f()}var Tt,ft={buffer:n,attributeBuffers:T,density:t},bt=[];for(Tt in ft.attributeBuffers)bt.push(ft.attributeBuffers[Tt].buffer);bt.push(n),postMessage(ft,bt)};