Hide menu
modeling/brep/brep.java

Refer to the B-Rep Geometry Creation Example.

edgeutil.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
import cadex.*;
public class edgeutil {
private static ModelData_Axis2Placement a2Axis = new ModelData_Axis2Placement();
static ModelData_Edge MakeEdgeFromLine() {
ModelData_Line aCurve = new ModelData_Line(new ModelData_Point(0., 0., 0.), ModelData_Direction.XDir());
return new ModelData_Edge(aCurve, -2., 2.);
}
static ModelData_Edge MakeEdgeFromCircle() {
ModelData_Circle aCurve = new ModelData_Circle(a2Axis, 5.);
return new ModelData_Edge(aCurve, 0., Math.PI);
}
static ModelData_Edge MakeEdgeFromEllipse() {
ModelData_Ellipse aCurve = new ModelData_Ellipse(a2Axis, 7., 3.);
return new ModelData_Edge(aCurve, 0., Math.PI);
}
static ModelData_Edge MakeEdgeFromParabola() {
ModelData_Parabola aCurve = new ModelData_Parabola(a2Axis, 5.);
return new ModelData_Edge(aCurve, -2., 2.);
}
static ModelData_Edge MakeEdgeFromHyperbola() {
ModelData_Hyperbola aCurve = new ModelData_Hyperbola(a2Axis, 7., 3.);
return new ModelData_Edge(aCurve, -2., 2.);
}
static ModelData_Edge MakeEdgeFromOffSetCurve() {
ModelData_Circle aBasisCurve = new ModelData_Circle(a2Axis, 5.);
ModelData_OffsetCurve aCurve = new ModelData_OffsetCurve(aBasisCurve, 10., ModelData_Direction.ZDir());
return new ModelData_Edge(aCurve, 0., Math.PI);
}
static ModelData_Edge MakeEdgeFromBezier() {
ModelData_Point[] aPoles = {
new ModelData_Point(-2., 1., 0.),
new ModelData_Point(-1., -1., 0.),
new ModelData_Point(0., 1., 0.),
new ModelData_Point(1., -1., 0.)
};
ModelData_BezierCurve aCurve = new ModelData_BezierCurve(aPoles);
return new ModelData_Edge(aCurve);
}
static ModelData_Edge MakeEdgeFromBSpline() {
ModelData_Point[] aPoles = {
new ModelData_Point(1., 1., 0.),
new ModelData_Point(2., 3., 0.),
new ModelData_Point(3., 2., 0.),
new ModelData_Point(4., 3., 0.),
new ModelData_Point(5., 1., 0.)
};
double[] aKnots = {0., 0.25, 0.75, 1.};
int[] aMultiplicities = {3, 1, 1, 3};
int aDegree = 2;
ModelData_BSplineCurve aCurve = new ModelData_BSplineCurve(aPoles, aKnots, aMultiplicities, aDegree);
return new ModelData_Edge(aCurve);
}
}

