JavaCAD
STL.java
Go to the documentation of this file.
1 
32 package eu.mihosoft.vrl.v3d;
33 
34 import eu.mihosoft.vrl.v3d.ext.imagej.STLLoader;
35 
36 import java.io.IOException;
37 import java.net.URI;
38 import java.net.URISyntaxException;
39 import java.net.URL;
40 import java.nio.file.FileSystem;
41 import java.nio.file.FileSystems;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.util.ArrayList;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48 
49 import javax.vecmath.Point3f;
50 
51 // TODO: Auto-generated Javadoc
57 public class STL {
58 
67  public static CSG file(URL path) throws IOException, URISyntaxException {
68  final URI uri =path.toURI();
69  Map<String, String> env = new HashMap<>();
70  env.put("create", "true");
71  FileSystem zipfs = FileSystems.newFileSystem(uri, env);
72  Path myFolderPath = Paths.get(uri);
73  return file(myFolderPath);
74  }
75 
83  public static CSG file(Path path) throws IOException {
84  STLLoader loader = new STLLoader();
85 
86  List<Polygon> polygons = new ArrayList<>();
87  List<Vector3d> vertices = new ArrayList<>();
88  for (Point3f p : loader.parse(path.toFile())) {
89  vertices.add(new Vector3d(p.x, p.y, p.z));
90  if (vertices.size() == 3) {
91  try {
92  polygons.add(Polygon.fromPointsAllowDegenerate(vertices));
93  } catch (RuntimeException ex) {
94  ex.printStackTrace();
95  }
96  vertices = new ArrayList<>();
97  }
98  }
99 
100  return CSG.fromPolygons(new PropertyStorage(), polygons);
101  }
102 }
static CSG fromPolygons(List< Polygon > polygons)
Definition: CSG.java:621
static Polygon fromPointsAllowDegenerate(List< Vector3d > vertices2)
Definition: Polygon.java:410
static CSG file(Path path)
Definition: STL.java:83
static CSG file(URL path)
Definition: STL.java:67
ArrayList< Point3f > parse(File f)
Definition: STLLoader.java:82