Search in sources :

Example 1 with IfcPolyline

use of org.bimserver.models.ifc2x3tc1.IfcPolyline in project BIMserver by opensourceBIM.

the class IfcTools2D method curveToPath.

private static Path2D.Float curveToPath(double[] matrix, IfcCurve outerCurve, double multiplierMillimeters) {
    Path2D.Float path2d = new Path2D.Float();
    if (outerCurve instanceof IfcPolyline) {
        IfcPolyline ifcPolyline = (IfcPolyline) outerCurve;
        IfcCartesianPoint first = ifcPolyline.getPoints().get(0);
        double[] res = new double[4];
        Matrix.multiplyMV(res, 0, matrix, 0, new double[] { first.getCoordinates().get(0), first.getCoordinates().get(1), 0, 1 }, 0);
        path2d.moveTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
        for (IfcCartesianPoint cartesianPoint : ifcPolyline.getPoints()) {
            EList<Double> coords = cartesianPoint.getCoordinates();
            Matrix.multiplyMV(res, 0, matrix, 0, new double[] { coords.get(0), coords.get(1), 0, 1 }, 0);
            path2d.lineTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
        }
        path2d.closePath();
        return path2d;
    }
    return null;
}
Also used : Path2D(java.awt.geom.Path2D) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcPolyline(org.bimserver.models.ifc2x3tc1.IfcPolyline)

Example 2 with IfcPolyline

use of org.bimserver.models.ifc2x3tc1.IfcPolyline in project BIMserver by opensourceBIM.

the class IfcTools2D method getArea.

