Search in sources :

Example 1 with IfcObjectPlacement

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

the class IfcTools2D method placementToMatrix.

public static double[] placementToMatrix(IfcObjectPlacement objectPlacement) {
    double[] matrix = Matrix.identity();
    if (objectPlacement instanceof IfcLocalPlacement) {
        IfcLocalPlacement ifcLocalPlacement = (IfcLocalPlacement) objectPlacement;
        IfcAxis2Placement relativePlacement = ifcLocalPlacement.getRelativePlacement();
        if (relativePlacement instanceof IfcAxis2Placement3D) {
            IfcAxis2Placement3D ifcAxis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
            matrix = placement3DToMatrix(ifcAxis2Placement3D);
        }
        IfcObjectPlacement relativeTo = ifcLocalPlacement.getPlacementRelTo();
        if (relativeTo != null) {
            double[] baseMatrix = placementToMatrix(relativeTo);
            double[] rhs = matrix;
            matrix = Matrix.identity();
            Matrix.multiplyMM(matrix, 0, baseMatrix, 0, rhs, 0);
        }
    }
    return matrix;
}
Also used : IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) IfcAxis2Placement(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement)

Example 2 with IfcObjectPlacement

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

the class IfcTools2D method get2D.

public Area get2D(IfcProduct ifcProduct, double multiplierMillimeters) {
    IfcObjectPlacement objectPlacement = ifcProduct.getObjectPlacement();
    double[] productMatrix = placementToMatrix(objectPlacement);
    // Matrix.dump(productMatrix);
    IfcProductRepresentation representation = ifcProduct.getRepresentation();
    if (representation == null) {
        return null;
    }
    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
        if ("Curve2D".equals(ifcRepresentation.getRepresentationType())) {
        // Skip
        } else {
            if (ifcRepresentation instanceof IfcShapeRepresentation) {
                IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation;
                for (IfcRepresentationItem ifcRepresentationItem : ifcShapeRepresentation.getItems()) {
                    Area area = getArea(multiplierMillimeters, productMatrix, ifcRepresentationItem);
                    if (area != null && area.getPathIterator(null).isDone()) {
                        return area;
                    }
                }
            }
        }
    }
    // Fall back to 3D geometry projected from the top
    GeometryInfo geometry = ifcProduct.getGeometry();
    if (geometry != null) {
        GeometryData geometryData = geometry.getData();
        if (geometryData != null) {
            int[] indices = GeometryUtils.toIntegerArray(geometryData.getIndices());
            float[] vertices = GeometryUtils.toFloatArray(geometryData.getVertices());
            float[] matrix = GeometryUtils.toFloatArray(GeometryUtils.toDoubleArray(geometry.getTransformation()));
            Area area = new Area();
            for (int i = 0; i < indices.length; i += 3) {
                int index1 = indices[i + 0];
                int index2 = indices[i + 1];
                int index3 = indices[i + 2];
                float[] a = new float[] { vertices[index1 * 3], vertices[index1 * 3 + 1], vertices[index1 * 3 + 2] };
                float[] b = new float[] { vertices[index2 * 3], vertices[index2 * 3 + 1], vertices[index2 * 3 + 2] };
                float[] c = new float[] { vertices[index3 * 3], vertices[index3 * 3 + 1], vertices[index3 * 3 + 2] };
                float[][] points = new float[][] { a, b, c };
                // if (similar(a[2], b[2], c[2])) {
                boolean first = true;
                Path2D.Float path = new Path2D.Float();
                for (int j = 0; j < 3; j++) {
                    float[] point = points[j];
                    float[] res = new float[4];
                    Matrix.multiplyMV(res, 0, matrix, 0, new float[] { point[0], point[1], point[2], 1 }, 0);
                    // * multiplierMillimeters
                    float x = (float) (res[0]);
                    // * multiplierMillimeters
                    float y = (float) (res[1]);
                    if (first) {
                        path.moveTo(x, y);
                        first = false;
                    } else {
                        path.lineTo(x, y);
                    }
                }
                path.closePath();
                area.add(new Area(path));
            // }
            }
            return area;
        }
    } else {
        LOGGER.info("No geometry generated for " + ifcProduct);
    }
    return null;
}
Also used : IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) Path2D(java.awt.geom.Path2D) GeometryData(org.bimserver.models.geometry.GeometryData) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) Area(java.awt.geom.Area) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) IfcShapeRepresentation(org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation)

Example 3 with IfcObjectPlacement

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

the class IfcUtils method getAbsolutePosition.

/**
 * Not finished, does not take into account the directions
 *
 * @param ifcObjectPlacement
 * @return
 * @throws PlacementNotImplementedException
 */
