Search in sources :

Example 1 with IfcRepresentationItem

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

the class GuidHighlighter method highlightGuids.

private void highlightGuids(IfcModelInterface model, Set<String> highlightedGuids) {
    Set<IdEObject> newObjects = new HashSet<IdEObject>();
    IfcColourRgb gray = Ifc2x3tc1Factory.eINSTANCE.createIfcColourRgb();
    newObjects.add(gray);
    gray.setRed(0.5f);
    gray.setGreen(0.5f);
    gray.setBlue(0.5f);
    Set<IdEObject> toDelete = new HashSet<IdEObject>();
    for (IdEObject object : model.getValues()) {
        if (object instanceof IfcPresentationLayerAssignment) {
            toDelete.add(object);
        }
    }
    IfcPresentationLayerAssignment notSelectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
    notSelectedLayer.setName("Not Selected");
    notSelectedLayer.setIdentifier("Not Selected");
    newObjects.add(notSelectedLayer);
    IfcPresentationLayerAssignment selectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
    selectedLayer.setName("Selected");
    selectedLayer.setIdentifier("Selected");
    newObjects.add(selectedLayer);
    for (IdEObject idEObject : model.getValues()) {
        if (idEObject instanceof IfcProduct) {
            IfcProduct product = (IfcProduct) idEObject;
            String guid = product.getGlobalId();
            boolean hide = true;
            if (guid != null) {
                if (highlightedGuids.contains(guid)) {
                    hide = false;
                }
            }
            if (hide) {
                System.out.println("Hiding " + guid);
                IfcProductRepresentation representation = product.getRepresentation();
                if (representation != null) {
                    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
                        notSelectedLayer.getAssignedItems().add(ifcRepresentation);
                        for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
                            notSelectedLayer.getAssignedItems().add(ifcRepresentationItem);
                            for (IfcStyledItem ifcStyledItem : ifcRepresentationItem.getStyledByItem()) {
                                for (IfcPresentationStyleAssignment ifcPresentationStyleAssignment : ifcStyledItem.getStyles()) {
                                    for (IfcPresentationStyleSelect ifcPresentationStyleSelect : ifcPresentationStyleAssignment.getStyles()) {
                                        if (ifcPresentationStyleSelect instanceof IfcSurfaceStyle) {
                                            IfcSurfaceStyle ifcSurfaceStyle = (IfcSurfaceStyle) ifcPresentationStyleSelect;
                                            for (IfcSurfaceStyleElementSelect ifcSurfaceStyleElementSelect : ifcSurfaceStyle.getStyles()) {
                                                if (ifcSurfaceStyleElementSelect instanceof IfcSurfaceStyleRendering) {
                                                    IfcSurfaceStyleRendering ifcSurfaceStyleRendering = (IfcSurfaceStyleRendering) ifcSurfaceStyleElementSelect;
                                                    ifcSurfaceStyleRendering.setTransparency(0.98f);
                                                    ifcSurfaceStyleRendering.setDiffuseColour(gray);
                                                    ifcSurfaceStyleRendering.setReflectionColour(gray);
                                                    ifcSurfaceStyleRendering.setSpecularColour(gray);
                                                    ifcSurfaceStyleRendering.setSurfaceColour(gray);
                                                    ifcSurfaceStyleRendering.setTransmissionColour(gray);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                System.out.println("Not hiding " + guid);
                IfcProductRepresentation representation = product.getRepresentation();
                if (representation != null) {
                    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
                        selectedLayer.getAssignedItems().add(ifcRepresentation);
                        for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
                            selectedLayer.getAssignedItems().add(ifcRepresentationItem);
                        }
                    }
                }
            }
        }
    }
    for (IdEObject toDeleteObject : toDelete) {
        model.remove(toDeleteObject);
    }
    for (IdEObject newObject : newObjects) {
        try {
            model.add(model.getHighestOid() + 1, newObject);
        } catch (IfcModelInterfaceException e) {
            e.printStackTrace();
        }
    }
}
Also used : IfcSurfaceStyle(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyle) IdEObject(org.bimserver.emf.IdEObject) IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) IfcPresentationLayerAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationLayerAssignment) IfcColourRgb(org.bimserver.models.ifc2x3tc1.IfcColourRgb) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcStyledItem(org.bimserver.models.ifc2x3tc1.IfcStyledItem) IfcSurfaceStyleElementSelect(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleElementSelect) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) IfcPresentationStyleAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleAssignment) IfcPresentationStyleSelect(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleSelect) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation) HashSet(java.util.HashSet) IfcSurfaceStyleRendering(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleRendering)

Example 2 with IfcRepresentationItem

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

the class AddFurniture method main.

