1.下载dll 和 jar 包,vs2017 安装(安装windows 必备的就可以了)
vtk.jar 下载路径
https://download.csdn.net/download/Listest/86936510
vs2017下载路径
VisualStudio2017专业版和企业版激活密钥_lovoo的博客-CSDN博客_vs2017专业版密钥
vtk.jar 下载路径:
https://mvnrepository.com/artifact/org.bioimageanalysis.icy/icy-vtk/8.0.1https://mvnrepository.com/artifact/org.bioimageanalysis.icy/icy-vtk/8.0.1dll 下载路径:https://download.csdn.net/download/Listest/86931995
2.将dll 放到jre 的bin 目录下:C:\Program Files\Java\jdk1.8.0_202\jre\bin
3.将vtk.jar 拷贝到项目根目录下:
4.pom 文件加载本地vtk.jar 包,打包的时候要记得进行打包配置。---两个重点
- "1.0" encoding="UTF-8"?>
"http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-
wp_ite_dataGathering -
wp.itedatagathering -
1.1.8 -
-
4.0.0 -
-
carDataAnalyzing -
-
carDataAnalyzing -
-
-
wp.itedatagathering -
common -
-
-
-
-
vtk -
vtk -
1.0 -
system -
${project.basedir}/lib/vtk.jar -
-
-
-
-
-
org.springframework.boot -
spring-boot-starter-test -
test -
-
-
org.junit.vintage -
junit-vintage-engine -
-
-
jul-to-slf4j -
org.slf4j -
-
-
-
-
-
-
${project.artifactId} -
-
-
org.springframework.boot -
spring-boot-maven-plugin -
-
-
-
repackage -
-
-
-
-
true -
-
-
-
-
5.运行:start C:\"Program Files"\Java\jdk1.8.0_202\jre\bin\java -Dfile.encoding=utf-8 -Dloader.path="lib/" -jar carDataAnalyzing.jar
6.效果如图:--目的是将点云生成obj 文件,计算点云体积。
点云处理代码:
- package com.wpitedatagathering.dataanalyzing.utils;
-
-
- import com.wpitedatagathering.common.utils.SpringUtils;
- import com.wpitedatagathering.dataanalyzing.config.ScanDataConfig;
- import lombok.extern.slf4j.Slf4j;
- import vtk.*;
-
- import java.util.HashMap;
- import java.util.Map;
-
-
- @Slf4j
- public class VtkUtil {
- public static void init() {
- log.info("initdll-begin");
- System.out.println("初始化");
- if(!vtkNativeLibrary.LoadAllNativeLibraries()){
- for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
- if(!lib.IsLoaded()){
- System.out.println(lib.GetLibraryName()+" not load");
- }
- }
- }
- log.info("initdll-end");
- vtkNativeLibrary.DisableOutputWindow(null);
- }
-
-
-
- //txt 三维数据 转 obj 对象
- public static Map
txt2Obj(String fileName){ - System.out.println("txt 三维数据 转 obj 对象");
- Map
result = new HashMap<>(); - vtkSimplePointsReader reader = new vtkSimplePointsReader();
- ScanDataConfig scanDataConfig = SpringUtils.getBean(ScanDataConfig.class);
- String filePath = scanDataConfig.getFilePath();
- reader.SetFileName(filePath+"\\"+fileName+".txt");
- reader.Update();
-
- vtkPolyData vtkPolyData = reader.GetOutput();
- vtkCellArray vtkCellArray = new vtkCellArray();
- vtkPolyData boundary = new vtkPolyData();
- boundary.SetPoints(vtkPolyData.GetPoints());
- boundary.SetPolys(vtkCellArray);
- //三角剖析
- vtkDelaunay2D vtkDelaunay2D = new vtkDelaunay2D();
- vtkDelaunay2D.SetInputData(vtkPolyData);
- vtkDelaunay2D.Update();
- vtkMassProperties vtkMassProperties = new vtkMassProperties();
- vtkMassProperties.SetInputData(vtkDelaunay2D.GetOutput());
- vtkMassProperties.Update();
-
- double volume = vtkMassProperties.GetVolume();
- double surfaceArea = vtkMassProperties.GetSurfaceArea();
- System.out.println("面 积:"+surfaceArea);
- System.out.println("体 积:"+volume);
- result.put("volume",volume);
- result.put("area",surfaceArea);
-
- vtkSTLWriter vtkSTLWriter = new vtkSTLWriter();
- String fileNameSTL = filePath+"\\"+fileName+".stl";
- vtkSTLWriter.SetFileName(fileNameSTL);
- vtkSTLWriter.SetInputConnection(vtkDelaunay2D.GetOutputPort());
- vtkSTLWriter.Write();
- vtkPolyDataMapper mapper = new vtkPolyDataMapper();
- mapper.SetInputConnection(vtkDelaunay2D.GetOutputPort());
- vtkActor vtkActor = new vtkActor();
- vtkActor.SetMapper(mapper);
- VtkUtil.save2Obj(mapper,vtkActor,filePath+"\\"+fileName);
-
- result.put("obj",fileName+".obj");
- result.put("mtl",fileName+".mtl");
- result.put("stl",fileName+".stl");
- return result;
- }
-
-
- public static void save2Obj(vtkPolyDataMapper mapper,vtkActor vtkActor,String fileName){
- vtkActor actor = new vtkActor();
- actor.SetMapper(mapper);
- actor.GetProperty().SetRepresentationToWireframe();
- vtkRenderer ren = new vtkRenderer();
- vtkRenderWindow renWin = new vtkRenderWindow();
- renWin.AddRenderer(ren);
-
- vtkRenderWindowInteractor iRen = new vtkRenderWindowInteractor();
- iRen.SetRenderWindow(renWin);
- // Visualize
- ren.AddActor(actor);
- ren.AddActor(vtkActor);
- vtkOBJExporter objExporter = new vtkOBJExporter();
- objExporter.SetFilePrefix(fileName);
- objExporter.SetInput(renWin);
- objExporter.Write();
-
- renWin.RemoveRenderer(ren);
-
- }
- }