Skip to content

Commit

Permalink
feat(TubeFilter): Initial implementation of tube filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sankhesh committed Jan 23, 2018
1 parent ae26c4a commit ce3f2a9
Show file tree
Hide file tree
Showing 8 changed files with 791 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Sources/Common/DataModel/DataSetAttributes/FieldData.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ function vtkFieldData(publicAPI, model) {
};
publicAPI.getCopyFieldFlags = () => model.copyFieldFlags;
publicAPI.getFlag = (arrayName) => model.copyFieldFlags[arrayName];
publicAPI.passData = (other) => {
publicAPI.passData = (other, fromId = -1, toId = -1) => {
other.getArrays().forEach((arr, idx) => {
const copyFlag = publicAPI.getFlag(arr.getName());
if (
copyFlag !== false &&
!(model.doCopyAllOff && copyFlag !== true) &&
arr
) {
publicAPI.addArray(arr);
if (copyFlag !== false && !(model.doCopyAllOff && copyFlag !== true) && arr) {
const destArr = publicAPI.getArrayByName(arr.getName());
if (((fromId < 1) && (toId < 1)) || !destArr) {
publicAPI.addArray(arr);
} else if ((idx >= fromId) && ((toId > -1) || (idx < toId))) {
destArr.setTuple(arr.getTuple(idx));
}
}
});
};
Expand Down
6 changes: 5 additions & 1 deletion Sources/Common/DataModel/DataSetAttributes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ function vtkDataSetAttributes(publicAPI, model) {
value
);
publicAPI[`copy${value}Off`] = () => {
publicAPI.initialize();
const attType = value.toUpperCase();
model.copyAttributeFlags[AttributeCopyOperations.ALLCOPY][AttributeTypes[attType]] = false;
model.copyAttributeFlags[
AttributeCopyOperations.PASSDATA][
AttributeTypes[attType]]
= false;
};
});

Expand Down
10 changes: 10 additions & 0 deletions Sources/Filters/General/TubeFilter/Constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const VtkVaryRadius = {
VARY_RADIUS_OFF: 0, // default
VARY_RADIUS_BY_SCALAR: 1,
VARY_RADIUS_BY_VECTOR: 2,
VARY_RADIUS_BY_ABSOLUTE_SCALAR: 3,
};

export default {
VtkVaryRadius,
};
Empty file.
14 changes: 14 additions & 0 deletions Sources/Filters/General/TubeFilter/example/controlPanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<table>
<tr>
<td>Number of Points</td>
<td>
<input class='numberOfPoints' type="range" min="1" max="500" step="1" value="25" />
</td>
</tr>
<tr>
<td>Radius</td>
<td>
<input class='radius' type="range" min="0.1" max="0.5" step=".01" value="0.25" />
</td>
</tr>
</table>
117 changes: 117 additions & 0 deletions Sources/Filters/General/TubeFilter/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import 'vtk.js/Sources/favicon';

import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
// import vtkPointSource from 'vtk.js/Sources/Filters/Sources/PointSource';
// import vtkOutlineFilter from 'vtk.js/Sources/Filters/General/OutlineFilter';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkTubeFilter from 'vtk.js/Sources/Filters/General/TubeFilter';
import vtkPoints from 'vtk.js/Sources/Common/Core/Points';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import { VtkPointPrecision } from 'vtk.js/Sources/Filters/General/Constants';
import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants';

import controlPanel from './controlPanel.html';

// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------

const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0] });
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();

// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------

function addRepresentation(name, filter, props = {}) {
const mapper = vtkMapper.newInstance();
if (filter.isA('vtkPolyData')) {
mapper.setInputData(filter);
} else {
mapper.setInputConnection(filter.getOutputPort());
}

const actor = vtkActor.newInstance();
actor.setMapper(mapper);
actor.getProperty().set(props);
renderer.addActor(actor);

global[`${name}Actor`] = actor;
global[`${name}Mapper`] = mapper;
}

vtkMath.randomSeed(1);
const numSegments = 2;

function initializePolyData(dType) {
let pointType = VtkDataTypes.FLOAT;
if (dType === VtkPointPrecision.SINGLE) {
pointType = VtkDataTypes.FLOAT;
} else if (dType === VtkPointPrecision.DOUBLE) {
pointType = VtkDataTypes.DOUBLE;
}
const polyData = vtkPolyData.newInstance();
const points = vtkPoints.newInstance({ dataType: pointType });
points.setNumberOfPoints(numSegments + 1);
const pointData = points.getData();
const verts = new Uint32Array(2 * (numSegments + 1));
const lines = new Uint32Array(numSegments + 2);
lines[0] = numSegments + 1;

for (let i = 0; i < (numSegments + 1); ++i) {
for (let j = 0; j < 3; ++j) {
pointData[(3 * i) + j] = Math.random();
}
console.log(`${pointData[3 * i]}, ${pointData[(3 * i) + 1]}, ${pointData[(3 * i) + 2]}`);
verts[i] = 1;
verts[i + 1] = i;
lines[i + 1] = i;
console.log(`Line = ${lines[i + 1]}`);
}

polyData.setPoints(points);
polyData.getVerts().setData(verts);
polyData.getLines().setData(lines);
return polyData;
}

// ----------------------------------------------------------------------------


// const pointSource = vtkPointSource.newInstance({ numberOfPoints: 25, radius: 0.25 });
const polyData = initializePolyData(VtkPointPrecision.DOUBLE);
const tubeFilter = vtkTubeFilter.newInstance();
tubeFilter.setCapping(false);
tubeFilter.setNumberOfSides(20);

tubeFilter.setInputData(polyData);

addRepresentation('polyData', polyData, {});
// addRepresentation('pointSource', pointSource, { pointSize: 5 });
addRepresentation('tubeFilter', tubeFilter, {});

renderer.resetCamera();
renderWindow.render();

// -----------------------------------------------------------
// UI control handling
// -----------------------------------------------------------

fullScreenRenderer.addController(controlPanel);

// ['numberOfPoints', 'radius'].forEach((propertyName) => {
// document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
// const value = Number(e.target.value);
// pointSource.set({ [propertyName]: value });
// renderWindow.render();
// });
// });

// // ----- Console play ground -----
// global.pointSource = pointSource;
global.tubeFilter = tubeFilter;
global.renderer = renderer;
global.renderWindow = renderWindow;
Loading

0 comments on commit ce3f2a9

Please sign in to comment.