├── LICENSE ├── README.md ├── plugin.yml ├── screenshots └── screenshot.png ├── web_client ├── PointCloudView.js ├── main.js ├── stylesheets │ └── pc.styl └── templates │ ├── pc.pug │ └── viewButton.pug └── webpack.helper.js /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Point Cloud Viewer 2 | 3 | Point cloud viewer that can read LAS (LAZ untested) files and display them in Girder item browser using vtk.js 4 | 5 | ![](https://github.com/OpenGeoscience/pointcloud_viewer/blob/master/screenshots/screenshot.png) 6 | 7 | # Contact 8 | 9 | Contact kitware@kitware.com for questions regarding using Point Cloud Viewer 10 | 11 | # License 12 | 13 | Copyright 2017 Kitware Inc. 14 | 15 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 16 | 17 | http://www.apache.org/licenses/LICENSE-2.0 18 | 19 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 20 | 21 | # Setup 22 | (Assuming Debian specifically Ubuntu 16.04) 23 | 24 | ## Prerequisite 25 | 26 | Install MongoDB: 27 | Instructions are here: https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu 28 | 29 | Install Girder: 30 | mkdir girder_pointcloud_viewer 31 | cd girder_pointcloud_viewer 32 | git clone --branch 2.x-maintenance https://github.com/girder/girder.git 33 | cd girder 34 | pip install -e . 35 | cd .. 36 | 37 | ## Install Girder Point Cloud Viewer Plugin 38 | 39 | git clone https://github.com/OpenGeoscience/pointcloud_viewer.git 40 | Execute `girder-install plugin -s ~/pointcloud_viewer` within the girder virtualenv 41 | Execute `girder-install web --dev --plugins pointcloud_viewer` 42 | 43 | Running: 44 | Run `girder-server` 45 | Navigate to `localhost:8080` and create a user and a file assetstore and enable this Point Cloud Viewer plugin 46 | Navigate to `localhost:8080` and navigate to a folder of LAS item 47 | Click on one of the LAS item 48 | Click on globe icon -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | name: Point Cloud Viewer 2 | version: 0.1.0 3 | npm: 4 | dependencies: 5 | babel-preset-es2015: ^6.24.1 6 | babel-preset-es2016: ^6.24.1 7 | vtk.js: 5.1.1 8 | bluebird: 3.5.0 9 | shader-loader: 1.3.1 10 | -------------------------------------------------------------------------------- /screenshots/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGeoscience/pointcloud_viewer/2b09177b4f7949fef543cd6a04ac43adf4f7d8e3/screenshots/screenshot.png -------------------------------------------------------------------------------- /web_client/PointCloudView.js: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2014 Uday Verma, uday.karan@gmail.com 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | // Girder imports 24 | import View from 'girder/views/View'; 25 | 26 | // Web imports 27 | import template from './templates/pc.pug'; 28 | import './stylesheets/pc.styl'; 29 | 30 | // TODO: Replace this with ES4 promise 31 | import Promise from 'bluebird'; 32 | 33 | // VTK JS import 34 | import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; 35 | import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper'; 36 | import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; 37 | import vtkPoints from 'vtk.js/Sources/Common/Core/Points'; 38 | import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray'; 39 | import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray'; 40 | import vtkOpenGLRenderWindow from 'vtk.js/Sources/Rendering/OpenGL/RenderWindow'; 41 | import vtkRenderWindowInteractor from 'vtk.js/Sources/Rendering/Core/RenderWindowInteractor'; 42 | import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow'; 43 | import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer'; 44 | 45 | /** 46 | * Point format spec - currently reading 0, 1, 2, 3 47 | */ 48 | var pointFormatReaders = { 49 | 0: function(dv) { 50 | return { 51 | "position": [ dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], 52 | "intensity": dv.getUint16(12, true), 53 | "classification": dv.getUint8(15, true) 54 | }; 55 | }, 56 | 1: function(dv) { 57 | return { 58 | "position": [ dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], 59 | "intensity": dv.getUint16(12, true), 60 | "classification": dv.getUint8(15, true) 61 | }; 62 | }, 63 | 2: function(dv) { 64 | return { 65 | "position": [ dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], 66 | "intensity": dv.getUint16(12, true), 67 | "classification": dv.getUint8(15, true), 68 | "color": [dv.getUint16(20, true), dv.getUint16(22, true), dv.getUint16(24, true)] 69 | }; 70 | }, 71 | 3: function(dv) { 72 | return { 73 | "position": [ dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], 74 | "intensity": dv.getUint16(12, true), 75 | "classification": dv.getUint8(15, true), 76 | "color": [dv.getUint16(28, true), dv.getUint16(30, true), dv.getUint16(32, true)] 77 | }; 78 | } 79 | }; 80 | 81 | /** 82 | * 83 | * @param {*} buf 84 | * @param {*} Type 85 | * @param {*} offset 86 | * @param {*} count 87 | */ 88 | function readAs(buf, Type, offset, count) { 89 | count = (count === undefined || count === 0 ? 1 : count); 90 | var sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count); 91 | 92 | var r = new Type(sub); 93 | if (count === undefined || count === 1) 94 | return r[0]; 95 | 96 | var ret = []; 97 | for (var i = 0 ; i < count ; i ++) { 98 | ret.push(r[i]); 99 | } 100 | 101 | return ret; 102 | } 103 | 104 | /** 105 | * Parse LAS header 106 | * 107 | * @param {*} arraybuffer 108 | */ 109 | function parseLASHeader(arraybuffer) { 110 | var _this = {}; 111 | 112 | _this.pointsOffset = readAs(arraybuffer, Uint32Array, 32*3); 113 | _this.pointsFormatId = readAs(arraybuffer, Uint8Array, 32*3+8); 114 | _this.pointsStructSize = readAs(arraybuffer, Uint16Array, 32*3+8+1); 115 | _this.pointsCount = readAs(arraybuffer, Uint32Array, 32*3 + 11); 116 | 117 | var start = 32*3 + 35; 118 | _this.scale = readAs(arraybuffer, Float64Array, start, 3); start += 24; // 8*3 119 | _this.offset = readAs(arraybuffer, Float64Array, start, 3); start += 24; 120 | 121 | var bounds = readAs(arraybuffer, Float64Array, start, 6); start += 48; // 8*6; 122 | _this.maxs = [bounds[0], bounds[2], bounds[4]]; 123 | _this.mins = [bounds[1], bounds[3], bounds[5]]; 124 | 125 | return _this; 126 | } 127 | 128 | /** 129 | * LAS Reader 130 | * @param {*} arraybuffer 131 | */ 132 | var LASLoader = function(arraybuffer) { 133 | this.arraybuffer = arraybuffer; 134 | }; 135 | 136 | /** 137 | * Open the file 138 | */ 139 | LASLoader.prototype.open = function() { 140 | this.readOffset = 0; 141 | return new Promise(function(res, rej) { 142 | setTimeout(res, 0); 143 | }); 144 | }; 145 | 146 | /** 147 | * Get header information 148 | */ 149 | LASLoader.prototype.getHeader = function() { 150 | var _this = this; 151 | 152 | return new Promise(function(res, rej) { 153 | setTimeout(function() { 154 | _this.header = parseLASHeader(_this.arraybuffer); 155 | res(_this.header); 156 | }, 0); 157 | }); 158 | }; 159 | 160 | /** 161 | * Read point data in mini-batch mode 162 | */ 163 | LASLoader.prototype.readData = function(count, offset, skip) { 164 | var _this = this; 165 | 166 | return new Promise(function(res, rej) { 167 | setTimeout(function() { 168 | if (!_this.header) 169 | return rej(new Error("Cannot start reading data till a header request is issued")); 170 | 171 | var start; 172 | if (skip <= 1) { 173 | count = Math.min(count, _this.header.pointsCount - _this.readOffset); 174 | start = _this.header.pointsOffset + _this.readOffset * _this.header.pointsStructSize; 175 | var end = start + count * _this.header.pointsStructSize; 176 | res({ 177 | buffer: _this.arraybuffer.slice(start, end), 178 | count: count, 179 | hasMoreData: _this.readOffset + count < _this.header.pointsCount}); 180 | _this.readOffset += count; 181 | } 182 | else { 183 | var pointsToRead = Math.min(count * skip, _this.header.pointsCount - _this.readOffset); 184 | var bufferSize = Math.ceil(pointsToRead / skip); 185 | var pointsRead = 0; 186 | 187 | var buf = new Uint8Array(bufferSize * _this.header.pointsStructSize); 188 | for (var i = 0 ; i < pointsToRead ; i ++) { 189 | if (i % skip === 0) { 190 | start = _this.header.pointsOffset + _this.readOffset * _this.header.pointsStructSize; 191 | var src = new Uint8Array(_this.arraybuffer, start, _this.header.pointsStructSize); 192 | 193 | buf.set(src, pointsRead * _this.header.pointsStructSize); 194 | pointsRead ++; 195 | } 196 | 197 | _this.readOffset ++; 198 | } 199 | 200 | res({ 201 | buffer: buf.buffer, 202 | count: pointsRead, 203 | hasMoreData: _this.readOffset < _this.header.pointsCount 204 | }); 205 | } 206 | }, 0); 207 | }); 208 | }; 209 | 210 | /** 211 | * Close the reader 212 | */ 213 | LASLoader.prototype.close = function() { 214 | var _this = this; 215 | return new Promise(function(res, rej) { 216 | _this.arraybuffer = null; 217 | setTimeout(res, 0); 218 | }); 219 | }; 220 | 221 | // LAZ Loader 222 | // Uses NaCL module to load LAZ files 223 | // 224 | var LAZLoader = function(arraybuffer) { 225 | this.arraybuffer = arraybuffer; 226 | this.ww = new Worker("workers/laz-loader-worker.js"); 227 | 228 | this.nextCB = null; 229 | var _this = this; 230 | 231 | this.ww.onmessage = function(e) { 232 | if (_this.nextCB !== null) { 233 | console.log('dorr: >>', e.data); 234 | _this.nextCB(e.data); 235 | _this.nextCB = null; 236 | } 237 | }; 238 | 239 | this.dorr = function(req, cb) { 240 | console.log('dorr: <<', req); 241 | _this.nextCB = cb; 242 | _this.ww.postMessage(req); 243 | }; 244 | }; 245 | 246 | LAZLoader.prototype.open = function() { 247 | 248 | // nothing needs to be done to open this file 249 | // 250 | var _this = this; 251 | return new Promise(function(res, rej) { 252 | _this.dorr({type:"open", arraybuffer: _this.arraybuffer}, function(r) { 253 | if (r.status !== 1) 254 | return rej(new Error("Failed to open file")); 255 | 256 | res(true); 257 | }); 258 | }); 259 | }; 260 | 261 | /** 262 | * 263 | */ 264 | LAZLoader.prototype.getHeader = function() { 265 | var _this = this; 266 | 267 | return new Promise(function(res, rej) { 268 | _this.dorr({type:'header'}, function(r) { 269 | if (r.status !== 1) 270 | return rej(new Error("Failed to get header")); 271 | 272 | res(r.header); 273 | }); 274 | }); 275 | }; 276 | 277 | /** 278 | * 279 | */ 280 | LAZLoader.prototype.readData = function(count, offset, skip) { 281 | var _this = this; 282 | 283 | return new Promise(function(res, rej) { 284 | _this.dorr({type:'read', count: count, offset: offset, skip: skip}, function(r) { 285 | if (r.status !== 1) 286 | return rej(new Error("Failed to read data")); 287 | res({ 288 | buffer: r.buffer, 289 | count: r.count, 290 | hasMoreData: r.hasMoreData 291 | }); 292 | }); 293 | }); 294 | }; 295 | 296 | /** 297 | * 298 | */ 299 | LAZLoader.prototype.close = function() { 300 | var _this = this; 301 | 302 | return new Promise(function(res, rej) { 303 | _this.dorr({type:'close'}, function(r) { 304 | if (r.status !== 1) 305 | return rej(new Error("Failed to close file")); 306 | 307 | res(true); 308 | }); 309 | }); 310 | }; 311 | 312 | /** 313 | * A single consistent interface for loading LAS/LAZ files 314 | */ 315 | var LASFile = function(arraybuffer) { 316 | this.arraybuffer = arraybuffer; 317 | 318 | this.determineVersion(); 319 | if (this.version > 13) 320 | throw new Error("Only file versions <= 1.3 are supported at this time"); 321 | 322 | this.determineFormat(); 323 | if (pointFormatReaders[this.formatId] === undefined) 324 | throw new Error("The point format ID is not supported"); 325 | 326 | this.loader = this.isCompressed ? 327 | new LAZLoader(this.arraybuffer) : 328 | new LASLoader(this.arraybuffer); 329 | }; 330 | 331 | /** 332 | * 333 | */ 334 | LASFile.prototype.determineFormat = function() { 335 | var formatId = readAs(this.arraybuffer, Uint8Array, 32*3+8); 336 | var bit_7 = (formatId & 0x80) >> 7; 337 | var bit_6 = (formatId & 0x40) >> 6; 338 | 339 | if (bit_7 === 1 && bit_6 === 1) 340 | throw new Error("Old style compression not supported"); 341 | 342 | this.formatId = formatId & 0x3f; 343 | this.isCompressed = (bit_7 === 1 || bit_6 === 1); 344 | }; 345 | 346 | /** 347 | * 348 | */ 349 | LASFile.prototype.determineVersion = function() { 350 | var ver = new Int8Array(this.arraybuffer, 24, 2); 351 | this.version = ver[0] * 10 + ver[1]; 352 | this.versionAsString = ver[0] + "." + ver[1]; 353 | }; 354 | 355 | /** 356 | * 357 | */ 358 | LASFile.prototype.open = function() { 359 | return this.loader.open(); 360 | }; 361 | 362 | /** 363 | * 364 | */ 365 | LASFile.prototype.getHeader = function() { 366 | return this.loader.getHeader(); 367 | }; 368 | 369 | /** 370 | * 371 | */ 372 | LASFile.prototype.readData = function(count, start, skip) { 373 | return this.loader.readData(count, start, skip); 374 | }; 375 | 376 | LASFile.prototype.close = function() { 377 | return this.loader.close(); 378 | }; 379 | 380 | /** 381 | * Decodes LAS records into points 382 | * 383 | * @param {*} buffer 384 | * @param {*} len 385 | * @param {*} header 386 | */ 387 | var LASDecoder = function(buffer, len, header) { 388 | console.log(header); 389 | console.log("POINT FORMAT ID:", header.pointsFormatId); 390 | this.arrayb = buffer; 391 | this.decoder = pointFormatReaders[header.pointsFormatId]; 392 | this.pointsCount = len; 393 | this.pointSize = header.pointsStructSize; 394 | this.scale = header.scale; 395 | this.offset = header.offset; 396 | this.mins = header.mins; 397 | this.maxs = header.maxs; 398 | }; 399 | 400 | /** 401 | * 402 | */ 403 | LASDecoder.prototype.getPoint = function(index) { 404 | if (index < 0 || index >= this.pointsCount) 405 | throw new Error("Point index out of range"); 406 | 407 | var dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize); 408 | return this.decoder(dv); 409 | }; 410 | 411 | // NACL Module support 412 | // Called by the common.js module. 413 | // 414 | // 444 | 445 | /** 446 | * 447 | */ 448 | LASFile.prototype.getUnpacker = function() { 449 | return LASDecoder; 450 | }; 451 | 452 | // 453 | 454 | /** 455 | * An object that manages a bunch of particle systems 456 | */ 457 | var ParticleSystem = function(vs, fs) { 458 | this.pss = []; // particle systems in use 459 | 460 | this.mx = null; 461 | this.mn = null; 462 | this.cg = null; 463 | this.cn = null; 464 | this.cx = null; 465 | this.in_x = null; 466 | this.in_y = null; 467 | this.klass = null; 468 | this.pointsSoFar = 0; 469 | 470 | this.renderer = null; 471 | this.renderWindow = null; 472 | }; 473 | 474 | /** 475 | * 476 | */ 477 | ParticleSystem.prototype.push = function(lasBuffer) { 478 | var count = lasBuffer.pointsCount, 479 | p, z, 480 | cg = null, 481 | mx = null, 482 | mn = null, 483 | cn = null, 484 | cx = null, 485 | in_x = null, 486 | in_n = null, 487 | klass = null; 488 | 489 | var pointBuffer = new Float32Array(count * 3); 490 | var cellBuffer = new Int32Array(count+1); 491 | var scalarBuffer = new Float32Array(count); 492 | cellBuffer[0] = count; 493 | var maxz, minz; 494 | 495 | for ( var i = 0; i < count; i ++) { 496 | p = lasBuffer.getPoint(i); 497 | z = p.position[2] * lasBuffer.scale[2] + 498 | (lasBuffer.offset[2] - lasBuffer.mins[2]); 499 | if (maxz === undefined) { 500 | maxz = z; 501 | minz = z; 502 | } else { 503 | if (z > maxz) { 504 | maxz = z; 505 | } 506 | if (z < minz) { 507 | minz = z; 508 | } 509 | } 510 | } 511 | 512 | for ( var i = 0; i < count; i ++) { 513 | var p = lasBuffer.getPoint(i); 514 | 515 | pointBuffer[i*3] = p.position[0] * lasBuffer.scale[0] + 516 | (lasBuffer.offset[0] - lasBuffer.mins[0]); 517 | pointBuffer[i*3+1] = p.position[1] * lasBuffer.scale[1] + 518 | (lasBuffer.offset[1] - lasBuffer.mins[1]); 519 | pointBuffer[i*3+2] = p.position[2] * lasBuffer.scale[2] + 520 | (lasBuffer.offset[2] - lasBuffer.mins[2]); 521 | 522 | cellBuffer[i+1] = i; 523 | scalarBuffer[i] = (pointBuffer[i*3+2] - minz)/(maxz - minz); 524 | } 525 | 526 | const polydata = vtkPolyData.newInstance(); 527 | polydata.getPoints().setData(pointBuffer, 3); 528 | polydata.getVerts().setData(cellBuffer); 529 | 530 | const dataarray = vtkDataArray.newInstance({values:scalarBuffer, name: 'data'}); 531 | polydata.getPointData().setScalars(dataarray); 532 | 533 | this.pss.push(polydata); 534 | 535 | this.pointsSoFar += count; 536 | }; 537 | 538 | /** 539 | * 540 | */ 541 | ParticleSystem.prototype.normalizePositionsWithOffset = function(offset) { 542 | var _this = this; 543 | 544 | var off = offset.clone(); 545 | 546 | this.correctiveOffset = off.clone().sub(_this.corrective); 547 | this.cg.sub(off); 548 | this.mn.sub(off); 549 | this.mx.sub(off); 550 | }; 551 | 552 | /** 553 | * 554 | */ 555 | ParticleSystem.prototype.init = function(elem) { 556 | if (!this.renderer) { 557 | this.renderer = vtkRenderer.newInstance({ background: [0.1, 0.1, 0.1] });; 558 | this.openglRenderWindow = vtkOpenGLRenderWindow.newInstance(); 559 | this.renderWindow = vtkRenderWindow.newInstance(); 560 | this.renderWindow.addRenderer(this.renderer); 561 | this.renderWindow.addView(this.openglRenderWindow); 562 | 563 | this.openglRenderWindow.setContainer(elem); 564 | 565 | const interactor = vtkRenderWindowInteractor.newInstance(); 566 | interactor.setView(this.openglRenderWindow); 567 | interactor.initialize(); 568 | interactor.bindEvents(elem); 569 | } 570 | } 571 | 572 | /** 573 | * Render particle system using vtk.js 574 | */ 575 | ParticleSystem.prototype.render = function(firstTime) { 576 | if (firstTime) { 577 | for (var i = 0; i < this.pss.length; ++i) { 578 | const actor = vtkActor.newInstance(); 579 | actor.getProperty().setPointSize(5); 580 | const mapper = vtkMapper.newInstance(); 581 | mapper.setInputData(this.pss[i]); 582 | actor.setMapper(mapper); 583 | this.renderer.addActor(actor); 584 | } 585 | 586 | this.renderer.resetCamera(); 587 | } 588 | 589 | this.renderWindow.render(); 590 | } 591 | 592 | /** 593 | * Handle window resize 594 | */ 595 | ParticleSystem.prototype.resize = function(elem) { 596 | const dims = elem.getBoundingClientRect(); 597 | const windowWidth = Math.floor(dims.width); 598 | const windowHeight = Math.floor(dims.height); 599 | this.openglRenderWindow.setSize(windowWidth, windowHeight); 600 | this.render(); 601 | } 602 | 603 | ParticleSystem.prototype.destroy = function() { 604 | } 605 | 606 | /** 607 | * 608 | * @param {*} url 609 | * @param {*} cb 610 | */ 611 | var getBinary = function(url, cb) { 612 | var oReq = new XMLHttpRequest(); 613 | return new Promise(function(resolve, reject) { 614 | oReq.open("GET", url, true); 615 | oReq.responseType = "arraybuffer"; 616 | 617 | oReq.onload = function(oEvent) { 618 | if (oReq.status == 200) { 619 | console.log(oReq.getAllResponseHeaders()); 620 | return resolve(new LASFile(oReq.response)); 621 | } 622 | reject(new Error("Could not get binary data")); 623 | }; 624 | 625 | oReq.onerror = function(err) { 626 | reject(err); 627 | }; 628 | 629 | oReq.send(); 630 | }); 631 | }; 632 | 633 | /** 634 | * 635 | * @param {*} file 636 | * @param {*} cb 637 | */ 638 | var getBinaryLocal = function(file, cb) { 639 | var fr = new FileReader(); 640 | var p = Promise.defer(); 641 | 642 | fr.onprogress = function(e) { 643 | cb(e.loaded / e.total, e.loaded); 644 | }; 645 | fr.onload = function(e) { 646 | p.resolve(new LASFile(e.target.result)); 647 | }; 648 | 649 | fr.readAsArrayBuffer(file); 650 | 651 | return p.promise.cancellable().catch(Promise.CancellationError, function(e) { 652 | fr.abort(); 653 | throw e; 654 | }); 655 | }; 656 | 657 | 658 | /** 659 | * PointCloudView that loads and render LAS files using vtk.js 660 | */ 661 | const PointCloudView = View.extend({ 662 | parsys: null, 663 | render: function () { 664 | var _this = this; 665 | this.$el.html(template()); 666 | 667 | getBinary(this.model.downloadUrl()).then(function(las){ 668 | _this._loadData(_this.$('.g-pointcloud-vis-container')[0], las); 669 | }); 670 | 671 | return this; 672 | }, 673 | 674 | destroy: function () { 675 | var _this = this; 676 | _this.parsys.destroy(); 677 | delete _this.parsys; 678 | _this.parsys = null; 679 | View.prototype.destroy.call(this); 680 | }, 681 | 682 | /** 683 | * 684 | * @param {*} lf 685 | * @param {*} buffer 686 | */ 687 | _loadData: function(elem, lf, buffer) { 688 | var _this = this; 689 | 690 | return Promise.resolve(lf).then(function(lf) { 691 | return lf.open().then(function() { 692 | lf.isOpen = true; 693 | return lf; 694 | }) 695 | .catch(Promise.CancellationError, function(e) { 696 | // open message was sent at this point, but then handler was not called 697 | // because the operation was cancelled, explicitly close the file 698 | return lf.close().then(function() { 699 | throw e; 700 | }); 701 | }); 702 | }).then(function(lf) { 703 | return lf.getHeader().then(function(h) { 704 | return [lf, h]; 705 | }); 706 | }).then(function(v) { 707 | var lf = v[0]; 708 | var header = v[1]; 709 | 710 | // var skip = Math.round((10 - currentLoadFidelity())); 711 | var skip = 0; 712 | var totalRead = 0; 713 | var totalToRead = (skip <= 1 ? header.pointsCount : header.pointsCount / skip); 714 | var reader = function() { 715 | var p = lf.readData(10000000, 0, skip); 716 | return p.then(function(data) { 717 | var Unpacker = lf.getUnpacker(); 718 | if (_this.parsys == null) { 719 | _this.parsys = new ParticleSystem(); 720 | } 721 | _this.parsys.push(new Unpacker(data.buffer, 722 | data.count, 723 | header)); 724 | 725 | totalRead += data.count; 726 | 727 | if (data.hasMoreData) 728 | return reader(); 729 | else { 730 | header.totalRead = totalRead; 731 | header.versionAsString = lf.versionAsString; 732 | header.isCompressed = lf.isCompressed; 733 | return [lf, header, _this.parsys]; 734 | } 735 | }); 736 | }; 737 | 738 | // return the lead reader 739 | return reader(); 740 | }).then(function(v) { 741 | var lf = v[0]; 742 | 743 | // Close it 744 | return lf.close().then(function() { 745 | lf.isOpen = false; 746 | _this.parsys.init(elem); 747 | _this.parsys.render(true); 748 | _this.parsys.resize(elem); 749 | }).then(function() { 750 | // trim off the first element (our LASFile which we don't really want to pass to the user) 751 | // 752 | return v.slice(1); 753 | }); 754 | }).catch(Promise.CancellationError, function(e) { 755 | // If there was a cancellation, make sure the file is closed, if the file is open 756 | // close and then fail 757 | if (lf.isOpen) 758 | return lf.close().then(function() { 759 | lf.isOpen = false; 760 | console.log("File was closed"); 761 | throw e; 762 | }); 763 | throw e; 764 | }); 765 | } 766 | }); 767 | 768 | export default PointCloudView; 769 | -------------------------------------------------------------------------------- /web_client/main.js: -------------------------------------------------------------------------------- 1 | import _ from 'underscore'; 2 | import FileListWidget from 'girder/views/widgets/FileListWidget'; 3 | import { wrap } from 'girder/utilities/PluginUtils'; 4 | 5 | import PointCloudView from './PointCloudView'; 6 | import viewButtonTemplate from './templates/viewButton.pug'; 7 | 8 | wrap(FileListWidget, 'render', function (render) { 9 | render.call(this); 10 | 11 | this.$el.prepend($('
', {class: 'g-pointcloud-view-container'})); 12 | 13 | _.each(this.$('.g-file-list-link'), (link) => { 14 | const file = this.collection.get($(link).attr('cid')); 15 | if (file.get('mimeType') === 'text/plain' || _.contains(file.get('exts'), 'las')) { 16 | $(link).after(viewButtonTemplate({cid: file.cid})); 17 | } 18 | }); 19 | 20 | this.$('.g-view-with-pc').tooltip(); 21 | 22 | return this; 23 | }); 24 | 25 | FileListWidget.prototype.events['click .g-view-with-pc'] = function (e) { 26 | const file = this.collection.get($(e.currentTarget).attr('file-cid')); 27 | 28 | if (this.PointCloudView) { 29 | this.PointCloudView.destroy(); 30 | } 31 | 32 | this.PointCloudView = new PointCloudView({ 33 | parentView: this, 34 | el: this.$('.g-pointcloud-view-container'), 35 | model: file 36 | }).render(); 37 | }; 38 | -------------------------------------------------------------------------------- /web_client/stylesheets/pc.styl: -------------------------------------------------------------------------------- 1 | .g-pointcloud-vis-container 2 | height 500px 3 | width 100% 4 | background-color #eee 5 | position relative 6 | outline none 7 | 8 | .g-pc-overlay-topleft 9 | position absolute 10 | top 10px 11 | left 10px 12 | z-index 100 13 | font-size 15px 14 | text-shadow 0 0 3px white 15 | -------------------------------------------------------------------------------- /web_client/templates/pc.pug: -------------------------------------------------------------------------------- 1 | .g-pointcloud-vis-container 2 | .g-pc-overlay-topleft 3 | -------------------------------------------------------------------------------- /web_client/templates/viewButton.pug: -------------------------------------------------------------------------------- 1 | a.g-view-with-pc(file-cid=cid, title="View with Point Cloud Viewer") 2 | i.icon-globe 3 | -------------------------------------------------------------------------------- /webpack.helper.js: -------------------------------------------------------------------------------- 1 | module.exports = function (config) { 2 | config.module.rules.push({ 3 | resource: { 4 | test: /node_modules(\/|\\)vtk\.js(\/|\\).*.glsl$/, 5 | include: [/node_modules(\/|\\)vtk\.js(\/|\\)/] 6 | }, 7 | use: [ 8 | 'shader-loader' 9 | ] 10 | }); 11 | config.module.rules.push({ 12 | resource: { 13 | test: /node_modules(\/|\\)vtk\.js(\/|\\).*.js$/, 14 | include: [/node_modules(\/|\\)vtk\.js(\/|\\)/] 15 | }, 16 | use: [ 17 | { 18 | loader: 'babel-loader', 19 | options: { 20 | presets: ['es2015', 'es2016'] 21 | } 22 | } 23 | ] 24 | }); 25 | return config; 26 | }; 27 | --------------------------------------------------------------------------------