public static double[] getAbsolutePosition(IfcObjectPlacement ifcObjectPlacement) throws PlacementNotImplementedException {
    if (ifcObjectPlacement instanceof IfcGridPlacement) {
        throw new PlacementNotImplementedException("IfcGridPlacement has not been implemented");
    } else if (ifcObjectPlacement instanceof IfcLocalPlacement) {
        IfcLocalPlacement ifcLocalPlacement = (IfcLocalPlacement) ifcObjectPlacement;
        IfcAxis2Placement relativePlacement = ifcLocalPlacement.getRelativePlacement();
        if (relativePlacement instanceof IfcAxis2Placement2D) {
            throw new PlacementNotImplementedException("IfcAxis2Placement2D has not been implemented");
        } else if (relativePlacement instanceof IfcAxis2Placement3D) {
            IfcAxis2Placement3D ifcAxis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
            IfcObjectPlacement placementRelativeTo = ifcLocalPlacement.getPlacementRelTo();
            if (placementRelativeTo == null) {
                IfcCartesianPoint ifcCartesianPoint = ifcAxis2Placement3D.getLocation();
                return new double[] { ifcCartesianPoint.getCoordinates().get(0), ifcCartesianPoint.getCoordinates().get(1), ifcCartesianPoint.getCoordinates().get(2) };
            } else {
                double[] relative = getAbsolutePosition(placementRelativeTo);
                IfcCartesianPoint ifcCartesianPoint = ifcAxis2Placement3D.getLocation();
                return new double[] { relative[0] + ifcCartesianPoint.getCoordinates().get(0), relative[1] + ifcCartesianPoint.getCoordinates().get(1), relative[2] + ifcCartesianPoint.getCoordinates().get(2) };
            }
        }
    }
    return new double[] { 0d, 0d, 0d };
}
Also used : IfcGridPlacement(org.bimserver.models.ifc2x3tc1.IfcGridPlacement) IfcAxis2Placement2D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement2D) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) IfcAxis2Placement(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement)

Example 4 with IfcObjectPlacement

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

the class TestMoveObject method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Get the appropriate deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin the file
        bimServerClient.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, true);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAllWithSubTypes(IfcFurnishingElement.class)) {
            IfcObjectPlacement objectPlacement = ifcFurnishingElement.getObjectPlacement();
            if (objectPlacement != null && objectPlacement instanceof IfcLocalPlacement) {
                IfcLocalPlacement localPlacement = (IfcLocalPlacement) objectPlacement;
                IfcAxis2Placement relativePlacement = localPlacement.getRelativePlacement();
                if (relativePlacement != null) {
                    if (relativePlacement instanceof IfcAxis2Placement3D) {
                        IfcAxis2Placement3D axis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
                        IfcCartesianPoint location = axis2Placement3D.getLocation();
                        double newValue = location.getCoordinates().get(2) + 50;
                        System.out.println("Changing z value of " + ifcFurnishingElement.getName() + " from " + location.getCoordinates().get(2) + " to " + newValue);
                        location.getCoordinates().set(2, newValue);
                    }
                }
            }
        }
        long newRoid = model.commit("Moved all furniture 50 meters up");
        SSerializerPluginConfiguration ifcSerializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
        bimServerClient.download(newRoid, ifcSerializer.getOid(), Paths.get("movedf.ifc"));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) URL(java.net.URL) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IfcAxis2Placement(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement) Test(org.junit.Test)

Aggregations

IfcObjectPlacement (org.bimserver.models.ifc2x3tc1.IfcObjectPlacement)4 IfcAxis2Placement (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement)3 IfcAxis2Placement3D (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D)3 IfcCartesianPoint (org.bimserver.models.ifc2x3tc1.IfcCartesianPoint)3 IfcLocalPlacement (org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)3 Area (java.awt.geom.Area)1 Path2D (java.awt.geom.Path2D)1 URL (java.net.URL)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1 SProject (org.bimserver.interfaces.objects.SProject)1 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)1 GeometryData (org.bimserver.models.geometry.GeometryData)1 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)1 IfcAxis2Placement2D (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement2D)1 IfcFurnishingElement (org.bimserver.models.ifc2x3tc1.IfcFurnishingElement)1 IfcGridPlacement (org.bimserver.models.ifc2x3tc1.IfcGridPlacement)1 IfcProductRepresentation (org.bimserver.models.ifc2x3tc1.IfcProductRepresentation)1 IfcRepresentation (org.bimserver.models.ifc2x3tc1.IfcRepresentation)1 IfcRepresentationItem (org.bimserver.models.ifc2x3tc1.IfcRepresentationItem)1