faceutil.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
import cadex.*;
public class faceutil {
private static ModelData_Axis3Placement a3Axis = new ModelData_Axis3Placement();
static ModelData_Face MakePlanarFace() {
ModelData_Plane aSurface = new ModelData_Plane(a3Axis);
return new ModelData_Face(aSurface, -2., 2., -2., 2.);
}
static ModelData_Face MakeSphericalFace() {
ModelData_SphericalSurface aSurface = new ModelData_SphericalSurface(a3Axis, 10.);
return new ModelData_Face(aSurface, 0., Math.PI / 2, 0., Math.PI / 2);
}
static ModelData_Face MakeCylindricalFace() {
ModelData_CylindricalSurface aSurface = new ModelData_CylindricalSurface(a3Axis, 5.);
return new ModelData_Face(aSurface, 0., Math.PI, -2., 2.);
}
static ModelData_Face MakeConicalFace() {
ModelData_ConicalSurface aSurface = new ModelData_ConicalSurface(a3Axis, 1., 7.);
return new ModelData_Face(aSurface, 0., Math.PI, -2., 2.);
}
static ModelData_Face MakeToroidalFace() {
ModelData_ToroidalSurface aSurface = new ModelData_ToroidalSurface(a3Axis, 7., 3.);
return new ModelData_Face(aSurface, 0., Math.PI, 0., Math.PI);
}
static ModelData_Face MakeFaceFromSurfaceOfLinearExtrusion() {
ModelData_Point[] aPoles = {
new ModelData_Point(-2., 1., 0.),
new ModelData_Point(-1., -1., 0.),
new ModelData_Point(0., 1., 0.),
new ModelData_Point(1., -1., 0.),
new ModelData_Point(2., 1., 0.)
};
ModelData_BezierCurve aBasisCurve = new ModelData_BezierCurve(aPoles);
ModelData_SurfaceOfLinearExtrusion aSurface = new ModelData_SurfaceOfLinearExtrusion(aBasisCurve, ModelData_Direction.ZDir());
return new ModelData_Face(aSurface, 0.1, 0.9, -10., 10.);
}
static ModelData_Face MakeFaceFromSurfaceOfRevolution() {
ModelData_Point[] aPoles = {
new ModelData_Point(-2., 1., 0.),
new ModelData_Point(-1., 3., 0.),
new ModelData_Point(0., 2., 0.),
new ModelData_Point(1., 1., 0.),
new ModelData_Point(2., 2., 0.)
};
ModelData_BezierCurve aBasisCurve = new ModelData_BezierCurve(aPoles);
ModelData_SurfaceOfRevolution aSurface =
new ModelData_SurfaceOfRevolution(aBasisCurve, new ModelData_Point(0., 0., 0.), ModelData_Direction.XDir());
return new ModelData_Face(aSurface, 0., Math.PI * 3 / 4, 0.1, 0.9);
}
static ModelData_Face MakeFaceFromOffsetSurface() {
ModelData_Point[] aPoles = {
new ModelData_Point(0., 0., 1.),
new ModelData_Point(0., 2., 1.),
new ModelData_Point(2., 0., 1.),
new ModelData_Point(2., 2., -1.)
};
ModelData_BezierSurface aBasisSurface = new ModelData_BezierSurface(aPoles, 2, 2);
ModelData_OffsetSurface aSurface = new ModelData_OffsetSurface(aBasisSurface, 10.);
return new ModelData_Face(aSurface, 0.1, 0.9, 0.1, 0.9);
}
static ModelData_Face MakeFaceFromBezier() {
ModelData_Point[] aPoles = {
new ModelData_Point(0., 0., 1.),
new ModelData_Point(0., 2., 1.),
new ModelData_Point(2., 0., 1.),
new ModelData_Point(2., 2., -1.)
};
ModelData_BezierSurface aSurface = new ModelData_BezierSurface(aPoles, 2, 2);
return new ModelData_Face(aSurface, 0.25, 0.75, 0.25, 0.75);
}
static ModelData_Face MakeFaceFromBSpline() {
ModelData_Point[] aPoles = {
new ModelData_Point(0., 0., 1.),
new ModelData_Point(0., 2., 3.),
new ModelData_Point(0., 6., 2.),
new ModelData_Point(0., 8., 3.),
new ModelData_Point(0., 10., 1.),
new ModelData_Point(2., 0., 2.),
new ModelData_Point(2., 2., 2.),
new ModelData_Point(2., 6., 2.),
new ModelData_Point(2., 8., 2.),
new ModelData_Point(2., 10., 2.),
new ModelData_Point(4., 0., 3.),
new ModelData_Point(4., 2., 1.),
new ModelData_Point(4., 6., 2.),
new ModelData_Point(4., 8., 1.),
new ModelData_Point(4., 10., 3.),
new ModelData_Point(6., 0., 2.),
new ModelData_Point(6., 2., 2.),
new ModelData_Point(6., 6., 2.),
new ModelData_Point(6., 8., 2.),
new ModelData_Point(6., 10., 2.),
new ModelData_Point(10., 0., 3.),
new ModelData_Point(10., 2., 1.),
new ModelData_Point(10., 6., 2.),
new ModelData_Point(10., 8., 1.),
new ModelData_Point(10., 10., 3.),
};
int aUPoles = 5, aVPoles = 5;
double[] aUKnots = {0., 0.25, 0.75, 1.}, aVKnots = {0., 0.25, 0.75, 1.};
int[] aUMultiplicities = {3, 1, 1, 3}, aVMultiplicities = {3, 1, 1, 3};
int aUDegree = 2;
int aVDegree = 2;
ModelData_BSplineSurface aSurface =
new ModelData_BSplineSurface(
aPoles, aUPoles, aVPoles, aUKnots, aVKnots, aUMultiplicities, aVMultiplicities, aUDegree, aVDegree);
return new ModelData_Face(aSurface, 0.25, 0.75, 0.25, 0.75);
}
static ModelData_Face MakeFaceWithInnerWire() {
ModelData_Axis2Placement anAxis2 = new ModelData_Axis2Placement();
ModelData_Circle anInnerCircle = new ModelData_Circle(anAxis2, 10.);
ModelData_Circle anOuterCircle = new ModelData_Circle(anAxis2, 20.);
ModelData_Edge anOuterEdge = new ModelData_Edge(anOuterCircle);
ModelData_Edge anInnerEdge = new ModelData_Edge(anInnerCircle);
ModelData_Wire anOuterWire = new ModelData_Wire(anOuterEdge);
ModelData_Wire anInnerWire = new ModelData_Wire(ModelData_Edge.Cast(anInnerEdge.Reversed()));
ModelData_Axis3Placement anAxis3 = new ModelData_Axis3Placement(anAxis2);
ModelData_Plane aPlane = new ModelData_Plane(anAxis3);
ModelData_Face aFace = new ModelData_Face(aPlane);
aFace.Append(anOuterWire);
aFace.Append(anInnerWire);
return aFace;
}
}

