过滤器 WarpScalar
介绍
先看一个官方的一句话介绍:
vtkWarpScalar - deform geometry with scalar data
vtkWarpScalar - 使用标量数据变形几何体
详细介绍
vtkWarpScalar is a filter that modifies point coordinates by moving
points along point normals by the scalar amount times the scale
factor. Useful for creating carpet or x-y-z plots.If normals are not present in data, the Normal instance variable will
be used as the direction along which to warp the geometry. If normals
are present but you would like to use the Normal instance variable,
set the UseNormal boolean to true.If XYPlane boolean is set true, then the z-value is considered to be a
scalar value (still scaled by scale factor), and the displacement is
along the z-axis. If scalars are also present, these are copied
through and can be used to color the surface.Note that the filter passes both its point data and cell data to its
output, except for normals, since these are distorted by the warping.
vtkWarpScalar是一个过滤器,它通过沿点法线移动点坐标,移动的距离是标量值乘以缩放因子来修改点坐标。这对于创建地毯图或x-y-z图非常有用。
如果数据中不存在法线,将使用Normal实例变量作为变形几何体的方向。如果数据中存在法线,但您想要使用Normal实例变量,请将UseNormal布尔值设置为true。
如果设置了XYPlane布尔值为true,那么z值将被视为标量值(仍然乘以缩放因子),位移将沿z轴进行。如果也存在标量值,这些值将被复制并通过它们可以用来给表面着色。
请注意,该过滤器将其点数据和单元数据传递到输出,但不包括法线,因为这些法线由于变形而发生了扭曲。
代码效果
核心代码是:
//wrapscalar的过滤器const filter = vtkWarpScalar.newInstance({scaleFactor: 0.1,useNormal: false,});
//自定义的过滤器const randFilter = macro.newInstance((publicAPI, model) => {macro.obj(publicAPI, model); // make it an objectmacro.algo(publicAPI, model, 1, 1); // mixin algorithm code 1 in, 1 outpublicAPI.requestData = (inData, outData) => {console.log(inData[0].getPoints());// implement requestDataif (!outData[0] || inData[0].getMTime() > outData[0].getMTime()) {const newArray = new Float32Array(inData[0].getPoints().getNumberOfPoints());for (let i = 0; i < newArray.length; i++) {// newArray[i] = i % 2 ? 1 : 0;// scalar是随机newArray[i] = Math.random();}const da = vtkDataArray.newInstance({name: "spike",values: newArray,});const newDataSet = vtk({ vtkClass: inData[0].getClassName() });// 浅拷贝数据newDataSet.shallowCopy(inData[0]);newDataSet.getPointData().setScalars(da);outData[0] = newDataSet;}};})();randFilter.setInputConnection(planeSource.getOutputPort());filter.setInputConnection(randFilter.getOutputPort());mapper.setInputConnection(filter.getOutputPort());// Select array to processfilter.setInputArrayToProcess(0, "spike", "PointData", "Scalars");
打印了一下中间数据inData[0].getPoints().getData()
总共是363个数据,表示是121个点,因为我们平面是10 X10分段的,意味着有(10+1)X(10+1)个点,没错。
其实这个过滤器还有一个问题就是目前看,每次都要从上次数据里面拷贝数据过来,如果过滤器多了,这个数据不清楚释放的是否及时。
如果scalar变成这个值:newArray[i] = i % 2 ? 1 : 0;显示效果是
这个用来做地形图和热力图会比较有场景
全部代码都放到github上了
新坑_Learning vtkjs_git地址
关注我,我持续更新vtkjs的example学习案例
也欢迎各位给我提意见,技术交流~
大鸿
WeChat : HugeYen
WeChat Public Account : BIM树洞
做一个静谧的树洞君
用建筑的语言描述IT事物;
用IT的思维解决建筑问题;
共建BIM桥梁,聚合团队。
本学习分享资料不得用于商业用途,仅做学习交流!!如有侵权立即删除!!