Merge pull request #8 from potree/documentation

Documentation
This commit is contained in:
potree 2014-02-14 16:58:55 +01:00
commit d9c0fc2453
18 changed files with 312 additions and 0 deletions

83
doc/doc.md Normal file
View File

@ -0,0 +1,83 @@
# Documentation
* [File Format Description](./file_format.md)
* [Materials and Rendermodes](./materials_and_rendermodes.md)
* [How Does Loading Nodes Work?](./how_does_loading_nodes_work.md)
## Introduction
Potree is a WebGL based viewer for large point clouds. The idea is that, similar to Google Maps, only visible parts up to a certain level of detail
will be loaded and displayed. In order to achieve this, points are partitioned into an octree.
The root node r contains a sparse subset of the data. All of its children contain another sparse subset which, combined, will gradualy increase
the level of detail.
| ![](./images/r.png "") | ![](./images/r1.png "") | ![](./images/r_and_r1.png "") | ![](./images/r_and_rx.png "") |
| ------------- |:-------------:| -----:| --- |
| root | r0, first child of root | root and r0 combined | root and all its children combined |
## Getting Started
1. Deploy potree on a webserver.
2. Open lion.html.
This should be the result:
![](./images/lion_demo_screenshot.jpg)
And this is what happens inside lion.html:
Initialize potree inside the canvas element:
var canvas = document.getElementById("canvas");
var success = Potree.init(canvas);
if(!success){
return;
}
Load a point cloud and add it to the scene:
var scene = Potree.currentScene;
var cloudURL = "resources/pointclouds/lion_takanawa/cloud.js";
var pcoNode = POCLoader.load(cloudURL);
scene.rootNode.addChild(pcoNode);
Directly manipulate the transformation matrix of the point cloud node:
In this case, the point cloud was upside down so it has to be mirrored along the y-axis.
pcoNode.transform = [1, 0, 0, 0,
0, -1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1];
Transform the camera:
var cam = scene.activeCamera;
cam.rotateY(Math.PI/2);
cam.translate(-1,-1,-1);
Set the point Size:
var material = MaterialManager.getMaterial("pointCloud");
material.pointSize = 1;
A high LOD multiplicator will display more nodes that are small or far away:
Potree.Settings.LODMultiplicator = 20.0;
## Compatibility
| Browser | Result |
| -------------------- |:-------------:|
| Chrome 32 | works |
| Firefox 26 | works |
| Safari | works |
| Opera 19 | works |
| Internet Explorer 11 | does not work |
## License
Potree is available under the [FreeBSD License](http://en.wikipedia.org/wiki/BSD_licenses) license.

60
doc/file_format.md Normal file
View File

@ -0,0 +1,60 @@
# File Format
## File Hierarchy
Points are stored in an octree. All nodes, even intermediate nodes, contain a subset of the whole point cloud.
.cloud.js Contains bounding box, vertex format and octree hierarchy
./data Contains one file for each octree node.
./data/r The root node.
./data/rx The x.th child of the root. x = 0 to 7
./data/rxy The y.th child of the x.th child of the root.
Each node may have up to 8 child nodes. The numbers from 0 to 7 inside the node name indicate which child it is. For example:
* r is the root node
* r0 is the first child of the root node
* r03 is the fourth child of the first child of the root node
## Octree Hierarchy
Child nodes are arranged like this:
3----7
/| /|
y 2----6 |
| -z | 1--|-5
|/ |/ |/
O----x 0----4
This means that node 0 is at the origin, node 1 is translated along the -z axis, node 2 is on top of node 0 and so on.
## cloud.js
Stores information about the pointcloud in JSON format.
The property "pointAttributes" indicates how each point is stored. At the moment, you should stick to the format given in the example below. "POSITION_CARTESIAN" and "COLOR_PACKED" means that each point is stored as 3 32bit floats for x,y and z coordinates and 4 unsigned bytes for r,g,b and a colors.
The hierarchy property contains all nodes and the number of points in each node. The nodes must be stored top to bottom, i.e. root at the beginning and leaf-nodes at the end.
{
"octreeDir": "data",
"boundingBox": {
"lx": -10.0,
"ly": -10.0,
"lz": -10.0,
"ux": 10.0,
"uy": 10.0,
"uz": 10.0
},
"pointAttributes": [
"POSITION_CARTESIAN",
"COLOR_PACKED"
],
"hierarchy": [
["r", 9103],
["r0", 7809],
["r1", 3491],
["r3", 4309],
["r03", 8521]
]
}

View File

@ -0,0 +1,91 @@
# How Does Loading Nodes Work?
Relevant classes are:
* <b>PointCloudOctree</b> <br>
Manages the octree. Contains methods that finds currently visible nodes for rendering
or loading.
* <b>PointCloudOctreeNode</b><br>
The hierarchy consists of instances of this class. Contains methods to load or unload
point cloud data.
* <b>PointCloudOctreeSceneNode</b><br>
A subclass of SceneNode that can be attached to the scenegraph.
Contains the PointCloudOctree instance.
* <b>POCLoader</b><br>
Loads the point cloud hierarchy from a file.
## Loading Data
At first, <b>POCLoader.load(file)</b> reads the point cloud hierarchy from cloud.js and
builds a graph of _PointcloudOctreeNode_ instances.
This graph will be attached to a _PointCloudOctree_ instance.
During rendering, <b>PointCloudOctree.prepareRender()</b> traverses through nodes that
are visible from the current point of view. If it encounters a node whose point cloud data
has not been loaded, it will stop traversing further down the hierarchy and schedule
it for loading by adding it to _loadQueue_.
// schedule loading of missing point cloud data
if (shouldBeRendered && current.pointCloud == null) {
if(!current.isLoading){
this.loadQueue.push(current);
}
continue;
}
The last step of _prepareRender() is a call to <b>PointcloudOctree.processLoadQueue()</b>.
Nodes in _loadQueue_ are sorted by their size and we want to load larger nodes first so
_processLoadQueue()_ will tell the first few nodes in _loadQueue_ to start loading
point cloud data by calling _PointcloudOctreeNode.loadCloudAjax(node)_.
The remaining nodes in the queue will be ignored.
They'll be loaded at a later time once all their ancestors have been loaded.
Additionaly, there are checks to make sure that the size of all loaded nodes does not
exceed the point cloud memory limit and that no more than _loadingNodesLimit_
nodes are loaded at a time.
// process the first x nodes in the queue.
if(this.loadQueue.length > 0 ){
for(var i = 0; i < Math.min(x, this.loadQueue.length); i++){
if(lru.byteSize + this.loadQueue[i].sizeInBytes() < PointcloudOctreeNode.memoryThreshold){
if(this.nodesBeeingLoaded.length < this.loadingNodesLimit){
PointcloudOctreeNode.loadCloudAjax(this.loadQueue[i]);
}
}
}
}
<b>PointcloudOctreeNode.loadCloudAjax(node)</b> creates an asynchronous XMLHttpRequest
to read the point cloud data from the corresponding file in _./data_.
Once the request is finished, _PointcloudOctreeNode.loadCloudData(node, buffer, url)_
is called to send the data directly to the GPU.
## Cleanup Data
Pointcloud data can be very large and often it might be necessary to unload some data
to create space for new data.
_PointcloudOctreeNode.memoryThreshold_ defines a limit for how much point cloud data
potree will load. If loading a new node exceeds this limit, potree will first remove
some old nodes that weren't rendered in a while.
<b>PointcloudOctreeNode.lruNodes</b> (least-recently-used nodes) contains a list of all loaded nodes, ordered by
the last time they've been rendered. Recently rendered nodes are at the end of the list.
<b>PointcloudOctree.cleanupCache(bytesNeeded, exceptionsRenderQueue)</b>
checks if the byte size of all currently loaded nodes, plus the additional size of
_bytesNeeded_ exceeds the limit. If it does, it will remove the first few nodes
of _lruNodes_, except nodes contained in _exceptionsRenderQueue_.
This is done to avoid removing nodes that were scheduled to be rendered.

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
doc/images/pompei.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 KiB

BIN
doc/images/r.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
doc/images/r1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
doc/images/r_and_r1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
doc/images/r_and_rx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
doc/images/rx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,78 @@
# Materials And Rendermodes
The default material for point clouds is an instance of PointCloudMaterial with the name "pointCloud".
In order to change its attributes, you have to retrieve it by calling:
var material = MaterialManager.getMaterial("pointCloud");
There are 3 rendermodes available:
* <b>FIXED_CIRCLE</b>
Render points as circles with a fixed size. The pointSize attribute indicates the pixel diameter.
* <b>WEIGHTED_CIRCLE</b>
Render points as circles with a size depending on the distance to the viewer.
* <b>FILTERED_SPLAT</b>
Interpolates between overlapping points. High quality but very slow.
You can change the render mode by calling
material.renderMode = PointCloudRenderMode.FIXED_CIRCLE;
| ![](./images/lion_fixed_circles.jpg "") | ![](./images/lion_weighted_circles.jpg "") | ![](./images/lion_filtered_splats.jpg "") |
| --------------------------------------- | ------------------------------------------ | ----------------------------------------- |
| FIXED_CIRCLES with point-size 2. All points have pixel diameter 2.| WEIGHTED_CIRCLES with point-size 1. Size varies depending on distance from camera. | FILTERED_SPLATS with point-size 1. In this mode, points have the same size as with WEIGHTED_CIRCLES, but overlapping points are interpolated. |
## PointCloudMaterial
PointCloudMaterial is actually a combination of other materials.
It dispatches render calls to the material in use.
## FixedPointSizeMaterial
Used when rendermode is set to FIXED_CIRCLE.
The _render(sceneNode, renderer)_ function extracts extracts all pointCloud from sceneNode,
that should be rendered. The _renderPointClouds()_ function invokes the WebGL
draw calls.
## WeightedPointSizeMaterial
Used when rendermode is set to WEIGHTED_CIRCLE.
It works the same way as FixedPointSizeMaterial, except with a different vertex shader
that adjusts the point size according to the distance from the viewer.
## FilteredSplatsMaterial
Used when rendermode is set to FILTERED_SPLATS.
This material is based on the paper [High Quality Splatting on Today's GPUs](http://graphics.ucsd.edu/~matthias/Papers/HighQualitySplattingOnGPUs.pdf).
The idea is, that overlapping points should be blended together, if their distance to the viewer is roughly the same.
Simple point rendering usualy leads to overlapping points:
![](./images/filtered_splats_overlapping.png "")
This material consists of 3 passes:
1. <b>Depth-Pass</b> Renders the point cloud into a depth buffer. Depth values are pushed away from the viewer with an offset given by uBlendDepth.
Fragments within this offset-range will be blended together. Fragments that are farther away will be discarded during the depth test.
2. <b>Attribute-Pass</b> Renders the point cloud with weighted attributes and blend mode set to ADD.
The weight function gives fragments that are closer to the center a higher weight.<br>
The result of this pass is a weighted sum of overlapping attributes, stored in the RGB component:<br>
![](./images/filtered_splats_weighted_sum.png "")
And the sum of weights, stored in the alpha component:<br>
![](./images/filtered_spats_sum_of_weights.png "")
3. <b>Normalization-Pass</b> In this pass, the output of the previous pass is normalized by
dividing the weighted sum of colors in the RGB component by the sum of weights in the alpha component.
It's essentially a screen-space filter so this time, not the point cloud is rendered but
a rectangle that spans the whole screen with the output of the previous pass
as the its texture. This is one possible result:<br>
![](./images/filtered_splats_normalized.png "")<br>
The smoothness of the transition depends on the weight function. By adjusting the weight function, you can get
very smooth or relatively sharp borders.