Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom resolutions properly #242

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/depthcloud/DepthCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ ROS3D.DepthCloud = function(options) {
this.pointSize = options.pointSize || 3;
this.width = options.width || 1024;
this.height = options.height || 1024;
this.resolutionFactor = Math.max(this.width, this.height) / 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something special about 1024 besides being the default height/width? Should this be max / min instead of max / 1024?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be max / min instead of max / 1024?

No. It should be a ratio of the default 1024 resolution. The max is just for completeness, we can use either the width or height, since the encoded image is always square.

this.whiteness = options.whiteness || 0;
this.varianceThreshold = options.varianceThreshold || 0.000016667;

var metaLoaded = false;

this.isMjpeg = this.streamType.toLowerCase() === 'mjpeg';

this.video = document.createElement(this.isMjpeg ? 'img' : 'video');
Expand All @@ -60,6 +59,7 @@ ROS3D.DepthCloud = function(options) {
'',
'uniform float focallength;',
'uniform float maxDepthPerTile;',
'uniform float resolutionFactor;',
'',
'varying vec2 vUvP;',
'varying vec2 colorP;',
Expand Down Expand Up @@ -163,8 +163,8 @@ ROS3D.DepthCloud = function(options) {
' float z = -depth;',
' ',
' pos = vec4(',
' ( position.x / width - 0.5 ) * z * 0.5 * maxDepthPerTile * (1000.0/focallength) * -1.0,',
' ( position.y / height - 0.5 ) * z * 0.5 * maxDepthPerTile * (1000.0/focallength),',
' ( position.x / width - 0.5 ) * z * 0.5 * maxDepthPerTile * resolutionFactor * (1000.0/focallength) * -1.0,',
' ( position.y / height - 0.5 ) * z * 0.5 * maxDepthPerTile * resolutionFactor * (1000.0/focallength),',
' (- z + zOffset / 1000.0) * maxDepthPerTile,',
' 1.0);',
' ',
Expand Down Expand Up @@ -285,6 +285,10 @@ ROS3D.DepthCloud.prototype.initStreamer = function() {
type : 'f',
value : this.maxDepthPerTile
},
'resolutionFactor': {
type : 'f',
value : this.resolutionFactor
},
},
vertexShader : this.vertex_shader,
fragmentShader : this.fragment_shader
Expand Down