-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TubeFilter): Initial implementation of tube filter
- Loading branch information
Showing
8 changed files
with
791 additions
and
8 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,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
14
Sources/Filters/General/TubeFilter/example/controlPanel.html
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,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> |
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,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; |
Oops, something went wrong.