BowlerKernel
Polyhedron.java
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package eu.mihosoft.vrl.v3d;
7 
8 import java.util.ArrayList;
9 import java.util.Arrays;
10 import java.util.List;
11 import java.util.function.Function;
12 import java.util.stream.Collectors;
13 
14 // TODO: Auto-generated Javadoc
20 public class Polyhedron extends Primitive {
21 
24 
26  private final List<Vector3d> points = new ArrayList<>();
27 
29  private final List<List<Integer>> faces = new ArrayList<>();
30 
38  public Polyhedron(List<Vector3d> points, List<List<Integer>> faces) {
39  this.points.addAll(points);
40  this.faces.addAll(faces);
41  }
42 
50  public Polyhedron(Vector3d[] points, Integer[][] faces) {
51  this.points.addAll(Arrays.asList(points));
52 
53  for (Integer[] list : faces) {
54  this.faces.add(Arrays.asList(list));
55  }
56 
57  }
58 
59  /* (non-Javadoc)
60  * @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
61  */
62  @Override
63  public List<Polygon> toPolygons() {
64 
65  Function<Integer, Vector3d> indexToPoint = (Integer i) -> {
66  return points.get(i).clone();
67  };
68 
69  Function<List<Integer>, Polygon> faceListToPolygon
70  = (List<Integer> faceList) -> {
71  return Polygon.fromPoints(faceList.stream().map(indexToPoint).
72  collect(Collectors.toList()), properties);
73  };
74 
75  return faces.stream().map(faceListToPolygon).
76  collect(Collectors.toList());
77  }
78 
79  /* (non-Javadoc)
80  * @see eu.mihosoft.vrl.v3d.Primitive#getProperties()
81  */
82  @Override
84  return properties;
85  }
86 
87 }
static Polygon fromPoints(List< Vector3d > points, PropertyStorage shared)
Definition: Polygon.java:386
Polyhedron(Vector3d[] points, Integer[][] faces)
Definition: Polyhedron.java:50
PropertyStorage getProperties()
Definition: Polyhedron.java:83
List< Polygon > toPolygons()
Definition: Polyhedron.java:63
final List< List< Integer > > faces
Definition: Polyhedron.java:29
final PropertyStorage properties
Definition: Polyhedron.java:23
final List< Vector3d > points
Definition: Polyhedron.java:26
Polyhedron(List< Vector3d > points, List< List< Integer >> faces)
Definition: Polyhedron.java:38