potree/examples/profile.html
2014-10-02 11:52:32 +02:00

409 lines
11 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://openlayers.org/en/v3.0.0/css/ol.css" type="text/css">
<style>
body{
margin: 0;
padding: 0;
}
.map {
position: absolute;
height: 300px;
width: 400px;
right: 5px;
bottom: 5px;
z-index: 1000;
}
#renderArea{
position: absolute;
width: 100%;
height: 100%;
right: 0;
bottom: 0;
z-index: 0;
margin: 0;
padding: 0;
}
.info{
position: absolute;
z-index: 2000;
color:white;
font-weight: bold;
text-shadow: 1px 1px 1px black,
1px -1px 1px black,
-1px 1px 1px black,
-1px -1px 1px black;
}
a:hover, a:visited, a:link, a:active{
color: #ccccff;
text-decoration: none;
}
</style>
<script src="http://openlayers.org/en/v3.0.0/build/ol.js" type="text/javascript"></script>
<script src="../libs/signals/signals.min.js"></script>
<script src="../libs/three.js/build/three.js"></script>
<script src="../libs/other/dat.gui.min.js"></script>
<script src="../libs/proj4/proj4.js"></script>
<script src="../build/js/potree.js"></script>
<script src="../src/utils/ProfileTool.js"></script>
<script src="../src/utils/TranslationTool.js"></script>
<script src="../src/PointCloudOctree.js"></script>
<script src="profile.js"></script>
<title>Georeferencing Example</title>
</head>
<body>
<div id="map" class="map"></div>
<div id="renderArea"></div>
<div class="info" style="position: absolute; left: 300px; right: 300px; top: 10px; text-align: center;">
<a href="http://potree.org" target="_blank">potree.org</a><br>
Georeferencing (sync with OpenLayers3) and Measurement.<br>
Double click to generate measurement points. Measurement points will be displayed
in the point cloud as well as the OpenStreetMap window.
<br><br>
Point cloud courtesy of <a href="http://www.sigeom.ch/" target="_blank">sigeom sa</a><br>
Rue des Oeuches 45<br>
2740 Moutier<br>
Switzerland <br>
</div>
<script type="text/javascript">
//var pointcloudPath = "../resources/pointclouds/sorvilier/cloud.js";
var pointcloudPath = "../../../../pointclouds/bruno_friedmann/vol_total/vol_total_bin/cloud.js";
var defaultPointSize = 1.3;
var defaultLOD = 12;
// add EPSG:21781 to the proj4 projection database
proj4.defs('EPSG:21781', "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs ");
var fromSwiss = proj4.defs("EPSG:21781");
var toWGS84 = proj4.defs("WGS84");
// extent (with altitude) in EPSG:21781 / Swiss Coordinate System
var minSwiss = [584757.154, 230878.747, 662.379];
var maxSwiss = [593758.872, 232521.598, 850.323];
// extent in EPSG:4326 / WGS84 World Geodetic System
var minExtent = proj4(proj4.defs("EPSG:21781"), proj4.defs("WGS84"), [minSwiss[0], minSwiss[1]]);
var maxExtent = proj4(proj4.defs("EPSG:21781"), proj4.defs("WGS84"), [maxSwiss[0], maxSwiss[1]]);
// extent in EPSG:3857 / WGS84 Web Mercator
var minT = ol.proj.transform(minExtent, 'EPSG:4326', 'EPSG:3857');
var maxT = ol.proj.transform(maxExtent, 'EPSG:4326', 'EPSG:3857');
// the offset of the point cloud in EPSG:21781 coordinate system to local scene coordinates.
// subtract this offset in order to move from local scene coordinates (obtained from picking, etc.)
// to EPSG:21781 coordinates
var offset = new THREE.Vector3();
// OpenLayers3 stuff
var featureVector;
var camFrustumFeatureVector;
var camFrustum;
// three.js / potree stuff
var renderer;
var scene, sceneHUD;
var camera, cameraHUD;
var skybox;
var materials = {};
var clock = new THREE.Clock();
var viewerControls;
var profileTool;
var translationTool;
function initMapView(){
var extent = [minT[0], minT[1], maxT[0], maxT[1]];
var center = [(maxT[0] + minT[0]) / 2, (maxT[1] + minT[1]) / 2];
// draw the extent as box inside the map view
var box = new ol.geom.LineString([
minT, [maxT[0], minT[1]], maxT, [minT[0], maxT[1]], minT
]);
var feature = new ol.Feature(box);
featureVector = new ol.source.Vector({
features: [feature]
});
var layer = new ol.layer.Vector({
source: featureVector,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#ff0000',
width: 2
}),
image: new ol.style.Circle({
radius: 3,
fill: new ol.style.Fill({
color: '#0000ff'
})
})
})
});
camFrustumFeatureVector = new ol.source.Vector({
features: []
});
var camFrustumLayer = new ol.layer.Vector({
source: camFrustumFeatureVector,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#ff0000',
width: 2
}),
image: new ol.style.Circle({
radius: 3,
fill: new ol.style.Fill({
color: '#ff0000'
})
})
})
});
// create the map
var map = new ol.Map({
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}).extend([
new ol.control.ZoomToExtent({
extent: extent,
closest: true
})
]),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
layer,
camFrustumLayer
],
target: 'map',
view: new ol.View({
center: center,
zoom: 12
})
});
}
function initPotreeView(){
var renderArea = document.getElementById("renderArea");
var near = 0.1;
var far = 100000;
var fov = 60;
var aspect = renderArea.clientWidth / renderArea.clientHeight;
scene = new THREE.Scene();
sceneHUD = new THREE.Scene();
camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
cameraHUD = new THREE.OrthographicCamera( -1, 1, 1, -1, -100, 1000 );
renderer = new THREE.WebGLRenderer();
renderer.setSize(renderArea.clientWidth, renderArea.clientHeight);
renderer.autoClear = false;
renderArea.appendChild(renderer.domElement);
skybox = Potree.utils.loadSkybox("../resources/textures/skybox/");
camera.position.set(5050, 158, -600);
//controls = new THREE.FirstPersonControls(camera, renderer.domElement);
camera.rotation.order = 'ZYX';
camera.rotation.x = -0.5;
camera.rotation.y = -3*Math.PI/4;
//controls.moveSpeed *= 10;
materials.rgb = new Potree.PointCloudRGBMaterial({ size: defaultPointSize});
// load pointcloud
var pco = POCLoader.load(pointcloudPath, {toOrigin: true});
offset = pco.offset;
pointcloud = new Potree.PointCloudOctree(pco, materials.rgb);
pointcloud.LOD = defaultLOD;
pointcloud.applyMatrix(new THREE.Matrix4().set(
1,0,0,0,
0,0,1,0,
0,-1,0,0,
0,0,0,1
));
scene.add(pointcloud);
profileTool = new Potree.ProfileTool(200, 100, 2);
profileTool.position.set(5250, 100, -500);
profileTool.rotation.y = Math.PI / 2;
scene.add(profileTool);
sceneHUD.add(profileTool.hudElement);
translationTool = new Potree.TranslationTool(camera);
translationTool.setTargets([profileTool]);
scene.add(translationTool);
//measuringTool = new Potree.MeasuringTool(scene, camera, renderer.domElement);
// execute this event whenever a new measurement point has been set
//measuringTool.addEventListener("newpoint", function(event){
// // transform from local scene to swiss projection.
// var point = new THREE.Vector3(event.position.x, -event.position.z, event.position.y);
// point = point.sub(offset);
//
// // transform from swiss projection to WGS84
// var fromSwiss = proj4.defs("EPSG:21781");
// var toWGS84 = proj4.defs("WGS84");
// var coordinate = proj4(fromSwiss, toWGS84, [point.x, point.y]);
//
// // transform from WGS84 to Web Mercator
// coordinate = ol.proj.transform(coordinate, 'EPSG:4326', 'EPSG:3857');
//
// // add a point to the OpenLayers map
// var olPoint = new ol.geom.Point(coordinate);
// var feature = new ol.Feature(olPoint);
// featureVector.addFeature(feature);
//});
}
function initGUI(){
// dat.gui
var gui = new dat.GUI({
height : 5 * 32 - 1
});
var params = {
PointSize: defaultPointSize,
LOD: defaultLOD,
"bounding box" : false
};
var pLOD = gui.add(params, 'LOD', 0.5,20);
pLOD.onChange(function(value){
pointcloud.LOD = value;
});
var pPointSize = gui.add(params, 'PointSize', 0.01, 2.0);
pPointSize.onChange(function(value){
pointcloud.material.size = value;
});
var pBoundingBox = gui.add(params, 'bounding box');
pBoundingBox.onChange(function(value){
pointcloud.showBoundingBox = value;
});
}
function update(){
var renderArea = document.getElementById("renderArea");
var width = renderArea.clientWidth;
var height = renderArea.clientHeight;
//controls.update(clock.getDelta());
viewerControls.update(clock.getDelta());
pointcloud.update(camera);
if(camFrustum === undefined){
camFrustum = new ol.geom.LineString([ [0,0], [0, 0] ]);
var feature = new ol.Feature(camFrustum);
camFrustumFeatureVector.addFeature(feature);
}
var aspect = camera.aspect;
var top = Math.tan( THREE.Math.degToRad( camera.fov * 0.5 ) ) * camera.near;
var bottom = - top;
var left = aspect * bottom;
var right = aspect * top;
var camPos = new THREE.Vector3(0, 0, 0);
left = new THREE.Vector3(left, 0, -camera.near).multiplyScalar(3000);
right = new THREE.Vector3(right, 0, -camera.near).multiplyScalar(3000);
camPos.applyMatrix4(camera.matrixWorld);
left.applyMatrix4(camera.matrixWorld);
right.applyMatrix4(camera.matrixWorld);
// transform from local scene to swiss projection.
camPos = new THREE.Vector3(camPos.x, -camPos.z, camPos.y).sub(offset);
left = new THREE.Vector3(left.x, -left.z, left.y).sub(offset);
right = new THREE.Vector3(right.x, -right.z, right.y).sub(offset);
camPos = proj4(fromSwiss, toWGS84, [camPos.x, camPos.y]);
left = proj4(fromSwiss, toWGS84, [left.x, left.y]);
right = proj4(fromSwiss, toWGS84, [right.x, right.y]);
camPos = ol.proj.transform(camPos, 'EPSG:4326', 'EPSG:3857');
left = ol.proj.transform(left, 'EPSG:4326', 'EPSG:3857');
right = ol.proj.transform(right, 'EPSG:4326', 'EPSG:3857');
camFrustum.setCoordinates([camPos, left, right, camPos]);
profileTool.hudElement.scale.x = 400 / width;
profileTool.hudElement.scale.y = 300 / height;
profileTool.hudElement.position.x = 1 - 405 / width;
profileTool.hudElement.position.y = -1 + 905 / height;
}
function render(){
// resize
var renderArea = document.getElementById("renderArea");
var width = renderArea.clientWidth;
var height = renderArea.clientHeight;
renderer.setSize(width, height-10);
camera.aspect = width / height;
camera.updateProjectionMatrix();
// render skybox
skybox.camera.rotation.copy(camera.rotation);
renderer.render(skybox.scene, skybox.camera);
// render scenes
renderer.render(scene, camera);
renderer.render(measuringControl.sceneMeasurement, camera);
renderer.render(sceneHUD, cameraHUD);
profileTool.render(renderer, scene);
}
function loop(){
requestAnimationFrame(loop);
update();
render();
}
initMapView();
initPotreeView();
initGUI();
initSignals();
loop();
</script>
</body>
</html>