private Area getArea(double multiplierMillimeters, double[] productMatrix, IfcRepresentationItem ifcRepresentationItem) {
    if (ifcRepresentationItem instanceof IfcExtrudedAreaSolid) {
        IfcExtrudedAreaSolid ifcExtrudedAreaSolid = (IfcExtrudedAreaSolid) ifcRepresentationItem;
        IfcAxis2Placement3D position = ifcExtrudedAreaSolid.getPosition();
        // 1 0 0 0 <- 3de argument
        // 0 1 0 0 <- cross product van 2 en 3 (levert ortogonale vector op)
        // 0 0 1 0 <- 2st argument
        // 5 0 0 1 <- 1st argument
        double[] matrix = placement3DToMatrix(position);
        if (productMatrix != null) {
            double[] rhs = matrix;
            matrix = Matrix.identity();
            Matrix.multiplyMM(matrix, 0, productMatrix, 0, rhs, 0);
        }
        IfcDirection extrudedDirection = ifcExtrudedAreaSolid.getExtrudedDirection();
        // TODO do something with this
        IfcProfileDef ifcProfileDef = ifcExtrudedAreaSolid.getSweptArea();
        if (ifcProfileDef instanceof IfcArbitraryProfileDefWithVoids) {
            IfcArbitraryProfileDefWithVoids ifcArbitraryProfileDefWithVoids = (IfcArbitraryProfileDefWithVoids) ifcProfileDef;
            IfcCurve outerCurve = ifcArbitraryProfileDefWithVoids.getOuterCurve();
            Path2D outerPath = null;
            if (outerCurve instanceof IfcPolyline) {
                outerPath = curveToPath(matrix, outerCurve, multiplierMillimeters);
            } else {
                storeUnimplemented(outerCurve);
            }
            if (outerPath != null) {
                Area area = new Area(outerPath);
                for (IfcCurve innerCurve : ifcArbitraryProfileDefWithVoids.getInnerCurves()) {
                    Path2D.Float innerPath = curveToPath(matrix, innerCurve, multiplierMillimeters);
                    if (innerPath != null) {
                        area.subtract(new Area(innerPath));
                    }
                }
                return area;
            }
        } else if (ifcProfileDef instanceof IfcArbitraryClosedProfileDef) {
            IfcArbitraryClosedProfileDef ifcArbitraryClosedProfileDef = (IfcArbitraryClosedProfileDef) ifcProfileDef;
            Path2D.Float path2d = new Path2D.Float();
            IfcCurve outerCurve = ifcArbitraryClosedProfileDef.getOuterCurve();
            boolean first = true;
            if (outerCurve instanceof IfcPolyline) {
                IfcPolyline ifcPolyline = (IfcPolyline) outerCurve;
                double[] res = new double[4];
                int i = 0;
                for (IfcCartesianPoint cartesianPoint : ifcPolyline.getPoints()) {
                    EList<Double> coords = cartesianPoint.getCoordinates();
                    Matrix.multiplyMV(res, 0, matrix, 0, new double[] { coords.get(0), coords.get(1), 0, 1 }, 0);
                    if (first) {
                        path2d.moveTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
                        first = false;
                    } else {
                        if (i > 1) {
                        }
                        path2d.lineTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
                    }
                    i++;
                }
                path2d.closePath();
                return new Area(path2d);
            } else if (outerCurve instanceof IfcCompositeCurve) {
                IfcCompositeCurve ifcCompositeCurve = (IfcCompositeCurve) outerCurve;
                for (IfcCompositeCurveSegment ifcCompositeCurveSegment : ifcCompositeCurve.getSegments()) {
                    IfcCurve curve = ifcCompositeCurveSegment.getParentCurve();
                    if (curve instanceof IfcPolyline) {
                        IfcPolyline ifcPolyline = (IfcPolyline) curve;
                        double[] res = new double[4];
                        for (IfcCartesianPoint cartesianPoint : ifcPolyline.getPoints()) {
                            EList<Double> coords = cartesianPoint.getCoordinates();
                            Matrix.multiplyMV(res, 0, matrix, 0, new double[] { coords.get(0), coords.get(1), 0, 1 }, 0);
                            if (first) {
                                path2d.moveTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
                                first = false;
                            } else {
                                path2d.lineTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
                            }
                        }
                    } else if (curve instanceof IfcTrimmedCurve) {
                        storeUnimplemented(curve);
                    } else {
                        storeUnimplemented(curve);
                    }
                }
                try {
                    path2d.closePath();
                    return new Area(path2d);
                } catch (Exception e) {
                // 
                }
            }
        } else if (ifcProfileDef instanceof IfcRectangleProfileDef) {
            IfcRectangleProfileDef ifcRectangleProfileDef = (IfcRectangleProfileDef) ifcProfileDef;
            double[] min = new double[] { ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(0) - ifcRectangleProfileDef.getXDim() / 2, ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(1) - ifcRectangleProfileDef.getYDim() / 2, 0, 1 };
            double[] max = new double[] { ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(0) + ifcRectangleProfileDef.getXDim() / 2, ifcRectangleProfileDef.getPosition().getLocation().getCoordinates().get(1) + ifcRectangleProfileDef.getYDim() / 2, 0, 1 };
            Cube cube = new Cube(min, max);
            cube.transform(matrix);
            double[] transformedMin = cube.getMin();
            double[] transformedMax = cube.getMax();
            Path2D.Float path2d = new Path2D.Float();
            path2d.moveTo(transformedMin[0] * multiplierMillimeters, transformedMin[1] * multiplierMillimeters);
            path2d.lineTo(transformedMax[0] * multiplierMillimeters, transformedMin[1] * multiplierMillimeters);
            path2d.lineTo(transformedMax[0] * multiplierMillimeters, transformedMax[1] * multiplierMillimeters);
            path2d.lineTo(transformedMin[0] * multiplierMillimeters, transformedMax[1] * multiplierMillimeters);
            path2d.lineTo(transformedMin[0] * multiplierMillimeters, transformedMin[1] * multiplierMillimeters);
            path2d.closePath();
            return new Area(path2d);
        } else {
            storeUnimplemented(ifcProfileDef);
        }
    } else if (ifcRepresentationItem instanceof IfcPolyline) {
        IfcPolyline ifcPolyline = (IfcPolyline) ifcRepresentationItem;
        double[] res = new double[4];
        Path2D.Float path2d = new Path2D.Float();
        boolean first = true;
        for (IfcCartesianPoint cartesianPoint : ifcPolyline.getPoints()) {
            EList<Double> coords = cartesianPoint.getCoordinates();
            Matrix.multiplyMV(res, 0, productMatrix, 0, new double[] { coords.get(0), coords.get(1), 0, 1 }, 0);
            if (first) {
                path2d.moveTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
                first = false;
            } else {
                path2d.lineTo(res[0] * multiplierMillimeters, res[1] * multiplierMillimeters);
            }
        }
        path2d.closePath();
        return new Area(path2d);
    } else {
        storeUnimplemented(ifcRepresentationItem);
    }
    return null;
}
Also used : IfcCurve(org.bimserver.models.ifc2x3tc1.IfcCurve) IfcArbitraryClosedProfileDef(org.bimserver.models.ifc2x3tc1.IfcArbitraryClosedProfileDef) IfcRectangleProfileDef(org.bimserver.models.ifc2x3tc1.IfcRectangleProfileDef) IfcArbitraryProfileDefWithVoids(org.bimserver.models.ifc2x3tc1.IfcArbitraryProfileDefWithVoids) Path2D(java.awt.geom.Path2D) IfcTrimmedCurve(org.bimserver.models.ifc2x3tc1.IfcTrimmedCurve) IfcProfileDef(org.bimserver.models.ifc2x3tc1.IfcProfileDef) IfcPolyline(org.bimserver.models.ifc2x3tc1.IfcPolyline) Area(java.awt.geom.Area) EList(org.eclipse.emf.common.util.EList) IfcCompositeCurve(org.bimserver.models.ifc2x3tc1.IfcCompositeCurve) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcCompositeCurveSegment(org.bimserver.models.ifc2x3tc1.IfcCompositeCurveSegment) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcDirection(org.bimserver.models.ifc2x3tc1.IfcDirection) IfcExtrudedAreaSolid(org.bimserver.models.ifc2x3tc1.IfcExtrudedAreaSolid)