public static void main(String[] args) {
    try {
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
        DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
        Deserializer deserializer = deserializerPlugin.createDeserializer(null);
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));
        deserializer = deserializerPlugin.createDeserializer(null);
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface furnishingModel = DeserializerUtils.readFromFile(deserializer, Paths.get("test.ifc"));
        model.fixOids(new IncrementingOidProvider());
        long oid = model.getHighestOid();
        IncrementingOidProvider oidProvider = new IncrementingOidProvider(oid + 1);
        IfcFurnishingElement picknick = (IfcFurnishingElement) furnishingModel.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
        ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), model);
        IfcProductDefinitionShape representation = (IfcProductDefinitionShape) picknick.getRepresentation();
        IfcRepresentation surfaceModel = null;
        IfcRepresentation boundingBox = null;
        for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
            IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation;
            if (ifcShapeRepresentation.getRepresentationType().equals("SurfaceModel")) {
                surfaceModel = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
            } else if (ifcShapeRepresentation.getRepresentationType().equals("BoundingBox")) {
                boundingBox = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false);
            }
        }
        IfcOwnerHistory ownerHistory = null;
        List<IfcOwnerHistory> all = model.getAll(IfcOwnerHistory.class);
        if (all.size() > 0) {
            ownerHistory = all.get(0);
        }
        for (IfcBuildingStorey ifcBuildingStorey : model.getAll(IfcBuildingStorey.class)) {
            for (IfcRelDecomposes ifcRelDecomposes : ifcBuildingStorey.getIsDecomposedBy()) {
                for (IfcObjectDefinition ifcObjectDefinition : ifcRelDecomposes.getRelatedObjects()) {
                    if (ifcObjectDefinition instanceof IfcSpace) {
                        IfcSpace ifcSpace = (IfcSpace) ifcObjectDefinition;
                        // IfcProductDefinitionShape slabRepr = (IfcProductDefinitionShape) ifcSpace.getRepresentation();
                        // IfcBoundingBox box = null;
                        // for (IfcRepresentation representation2 : slabRepr.getRepresentations()) {
                        // IfcShapeRepresentation shapeRepresentation = (IfcShapeRepresentation)representation2;
                        // if (shapeRepresentation.getRepresentationType().equals("BoundingBox")) {
                        // for (IfcRepresentationItem i2 : shapeRepresentation.getItems()) {
                        // box = (IfcBoundingBox)i2;
                        // }
                        // }
                        // }
                        IfcFurnishingElement newFurnishing = model.create(IfcFurnishingElement.class, oidProvider);
                        IfcRelContainedInSpatialStructure containedInSpatialStructure2 = model.create(IfcRelContainedInSpatialStructure.class, oidProvider);
                        containedInSpatialStructure2.setRelatingStructure(ifcBuildingStorey);
                        containedInSpatialStructure2.getRelatedElements().add(newFurnishing);
                        newFurnishing.setName("Generated");
                        newFurnishing.setGlobalId("TEST");
                        newFurnishing.setOwnerHistory(ownerHistory);
                        IfcProductDefinitionShape definitionShape = model.create(IfcProductDefinitionShape.class, oidProvider);
                        newFurnishing.setRepresentation(definitionShape);
                        definitionShape.getRepresentations().add(boundingBox);
                        definitionShape.getRepresentations().add(surfaceModel);
                        IfcLocalPlacement localPlacement = model.create(IfcLocalPlacement.class, oidProvider);
                        localPlacement.setPlacementRelTo(ifcSpace.getObjectPlacement());
                        IfcAxis2Placement3D axis2Placement3D = model.create(IfcAxis2Placement3D.class, oidProvider);
                        localPlacement.setRelativePlacement(axis2Placement3D);
                        IfcCartesianPoint pos = model.create(IfcCartesianPoint.class, oidProvider);
                        pos.getCoordinates().add(-3d);
                        pos.getCoordinates().add(+0.5d);
                        pos.getCoordinates().add(0d);
                        axis2Placement3D.setLocation(pos);
                        newFurnishing.setObjectPlacement(localPlacement);
                    }
                }
            }
        }
        model.resetExpressIds();
        SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
        Serializer serializer = serializerPlugin.createSerializer(null);
        serializer.init(model, null, true);
        SerializerUtils.writeToFile(serializer, Paths.get("withfurn.ifc"));
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (DeserializeException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    } catch (SerializerException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcObjectDefinition(org.bimserver.models.ifc2x3tc1.IfcObjectDefinition) IfcSpace(org.bimserver.models.ifc2x3tc1.IfcSpace) FileNotFoundException(java.io.FileNotFoundException) IfcOwnerHistory(org.bimserver.models.ifc2x3tc1.IfcOwnerHistory) PluginManager(org.bimserver.plugins.PluginManager) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcProductDefinitionShape(org.bimserver.models.ifc2x3tc1.IfcProductDefinitionShape) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) IfcShapeRepresentation(org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) Serializer(org.bimserver.plugins.serializers.Serializer) ModelHelper(org.bimserver.plugins.ModelHelper) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) SerializerException(org.bimserver.plugins.serializers.SerializerException) IfcRelDecomposes(org.bimserver.models.ifc2x3tc1.IfcRelDecomposes) Deserializer(org.bimserver.plugins.deserializers.Deserializer) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure)

