forked from RobotWebTools/roslibjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update exprts * (transpiler) read revision correctly * Fix typo * Make transpiler more robust More robust to whitespace; fix dot bug (dots are any character in regex); Arguments are optional to constructors * OccupancyMap* -> OcTree* Rename as to similar to OccupancyGrid*; Including seperation of all classes to their own file, needed by transpiler; Remove all seperate class property definitions; not supported by transpiler Co-authored-by: Peter Sari <sari@photoneo.com>
- Loading branch information
1 parent
7fc21e0
commit d3470f4
Showing
7 changed files
with
317 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @author Peter Sari - sari@photoneo.com | ||
*/ | ||
|
||
ROS3D.ColorOcTree = function(options) { | ||
ROS3D.OcTree.call(this, options); | ||
this.useOwnColor = (typeof options.palette !== 'undefined') && options.colorMode === ROS3D.OcTreeColorMode.COLOR; | ||
}; | ||
|
||
ROS3D.ColorOcTree.prototype.__proto__ = ROS3D.OcTree.prototype; | ||
|
||
ROS3D.ColorOcTree.prototype._readNodeData = function (dataStream, node) { | ||
node.value = dataStream.readFloat32(); // occupancy | ||
node.color = { | ||
r: dataStream.readUint8(), // red | ||
g: dataStream.readUint8(), // green | ||
b: dataStream.readUint8(), // blue | ||
}; | ||
|
||
}; | ||
|
||
ROS3D.ColorOcTree.prototype._obtainColor = function (node) { | ||
if (!this.useOwnColor) { return ROS3D.OcTree.prototype._obtainColor.call(this, node); } | ||
return node.color; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* @author Peter Sari - sari@photoneo.com | ||
*/ | ||
|
||
/** | ||
* Toggles voxel visibility | ||
* | ||
* * `occupied` - only voxels that are above or equal to the occupation threshold are shown | ||
* * `free` - only voxels that are below the occupation threshold are shown | ||
* * `all` - all allocated voxels are shown | ||
*/ | ||
ROS3D.OcTreeVoxelRenderMode = { | ||
OCCUPIED: 'occupied', | ||
FREE: 'free', | ||
ALL: 'all', | ||
}; | ||
|
||
/** | ||
* Coloring modes for each voxel | ||
* | ||
* * 'solid' - voxels will have a single solid color set by the tree globally | ||
* * 'occupancy' - voxels are false colored by their occupancy value. Fall back for `solid` if not available. | ||
* * 'color' - voxels will colorized by their | ||
*/ | ||
ROS3D.OcTreeColorMode = { | ||
SOLID: 'solid', | ||
OCCUPANCY: 'occupancy', | ||
COLOR: 'color' | ||
}; | ||
|
||
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- | ||
|
||
/** | ||
* Specilaization of BaseOcTree | ||
* | ||
* @constructor | ||
* @param options - object with following keys: | ||
* * inherited from BaseOctree | ||
* * occupancyThreshold (optional) - threshold value that separates occupied and free voxels from each other. (Default: 0) | ||
* * colorMode (optional) - Coloring mode @see ROS3D.OcTreeColorMode. | ||
* * palette (optional) - Palette used for false-coloring (default: predefined palette) | ||
* * paletteSclae (optional) - Scale of palette to represent a wider range of values (default: 1.) | ||
*/ | ||
|
||
ROS3D.OcTree = function(options) { | ||
ROS3D.OcTreeBase.call(this, options); | ||
|
||
this._defaultOccupiedValue = 1.; | ||
this._defaultFreeValue = -1.; | ||
|
||
this.occupancyThreshold = (typeof options.occupancyThreshold !== 'undefined') ? options.occupancyThreshold : 0.0000001; | ||
|
||
this.useFlatColoring = (typeof options.colorMode !== 'undefined') && options.colorMode === ROS3D.OcTreeColorMode.SOLID; | ||
|
||
this.palette = (typeof options.palette !== 'undefined') ? options.palette.map(color => new THREE.Color(color)) : | ||
[ | ||
{ r: 0, g: 0, b: 128, }, // dark blue (low) | ||
{ r: 0, g: 255, b: 0, }, // green | ||
{ r: 255, g: 255, b: 0, }, // yellow (mid) | ||
{ r: 255, g: 128, b: 0, }, // orange | ||
{ r: 255, g: 0, b: 0, } // red (high) | ||
]; | ||
|
||
this.paletteScale = (typeof options.paletteScale !== 'undefined') ? options.paletteScale : 1.; | ||
}; | ||
|
||
ROS3D.OcTree.prototype.__proto__ = ROS3D.OcTreeBase.prototype; | ||
|
||
ROS3D.OcTree.prototype._readNodeData = function (dataStream, node) { | ||
node.value = dataStream.readFloat32(); | ||
}; | ||
|
||
ROS3D.OcTree.prototype._obtainColor = function (node) { | ||
if (this.useFlatColoring) { | ||
return this.color; | ||
} | ||
|
||
// Use a simple sigmoid curve to fit values from -inf..inf into 0..1 range | ||
const value = 1. / (1. + Math.exp(-node.value * this.paletteScale)) * this.palette.length; // Normalize | ||
|
||
const intVal = Math.trunc(value); | ||
const fracVal = value - intVal; | ||
|
||
if (intVal < 0) { return this.palette[0]; } | ||
if (intVal >= this.palette.length - 1) { return this.palette[this.palette.length - 1]; } | ||
|
||
// Simple lerp | ||
return { | ||
r: fracVal * this.palette[intVal].r + (1. - fracVal) * this.palette[intVal + 1].r, | ||
g: fracVal * this.palette[intVal].g + (1. - fracVal) * this.palette[intVal + 1].g, | ||
b: fracVal * this.palette[intVal].b + (1. - fracVal) * this.palette[intVal + 1].b, | ||
}; | ||
|
||
}; | ||
|
||
ROS3D.OcTree.prototype._checkOccupied = function (node) { | ||
return node.value >= this.occupancyThreshold; | ||
}; |
Oops, something went wrong.