从IfcWall递归变换坐标

时间:2018-08-07 12:51:50

标签: ifc bim

我正在寻找一种从IfcWall获取绝对顶点的方法。大多数解析器仅给出相对位置。如何分解与其他元素的关系并使坐标为绝对坐标? BimServer API提供了转换矩阵,但某些值的输出接近0或接近无穷大。

是否有一个解析器,提供了一种简便的方法来获取Walls或具有几何图形的其他Ifc元素的坐标。还是我的方法不对?

我的方法: GeometryGymIfc和apstex ifcopentools

        IfcProject project = db.Project;
        IfcSpatialElement rootElement = project.RootElement;
        List<IfcWall> elements = project.Extract<IfcWall>();
        List<Wall> walls = new List<Wall>();
        List<IfcFacetedBrep> breps = new List<IfcFacetedBrep>();
        foreach (IfcWall element in elements)
        {
            IfcProductRepresentation representation = element.Representation;
            if (representation is null)
            {
                continue;
            }
            foreach (IfcRepresentation rep in representation.Representations)
            {
                IfcShapeRepresentation sr = rep as IfcShapeRepresentation;
                if (sr is null)
                {
                    continue;
                }
                foreach (IfcRepresentationItem item in sr.Items)
                {
                    IfcFacetedBrep fb = item as IfcFacetedBrep;
                    if (fb is null)
                    {
                        continue;
                    }
                    foreach (IfcFace face in fb.Outer.CfsFaces)
                    {
                        foreach (IfcFaceBound facebound in face.Bounds)
                        {
                            IfcLoop loop = facebound.Bound;
                            if (loop is IfcPolyloop == false)
                            {
                                continue;
                            }
                            foreach (IfcCartesianPoint point in ((IfcPolyloop)loop).Polygon)
                            {
                                walls.Add(new Wall(point.Coordinates.Item1, point.Coordinates.Item2, point.Coordinates.Item3));
                            }
                        }
                    }
                }
            }
        }

BIMSERVER:

        List<IfcWall> products = model.getAll(IfcWall.class);
        wall = new Wall[products.size()];
        for (IfcWall product : products) {
            if (product.getGeometry() != null) {
                //  Transformation Matrix
                double[] transformationMatrix = new double[product.getGeometry().getTransformation().length / 8];
                ByteBuffer tbuffer = ByteBuffer.wrap(product.getGeometry().getTransformation());
                tbuffer.order(ByteOrder.LITTLE_ENDIAN);
                DoubleBuffer dtbuffer = tbuffer.asDoubleBuffer();
                dtbuffer.get(transformationMatrix);
                for (int i = 0; i < 16; i++) {
                    System.out.println("transformationMatrix " + dtbuffer.get(i));
                }

                //  Coordinate matrix
                double[] coordinateMatrix = new double[product.getGeometry().getData().getVertices().length / 8];
                ByteBuffer cbuffer = ByteBuffer.wrap(product.getGeometry().getData().getVertices());
                cbuffer.order(ByteOrder.LITTLE_ENDIAN);
                DoubleBuffer dcbuffer = cbuffer.asDoubleBuffer();
                dcbuffer.get(coordinateMatrix);
                for (int i = 0; i < 16; i++) {
                    System.out.println("coordinateMatrix " + dcbuffer.get(i));
                }
                //Transformation
                transformationMatrix = Matrix.changeOrientation(transformationMatrix);
                Transform3D transform = new Transform3D(transformationMatrix);
                int count = 0;
                List<double[]> plist = new ArrayList<>();
                for (int i = 2; i < coordinateMatrix.length; i = i + 3) {
                    Point3d p = new Point3d(coordinateMatrix[i - 2], coordinateMatrix[i - 1], coordinateMatrix[i]);
                    transform.transform(p);
                    double[] parray = {p.x, p.y, p.z};
                    plist.add(parray);
                    count++;
                    if (count == 12) count = 0;
                }

                wall[wallcount] = new Wall(GuidCompressor.uncompressGuidString(product.getGlobalId()), product.getGlobalId(), product.getName(), plist);
                wallcount++;
            }
        }

0 个答案:

没有答案