X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.proconf.g3d.occ%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Focc%2Fgeometry%2FOccTriangulator.java;fp=org.simantics.proconf.g3d.occ%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Focc%2Fgeometry%2FOccTriangulator.java;h=ca5af06ada670af3202a0b676b902b36f7a5beb2;hb=477a3eae417fe71addfcf8f87dab41f87151a384;hp=0000000000000000000000000000000000000000;hpb=d0db32bb067d2a7c323054295f6356bdb42078c9;p=simantics%2F3d.git diff --git a/org.simantics.proconf.g3d.occ/src/org/simantics/proconf/g3d/occ/geometry/OccTriangulator.java b/org.simantics.proconf.g3d.occ/src/org/simantics/proconf/g3d/occ/geometry/OccTriangulator.java new file mode 100644 index 00000000..ca5af06a --- /dev/null +++ b/org.simantics.proconf.g3d.occ/src/org/simantics/proconf/g3d/occ/geometry/OccTriangulator.java @@ -0,0 +1,820 @@ +/******************************************************************************* + * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.proconf.g3d.occ.geometry; + +import java.io.IOException; +import java.util.Collection; + +import javax.vecmath.AxisAngle4d; +import javax.vecmath.Tuple3d; +import javax.vecmath.Vector2d; + +import org.jcae.opencascade.jni.BRepBuilderAPI_MakeEdge; +import org.jcae.opencascade.jni.BRepBuilderAPI_MakeFace; +import org.jcae.opencascade.jni.BRepBuilderAPI_MakeWire; +import org.jcae.opencascade.jni.BRepBuilderAPI_Transform; +import org.jcae.opencascade.jni.BRepOffsetAPI_ThruSections; +import org.jcae.opencascade.jni.BRepPrimAPI_MakePrism; +import org.jcae.opencascade.jni.BRepPrimAPI_MakeRevol; +import org.jcae.opencascade.jni.BRepPrimAPI_MakeTorus; +import org.jcae.opencascade.jni.BRep_Builder; +import org.jcae.opencascade.jni.GC_MakeArcOfCircle; +import org.jcae.opencascade.jni.GC_MakeSegment; +import org.jcae.opencascade.jni.GP_Elips; +import org.jcae.opencascade.jni.GP_Trsf; +import org.jcae.opencascade.jni.TopoDS_Edge; +import org.jcae.opencascade.jni.TopoDS_Face; +import org.jcae.opencascade.jni.TopoDS_Shape; +import org.jcae.opencascade.jni.TopoDS_Wire; +import org.simantics.proconf.g3d.csg.stubs.Barrel; +import org.simantics.proconf.g3d.csg.stubs.BooleanOperation; +import org.simantics.proconf.g3d.csg.stubs.Box; +import org.simantics.proconf.g3d.csg.stubs.CSGShape; +import org.simantics.proconf.g3d.csg.stubs.Cone; +import org.simantics.proconf.g3d.csg.stubs.Cylinder; +import org.simantics.proconf.g3d.csg.stubs.EllipticCylinder; +import org.simantics.proconf.g3d.csg.stubs.RectangularSolid; +import org.simantics.proconf.g3d.csg.stubs.RegularPrism; +import org.simantics.proconf.g3d.csg.stubs.Sphere; +import org.simantics.proconf.g3d.csg.stubs.Torus; +import org.simantics.layer0.utils.IEntity; +import org.simantics.proconf.g3d.base.G3DTools; +import org.simantics.proconf.g3d.base.GeometryProvider; +import org.simantics.proconf.g3d.occ.OccResources; +import org.simantics.utils.ErrorLogger; + +import com.jme.eclipse.test.ply.PLY_Loader; +import com.jme.scene.Geometry; +import com.jme.scene.Line; +import com.jme.scene.TriMesh; +import com.jme.util.geom.BufferUtils; + +public class OccTriangulator implements GeometryProvider{ + + + public static final double MIN_VALUE = 0.001; + + public OccTriangulator() { + + } + + + + public boolean canHandle(IEntity instance) { + if (instance.isInstanceOf(OccResources.csgResource.CSGShape)) { + return true; + } + return false; + } + + public Geometry[] getGeometryFromResource(IEntity resource, boolean transform) { + if (resource.isInstanceOf(OccResources.csgResource.CSGShape)) { + TopoDS_Shape shape = OccTriangulator.getShapeFromResource(resource, transform); + Geometry[] g = OccTriangulator.getGeometry(shape); + shape.delete(); + return g; + } + return null; + } + + public boolean reconstructGeometry(IEntity instance, boolean transform, Geometry[] geometry) { + if (instance.isInstanceOf(OccResources.csgResource.CSGShape)) { + TopoDS_Shape shape = OccTriangulator.getShapeFromResource(instance, transform); + boolean b = OccTriangulator.getGeometry(shape,geometry); + shape.delete(); + return b; + } + return false; + + } + + public static Geometry[] getGeometry(TopoDS_Shape tds_shape) { + Geometry g[] = new Geometry[]{new TriMesh(),new Line()}; + if (getGeometry(tds_shape, g)) + return g; + return null; + + } + + public static boolean getGeometry(TopoDS_Shape tds_shape, Geometry[] geometry) { + ViewableShapeImpl shape = new ViewableShapeImpl(tds_shape); + //System.out.println("Geometries in shape " + shape.numGeometries()); + if (shape.numGeometries() > 0) { + int totalIndicesCount = 0; + int totalVerticesCount = 0; + boolean hasTCoords = true; + for (int geometryIndex = 0; geometryIndex < shape.numGeometries(); geometryIndex++) { + IndexedGeometry geom = shape.getGeometry(geometryIndex); + totalIndicesCount += geom.getIndices().length; + totalVerticesCount += (geom.getCoordinates().length / 3); + if (geom.getTCoordinates() == null || geom.getTCoordinates().length == 0) + hasTCoords = false; + } + int currentVertex = 0; + int currentIndex = 0; + int indices[] = new int[totalIndicesCount]; + + + + //TriMesh mesh = new TriMesh(); + TriMesh mesh = (TriMesh)geometry[0]; + float data[] = new float[totalVerticesCount*3]; + float normals[] = new float[totalVerticesCount*3]; + float tcoords[] = null; + if (hasTCoords) + tcoords = new float[totalVerticesCount*2]; + for (int geometryIndex = 0; geometryIndex < shape.numGeometries(); geometryIndex++) { + IndexedGeometry geom = shape.getGeometry(geometryIndex); + System.arraycopy(geom.getCoordinates(), 0, data, currentVertex*3, geom.getCoordinates().length); + System.arraycopy(geom.getNormals(), 0, normals, currentVertex*3, geom.getCoordinates().length); + if (hasTCoords) + System.arraycopy(geom.getTCoordinates(), 0, tcoords, currentVertex*2, geom.getTCoordinates().length - 1); + + for (int i = 0; i < geom.getIndices().length; i++) { + indices[currentIndex + i] = geom.getIndices()[i] + currentVertex; + } + + currentVertex += geom.getCoordinates().length/3; + currentIndex += geom.getIndices().length; + + } + mesh.reconstruct(BufferUtils.createFloatBuffer(data),BufferUtils.createFloatBuffer(normals) , null, hasTCoords ? BufferUtils.createFloatBuffer(tcoords) : null, BufferUtils.createIntBuffer(indices)); + + int numEdgeVertices = 0; + int currentEdgeVertex = 0; + for (int i = 0; i < shape.getNumEdges(); i++) { + numEdgeVertices += shape.getEdge(i).length/3; + } + + Line lines = (Line)geometry[1]; + data = new float[numEdgeVertices*3]; + for (int i = 0; i < shape.getNumEdges(); i++) { + int index = currentEdgeVertex *3; + System.arraycopy(shape.getEdge(i), 0,data, index, shape.getEdge(i).length); + currentEdgeVertex+= shape.getEdge(i).length/3; + } + lines.reconstruct(BufferUtils.createFloatBuffer(data), null, null, null); + + tds_shape.delete(); + return true; + } else { + tds_shape.delete(); + return false; + } + } + /* + public static Geometry[] getGeometry(TopoDS_Shape tds_shape) { + return getGeometry(tds_shape,true); + } + */ + /* + public static boolean getGeometry(TopoDS_Shape tds_shape, Geometry[] geometry) { + return getGeometry(tds_shape,true, geometry); + } + */ + + private static TopoDS_Shape getPrimitiveFromResource(IEntity thing) { + if (!thing.isInstanceOf(OccResources.csgResource.Primitive)) + throw new IllegalArgumentException("Resource is not a primitive"); + TopoDS_Shape shape = null; + if (thing.isInstanceOf(OccResources.csgResource.Box)) { + Box box = new Box(thing); + double sx = box.getXAxisSize()[0]; + double sy = box.getYAxisSize()[0]; + double sz = box.getZAxisSize()[0]; + if (sx <= MIN_VALUE) + sx = MIN_VALUE; + if (sy <= MIN_VALUE) + sy = MIN_VALUE; + if (sz <= MIN_VALUE) + sz = MIN_VALUE; + + shape = makeBox(-sx * 0.5, -sy * 0.5, -sz * 0.5, sx * 0.5, sy * 0.5, sz * 0.5); + } else if (thing.isInstanceOf(OccResources.csgResource.Cone)) { + Cone cone = new Cone(thing); + double h = cone.getHeight()[0]; + double r1 = cone.getBottomRadius()[0]; + double r2 = cone.getTopRadius()[0]; + if (Math.abs(r1 - r2) > MIN_VALUE) { // OpenCASCADE won't work, + // if r1 == r2 + shape = makeCone(new double[] { 0.0, -h * 0.5, 0.0 }, new double[] { 0.0, 1.0, 0.0 }, r1, + r2, h); + } else { + shape = makeCylinder(new double[] { 0.0, -h * 0.5, 0.0 }, new double[] { 0.0, 1.0, 0.0 }, + r1, h); + } + } else if (thing.isInstanceOf(OccResources.csgResource.Sphere)) { + Sphere sphere = new Sphere(thing); + double r = sphere.getRadius()[0]; + if (r <= MIN_VALUE) + r = MIN_VALUE; + shape = makeSphere(0.0, 0.0, 0.0, r); + } else if (thing.isInstanceOf(OccResources.csgResource.Torus)) { + Torus torus = new Torus(thing); + double r1 = torus.getMajorRadius()[0]; + double r2 = torus.getMinorRadius()[0]; + if (r1 <= MIN_VALUE) + r1 = MIN_VALUE; + if (r2 <= MIN_VALUE) + r2 = MIN_VALUE; + shape = makeTorus(new double[] { 0.0, 0.0, 0.0 }, new double[] { 0.0, 1.0, 0.0 }, r1, r2); + } else if (thing.isInstanceOf(OccResources.csgResource.Cylinder)) { + Cylinder cylinder = new Cylinder(thing); + double h = cylinder.getHeight()[0]; + double r = cylinder.getRadius()[0]; + if (r <= MIN_VALUE) + r = MIN_VALUE; + if (h <= MIN_VALUE) + h = MIN_VALUE; + shape = makeCylinder(new double[] { 0.0, -h * 0.5, 0.0 }, new double[] { 0.0, 1.0, 0.0 }, r, h); + } else if (thing.isInstanceOf(OccResources.csgResource.Barrel)) { + Barrel barrel = new Barrel(thing); + double h = barrel.getHeight()[0]; + if (h <= 0.0) + h = 0.01; + double r1 = barrel.getMinorRadius()[0]; + if (r1 <= MIN_VALUE) + r1 = MIN_VALUE; + double r2 = barrel.getMajorRadius()[0]; + if (r2 <= MIN_VALUE) + r2 = MIN_VALUE; + if (Math.abs(r1 -r2)< MIN_VALUE) + r2 = r1 + MIN_VALUE; + double p0[] = new double[]{0.0,-h*0.5,0.0}; + double p1[] = new double[]{0.0,-h*0.5,r1}; + double p2[] = new double[]{0.0, 0.0 ,r2}; + double p3[] = new double[]{0.0, h*0.5,r1}; + double p4[] = new double[]{0.0, h*0.5,0.0}; + GC_MakeArcOfCircle m = new GC_MakeArcOfCircle(p1,p2,p3); + GC_MakeSegment s1 = new GC_MakeSegment(p0,p1); + GC_MakeSegment s2 = new GC_MakeSegment(p3,p4); + TopoDS_Edge e1 = (TopoDS_Edge)new BRepBuilderAPI_MakeEdge(s1.value()).shape(); + TopoDS_Edge e2 = (TopoDS_Edge)new BRepBuilderAPI_MakeEdge(m.value()).shape(); + TopoDS_Edge e3 = (TopoDS_Edge)new BRepBuilderAPI_MakeEdge(s2.value()).shape(); + TopoDS_Wire w = (TopoDS_Wire) new BRepBuilderAPI_MakeWire(e1,e2,e3).shape(); + TopoDS_Face F = (TopoDS_Face) new BRepBuilderAPI_MakeFace(w).shape(); + shape = new BRepPrimAPI_MakeRevol(F,new double[]{0.0,0.0,0.0,0.0,1.0,0.0}).shape(); + m.delete(); + s1.delete(); + s2.delete(); + e1.delete(); + e2.delete(); + e3.delete(); + w.delete(); + F.delete(); + } else if (thing.isInstanceOf(OccResources.csgResource.EllipticCylinder)) { + EllipticCylinder cylinder = new EllipticCylinder(thing); + double h = cylinder.getHeight()[0]; + if (h < MIN_VALUE) + h = MIN_VALUE; + double r2 = cylinder.getMinorRadius()[0]; + if (r2 < MIN_VALUE) + r2 = MIN_VALUE; + double r1 = cylinder.getMajorRadius()[0]; + if (r1 < MIN_VALUE) + r1 = MIN_VALUE; + GP_Elips ellipse; + if (r1 < r2) { + // FIXME : ellipse should be rotated, but current JNI won't allow it since Ax2 is not separate object + ellipse = new GP_Elips(new double[]{0.0,-h*0.5,0.0,0.0,1.0,0.0},r2,r1); + } else { + ellipse = new GP_Elips(new double[]{0.0,-h*0.5,0.0,0.0,1.0,0.0},r1,r2); + } + TopoDS_Edge ed = (TopoDS_Edge) new BRepBuilderAPI_MakeEdge(ellipse).shape(); + TopoDS_Wire w = (TopoDS_Wire) new BRepBuilderAPI_MakeWire(ed).shape(); + TopoDS_Face F = (TopoDS_Face) new BRepBuilderAPI_MakeFace(w).shape(); + shape = new BRepPrimAPI_MakePrism(F, new double[] { 0.0, h, 0.0 }).shape(); + ellipse.delete(); + ed.delete(); + w.delete(); + F.delete(); + } else if (thing.isInstanceOf(OccResources.csgResource.RegularPrism)) { + RegularPrism prism = new RegularPrism(thing); + int n = prism.getCorners()[0]; + if (n < 3) + n = 3; + double h = prism.getHeight()[0]; + if (h < MIN_VALUE) + h = MIN_VALUE; + double r = prism.getRadius()[0]; + if (r < MIN_VALUE) + r = MIN_VALUE; + Vector2d vertices[] = new Vector2d[n]; + for (int i = 0; i < n; i++) { + vertices[i] = new Vector2d(Math.sin(Math.PI * 2.0 * i / n)*r,Math.cos(Math.PI * 2.0 * i / n)*r); + } + BRepBuilderAPI_MakeWire wire = new BRepBuilderAPI_MakeWire(); + for (int i = 0; i < n; i++) { + Vector2d v1 = vertices[i]; + Vector2d v2 = vertices[(i+1)%n]; + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{v1.x,-h*0.5,v1.y},new double[]{v2.x,-h*0.5,v2.y}).shape()); + } + TopoDS_Wire w = (TopoDS_Wire)wire.shape(); + TopoDS_Face F = (TopoDS_Face) new BRepBuilderAPI_MakeFace(w).shape(); + shape = new BRepPrimAPI_MakePrism(F, new double[] { 0.0, h, 0.0 }).shape(); + wire.delete(); + w.delete(); + F.delete(); + } else if (thing.isInstanceOf(OccResources.csgResource.RectangularSolid)) { + RectangularSolid solid = new RectangularSolid(thing); + double x1 = solid.getXAxisMinimumSize()[0]; + double x2 = solid.getXAxisMaximumSize()[0]; + double y = solid.getYAxisSize()[0]; + double z1 = solid.getZAxisMinimumSize()[0]; + double z2 = solid.getZAxisMaximumSize()[0]; + if (x1 < MIN_VALUE) + x1 = MIN_VALUE; + if (x2 < MIN_VALUE) + x2 = MIN_VALUE; + if (y < MIN_VALUE) + y = MIN_VALUE; + if (z1 < MIN_VALUE) + z1 = MIN_VALUE; + if (z2 < MIN_VALUE) + z2 = MIN_VALUE; + x1 *= 0.5; + x2 *= 0.5; + y *= 0.5; + z1 *= 0.5; + z2 *= 0.5; + + BRepBuilderAPI_MakeWire wire = new BRepBuilderAPI_MakeWire(); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{x1,-y,z1},new double[]{x1,-y,-z1}).shape()); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{x1,-y,-z1},new double[]{-x1,-y,-z1}).shape()); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{-x1,-y,-z1},new double[]{-x1,-y,z1}).shape()); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{-x1,-y,z1},new double[]{x1,-y,z1}).shape()); + TopoDS_Wire w1 = (TopoDS_Wire)wire.shape(); + wire.delete(); + wire = new BRepBuilderAPI_MakeWire(); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{x2, y,z2},new double[]{x2, y,-z2}).shape()); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{x2, y,-z2},new double[]{-x2, y,-z2}).shape()); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{-x2, y,-z2},new double[]{-x2, y,z2}).shape()); + wire.add((TopoDS_Edge)new BRepBuilderAPI_MakeEdge(new double[]{-x2, y,z2},new double[]{x2, y,z2}).shape()); + TopoDS_Wire w2 = (TopoDS_Wire)wire.shape(); + BRepOffsetAPI_ThruSections generatorb = new BRepOffsetAPI_ThruSections(true, true); + generatorb.addWire(w1); + generatorb.addWire(w2); + generatorb.build(); + shape = generatorb.shape(); + wire.delete(); + w1.delete(); + w2.delete(); + } else { + throw new UnsupportedOperationException("Unsupported primitive"); + + } + return shape; + } + + private static TopoDS_Shape getBooleanOp(IEntity thing, TopoDS_Shape topoDSshape1, TopoDS_Shape topoDSshape2) { + if (!thing.isInstanceOf(OccResources.csgResource.BooleanOperation)) + throw new IllegalArgumentException("Resource is not a boolean operation"); + TopoDS_Shape shape = null; + int type; + if (thing.isInstanceOf(OccResources.csgResource.Difference)) { + type = 0; + } else if (thing.isInstanceOf(OccResources.csgResource.Union)) { + type = 1; + } else if (thing.isInstanceOf(OccResources.csgResource.Intersection)) { + type = 2; + } else { + throw new UnsupportedOperationException("Unsupported boolean operation"); + } + + switch (type) { + case 0: + shape = makeCut(topoDSshape1, topoDSshape2); + break; + case 1: + shape = makeFuse(topoDSshape1, topoDSshape2); + break; + case 2: + shape = makeCommon(topoDSshape1, topoDSshape2); + break; + } + topoDSshape1.delete(); + topoDSshape2.delete(); + return shape; + } + + private static TopoDS_Shape getBooleanOpFromResource(IEntity thing) { + if (!thing.isInstanceOf(OccResources.csgResource.BooleanOperation)) + throw new IllegalArgumentException("Resource is not a boolean operation"); + + TopoDS_Shape shape = null; + TopoDS_Shape topoDSshape1 = null; + TopoDS_Shape topoDSshape2 = null; + BooleanOperation op = new BooleanOperation(thing); + CSGShape mainShape = op.getMainShape(); + Collection secondaryShapes = op.getSecondaryShape(); + if (mainShape == null || secondaryShapes.size() < 1) { + throw new RuntimeException("Cannot find requested Shapes for boolean operation"); + } + topoDSshape1 = getShapeFromResource(mainShape); + for (CSGShape shape2 : secondaryShapes) { + topoDSshape2 = getShapeFromResource(shape2); + shape = getBooleanOp(thing,topoDSshape1,topoDSshape2); + topoDSshape1.delete(); + topoDSshape1 = shape; + } + + topoDSshape2.delete(); + return shape; + } + + private static TopoDS_Shape getShapeFromResource(IEntity thing) { + return getShapeFromResource(thing, true); + } + + private static TopoDS_Shape getShapeFromResource(IEntity thing, boolean transform) { + if (thing.isInstanceOf(OccResources.csgResource.CSGShape)) { + TopoDS_Shape shape = null; + + if (thing.isInstanceOf(OccResources.csgResource.Primitive)) { + shape = getPrimitiveFromResource(thing); + + } else if (thing.isInstanceOf(OccResources.csgResource.BooleanOperation)) { + shape = getBooleanOpFromResource(thing); + + } else { + throw new UnsupportedOperationException("Shape must be a primitive or a boolean operation"); + } + Tuple3d c = null; + CSGShape shapeType = new CSGShape(thing); + + if (shapeType.getCenter() != null) + c = G3DTools.getVector(shapeType.getCenter()); + + TopoDS_Shape tShape = null; + if(c != null) { + tShape = makeTranslation(shape, c.x, c.y, c.z); + shape.delete(); + shape = tShape; + } + if (transform) { + //CSGShape shapeType = CSGShapeFactory.create(resource); + Tuple3d p = G3DTools.getVector(shapeType.getLocalPosition()); + AxisAngle4d r = G3DTools.getOrientation(shapeType.getLocalOrientation()); + + if (Math.abs(r.angle) > 0.01) { + tShape = makeRotation(shape, new double[] { 0.0, 0.0, 0.0, r.x, r.y, r.z }, r.angle); + shape.delete(); + shape = tShape; + } + tShape = makeTranslation(shape, p.x, p.y, p.z); + shape.delete(); + shape = tShape; + } + + return shape; + + } + throw new UnsupportedOperationException("Resource is not a shape"); + } + + private static TopoDS_Shape getShapeFromFile(String filename) { + assert (filename != null); + if (filename.endsWith("stp")) { + TopoDS_Shape shape = importSTEP(filename); + return shape; + } else if (filename.endsWith("step")) { + TopoDS_Shape shape = importSTEP(filename); + return shape; + } else if (filename.endsWith("iges")) { + TopoDS_Shape shape = importIGES(filename); + return shape; + } else if (filename.endsWith("brep")) { + TopoDS_Shape shape = importBREP(filename); + return shape; + } else { + throw new UnsupportedOperationException("Unsupported format " + filename); + } + + } + + + + public static Geometry[] getGeometryFromFile(String filename) { + if (filename.endsWith("ply")) { + try { + return new Geometry[]{PLY_Loader.loadPLY(filename)}; + } catch (IOException e) { + ErrorLogger.defaultLogError(e); + return null; + } + } + TopoDS_Shape shape = OccTriangulator.getShapeFromFile(filename); + Geometry g[] = OccTriangulator.getGeometry(shape); + shape.delete(); + return g; + } + + public static TopoDS_Shape importBREP(String filename) { + org.jcae.opencascade.jni.BRep_Builder aBuilder = new org.jcae.opencascade.jni.BRep_Builder(); + org.jcae.opencascade.jni.TopoDS_Shape myShape = org.jcae.opencascade.jni.BRepTools.read(filename, aBuilder); + aBuilder.delete(); + return myShape; + } + + public static TopoDS_Shape importIGES(String filename) { + org.jcae.opencascade.jni.IGESControl_Reader aReader = new org.jcae.opencascade.jni.IGESControl_Reader(); + aReader.readFile(filename); + aReader.clearShapes(); + aReader.transferRoots(); + TopoDS_Shape result = aReader.oneShape(); + aReader.delete(); + return result; + } + + public static TopoDS_Shape importSTEP(String filename) { + org.jcae.opencascade.jni.STEPControl_Reader aReader = new org.jcae.opencascade.jni.STEPControl_Reader(); + aReader.readFile(filename); + aReader.clearShapes(); + aReader.transferRoots(); + TopoDS_Shape result = aReader.oneShape(); + aReader.delete(); + return result; + } + + public static TopoDS_Shape archimede(TopoDS_Shape topoDS_Shape, double param, double param2, double param3) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape suppressHolesInFaceOrShell(TopoDS_Shape topoDS_Shape, TopoDS_Shape[] topoDS_Shape1) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape suppressHole(TopoDS_Shape topoDS_Shape, TopoDS_Shape[] topoDS_Shape1, + TopoDS_Shape[] topoDS_Shape2, TopoDS_Shape[] topoDS_Shape3) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape[] suppressFaces(TopoDS_Shape topoDS_Shape, TopoDS_Shape[] topoDS_Shape1) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape[] subShapeAll(TopoDS_Shape topoDS_Shape, short param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape subShape(TopoDS_Shape topoDS_Shape, short param, TopoDS_Shape[] topoDS_Shape2) { + throw new UnsupportedOperationException(); + } + + public static boolean setBlock(TopoDS_Shape topoDS_Shape) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape partitionKeepFaces(TopoDS_Shape[] topoDS_Shape, TopoDS_Shape topoDS_Shape1, boolean param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape orientationChange(TopoDS_Shape topoDS_Shape) { + throw new UnsupportedOperationException(); + } + + public static short nbLabels() { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeWire(TopoDS_Shape[] topoDS_Shape) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeVertex(double param, double param1, double param2) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeVector(double[] pointStruct, double[] pointStruct1) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeTranslation(TopoDS_Shape aShape, double x, double y, double z) { + GP_Trsf theTransformation = new GP_Trsf(); + theTransformation.setTranslation(new double[] { x, y, z }); + BRepBuilderAPI_Transform bt = new BRepBuilderAPI_Transform(aShape, theTransformation, true); + + TopoDS_Shape shape = bt.shape(); + bt.delete(); + theTransformation.delete(); + return shape; + } + + public static TopoDS_Shape makeTorus(double[] pointStruct, double[] dirStruct, double r1, double r2) { + double[] axe = new double[6]; + System.arraycopy(pointStruct, 0, axe, 0, 3); + System.arraycopy(dirStruct, 0, axe, 3, 3); + org.jcae.opencascade.jni.TopoDS_Shape tds = new BRepPrimAPI_MakeTorus(axe, r1, r2).shape(); + return tds; + } + + public static TopoDS_Shape makeSphere(double x, double y, double z, double radius) { + double[] c = new double[] { x, y, z }; + org.jcae.opencascade.jni.TopoDS_Shape tds = new org.jcae.opencascade.jni.BRepPrimAPI_MakeSphere(c, radius) + .shape(); + return tds; + } + + public static TopoDS_Shape makeSewingShape(TopoDS_Shape topoDS_Shape, double param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeSewing(TopoDS_Shape[] topoDS_Shape, double param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeScaleTransform(TopoDS_Shape topoDS_Shape, double[] pointStruct, double param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeRotation(TopoDS_Shape aShape, double[] axisStruct, double angle) { + + GP_Trsf theTransformation = new GP_Trsf(); + theTransformation.setRotation(axisStruct, angle); + BRepBuilderAPI_Transform bt = new BRepBuilderAPI_Transform(aShape, theTransformation, true); + TopoDS_Shape shape = bt.shape(); + bt.delete(); + theTransformation.delete(); + return shape; + } + + public static TopoDS_Shape makeRevolution(TopoDS_Shape topoDS_Shape, double[] axisStruct, double param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makePrism(TopoDS_Shape topoDS_Shape, double[] pointStruct, double[] pointStruct2) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makePlane(double[] pointStruct, double[] dirStruct, double param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makePlacedBox(double param, double param1, double param2, double param3, double param4, + double param5) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makePipe(TopoDS_Shape topoDS_Shape, TopoDS_Shape topoDS_Shape1) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makePanel(TopoDS_Shape topoDS_Shape, short param, double param2) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeMultiTranslation2D(TopoDS_Shape topoDS_Shape, double[] dirStruct, double param, + short param3, double[] dirStruct4, double param5, short param6) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeMultiTranslation1D(TopoDS_Shape topoDS_Shape, double[] dirStruct, double param, short param3) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeMultiRotation2D(TopoDS_Shape topoDS_Shape, double[] dirStruct, double[] pointStruct, + double param, short param4, double param5, short param6) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeMultiRotation1D(TopoDS_Shape topoDS_Shape, double[] dirStruct, double[] pointStruct, + short param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeMirrorByPlane(TopoDS_Shape topoDS_Shape, TopoDS_Shape topoDS_Shape1) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeLine(double[] pointStruct, double[] dirStruct) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeFilling(TopoDS_Shape topoDS_Shape, short param, short param2, double param3, double param4, + short param5) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeFillet(TopoDS_Shape topoDS_Shape, double param, short param2, TopoDS_Shape[] topoDS_Shape3) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeFace(TopoDS_Shape topoDS_Shape, boolean param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeEdge(double[] pointStruct, double[] pointStruct1) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeCylinder(double[] pointStruct, double[] dirStruct, double radius, double height) { + double[] axe = new double[6]; + System.arraycopy(pointStruct, 0, axe, 0, 3); + System.arraycopy(dirStruct, 0, axe, 3, 3); + org.jcae.opencascade.jni.TopoDS_Shape tds = new org.jcae.opencascade.jni.BRepPrimAPI_MakeCylinder(axe, radius, + height, 2 * Math.PI).shape(); + return tds; + } + + public static TopoDS_Shape makeCopy(TopoDS_Shape topoDS_Shape) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeCone(double[] pointStruct, double[] dirStruct, double radius1, double radius2, double height) { + double[] axe = new double[6]; + System.arraycopy(pointStruct, 0, axe, 0, 3); + System.arraycopy(dirStruct, 0, axe, 3, 3); + org.jcae.opencascade.jni.TopoDS_Shape tds = new org.jcae.opencascade.jni.BRepPrimAPI_MakeCone(axe, radius1, + radius2, height, 2 * Math.PI).shape(); + return tds; + } + + public static TopoDS_Shape makeCompound(TopoDS_Shape[] shapes) { + BRep_Builder builder = new BRep_Builder(); + org.jcae.opencascade.jni.TopoDS_Compound comp = new org.jcae.opencascade.jni.TopoDS_Compound(); + builder.makeCompound(comp); + for (int i = 0; i < shapes.length; i++) { + + builder.add(comp, shapes[i]); + } + builder.delete(); + return comp; + } + + public static TopoDS_Shape makeCircle(double[] pointStruct, double[] dirStruct, double param) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeChamfer(TopoDS_Shape topoDS_Shape, double param, double param2, short param3, + TopoDS_Shape[] topoDS_Shape4) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeCDG(TopoDS_Shape topoDS_Shape) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeBox(double x1, double y1, double z1, double x2, double y2, double z2) { + double[] p1 = new double[] { x1, y1, z1 }; + double[] p2 = new double[] { x2, y2, z2 }; + org.jcae.opencascade.jni.TopoDS_Shape tds = new org.jcae.opencascade.jni.BRepPrimAPI_MakeBox(p1, p2).shape(); + return tds; + } + + public static TopoDS_Shape makeCut(TopoDS_Shape shape1, TopoDS_Shape shape2) { + + org.jcae.opencascade.jni.TopoDS_Shape s = new org.jcae.opencascade.jni.BRepAlgoAPI_Cut(shape1, shape2).shape(); + return s; + } + + public static TopoDS_Shape makeCommon(TopoDS_Shape shape1, TopoDS_Shape shape2) { + + org.jcae.opencascade.jni.TopoDS_Shape s = new org.jcae.opencascade.jni.BRepAlgoAPI_Common(shape1, shape2).shape(); + return s; + } + + public static TopoDS_Shape makeFuse(TopoDS_Shape shape1, TopoDS_Shape shape2) { + + org.jcae.opencascade.jni.TopoDS_Shape s = new org.jcae.opencascade.jni.BRepAlgoAPI_Fuse(shape1, shape2).shape(); + return s; + } + + public static TopoDS_Shape makeArc(double[] pointStruct, double[] pointStruct1, double[] pointStruct2) { + throw new UnsupportedOperationException(); + } + + public static TopoDS_Shape makeWedge(double[] pointStruct, double[] dirStruct,double dx, double dy, double dz, double xmin, double zmin, double xmax, double zmax) { + double[] axe = new double[6]; + System.arraycopy(pointStruct, 0, axe, 0, 3); + System.arraycopy(dirStruct, 0, axe, 3, 3); + org.jcae.opencascade.jni.TopoDS_Shape s = new org.jcae.opencascade.jni.BRepPrimAPI_MakeWedge(axe, dx, dy, dz, xmin, zmin, xmax, zmax).shape(); + return s; + } + + + + public static void exportBREP(TopoDS_Shape shape, String filename) { + org.jcae.opencascade.jni.BRepTools.write(shape, filename); + } + + public static void exportIGES(TopoDS_Shape shape, String filename) { + throw new UnsupportedOperationException(); + +// IGESControl_Writer writer=new IGESControl_Writer(); +// writer.addShape(shape); writer.write(filename,false); + + } + + + + + +}