bodyutil.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
import cadex.*;
public class bodyutil {
public static ModelData_Body MakeSolidBody() {
ModelData_Solid aSolid = ModelAlgo_TopoPrimitives.CreateBox(new ModelData_Point(-3., -3., -4.), new ModelData_Point(3., 3., -2.));
ModelData_Body aBody = ModelData_Body.Create(aSolid);
return aBody;
}
public static ModelData_Body MakeSheetBody() {
ModelData_Plane aPlane = new ModelData_Plane(new ModelData_Point(0., 0., 0.), ModelData_Direction.ZDir());
ModelData_Face aFace1 = new ModelData_Face(aPlane, -4., 0., -4., 0.);
ModelData_Face aFace2 = new ModelData_Face(aPlane, 0., 4., 0., 4.);
ModelData_Shell aShell = new ModelData_Shell(aFace1);
aShell.Append(aFace2);
ModelData_Body aBody = ModelData_Body.Create(aShell);
return aBody;
}
public static ModelData_Body MakeWireframeBody() {
ModelData_Axis2Placement anAxis = new ModelData_Axis2Placement();
ModelData_Circle aCircle = new ModelData_Circle(anAxis, 5.);
ModelData_Edge anEdge1 = new ModelData_Edge(aCircle, 1., 3.);
ModelData_Edge anEdge2 = new ModelData_Edge(aCircle, 3., 6.);
ModelData_Wire aWire = new ModelData_Wire(anEdge1);
aWire.Append(anEdge2);
ModelData_Body aBody = ModelData_Body.Create(aWire);
return aBody;
}
public static ModelData_Body MakeAcornBody() {
ModelData_Vertex aVertex = new ModelData_Vertex(new ModelData_Point(0., 0., 0.));
ModelData_Body aBody = ModelData_Body.Create(aVertex);
return aBody;
}
}

