|
@@ -34,6 +34,13 @@ import vtkOrientationMarkerWidget from '@kitware/vtk.js/Interaction/Widgets/Orie
|
|
|
|
|
|
import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera';
|
|
|
|
|
|
+import vtkPLYReader from '@kitware/vtk.js/IO/Geometry/PLYReader';
|
|
|
+import vtkTexture from '@kitware/vtk.js/Rendering/Core/Texture';
|
|
|
+import vtkMatrixBuilder from '@kitware/vtk.js/Common/Core/MatrixBuilder';
|
|
|
+
|
|
|
+import axios from 'axios';
|
|
|
+
|
|
|
+
|
|
|
export class VtkModel {
|
|
|
constructor() {
|
|
|
|
|
@@ -159,13 +166,176 @@ export class VtkModel {
|
|
|
// this.actorpipsite.setPosition(parseFloat(node.x), parseFloat(node.y), parseFloat(node.z));
|
|
|
this.actorpipsite.getProperty().setColor(WHITE);
|
|
|
|
|
|
+ this.jcdActors = []; //检测点数据
|
|
|
+ this.jcreader = vtkPLYReader.newInstance();
|
|
|
+ fetchJSFileAsArrayBuffer('src/assets/3d/jiancd.ply').then(arrayBuffer => {
|
|
|
+ // 读取PLY数据
|
|
|
+ this.jcreader.parseAsArrayBuffer(arrayBuffer);
|
|
|
+ });
|
|
|
+ this.pnameActors =[];
|
|
|
+
|
|
|
+ this.soureActors =[];
|
|
|
+ this.soureReader = vtkPLYReader.newInstance();
|
|
|
+ fetchJSFileAsArrayBuffer('src/assets/3d/fire.ply').then(arrayBuffer => {
|
|
|
+ // 读取PLY数据
|
|
|
+ this.soureReader.parseAsArrayBuffer(arrayBuffer);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ xyz_back(){
|
|
|
+ this.renderer.resetCamera();
|
|
|
+ }
|
|
|
+ x_up(){
|
|
|
+ cam.setViewUp([0,0,1]);
|
|
|
+ cam.setPosition(495544.15625+7000, 5403554.25, 467.62999725341797);//相机位置
|
|
|
+ }
|
|
|
+ x_down(){
|
|
|
+ this.renderer.getActiveCamera();
|
|
|
+ cam.setViewUp([0,0,1]);
|
|
|
+ cam.setPosition(-1*(495544.15625+7000), 5403554.25, 467.62999725341797);//相机位置
|
|
|
+ }
|
|
|
+ y_up(){
|
|
|
+ this.renderer.getActiveCamera();
|
|
|
+ cam.setViewUp([0,0,1]);
|
|
|
+ cam.setPosition(495544.15625, 5403554.25+7000, 467.62999725341797);//相机位置
|
|
|
+ }
|
|
|
+ y_down(){
|
|
|
+ this.renderer.getActiveCamera();
|
|
|
+ cam.setViewUp([0,0,1]);
|
|
|
+ cam.setPosition(495544.15625, -1*(5403554.25+7000), 467.62999725341797);//相机位置
|
|
|
+ }
|
|
|
+ z_up(){
|
|
|
+ this.renderer.getActiveCamera();
|
|
|
+ cam.setViewUp([0,1,0]);
|
|
|
+ cam.setPosition(495544.15625, 5403554.25, 467.62999725341797+7000);//相机位置
|
|
|
+ }
|
|
|
+ z_down(){
|
|
|
+ this.renderer.getActiveCamera();
|
|
|
+ cam.setViewUp([0,1,0]);
|
|
|
+ cam.setPosition(495544.15625, 5403554.25, 1*(467.62999725341797+7000));//相机位置
|
|
|
}
|
|
|
|
|
|
+ //显示巷道名称
|
|
|
+ initPname() {
|
|
|
+ fetch('src/assets/3d/pipname.json')
|
|
|
+ .then(response => response.json()).then(data => {
|
|
|
+ let pipnames = data;
|
|
|
+ pipnames.forEach((pipname)=>{
|
|
|
+ let pnameReader = vtkPLYReader.newInstance();
|
|
|
+ fetchJSFileAsArrayBuffer('src/assets/3d/'+pipname.name+'.ply').then(arrayBuffer => {
|
|
|
+ // 读取PLY数据
|
|
|
+ pnameReader.parseAsArrayBuffer(arrayBuffer);
|
|
|
+ });
|
|
|
+ const mapper = vtkMapper.newInstance();
|
|
|
+ mapper.setInputConnection(pnameReader.getOutputPort());
|
|
|
+ const actor = vtkActor.newInstance();
|
|
|
+ actor.setPosition(pipname.x,pipname.y,pipname.z);
|
|
|
+ actor.getProperty().setColor(TEXTCOLOR);
|
|
|
+ actor.setMapper(mapper);
|
|
|
+ actor.setScale(20,20,20);//放大
|
|
|
+ this.pnameActors.push(actor);
|
|
|
+ // this.renderer.addActor(actor);
|
|
|
+ });
|
|
|
+ }).catch(error => {
|
|
|
+ console.error('Error fetching JSON:', error);
|
|
|
+ });
|
|
|
+}
|
|
|
+//显示巷道名称
|
|
|
+showPname(){
|
|
|
+ this.pnameActors.forEach((actor)=>{
|
|
|
+ this.renderer.addActor(actor);
|
|
|
+ });
|
|
|
+}
|
|
|
+//隐藏巷道名称
|
|
|
+removePname(){
|
|
|
+ this.pnameActors.forEach((actor)=>{
|
|
|
+ this.renderer.removeActor(actor);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ //添加一个灾源点
|
|
|
+ initSoures(pid,site){
|
|
|
+ let pipe =this.pipeByPid(pid);
|
|
|
+ let point1 = this.pointByPipeNodeId(pipe.snId);
|
|
|
+ let point2 = this.pointByPipeNodeId(pipe.enId);
|
|
|
+ let py = site/(1-site);
|
|
|
+ let pipsite_point=[
|
|
|
+ (point1[0]+py*point2[0])/(1+py),
|
|
|
+ (point1[1]+py*point2[1])/(1+py),
|
|
|
+ (point1[2]+py*point2[2])/(1+py),
|
|
|
+ ]
|
|
|
+ this.initSoure(pipsite_point[0],pipsite_point[1],pipsite_point[2]);
|
|
|
+ }
|
|
|
+ initSoure(x,y,z) {
|
|
|
+ const mapper = vtkMapper.newInstance();
|
|
|
+ mapper.setInputConnection(this.soureReader.getOutputPort());
|
|
|
+ const actor = vtkActor.newInstance();
|
|
|
+ actor.setPosition(x,y,z);
|
|
|
+ actor.getProperty().setColor(SOURECOLOR);
|
|
|
+ actor.setMapper(mapper);
|
|
|
+ // 旋转actor
|
|
|
+ actor.rotateY(45);// 绕y轴旋转
|
|
|
+ actor.setScale(5,5,5);//放大
|
|
|
+ this.soureActors.push(actor);
|
|
|
+ this.renderer.addActor(actor);
|
|
|
+ }
|
|
|
+ //显示灾源点
|
|
|
+showSoure(){
|
|
|
+ this.soureActors.forEach((actor)=>{
|
|
|
+ this.renderer.addActor(actor);
|
|
|
+ });
|
|
|
+}
|
|
|
+//隐藏灾源点
|
|
|
+removeSoure(){
|
|
|
+ this.soureActors.forEach((actor)=>{
|
|
|
+ this.renderer.removeActor(actor);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+//初始化监测点
|
|
|
+initCheckNodes(checkNodes){
|
|
|
+ checkNodes.forEach((checkNode) => {
|
|
|
+ let pipe =this.pipeByPid(checkNode.pid);
|
|
|
+ let site =checkNode.site;
|
|
|
+ let point1 = this.pointByPipeNodeId(pipe.snId);
|
|
|
+ let point2 = this.pointByPipeNodeId(pipe.enId);
|
|
|
+ let py = site/(1-site);
|
|
|
+ let pipsite_point=[
|
|
|
+ (point1[0]+py*point2[0])/(1+py),
|
|
|
+ (point1[1]+py*point2[1])/(1+py),
|
|
|
+ (point1[2]+py*point2[2])/(1+py),
|
|
|
+ ]
|
|
|
+ this.initjc(pipsite_point[0],pipsite_point[1],pipsite_point[2]);
|
|
|
+ });
|
|
|
+}
|
|
|
+initjc(x,y,z) {
|
|
|
+ const mapper = vtkMapper.newInstance();
|
|
|
+ mapper.setInputConnection(this.jcreader.getOutputPort());
|
|
|
+ const actor = vtkActor.newInstance();
|
|
|
+ actor.setPosition(x,y,z);
|
|
|
+ actor.getProperty().setColor(JCDCOLOR);
|
|
|
+ actor.setMapper(mapper);
|
|
|
+ this.jcdActors.push(actor);
|
|
|
+ // this.renderer.addActor(actor);
|
|
|
+}
|
|
|
+//显示监测点
|
|
|
+showjc(){
|
|
|
+ this.jcdActors.forEach((actor)=>{
|
|
|
+ this.renderer.addActor(actor);
|
|
|
+ });
|
|
|
+}
|
|
|
+//隐藏监测点
|
|
|
+removejc(){
|
|
|
+ this.jcdActors.forEach((actor)=>{
|
|
|
+ this.renderer.removeActor(actor);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
//显示所选择巷道位置
|
|
|
addpipsite(pipe,site){
|
|
|
let point1 = this.pointByPipeNodeId(pipe.snId);
|
|
|
let point2 = this.pointByPipeNodeId(pipe.enId);
|
|
|
- console.log(point1[0],point2[0],site,(point1[0]+point2[0])*site);
|
|
|
|
|
|
let py = site/(1-site);
|
|
|
let pipsite_point=[
|
|
@@ -441,6 +611,7 @@ export class VtkModel {
|
|
|
}
|
|
|
modelCreate() {
|
|
|
console.log("modelInit..");
|
|
|
+
|
|
|
const points = this.polyData.getPoints();
|
|
|
const lines = this.polyData.getLines();
|
|
|
|
|
@@ -497,39 +668,6 @@ export class VtkModel {
|
|
|
this.renderer.resetCamera();
|
|
|
const cam = this.renderer.getActiveCamera();
|
|
|
|
|
|
- // const cam = vtkCamera.newInstance();
|
|
|
- // const cam =this.renderer.getActiveCamera();
|
|
|
- // this.renderer.setActiveCamera(cam);
|
|
|
- // cam.setFocalPoint(0, 0, 0);
|
|
|
- // cam.setPosition(0, 0, 10);
|
|
|
- // cam.setClippingRange(0.1, 2.0);
|
|
|
- // cam.setViewAngle(300);
|
|
|
- // console.log(
|
|
|
- // cam.getPosition(),//摄像头位置
|
|
|
- // cam.getViewAngle(),//相机视角 默认30
|
|
|
- // cam.getFocalPoint(),//相机焦点
|
|
|
- // cam.getViewUp(),//相机方向
|
|
|
- // );
|
|
|
- // position?: number[]; //摄像头位置
|
|
|
- // focalPoint?: number[]; //相机焦点
|
|
|
- // viewUp?: number[];//相机方向
|
|
|
- // directionOfProjection?: number[]; //相机到焦点的方向
|
|
|
- // parallelProjection?: boolean;//透视 平行
|
|
|
- // useHorizontalViewAngle?: boolean;//水平视角使用
|
|
|
- // viewAngle?: number;//相机视角
|
|
|
- // parallelScale?: number;//平行位置投影比例
|
|
|
- // clippingRange?: number[];//近远平面
|
|
|
- // windowCenter?: number[];//窗口中心位置 范围 ([-1,+1],[-1,+1])
|
|
|
- // viewPlaneNormal?: number[];//投影平面法线 (投影反方向)
|
|
|
- // useOffAxisProjection?: boolean;//离轴投影
|
|
|
- // screenBottomLeft?: number[];//左上角的点
|
|
|
- // screenBottomRight?: number[];//右上角的点
|
|
|
- // screenTopRight?: number[];//右上角的点 用于离轴投影
|
|
|
- // freezeFocalPoint?: boolean;
|
|
|
- // physicalTranslation?: number[];//物理翻译
|
|
|
- // physicalScale?: number;//物理尺度
|
|
|
- // physicalViewUp?: number[];//物理方向
|
|
|
- // physicalViewNorth?: number[];//物理北
|
|
|
|
|
|
console.log("透视或平行相机", cam.getParallelProjection());
|
|
|
// cam.setParallelProjection(true);
|
|
@@ -541,34 +679,33 @@ export class VtkModel {
|
|
|
console.log("窗口中心位置", cam.getWindowCenter());//[0, 0]
|
|
|
// cam.setWindowCenter([1,-1]);
|
|
|
console.log("相机视角", cam.getViewAngle());//30
|
|
|
- cam.setViewAngle(15);
|
|
|
+ // cam.setViewAngle(90);
|
|
|
|
|
|
console.log("摄像头位置", cam.getPosition());//[495544.15625, 5403554.25, 9989.55990464236]
|
|
|
- cam.setPosition(495544.15625, 5403554.25, 9989.55990464236);
|
|
|
+ // cam.setPosition(495544.15625, 5403554.25, 9989.55990464236);
|
|
|
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]
|
|
|
// cam.setViewUp([0,1,1]);
|
|
|
console.log("近远平面", cam.getClippingRange());// [9141.491986233214, 9913.53967078369]
|
|
|
// cam.setClippingRange(9241.491986233214,9300.53967078369);
|
|
|
|
|
|
// 设置环境光和光照
|
|
|
- const light = vtkLight.newInstance();
|
|
|
- light.setColor(1.0, 1.0, 1.0); // 白色环境光
|
|
|
- light.setIntensity(3.0); // 强度为1.0
|
|
|
- this.renderer.addLight(light);
|
|
|
-
|
|
|
- // const cameraLight = vtkLight.newInstance();
|
|
|
- // cameraLight.setColor(1.0, 0.0, 0.0); // 红色光照
|
|
|
- // cameraLight.setPositional(true); // 定向光源
|
|
|
- // cameraLight.setConeAngle(-30.0); // 光束角度
|
|
|
- // cameraLight.setPosition(this.renderer.getActiveCamera().getFocalPoint());
|
|
|
- // cameraLight.setIntensity(0.8);
|
|
|
- // this.renderer.addLight(cameraLight);
|
|
|
-
|
|
|
- this.renderer.resetCamera();
|
|
|
+ // const light = vtkLight.newInstance();
|
|
|
+ // light.setColor(1.0, 1.0, 1.0); // 白色环境光
|
|
|
+ // light.setIntensity(3.0); // 强度为1.0
|
|
|
+ // this.renderer.addLight(light);
|
|
|
+ // this.renderer.resetCamera();
|
|
|
+ // cam.setPosition(0, 0, 9989);
|
|
|
+ //相机焦点 495544.15625 5403554.25 467.62999725341797
|
|
|
+ // cam.setPosition( 495544.15625+500, 5403554.25, 467.62999725341797);
|
|
|
+ // cam.setPosition( 495544.15625-500, 5403554.25, 467.62999725341797);
|
|
|
+ // cam.setViewUp([0,0,1]);
|
|
|
+ // this.renderer.updateCamera();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
modelClearShow() {
|
|
|
this.renderer.removeActor(this.actor);
|
|
|
this.renderer.removeActor(this.actor2);
|
|
@@ -603,7 +740,13 @@ export class VtkModel {
|
|
|
this.renderer.addActor(pipeActor.actor);
|
|
|
});
|
|
|
}
|
|
|
+ // this.addjc(495530.903,5403828.821,432.40);
|
|
|
+ // this.addpname(495530.903,5403829.821,432.40);
|
|
|
+ // this.addSoure(495530.903,5403829.821,432.40);
|
|
|
+ // this.addpname(495530.903,5403829.821,432.40);
|
|
|
+ this.initPname();
|
|
|
this.renderer.addActor(this.axesActor);
|
|
|
+ // this.rotateY();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -639,6 +782,15 @@ export class VtkModel {
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+ pipeByPid(pid) {
|
|
|
+ console.log("pipeByPid",this.pipes.length)
|
|
|
+ for (let index = 0; index < this.pipes.length; index++) {
|
|
|
+ const pipe = this.pipes[index];
|
|
|
+ if (pipe.id == pid) {
|
|
|
+ return pipe;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
pointByPipeNodeId(nid) {
|
|
|
for (let index = 0; index < this.validNodes.length; index++) {
|
|
|
const node = this.validNodes[index];
|
|
@@ -860,9 +1012,44 @@ function processSelections(selections) {
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+// 异步函数,用于读取JS文件并转换为ArrayBuffer
|
|
|
+async function fetchJSFileAsArrayBuffer(url) {
|
|
|
+ try {
|
|
|
+ // 使用fetch API异步加载JS文件
|
|
|
+ const response = await fetch(url, {
|
|
|
+ method: 'GET',
|
|
|
+ responseType: 'arraybuffer' // 指定响应类型为arraybuffer
|
|
|
+ });
|
|
|
+
|
|
|
+ // 确保响应成功
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取ArrayBuffer对象
|
|
|
+ const arrayBuffer = await response.arrayBuffer();
|
|
|
+
|
|
|
+ // 可选:验证转换后的ArrayBuffer内容
|
|
|
+ const decoder = new TextDecoder(); // 使用TextDecoder将ArrayBuffer解码为字符串
|
|
|
+ const content = decoder.decode(arrayBuffer);
|
|
|
+ // console.log('File content:', content);
|
|
|
+
|
|
|
+ return arrayBuffer;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error fetching the file:', error);
|
|
|
+ throw error; // 重新抛出错误以便上层处理
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const throttleMouseHandler = throttle(pickOnMouseEvent, 20);
|
|
|
const WHITE = [1, 0.2, 1];
|
|
|
const GREEN = [0.1, 0.8, 0.1];
|
|
|
const REA = [1, 0, 0];
|
|
|
+
|
|
|
+const JCDCOLOR = [0.5, 0, 0];
|
|
|
+const SOURECOLOR = [0.5, 0.5, 0];
|
|
|
+const TEXTCOLOR = [1, 1, 1];
|
|
|
+
|
|
|
const vtkmodel = new VtkModel();
|
|
|
export { vtkmodel };
|