• vtk for java 打包部署和运行


    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. "1.0" encoding="UTF-8"?>
    2. "http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. wp_ite_dataGathering
    6. wp.itedatagathering
    7. 1.1.8
    8. 4.0.0
    9. carDataAnalyzing
    10. carDataAnalyzing
    11. wp.itedatagathering
    12. common
    13. vtk
    14. vtk
    15. 1.0
    16. system
    17. ${project.basedir}/lib/vtk.jar
    18. org.springframework.boot
    19. spring-boot-starter-test
    20. test
    21. org.junit.vintage
    22. junit-vintage-engine
    23. jul-to-slf4j
    24. org.slf4j
    25. ${project.artifactId}
    26. org.springframework.boot
    27. spring-boot-maven-plugin
    28. repackage
    29. 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 文件,计算点云体积。

    点云处理代码:

    1. package com.wpitedatagathering.dataanalyzing.utils;
    2. import com.wpitedatagathering.common.utils.SpringUtils;
    3. import com.wpitedatagathering.dataanalyzing.config.ScanDataConfig;
    4. import lombok.extern.slf4j.Slf4j;
    5. import vtk.*;
    6. import java.util.HashMap;
    7. import java.util.Map;
    8. @Slf4j
    9. public class VtkUtil {
    10. public static void init() {
    11. log.info("initdll-begin");
    12. System.out.println("初始化");
    13. if(!vtkNativeLibrary.LoadAllNativeLibraries()){
    14. for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
    15. if(!lib.IsLoaded()){
    16. System.out.println(lib.GetLibraryName()+" not load");
    17. }
    18. }
    19. }
    20. log.info("initdll-end");
    21. vtkNativeLibrary.DisableOutputWindow(null);
    22. }
    23. //txt 三维数据 转 obj 对象
    24. public static Map txt2Obj(String fileName){
    25. System.out.println("txt 三维数据 转 obj 对象");
    26. Map result = new HashMap<>();
    27. vtkSimplePointsReader reader = new vtkSimplePointsReader();
    28. ScanDataConfig scanDataConfig = SpringUtils.getBean(ScanDataConfig.class);
    29. String filePath = scanDataConfig.getFilePath();
    30. reader.SetFileName(filePath+"\\"+fileName+".txt");
    31. reader.Update();
    32. vtkPolyData vtkPolyData = reader.GetOutput();
    33. vtkCellArray vtkCellArray = new vtkCellArray();
    34. vtkPolyData boundary = new vtkPolyData();
    35. boundary.SetPoints(vtkPolyData.GetPoints());
    36. boundary.SetPolys(vtkCellArray);
    37. //三角剖析
    38. vtkDelaunay2D vtkDelaunay2D = new vtkDelaunay2D();
    39. vtkDelaunay2D.SetInputData(vtkPolyData);
    40. vtkDelaunay2D.Update();
    41. vtkMassProperties vtkMassProperties = new vtkMassProperties();
    42. vtkMassProperties.SetInputData(vtkDelaunay2D.GetOutput());
    43. vtkMassProperties.Update();
    44. double volume = vtkMassProperties.GetVolume();
    45. double surfaceArea = vtkMassProperties.GetSurfaceArea();
    46. System.out.println("面 积:"+surfaceArea);
    47. System.out.println("体 积:"+volume);
    48. result.put("volume",volume);
    49. result.put("area",surfaceArea);
    50. vtkSTLWriter vtkSTLWriter = new vtkSTLWriter();
    51. String fileNameSTL = filePath+"\\"+fileName+".stl";
    52. vtkSTLWriter.SetFileName(fileNameSTL);
    53. vtkSTLWriter.SetInputConnection(vtkDelaunay2D.GetOutputPort());
    54. vtkSTLWriter.Write();
    55. vtkPolyDataMapper mapper = new vtkPolyDataMapper();
    56. mapper.SetInputConnection(vtkDelaunay2D.GetOutputPort());
    57. vtkActor vtkActor = new vtkActor();
    58. vtkActor.SetMapper(mapper);
    59. VtkUtil.save2Obj(mapper,vtkActor,filePath+"\\"+fileName);
    60. result.put("obj",fileName+".obj");
    61. result.put("mtl",fileName+".mtl");
    62. result.put("stl",fileName+".stl");
    63. return result;
    64. }
    65. public static void save2Obj(vtkPolyDataMapper mapper,vtkActor vtkActor,String fileName){
    66. vtkActor actor = new vtkActor();
    67. actor.SetMapper(mapper);
    68. actor.GetProperty().SetRepresentationToWireframe();
    69. vtkRenderer ren = new vtkRenderer();
    70. vtkRenderWindow renWin = new vtkRenderWindow();
    71. renWin.AddRenderer(ren);
    72. vtkRenderWindowInteractor iRen = new vtkRenderWindowInteractor();
    73. iRen.SetRenderWindow(renWin);
    74. // Visualize
    75. ren.AddActor(actor);
    76. ren.AddActor(vtkActor);
    77. vtkOBJExporter objExporter = new vtkOBJExporter();
    78. objExporter.SetFilePrefix(fileName);
    79. objExporter.SetInput(renWin);
    80. objExporter.Write();
    81. renWin.RemoveRenderer(ren);
    82. }
    83. }

  • 相关阅读:
    Nginx中关于虚拟主机的一点冷门知识
    2022 年坑过我的 JAVA 面试题
    Anaconda Prompt中的指令集
    [java/初学者]static修饰的静态变量、方法及代码块的特性与使用
    Neural Insights for Digital Marketing Content Design 阅读笔记
    opensips开启lua支持
    达梦8.0主备安装
    EDA实验------数控分频器设计(QuartusII)
    如何使用VSCode将iPad Pro转化为功能强大的开发工具?
    Shell脚本:Linux Shell脚本学习指南(第二部分Shell编程)一
  • 原文地址:https://blog.csdn.net/Listest/article/details/127753061