[vtkusers] Create PolyData in vtk.js
marf
marvin.huber at basf.com
Wed Jul 18 06:21:13 EDT 2018
First off, thank you very much for your answer :-)
So my current state is, that I can render the data from a .vtu file as
polydata through using a mapper and an actor like this:
*const reader = xmlUnstructuredGridReader.newInstance();
const mapper = vtk.Rendering.Core.vtkMapper.newInstance({ scalarVisibility:
true });
const actor = vtk.Rendering.Core.vtkActor.newInstance();
await reader.parseAsArrayBuffer(serverFile);
actor.setMapper(mapper);
mapper.setInputConnection(reader.getOutputPort());
renderer.addActor(actor);
renderer.resetCamera();
this.onReady(renderWindow);
//UnstructuredGridReader is written by myself (with inspiration from the
vtkPolyDataReader) and utilizes the vtkXMLReader to read a .vtu file into a
polydataobject*
But now I also want to show more information, by coloring the model. I found
that this could by done by using a vtkLookupTable and tried the following,
before actor.setMapper(mapper)
*
const bounds = reader.getOutputData().getBounds();
const max = Math.max.apply(Math, bounds);
const min = Math.min.apply(Math, bounds);
const lookup = vtk.Common.Core.vtkLookupTable.newInstance();
lookup.setNumberOfColors(64),
lookup.setHueRange(0.0, 0.667);
lookup.setRange(min, max);
lookup.build();
mapper.setLookupTable(lookup);
mapper.setInterpolateScalarsBeforeMapping(true);
mapper.setUseLookupTableScalarRange(lookup);*
This did not do anything at all. So I treid coloring the point individually
kind of like this:
*for (let i = 0; i < pointsData.getNumberOfPoints(); i++) {
const color = [];
color[0] = 0.2;
color[1] = 0.1;
color[2] = 0.1;
colors.insertNextTupleValue(color);
}
reader.getOutputData().getPointData().setScalars(colors);*
Since colors apparently should be a vtkUnsignedCharArray and that is not
implemented in vtkjs yet, I mocked it like this:
*
const colors = {
tupleValues: [ ],
insertNextTupleValue: (color) => {
for (let i = 0; i < color.length; i++) {
colors.tupleValues.push(color[i]);
}
},
getNumberOfComponents: () => {
return 3;
},
getDataType: () => {
return 'array';
},
getNumberOfTuples: () => {
return colors.tupleValues.length / colors.getNumberOfComponents();
},
getData: () => {
return colors.tupleValues;
}
};
*
This actually lets me color the model, but there are some issues
- It will only ever pick up color[0] for a point, that can range from 0 ( =
orange-red) to 1 ( = blue) and misses a real red and all purple variations
- I have to kind of figure out the colors since rgb does not work at all
afaik
</ul>
Sorry for the very long post, I hope it is not even more confusing
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list