|
@@ -55,29 +55,29 @@ export class VtkModel {
|
|
this.validNodes = [];//节点数据
|
|
this.validNodes = [];//节点数据
|
|
this.pipes = [];//管道数据
|
|
this.pipes = [];//管道数据
|
|
|
|
|
|
- this.renderWindowWith =null;
|
|
|
|
- this.renderer =null;
|
|
|
|
|
|
+ this.renderWindowWith = null;
|
|
|
|
+ this.renderer = null;
|
|
this.renderWindow = null;
|
|
this.renderWindow = null;
|
|
|
|
|
|
|
|
|
|
- //选取
|
|
|
|
- this.lastActor = null;
|
|
|
|
- this.nodeActors = []; //节点actor 数据
|
|
|
|
- this.pipeActors = []; //管道actor 数据
|
|
|
|
- this.interactor = null;
|
|
|
|
- this.apiSpecificRenderWindow = null;
|
|
|
|
- this.hardwareSelector = null;
|
|
|
|
-
|
|
|
|
- //模板数据
|
|
|
|
- this.polyData = vtkPolyData.newInstance();
|
|
|
|
- this.mapper = vtkMapper.newInstance();
|
|
|
|
- this.actor = vtkActor.newInstance();
|
|
|
|
- this.actor.getProperty().setRepresentation(Representation.SURFACE); //线
|
|
|
|
- this.actor.getProperty().setColor(WHITE);
|
|
|
|
- this.mapper.setInputData(this.polyData);
|
|
|
|
- this.actor.setMapper(this.mapper);
|
|
|
|
-
|
|
|
|
- //点数据
|
|
|
|
|
|
+ //选取
|
|
|
|
+ this.lastActor = null;
|
|
|
|
+ this.nodeActors = []; //节点actor 数据
|
|
|
|
+ this.pipeActors = []; //管道actor 数据
|
|
|
|
+ this.interactor = null;
|
|
|
|
+ this.apiSpecificRenderWindow = null;
|
|
|
|
+ this.hardwareSelector = null;
|
|
|
|
+
|
|
|
|
+ //模板数据
|
|
|
|
+ this.polyData = vtkPolyData.newInstance();
|
|
|
|
+ this.mapper = vtkMapper.newInstance();
|
|
|
|
+ this.actor = vtkActor.newInstance();
|
|
|
|
+ this.actor.getProperty().setRepresentation(Representation.SURFACE); //线
|
|
|
|
+ this.actor.getProperty().setColor(WHITE);
|
|
|
|
+ this.mapper.setInputData(this.polyData);
|
|
|
|
+ this.actor.setMapper(this.mapper);
|
|
|
|
+
|
|
|
|
+ //点数据
|
|
this.actor2 = vtkActor.newInstance();
|
|
this.actor2 = vtkActor.newInstance();
|
|
this.actor2.getProperty().setRepresentation(Representation.POINTS); //点
|
|
this.actor2.getProperty().setRepresentation(Representation.POINTS); //点
|
|
this.actor2.getProperty().setColor(WHITE);
|
|
this.actor2.getProperty().setColor(WHITE);
|
|
@@ -85,33 +85,102 @@ export class VtkModel {
|
|
this.actor2.setMapper(this.mapper);
|
|
this.actor2.setMapper(this.mapper);
|
|
|
|
|
|
|
|
|
|
- //结果数据
|
|
|
|
- this.jgActor = vtkActor.newInstance();
|
|
|
|
- this.jgMapper = vtkMapper.newInstance();
|
|
|
|
- this.jgActor.getProperty().setRepresentation(Representation.SURFACE); //面
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- this.scalarBarActor = vtkScalarBarActor.newInstance();
|
|
|
|
- this.scalarBarActor.setGenerateTicks(this.generateTicks(5));
|
|
|
|
- this.scalarBarActor.setDrawAboveRangeSwatch(true);
|
|
|
|
- this.scalarBarActor.setDrawNanAnnotation(false);
|
|
|
|
- this.scalarBarActor.setBoxPosition([1, 0]);
|
|
|
|
- // 修改设条颜色
|
|
|
|
- const ctf = vtkColorTransferFunction.newInstance();
|
|
|
|
- ctf.addRGBPoint(0.0, 0.0, 0.0, 1.0);
|
|
|
|
- ctf.addRGBPoint(1.0, 0.0, 1.0, 0.5);
|
|
|
|
- ctf.addRGBPoint(2.0, 0.0, 1.0, 0.0);
|
|
|
|
- ctf.addRGBPoint(3.0, 1.0, 0.5, 0.0);
|
|
|
|
- ctf.addRGBPoint(4.0, 1.0, 0.0, 0.0);
|
|
|
|
- this.jgMapper.setLookupTable(ctf);
|
|
|
|
- const lut = this.jgMapper.getLookupTable();
|
|
|
|
- this.scalarBarActor.setScalarsToColors(lut);
|
|
|
|
- this.jgActor.setMapper(this.jgMapper);
|
|
|
|
-
|
|
|
|
|
|
+ //结果数据
|
|
|
|
+ this.jgActor = vtkActor.newInstance();
|
|
|
|
+ this.jgMapper = vtkMapper.newInstance();
|
|
|
|
+ this.jgActor.getProperty().setRepresentation(Representation.SURFACE); //面
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ this.scalarBarActor = vtkScalarBarActor.newInstance();
|
|
|
|
+ this.scalarBarActor.setGenerateTicks(this.generateTicks(5));
|
|
|
|
+ this.scalarBarActor.setDrawAboveRangeSwatch(true);
|
|
|
|
+ this.scalarBarActor.setDrawNanAnnotation(false);
|
|
|
|
+ this.scalarBarActor.setBoxPosition([1, 0]);
|
|
|
|
+ // 修改设条颜色
|
|
|
|
+ const ctf = vtkColorTransferFunction.newInstance();
|
|
|
|
+ ctf.addRGBPoint(0.0, 0.0, 0.0, 1.0);
|
|
|
|
+ ctf.addRGBPoint(1.0, 0.0, 1.0, 0.5);
|
|
|
|
+ ctf.addRGBPoint(2.0, 0.0, 1.0, 0.0);
|
|
|
|
+ ctf.addRGBPoint(3.0, 1.0, 0.5, 0.0);
|
|
|
|
+ ctf.addRGBPoint(4.0, 1.0, 0.0, 0.0);
|
|
|
|
+ this.jgMapper.setLookupTable(ctf);
|
|
|
|
+ const lut = this.jgMapper.getLookupTable();
|
|
|
|
+ this.scalarBarActor.setScalarsToColors(lut);
|
|
|
|
+ this.jgActor.setMapper(this.jgMapper);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ this.ways = [];
|
|
|
|
+ this.wayActors = [];
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+ waysInit(ways) {
|
|
|
|
+ this.renderWindowWith.resize();
|
|
|
|
+ this.ways = ways;
|
|
|
|
|
|
- initMode(rootContainer){
|
|
|
|
- this.renderWindowWith = vtkGenericRenderWindow.newInstance();
|
|
|
|
|
|
+ this.ways.forEach((way) => {
|
|
|
|
+ let nodes1 = [];
|
|
|
|
+ let nodes2 = [];
|
|
|
|
+ for (let index = 0; index < way.nrows.length - 1; index++) {
|
|
|
|
+ nodes1.push(way.nrows[index]);
|
|
|
|
+ }
|
|
|
|
+ for (let index = 1; index < way.nrows.length; index++) {
|
|
|
|
+ nodes2.push(way.nrows[index]);
|
|
|
|
+ }
|
|
|
|
+ for (let index = 0; index < nodes2.length; index++) {
|
|
|
|
+ const lineSource = vtkLineSource.newInstance();
|
|
|
|
+ let snode = nodes1[index];
|
|
|
|
+ let enode = nodes2[index];
|
|
|
|
+ let point1 = [parseFloat(snode.x), parseFloat(snode.y), parseFloat(snode.z)];
|
|
|
|
+ let point2 = [parseFloat(enode.x), parseFloat(enode.y), parseFloat(enode.z)];
|
|
|
|
+ lineSource.setPoint1(point1);
|
|
|
|
+ lineSource.setPoint2(point2);
|
|
|
|
+ lineSource.setResolution(12);
|
|
|
|
+ const actor = vtkActor.newInstance();
|
|
|
|
+ const mapper = vtkMapper.newInstance();
|
|
|
|
+ actor.setMapper(mapper);
|
|
|
|
+ actor.getProperty().setLineWidth(3);//设置线宽
|
|
|
|
+ if(way.safety=="safety"){
|
|
|
|
+ actor.getProperty().setColor(GREEN);
|
|
|
|
+ }else if(way.safety=="danger"){
|
|
|
|
+ actor.getProperty().setColor(REA);
|
|
|
|
+ }
|
|
|
|
+ const initialValues = {
|
|
|
|
+ base: 0,
|
|
|
|
+ center: point2,
|
|
|
|
+ height: 9,
|
|
|
|
+ radius: 5,
|
|
|
|
+ resolution: 2,
|
|
|
|
+ direction: [
|
|
|
|
+ point2[0]-point1[0],
|
|
|
|
+ point2[1]-point1[1],
|
|
|
|
+ point2[2]-point1[2],
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
+ const vtk2d = vtkConeSource.newInstance(initialValues);
|
|
|
|
+ const mapper2 = vtkMapper.newInstance();
|
|
|
|
+ mapper2.setInputConnection(vtk2d.getOutputPort());
|
|
|
|
+ const actor2 = vtkActor.newInstance();
|
|
|
|
+ actor2.setMapper(mapper2);
|
|
|
|
+ if(way.safety=="safety"){
|
|
|
|
+ actor2.getProperty().setColor(GREEN);
|
|
|
|
+ }else if(way.safety=="danger"){
|
|
|
|
+ actor2.getProperty().setColor(REA);
|
|
|
|
+ }
|
|
|
|
+ this.wayActors.push(actor2);
|
|
|
|
+
|
|
|
|
+ mapper.setInputConnection(lineSource.getOutputPort());
|
|
|
|
+ this.wayActors.push(actor);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ this.wayActors.forEach((wayAcotor) => {
|
|
|
|
+ this.renderer.addActor(wayAcotor);
|
|
|
|
+ });
|
|
|
|
+ // vtkmodel.renderer.resetCamera();
|
|
|
|
+ vtkmodel.renderWindow.render();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ initMode(rootContainer) {
|
|
|
|
+ this.renderWindowWith = vtkGenericRenderWindow.newInstance();
|
|
this.renderWindowWith.setContainer(rootContainer);
|
|
this.renderWindowWith.setContainer(rootContainer);
|
|
this.renderer = this.renderWindowWith.getRenderer();
|
|
this.renderer = this.renderWindowWith.getRenderer();
|
|
this.renderer.setBackground(0.0, 0.0, 0.0, 0.0)
|
|
this.renderer.setBackground(0.0, 0.0, 0.0, 0.0)
|
|
@@ -131,7 +200,7 @@ export class VtkModel {
|
|
document.addEventListener("mousemove", throttleMouseHandler);
|
|
document.addEventListener("mousemove", throttleMouseHandler);
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
// //箭头
|
|
// //箭头
|
|
// this.arrowActors = [];
|
|
// this.arrowActors = [];
|
|
// const viewColors = [
|
|
// const viewColors = [
|
|
@@ -221,7 +290,7 @@ export class VtkModel {
|
|
//添加箭头
|
|
//添加箭头
|
|
addArrow(velocitys) {
|
|
addArrow(velocitys) {
|
|
this.clearArrow();
|
|
this.clearArrow();
|
|
- this.arrowActors=[];
|
|
|
|
|
|
+ this.arrowActors = [];
|
|
velocitys.forEach(velocity => {
|
|
velocitys.forEach(velocity => {
|
|
velocity.points.forEach(point => {
|
|
velocity.points.forEach(point => {
|
|
// const initialValues = {
|
|
// const initialValues = {
|
|
@@ -235,17 +304,18 @@ export class VtkModel {
|
|
// ] };
|
|
// ] };
|
|
// const vtk2d = vtk2DShape.newInstance(initialValues);
|
|
// const vtk2d = vtk2DShape.newInstance(initialValues);
|
|
|
|
|
|
- const initialValues = {
|
|
|
|
- base:0,
|
|
|
|
- center: [point.x,point.y,point.z],
|
|
|
|
- height:7,
|
|
|
|
- radius:2,
|
|
|
|
- resolution:3,
|
|
|
|
- direction:[
|
|
|
|
|
|
+ const initialValues = {
|
|
|
|
+ base: 0,
|
|
|
|
+ center: [point.x, point.y, point.z],
|
|
|
|
+ height: 7,
|
|
|
|
+ radius: 8,
|
|
|
|
+ resolution: 3,
|
|
|
|
+ direction: [
|
|
velocity.vector[0],
|
|
velocity.vector[0],
|
|
velocity.vector[1],
|
|
velocity.vector[1],
|
|
velocity.vector[2]
|
|
velocity.vector[2]
|
|
- ] };
|
|
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
const vtk2d = vtkConeSource.newInstance(initialValues);
|
|
const vtk2d = vtkConeSource.newInstance(initialValues);
|
|
const mapper = vtkMapper.newInstance();
|
|
const mapper = vtkMapper.newInstance();
|
|
mapper.setInputConnection(vtk2d.getOutputPort());
|
|
mapper.setInputConnection(vtk2d.getOutputPort());
|
|
@@ -257,14 +327,17 @@ export class VtkModel {
|
|
});
|
|
});
|
|
// this.renderWindow.render();
|
|
// this.renderWindow.render();
|
|
}
|
|
}
|
|
- clearArrow(){
|
|
|
|
- if(this.arrowActors){
|
|
|
|
- this.arrowActors.forEach(actor =>{
|
|
|
|
|
|
+ clearArrow() {
|
|
|
|
+ if (this.arrowActors) {
|
|
|
|
+ this.arrowActors.forEach(actor => {
|
|
this.renderer.removeActor(actor);
|
|
this.renderer.removeActor(actor);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
modelInit(validNodes, pipes) {
|
|
modelInit(validNodes, pipes) {
|
|
this.renderWindowWith.resize();
|
|
this.renderWindowWith.resize();
|
|
this.validNodes = validNodes;
|
|
this.validNodes = validNodes;
|
|
@@ -362,7 +435,7 @@ export class VtkModel {
|
|
// physicalScale?: number;//物理尺度
|
|
// physicalScale?: number;//物理尺度
|
|
// physicalViewUp?: number[];//物理方向
|
|
// physicalViewUp?: number[];//物理方向
|
|
// physicalViewNorth?: number[];//物理北
|
|
// physicalViewNorth?: number[];//物理北
|
|
-
|
|
|
|
|
|
+
|
|
console.log("透视或平行相机", cam.getParallelProjection());
|
|
console.log("透视或平行相机", cam.getParallelProjection());
|
|
// cam.setParallelProjection(true);
|
|
// cam.setParallelProjection(true);
|
|
// console.log("透视或平行相机",cam.getParallelProjection());
|
|
// console.log("透视或平行相机",cam.getParallelProjection());
|
|
@@ -380,8 +453,8 @@ export class VtkModel {
|
|
console.log("相机焦点", cam.getFocalPoint());// [495544.15625, 5403554.25, 467.62999725341797]
|
|
console.log("相机焦点", cam.getFocalPoint());// [495544.15625, 5403554.25, 467.62999725341797]
|
|
cam.setFocalPoint(495544.15625, 5403554.25, 467.62999725341797);
|
|
cam.setFocalPoint(495544.15625, 5403554.25, 467.62999725341797);
|
|
console.log("相机方向", cam.getViewUp());//[0,1,0]
|
|
console.log("相机方向", cam.getViewUp());//[0,1,0]
|
|
- // cam.setViewUp([0,1,1]);
|
|
|
|
- console.log("近远平面",cam.getClippingRange());// [9141.491986233214, 9913.53967078369]
|
|
|
|
|
|
+ // cam.setViewUp([0,1,1]);
|
|
|
|
+ console.log("近远平面", cam.getClippingRange());// [9141.491986233214, 9913.53967078369]
|
|
// cam.setClippingRange(9241.491986233214,9300.53967078369);
|
|
// cam.setClippingRange(9241.491986233214,9300.53967078369);
|
|
this.renderWindow.render();
|
|
this.renderWindow.render();
|
|
|
|
|
|
@@ -396,10 +469,15 @@ export class VtkModel {
|
|
this.pipeActors.forEach((pipeActor) => {
|
|
this.pipeActors.forEach((pipeActor) => {
|
|
this.renderer.removeActor(pipeActor.actor);
|
|
this.renderer.removeActor(pipeActor.actor);
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ wayClearShow(){
|
|
|
|
+ this.wayActors.forEach((wayAcotor) => {
|
|
|
|
+ this.renderer.removeActor(wayAcotor);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
modelShow() {
|
|
modelShow() {
|
|
this.modelClearShow();
|
|
this.modelClearShow();
|
|
|
|
+
|
|
if (!this.isSelectNode) {//不选择节点
|
|
if (!this.isSelectNode) {//不选择节点
|
|
this.renderer.addActor(this.actor2);
|
|
this.renderer.addActor(this.actor2);
|
|
}
|
|
}
|
|
@@ -416,7 +494,7 @@ export class VtkModel {
|
|
this.renderer.addActor(pipeActor.actor);
|
|
this.renderer.addActor(pipeActor.actor);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- this.renderer.addActor( this.axesActor);
|
|
|
|
|
|
+ this.renderer.addActor(this.axesActor);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -465,6 +543,7 @@ export class VtkModel {
|
|
clearModeAddJg() {
|
|
clearModeAddJg() {
|
|
this.renderer.addActor(this.jgActor);
|
|
this.renderer.addActor(this.jgActor);
|
|
this.renderer.addActor(this.scalarBarActor);
|
|
this.renderer.addActor(this.scalarBarActor);
|
|
|
|
+ this.wayClearShow();
|
|
this.modelClearShow();
|
|
this.modelClearShow();
|
|
this.isJg = true; //显示结果
|
|
this.isJg = true; //显示结果
|
|
}
|
|
}
|
|
@@ -473,6 +552,7 @@ export class VtkModel {
|
|
this.renderer.removeActor(this.jgActor);
|
|
this.renderer.removeActor(this.jgActor);
|
|
this.clearArrow();
|
|
this.clearArrow();
|
|
this.modelShow();
|
|
this.modelShow();
|
|
|
|
+ this.wayClearShow();
|
|
this.isJg = false; //不显示结果
|
|
this.isJg = false; //不显示结果
|
|
}
|
|
}
|
|
clearAll() {
|
|
clearAll() {
|
|
@@ -480,6 +560,7 @@ export class VtkModel {
|
|
this.renderer.removeActor(this.scalarBarActor);
|
|
this.renderer.removeActor(this.scalarBarActor);
|
|
this.clearArrow();
|
|
this.clearArrow();
|
|
this.modelClearShow();
|
|
this.modelClearShow();
|
|
|
|
+ this.wayClearShow();
|
|
this.renderWindow.render();
|
|
this.renderWindow.render();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -522,7 +603,7 @@ export class VtkModel {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-function createRGBStringFromRGBValues(rgb){
|
|
|
|
|
|
+function createRGBStringFromRGBValues(rgb) {
|
|
if (rgb.length !== 3) {
|
|
if (rgb.length !== 3) {
|
|
return 'rgb(0, 0, 0)';
|
|
return 'rgb(0, 0, 0)';
|
|
}
|
|
}
|
|
@@ -563,8 +644,8 @@ function eventToWindowXY(event) {
|
|
const x = Math.round((width * clientX) / window.innerWidth);
|
|
const x = Math.round((width * clientX) / window.innerWidth);
|
|
const y = Math.round(height * (1 - clientY / window.innerHeight)); // Need to flip Y
|
|
const y = Math.round(height * (1 - clientY / window.innerHeight)); // Need to flip Y
|
|
return [x, y];
|
|
return [x, y];
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
function processSelections(selections) {
|
|
function processSelections(selections) {
|
|
if (!selections || selections.length === 0) {//没有选择
|
|
if (!selections || selections.length === 0) {//没有选择
|
|
@@ -644,5 +725,6 @@ function processSelections(selections) {
|
|
const throttleMouseHandler = throttle(pickOnMouseEvent, 20);
|
|
const throttleMouseHandler = throttle(pickOnMouseEvent, 20);
|
|
const WHITE = [1, 0.2, 1];
|
|
const WHITE = [1, 0.2, 1];
|
|
const GREEN = [0.1, 0.8, 0.1];
|
|
const GREEN = [0.1, 0.8, 0.1];
|
|
|
|
+const REA = [1, 0, 0];
|
|
const vtkmodel = new VtkModel();
|
|
const vtkmodel = new VtkModel();
|
|
export { vtkmodel };
|
|
export { vtkmodel };
|