Skip to content

Commit 188017c

Browse files
committed
Add hull to the client server system
1 parent e40eef7 commit 188017c

7 files changed

Lines changed: 57 additions & 9 deletions

File tree

src/main/java/eu/mihosoft/vrl/v3d/CSG.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ public CSG dumbUnion(CSG csg) {
878878
public CSG union(List<CSG> csgs) {
879879
if (CSGClient.isRunning()) {
880880
ArrayList<CSG> go = new ArrayList<CSG>(csgs);
881+
go.add(this);
881882
try {
882883
return CSGClient.getClient().union(go).get(0);
883884
} catch (Exception e) {

src/main/java/eu/mihosoft/vrl/v3d/CSGClient.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.security.cert.X509Certificate;
1212

1313
//CSG Client class that maintains connection and provides clean API
14-
class CSGClient {
14+
public class CSGClient {
1515
// statics
1616
private static CSGClient client = null;
1717

@@ -71,7 +71,9 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) {
7171
public ArrayList<CSG> union(List<CSG> csgList) throws Exception {
7272
return performOperation(csgList, CSGRemoteOperation.UNION);
7373
}
74-
74+
public ArrayList<CSG> hull(List<Vector3d> points, PropertyStorage storage) throws Exception {
75+
return performOperation(new ArrayList<CSG>(), CSGRemoteOperation.hull,points,storage);
76+
}
7577
/**
7678
* Perform difference operations on consecutive CSG pairs
7779
*
@@ -119,11 +121,16 @@ public ArrayList<CSG> minkowskiHullShape(ArrayList<CSG> csgList) throws Exceptio
119121
public ArrayList<CSG> triangulate(ArrayList<CSG> csgList) throws Exception {
120122
return performOperation(csgList, CSGRemoteOperation.TRIANGULATE);
121123
}
122-
123124
/**
124125
* Internal method to perform operations and handle request/response
125126
*/
126-
private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation operation) throws Exception {
127+
private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation operation)throws Exception{
128+
return performOperation(csgList,operation,null,null);
129+
}
130+
/**
131+
* Internal method to perform operations and handle request/response
132+
*/
133+
private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation operation,List<Vector3d> points, PropertyStorage storage) throws Exception {
127134
ArrayList<CSG> back = null;
128135
SSLSocket socket = (SSLSocket) factory.createSocket(hostname, port);
129136
try {
@@ -142,7 +149,7 @@ private ArrayList<CSG> performOperation(List<CSG> csgList, CSGRemoteOperation op
142149
tmp.setRegenerate(null);
143150
toSend.add(tmp);
144151
}
145-
CSGRequest request = new CSGRequest(toSend, operation);
152+
CSGRequest request = new CSGRequest(toSend, operation,points,storage);
146153
if (key != null)
147154
request.setAPIKEY(key);
148155
oos.writeObject(request);

src/main/java/eu/mihosoft/vrl/v3d/CSGRemoteOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ public enum CSGRemoteOperation {
44
UNION,
55
DIFFERENCE,
66
INTERSECT,
7-
TRIANGULATE, minkowskiHullShape
7+
TRIANGULATE, minkowskiHullShape,hull
88
}

src/main/java/eu/mihosoft/vrl/v3d/CSGRequest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ class CSGRequest implements Serializable {
99
private List<CSG> csgList;
1010
private CSGRemoteOperation operation;
1111
private String APIKEY;
12+
private List<Vector3d> points;
13+
private PropertyStorage storage;
1214

1315
public CSGRequest() {
1416
this.csgList = new ArrayList<>();
1517
this.operation = CSGRemoteOperation.UNION;
1618
}
1719

18-
public CSGRequest(List<CSG> csgList, CSGRemoteOperation operation) {
20+
public CSGRequest(List<CSG> csgList, CSGRemoteOperation operation,List<Vector3d> points, PropertyStorage storage) {
21+
this.setPoints(points);
22+
this.setStorage(storage);
1923
this.csgList = csgList != null ? new ArrayList<>(csgList) : new ArrayList<>();
2024
this.operation = operation != null ? operation : CSGRemoteOperation.UNION;
2125
}
@@ -48,4 +52,20 @@ public String getAPIKey() {
4852
public void setAPIKEY(String aPIKEY) {
4953
APIKEY = aPIKEY;
5054
}
55+
56+
public List<Vector3d> getPoints() {
57+
return points;
58+
}
59+
60+
public void setPoints(List<Vector3d> points) {
61+
this.points = points;
62+
}
63+
64+
public PropertyStorage getStorage() {
65+
return storage;
66+
}
67+
68+
public void setStorage(PropertyStorage storage) {
69+
this.storage = storage;
70+
}
5171
}

src/main/java/eu/mihosoft/vrl/v3d/CSGServerHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import javax.net.ssl.SSLSocket;
1111

12+
import eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil;
13+
1214
class CSGServerHandler implements Runnable {
1315
private SSLSocket clientSocket;
1416

@@ -113,6 +115,9 @@ private CSGResponse processCSGRequest(CSGRequest request) {
113115
CSG t = csgList.remove(0);
114116
back.addAll(m1.minkowskiHullShape(t));
115117
break;
118+
case hull:
119+
back.add(HullUtil.hull(request.getPoints(), request.getStorage()));
120+
break;
116121
default:
117122
throw new RuntimeException("No Such Operation " + request.getOperation());
118123
}

src/main/java/eu/mihosoft/vrl/v3d/ext/quickhull3d/HullUtil.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
package eu.mihosoft.vrl.v3d.ext.quickhull3d;
77

88
import eu.mihosoft.vrl.v3d.CSG;
9+
import eu.mihosoft.vrl.v3d.CSGClient;
910
import eu.mihosoft.vrl.v3d.Vector3d;
1011
import eu.mihosoft.vrl.v3d.Polygon;
1112
import eu.mihosoft.vrl.v3d.PropertyStorage;
1213
import java.util.ArrayList;
14+
import java.util.Arrays;
1315
import java.util.List;
1416

1517
/**
@@ -58,7 +60,16 @@ public static CSG hull(List<?> points) {
5860
* @return the csg
5961
*/
6062
public static CSG hull(List<Vector3d> points, PropertyStorage storage) {
61-
63+
if (CSGClient.isRunning()) {
64+
try {
65+
CSG csg = CSGClient.getClient().hull(points,new PropertyStorage()).get(0);
66+
csg.setStorage(storage);
67+
return csg;
68+
} catch (Exception e) {
69+
// TODO Auto-generated catch block
70+
e.printStackTrace();
71+
}
72+
}
6273
Point3d[] hullPoints = points.stream().map((vec) -> new Point3d(vec.x, vec.y, vec.z)).toArray(Point3d[]::new);
6374

6475
QuickHull3D hull = new QuickHull3D();

src/test/java/eu/mihosoft/vrl/v3d/ServerClientTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void test() throws Exception {
3737
// Create client with try-with-resources for automatic cleanup
3838
try {
3939

40-
CSG a = new Cube(20).toCSG();
40+
CSG a = new Cube(20).toCSG().movex(100).movez(100);
4141
a.getBounds();
4242
a.setManipulator(new javafx.scene.transform.Affine());
4343
a.setManufacturing(new PrepForManufacturing() {
@@ -58,6 +58,7 @@ public CSG prep(CSG incoming) {
5858
CSG d1 = a.difference(b);
5959
CSG t1 = d1.clone().triangulate(true);
6060
ArrayList<CSG> m1 = a.minkowskiHullShape(b);
61+
CSG h1 = u1.hull();
6162

6263
CSGClient.start(hostname, port, f);
6364
// Set a low number to ensure the Server is used. this defaults to 200
@@ -83,6 +84,9 @@ public CSG prep(CSG incoming) {
8384
fail();
8485
}
8586
}
87+
CSG h = u1.hull();
88+
if(h.getPolygons().size()!=h1.getPolygons().size())
89+
fail();
8690
CSGClient.close();
8791
} catch (Exception e) {
8892
System.err.println("Communication error: " + e.getMessage());

0 commit comments

Comments
 (0)