brep.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
import cadex.*;
public class brep {
static {
try {
System.loadLibrary("CadExCore");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) {
String aKey = LicenseKey.Value();
// Activate the license (aKey must be defined in LicenseKey.java)
if (!LicenseManager.Activate(aKey)) {
System.out.println("Failed to activate CAD Exchanger license.");
System.exit(1);
}
ModelData_Edge aLine = edgeutil.MakeEdgeFromLine();
SaveModel(aLine, "LineEdge");
ModelData_Edge aCircle = edgeutil.MakeEdgeFromCircle();
SaveModel(aCircle, "CircleEdge");
ModelData_Edge anEllipse = edgeutil.MakeEdgeFromEllipse();
SaveModel(anEllipse, "EllipseEdge");
ModelData_Edge aParabola = edgeutil.MakeEdgeFromParabola();
SaveModel(aParabola, "ParabolaEdge");
ModelData_Edge aHyperbola = edgeutil.MakeEdgeFromHyperbola();
SaveModel(aHyperbola, "HyperbolaEdge");
ModelData_Edge anEdgeFromOffsetCurve = edgeutil.MakeEdgeFromOffSetCurve();
SaveModel(anEdgeFromOffsetCurve, "OffsetEdge");
ModelData_Edge aBezierEdge = edgeutil.MakeEdgeFromBezier();
SaveModel(aBezierEdge, "BezierEdge");
ModelData_Edge aBSplineEdge = edgeutil.MakeEdgeFromBSpline();
SaveModel(aBSplineEdge, "BSplineEdge");
ModelData_Face aPlane = faceutil.MakePlanarFace();
SaveModel(aPlane, "PlaneFace");
ModelData_Face aSphere = faceutil.MakeSphericalFace();
SaveModel(aSphere, "SphereFace");
ModelData_Face aCylinder = faceutil.MakeCylindricalFace();
SaveModel(aCylinder, "CylinderFace");
ModelData_Face aCone = faceutil.MakeConicalFace();
SaveModel(aCone, "ConeFace");
ModelData_Face aTorus = faceutil.MakeToroidalFace();
SaveModel(aTorus, "TorusFace");
ModelData_Face aFaceFromLESurface = faceutil.MakeFaceFromSurfaceOfLinearExtrusion();
SaveModel(aFaceFromLESurface, "LEFace");
ModelData_Face aFaceFromRevSurface = faceutil.MakeFaceFromSurfaceOfRevolution();
SaveModel(aFaceFromRevSurface, "RevFace");
ModelData_Face aFaceFromOffsetSurface = faceutil.MakeFaceFromOffsetSurface();
SaveModel(aFaceFromOffsetSurface, "OffsetFace");
ModelData_Face aBezierFace = faceutil.MakeFaceFromBezier();
SaveModel(aBezierFace, "BezierFace");
ModelData_Face aBSplineFace = faceutil.MakeFaceFromBSpline();
SaveModel(aBSplineFace, "BSplineFace");
ModelData_Face aFace = faceutil.MakeFaceWithInnerWire();
SaveModel(aFace, "InnerWireFace");
ModelData_Body aSolid = bodyutil.MakeSolidBody();
SaveModel(aSolid, "SolidBody");
ModelData_Body aSheet = bodyutil.MakeSheetBody();
SaveModel(aSheet, "SheetBody");
ModelData_Body aWireframe = bodyutil.MakeWireframeBody();
SaveModel(aWireframe, "WireframeBody");
ModelData_Body anAcorn = bodyutil.MakeAcornBody();
SaveModel(anAcorn, "AcornBody");
}
static boolean SaveModel(ModelData_Shape theShape, String theName) {
ModelData_Model aModel = new ModelData_Model();
ModelData_Part aPart = new ModelData_Part(new ModelData_BRepRepresentation(theShape), new Base_UTF16String(theName));
aModel.AddRoot(aPart);
Base_UTF16String aPath = new Base_UTF16String(theName + ".xml");
return new ModelData_ModelWriter().Write (aModel, aPath);
}
}
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22