1 package org.jcae.opencascade.jni;
3 import static org.junit.Assert.*;
6 import org.jcae.opencascade.Utilities;
9 * Create a square with an attached free edge
10 * @author Jerome Robert
12 public class TopoJunction
14 @Test public void sample()
17 double[] p1=new double[]{0, 0, 0};
18 double[] p2=new double[]{0, 1, 0};
19 double[] p3=new double[]{1, 1, 0};
20 double[] p4=new double[]{1, 0, 0};
21 double[] p5=new double[]{0.5, 0.5, 0};
22 double[] p6=new double[]{0.5, 0.5, 1};
24 TopoDS_Edge edge1=(TopoDS_Edge) new BRepBuilderAPI_MakeEdge(p1,p2).shape();
25 TopoDS_Edge edge2=(TopoDS_Edge) new BRepBuilderAPI_MakeEdge(p2,p3).shape();
26 TopoDS_Edge edge3=(TopoDS_Edge) new BRepBuilderAPI_MakeEdge(p3,p4).shape();
27 TopoDS_Edge edge4=(TopoDS_Edge) new BRepBuilderAPI_MakeEdge(p4,p1).shape();
29 TopoDS_Wire wirePlate=
30 (TopoDS_Wire) new BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4).shape();
32 TopoDS_Face face=(TopoDS_Face) new BRepBuilderAPI_MakeFace(wirePlate, true).shape();
35 TopoDS_Vertex vertex1=(TopoDS_Vertex) new BRepBuilderAPI_MakeVertex(p5).shape();
36 TopoDS_Vertex vertex2=(TopoDS_Vertex) new BRepBuilderAPI_MakeVertex(p6).shape();
37 TopoDS_Edge freeEdge=(TopoDS_Edge) new BRepBuilderAPI_MakeEdge(vertex1,vertex2).shape();
39 //Connect the wire to the plate
40 BRep_Builder bb=new BRep_Builder();
41 bb.add(face, vertex1);
43 //Project p5 on surface
44 double [] uv = new double[2];
45 Geom_Surface surface = BRep_Tool.surface(face);
46 GeomAPI_ProjectPointOnSurf proj = new GeomAPI_ProjectPointOnSurf(p5, surface);
47 proj.lowerDistanceParameters(uv);
48 double tolerance = proj.lowerDistance();
49 bb.updateVertex(vertex1, uv[0], uv[1], face, tolerance);
51 //Check that the vertex is on the face
52 double[] coords=BRep_Tool.parameters(vertex1, face);
53 assertEquals(coords[0], 0.5, 1.e-7);
54 assertEquals(coords[1], 0.5, 1.e-7);
56 //Put everything in a compound
57 TopoDS_Compound compound=new TopoDS_Compound();
58 bb.makeCompound(compound);
59 bb.add(compound, freeEdge);
60 bb.add(compound, face);
62 Utilities.dumpTopology(compound, System.out);
64 BRepTools.write(compound, "/tmp/test.brep");