Example 3 with IfcPolyline

use of org.bimserver.models.ifc2x3tc1.IfcPolyline in project BIMserver by opensourceBIM.

the class RichIfcModel method createRectangularExtrusionProductRepresentation.

public IfcProductRepresentation createRectangularExtrusionProductRepresentation(double width, double depth, double height) throws IfcModelInterfaceException {
    IfcPolyline ifcPolyline = create(IfcPolyline.class);
    EList<IfcCartesianPoint> points = ifcPolyline.getPoints();
    points.add(createIfcCartesianPoint(0, 0, 0));
    points.add(createIfcCartesianPoint(width, 0, 0));
    points.add(createIfcCartesianPoint(width, depth, 0));
    points.add(createIfcCartesianPoint(0, depth, 0));
    points.add(createIfcCartesianPoint(0, 0, 0));
    IfcArbitraryClosedProfileDef def = create(IfcArbitraryClosedProfileDef.class);
    def.setProfileType(IfcProfileTypeEnum.AREA);
    def.setOuterCurve(ifcPolyline);
    IfcExtrudedAreaSolid extrudedAreaSolid = create(IfcExtrudedAreaSolid.class);
    extrudedAreaSolid.setDepth(height);
    extrudedAreaSolid.setSweptArea(def);
    extrudedAreaSolid.setPosition(createBasicPosition(0, 0, 0));
    extrudedAreaSolid.setExtrudedDirection(createDirection(0, 0, 1));
    IfcProductRepresentation productRepresentation = create(IfcProductRepresentation.class);
    IfcShapeRepresentation shapeRepresentation = create(IfcShapeRepresentation.class);
    if (defaultRepresentationContext != null) {
        shapeRepresentation.setContextOfItems(defaultRepresentationContext);
    }
    shapeRepresentation.setRepresentationType("SweptSolid");
    shapeRepresentation.setRepresentationIdentifier("Body");
    shapeRepresentation.getItems().add(extrudedAreaSolid);
    productRepresentation.getRepresentations().add(shapeRepresentation);
    return productRepresentation;
}
Also used : IfcArbitraryClosedProfileDef(org.bimserver.models.ifc2x3tc1.IfcArbitraryClosedProfileDef) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcShapeRepresentation(org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation) IfcExtrudedAreaSolid(org.bimserver.models.ifc2x3tc1.IfcExtrudedAreaSolid) IfcPolyline(org.bimserver.models.ifc2x3tc1.IfcPolyline)

Aggregations

IfcCartesianPoint (org.bimserver.models.ifc2x3tc1.IfcCartesianPoint)3 IfcPolyline (org.bimserver.models.ifc2x3tc1.IfcPolyline)3 Path2D (java.awt.geom.Path2D)2 IfcArbitraryClosedProfileDef (org.bimserver.models.ifc2x3tc1.IfcArbitraryClosedProfileDef)2 IfcExtrudedAreaSolid (org.bimserver.models.ifc2x3tc1.IfcExtrudedAreaSolid)2 Area (java.awt.geom.Area)1 IfcArbitraryProfileDefWithVoids (org.bimserver.models.ifc2x3tc1.IfcArbitraryProfileDefWithVoids)1 IfcAxis2Placement3D (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D)1 IfcCompositeCurve (org.bimserver.models.ifc2x3tc1.IfcCompositeCurve)1 IfcCompositeCurveSegment (org.bimserver.models.ifc2x3tc1.IfcCompositeCurveSegment)1 IfcCurve (org.bimserver.models.ifc2x3tc1.IfcCurve)1 IfcDirection (org.bimserver.models.ifc2x3tc1.IfcDirection)1 IfcProductRepresentation (org.bimserver.models.ifc2x3tc1.IfcProductRepresentation)1 IfcProfileDef (org.bimserver.models.ifc2x3tc1.IfcProfileDef)1 IfcRectangleProfileDef (org.bimserver.models.ifc2x3tc1.IfcRectangleProfileDef)1 IfcShapeRepresentation (org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation)1 IfcTrimmedCurve (org.bimserver.models.ifc2x3tc1.IfcTrimmedCurve)1 EList (org.eclipse.emf.common.util.EList)1