Example 3 with IfcRepresentationItem

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

the class ModelColorizer method setColor.

public void setColor(IfcProduct product, double[] color, float transparency) throws IfcModelInterfaceException {
    if (!productToStyledItem.containsKey(product) || productToStyledItem.get(product).isEmpty()) {
        // There is no style, let's construct a path to a new one
        System.out.println("No style for " + product + " " + product.getGlobalId());
        IfcProductRepresentation productRepresentation = product.getRepresentation();
        if (product.getRepresentation() == null) {
            productRepresentation = model.create(IfcProductRepresentation.class);
            product.setRepresentation(productRepresentation);
        }
        IfcRepresentation representation = null;
        if (productRepresentation.getRepresentations().isEmpty()) {
            representation = model.create(IfcRepresentation.class);
            productRepresentation.getRepresentations().add(representation);
        } else {
            representation = productRepresentation.getRepresentations().get(0);
        }
        IfcRepresentationItem representationItem = null;
        if (representation.getItems().isEmpty()) {
            representationItem = model.create(IfcRepresentationItem.class);
            representation.getItems().add(representationItem);
        } else {
            representationItem = representation.getItems().get(0);
        }
        IfcStyledItem styledItem = model.create(IfcStyledItem.class);
        representationItem.getStyledByItem().clear();
        representationItem.getStyledByItem().add(styledItem);
        createStyle(color, transparency, styledItem);
    } else if (productToStyledItem.get(product).size() == 1) {
        // There is one style, we can work with that
        IfcStyledItem styledItem = productToStyledItem.get(product).iterator().next();
        Set<IfcProduct> products = styledItemToProduct.get(styledItem);
        if (products.isEmpty()) {
        // That's weird, inconsistent with other map
        } else if (products.size() == 1) {
            // That's probably us, we can alter the Style safely
            createStyle(color, transparency, styledItem);
        } else {
        // Multiple objects are using this style, we have to do some magic
        }
    } else {
        // There are multiple styles, that's a bit much...
        System.out.println(productToStyledItem.get(product).size() + " styles for " + product);
    }
}
Also used : IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) Set(java.util.Set) HashSet(java.util.HashSet) IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) IfcStyledItem(org.bimserver.models.ifc2x3tc1.IfcStyledItem) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation)

Example 4 with IfcRepresentationItem

use of org.bimserver.models.ifc2x3tc1.IfcRepresentationItem 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 5 with IfcRepresentationItem

use of org.bimserver.models.ifc2x3tc1.IfcRepresentationItem 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().getData());
            float[] vertices = GeometryUtils.toFloatArray(geometryData.getVertices().getData());
            double[] matrix = 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 double[] { point[0], point[1], point[2], 1 }, 0);
                    float x = (float) (res[0] * multiplierMillimeters);
                    float y = (float) (res[1] * multiplierMillimeters);
                    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)

Aggregations

IfcRepresentation (org.bimserver.models.ifc2x3tc1.IfcRepresentation)5 IfcProductRepresentation (org.bimserver.models.ifc2x3tc1.IfcProductRepresentation)4 IfcRepresentationItem (org.bimserver.models.ifc2x3tc1.IfcRepresentationItem)4 IfcCartesianPoint (org.bimserver.models.ifc2x3tc1.IfcCartesianPoint)3 IfcShapeRepresentation (org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation)3 Area (java.awt.geom.Area)2 Path2D (java.awt.geom.Path2D)2 HashSet (java.util.HashSet)2 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)2 IfcAxis2Placement3D (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D)2 IfcStyledItem (org.bimserver.models.ifc2x3tc1.IfcStyledItem)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Set (java.util.Set)1 IdEObject (org.bimserver.emf.IdEObject)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 GeometryData (org.bimserver.models.geometry.GeometryData)1 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)1 IfcArbitraryClosedProfileDef (org.bimserver.models.ifc2x3tc1.IfcArbitraryClosedProfileDef)1 IfcArbitraryProfileDefWithVoids (org.bimserver.models.ifc2x3tc1.IfcArbitraryProfileDefWithVoids)1