Fix setting radius by point.
This still needs to adjust opacity and color by point.
MODIFY
src/vtkjs/pointFeature.js
src/vtkjs/pointFeature.js
@@ -23,15 +23,13 @@ var vtkjs_pointFeature = function (arg) {
var object = require('../object');
var vtk = require('./vtkjsRenderer').vtkjs;
var vtkActor = vtk.Rendering.Core.vtkActor;
- var vtkMapper = vtk.Rendering.Core.vtkGlyph3DMapper;
+ var vtkGlyph3DMapper = vtk.Rendering.Core.vtkGlyph3DMapper;
+ var vtkDataArray = vtk.Common.Core.vtkDataArray;
var vtkPointSet = vtk.Common.DataModel.vtkPointSet;
var vtkSphereSource = vtk.Filters.Sources.vtkSphereSource;
object.call(this);
- /**
- * @private
- */
var m_this = this,
m_actor,
m_pointSet,
@@ -48,17 +46,19 @@ var vtkjs_pointFeature = function (arg) {
m_source = vtkSphereSource.newInstance();
m_source.setThetaResolution(30);
m_source.setPhiResolution(30);
- var mapper = vtkMapper.newInstance({
+ var mapper = vtkGlyph3DMapper.newInstance({
// Orientation
orient: false,
// Color
// useLookupTableScalarRange: true, // FIXME <----
// lookupTable, // FIXME <----
+ /*
colorByArrayName: 'color',
colorMode: vtkMapper.ColorMode.MAP_SCALARS,
scalarMode: vtkMapper.ScalarMode.USE_POINT_FIELD_DATA,
scalarVisibility: true,
+ */
// Opactity
// => not available yet
@@ -66,7 +66,7 @@ var vtkjs_pointFeature = function (arg) {
// Scaling
scaling: true,
scaleArray: 'radius',
- scaleMode: vtkGlyph3DMapper.ScaleModes.SCALE_BY_MAGNITUDE,
+ scaleMode: vtkGlyph3DMapper.ScaleModes.SCALE_BY_MAGNITUDE
});
mapper.setInputData(m_pointSet, 0);
mapper.setInputConnection(m_source.getOutputPort(), 1);
@@ -92,14 +92,14 @@ var vtkjs_pointFeature = function (arg) {
var i, i3, posVal,
nonzeroZ,
numPts = m_this.data().length,
+ position = new Array(numPts * 3),
data = m_this.data(),
posFunc = m_this.position(),
radFunc = m_this.style.get('radius'),
colorFunc = m_this.style.get('fillColor'),
- opacityFunc = m_this.style.get('fillOpacity');
+ opacityFunc = m_this.style.get('fillOpacity'),
+ unitsPerPixel = m_this.layer().map().unitsPerPixel(m_this.layer().map().zoom());
-
- const position = new Float64Array(numPts * 3);
const opacityArray = new Float32Array(numPts);
const colorArray = new Float32Array(numPts); // FIXME maybe not the right type
const radiusArray = new Float32Array(numPts);
@@ -115,8 +115,9 @@ var vtkjs_pointFeature = function (arg) {
// Register opacity/color/radius
opacityArray[i] = opacityFunc(data[i], i);
+ // The colorFunc returns an object with r, g, b on a scale of [0-1] (e.g., red is {r: 1, g: 0, b: 0})
colorArray[i] = colorFunc(data[i], i);
- radiusArray[i] = radFunc(data[i], i)
+ radiusArray[i] = radFunc(data[i], i) * unitsPerPixel;
}
position = transform.transformCoordinates(
m_this.gcs(), m_this.layer().map().gcs(),
@@ -131,11 +132,6 @@ var vtkjs_pointFeature = function (arg) {
}
}
- // TODO: points can vary, this needs to be refactors to have a distinct
- // size per point. What should be done with the strokeColor, strokeWidth,
- // and strokeOpacity? Honor the fill/stroke options or document that we
- // don't honot them. Handle the zero-data-itmes condition.
- rad *= m_this.layer().map().unitsPerPixel(m_this.layer().map().zoom());
m_pointSet.getPoints().setData(position, 3);
// Attach fields
@@ -143,6 +139,10 @@ var vtkjs_pointFeature = function (arg) {
m_pointSet.getPointData().addArray(vtkDataArray.newInstance({ name: 'opacity', values: opacityArray }));
m_pointSet.getPointData().addArray(vtkDataArray.newInstance({ name: 'radius', values: radiusArray }));
+ var clr = colorFunc(data[0], 0);
+ m_actor.getProperty().setColor(clr.r, clr.g, clr.b); // TODO fix colors
+ m_actor.getProperty().setOpacity(opacityFunc(data[0], 0)); // TODO fix opacity
+
m_this.buildTime().modified();
};
@@ -164,6 +164,7 @@ var vtkjs_pointFeature = function (arg) {
const newScaleArray = dataArray.getData().map((v, i) => radFunc(data[i], i) * scalingFactor);
dataArray.setData(newScaleArray);
+ m_pointSet.modified();
}
m_this.updateTime().modified();

Fix setting radius by point.

This still needs to adjust opacity and color by point.