private static Transform GetLocalTransform(ExporterIFC exporterIFC, double scale)
        {
            // We want to transform the geometry into the current local coordinate system.
            Transform geomTrf = Transform.Identity;

            geomTrf.BasisX = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, XYZ.BasisX);
            geomTrf.BasisY = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, XYZ.BasisY);
            geomTrf.BasisZ = geomTrf.BasisX.CrossProduct(geomTrf.BasisY);
            geomTrf.Origin = ExporterIFCUtils.TransformAndScalePoint(exporterIFC, XYZ.Zero) / scale;
            return(geomTrf);
        }
예제 #2
0
        private static Transform CreateProfileCurveTransform(ExporterIFC exporterIFC, Curve directrix, double param)
        {
            Transform directrixDirs = directrix.ComputeDerivatives(param, false);
            XYZ       origin        = ExporterIFCUtils.TransformAndScalePoint(exporterIFC, directrixDirs.Origin);

            // We are constructing the profile plane so that the normal matches the curve tangent, and the X matches the curve normal.
            XYZ profilePlaneXDir = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, directrixDirs.BasisZ.Normalize());
            XYZ profilePlaneYDir = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, -directrixDirs.BasisY.Normalize());
            XYZ profilePlaneZDir = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, directrixDirs.BasisX.Normalize());

            Transform profileCurveTransform = Transform.CreateTranslation(origin);

            profileCurveTransform.BasisX = profilePlaneXDir;
            profileCurveTransform.BasisY = profilePlaneYDir;
            profileCurveTransform.BasisZ = profilePlaneZDir;

            return(profileCurveTransform);
        }
예제 #3
0
        /// <summary>
        /// Creates a facetation of a simple swept solid from a list of curve loops.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="profileName">The profile name.</param>
        /// <param name="profileCurveLoops">The profile curve loops.</param>
        /// <param name="normal">The normal of the plane that the path lies on.</param>
        /// <param name="directrix">The path curve.</param>
        /// <returns>The list of facet handles.</returns>
        public static HashSet <IFCAnyHandle> CreateSimpleSweptSolidAsBRep(ExporterIFC exporterIFC, string profileName, IList <CurveLoop> profileCurveLoops,
                                                                          XYZ normal, Curve directrix)
        {
            // see definition of IfcSurfaceCurveSweptAreaSolid from
            // http://www.buildingsmart-tech.org/ifc/IFC2x4/rc4/html/schema/ifcgeometricmodelresource/lexical/ifcsurfacecurvesweptareasolid.htm

            HashSet <IFCAnyHandle> facetHnds = null;

            if (!CanCreateSimpleSweptSolid(profileCurveLoops, normal, directrix))
            {
                return(facetHnds);
            }

            // An extra requirement, as we can't tessellate an unbound curve.
            if (!directrix.IsBound)
            {
                return(facetHnds);
            }
            double originalStartParam = directrix.GetEndParameter(0);

            Plane axisPlane, profilePlane;

            CreateAxisAndProfileCurvePlanes(directrix, originalStartParam, out axisPlane, out profilePlane);

            IList <CurveLoop> curveLoops = null;

            try
            {
                // Check that curve loops are valid.
                curveLoops = ExporterIFCUtils.ValidateCurveLoops(profileCurveLoops, profilePlane.Normal);
            }
            catch (Exception)
            {
                return(null);
            }

            if (curveLoops == null || curveLoops.Count == 0)
            {
                return(facetHnds);
            }

            // Tessellate the curve loops.  We don't add the last point, as these should all be closed curves.
            IList <IList <XYZ> > tessellatedOutline = new List <IList <XYZ> >();

            foreach (CurveLoop curveLoop in curveLoops)
            {
                List <XYZ> tessellatedCurve = new List <XYZ>();
                foreach (Curve curve in curveLoop)
                {
                    if (curve is Line)
                    {
                        AddScaledPointToList(exporterIFC, tessellatedCurve, curve.GetEndPoint(0));
                    }
                    else
                    {
                        IList <XYZ> curveTessellation = CreateRoughTessellation(exporterIFC, curve);
                        tessellatedCurve.AddRange(curveTessellation);
                    }
                }

                if (tessellatedCurve.Count != 0)
                {
                    tessellatedOutline.Add(tessellatedCurve);
                }
            }

            IFCFile file = exporterIFC.GetFile();

            IList <IList <IList <IFCAnyHandle> > > facetVertexHandles = new List <IList <IList <IFCAnyHandle> > >();

            IList <IList <IFCAnyHandle> > tessellatedOutlineHandles = new List <IList <IFCAnyHandle> >();

            foreach (IList <XYZ> tessellatedOutlinePolygon in tessellatedOutline)
            {
                IList <IFCAnyHandle> tessellatedOutlinePolygonHandles = new List <IFCAnyHandle>();
                foreach (XYZ tessellatedOutlineXYZ in tessellatedOutlinePolygon)
                {
                    tessellatedOutlinePolygonHandles.Add(ExporterUtil.CreateCartesianPoint(file, tessellatedOutlineXYZ));
                }
                tessellatedOutlineHandles.Add(tessellatedOutlinePolygonHandles);
            }
            facetVertexHandles.Add(tessellatedOutlineHandles);

            // Tessellate the Directrix.  This only works for bound Directrix curves. Unfortunately, we get XYZ values, which we will have to convert
            // back to parameter values to get the local transform.
            IList <double> tessellatedDirectrixParameters = CreateRoughParametricTessellation(directrix);

            // Create all of the other outlines by transformng the first tessellated outline to the current transform.
            Transform profilePlaneTrf = Transform.CreateTranslation(ExporterIFCUtils.TransformAndScalePoint(exporterIFC, profilePlane.Origin));

            profilePlaneTrf.BasisX = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, profilePlane.XVec);
            profilePlaneTrf.BasisY = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, profilePlane.YVec);
            profilePlaneTrf.BasisZ = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, profilePlane.Normal);

            // The inverse transform will be applied to generate the delta transform for the profile curves from the start of the directrix
            // to the current location.  This could be optimized in the case of a Line, but current usage is really only for a single arc.
            // If that changes, we should revisit optimization possibilities.
            Transform profilePlaneTrfInverse = profilePlaneTrf.Inverse;

            // Create the delta transforms and the offset tessellated profiles.
            foreach (double parameter in tessellatedDirectrixParameters)
            {
                Transform directrixDirs  = CreateProfileCurveTransform(exporterIFC, directrix, parameter);
                Transform deltaTransform = directrixDirs.Multiply(profilePlaneTrfInverse);

                IList <IList <IFCAnyHandle> > currTessellatedOutline = new List <IList <IFCAnyHandle> >();
                foreach (IList <XYZ> pointLoop in tessellatedOutline)
                {
                    IList <IFCAnyHandle> currTessellatedPoinLoop = new List <IFCAnyHandle>();
                    foreach (XYZ point in pointLoop)
                    {
                        XYZ          transformedPoint       = deltaTransform.OfPoint(point);
                        IFCAnyHandle transformedPointHandle = ExporterUtil.CreateCartesianPoint(file, transformedPoint);
                        currTessellatedPoinLoop.Add(transformedPointHandle);
                    }
                    currTessellatedOutline.Add(currTessellatedPoinLoop);
                }
                facetVertexHandles.Add(currTessellatedOutline);
            }

            // Create the side facets.
            facetHnds = new HashSet <IFCAnyHandle>();

            int numFacets = facetVertexHandles.Count - 1;

            for (int ii = 0; ii < numFacets; ii++)
            {
                IList <IList <IFCAnyHandle> > firstOutline  = facetVertexHandles[ii];
                IList <IList <IFCAnyHandle> > secondOutline = facetVertexHandles[ii + 1];

                int numLoops = firstOutline.Count;
                for (int jj = 0; jj < numLoops; jj++)
                {
                    IList <IFCAnyHandle> firstLoop  = firstOutline[jj];
                    IList <IFCAnyHandle> secondLoop = secondOutline[jj];

                    int numVertices = firstLoop.Count;

                    for (int kk = 0; kk < numVertices; kk++)
                    {
                        IList <IFCAnyHandle> polyLoopHandles = new List <IFCAnyHandle>(4);
                        polyLoopHandles.Add(secondLoop[kk]);
                        polyLoopHandles.Add(secondLoop[(kk + 1) % numVertices]);
                        polyLoopHandles.Add(firstLoop[(kk + 1) % numVertices]);
                        polyLoopHandles.Add(firstLoop[kk]);

                        IFCAnyHandle face = BodyExporter.CreateFaceFromVertexList(file, polyLoopHandles);
                        facetHnds.Add(face);
                    }
                }
            }

            // Create the end facets.
            for (int ii = 0; ii < 2; ii++)
            {
                int faceIndex = (ii == 0) ? 0 : facetVertexHandles.Count - 1;

                int numLoops = facetVertexHandles[faceIndex].Count;
                HashSet <IFCAnyHandle> faceBounds = new HashSet <IFCAnyHandle>();

                for (int jj = 0; jj < numLoops; jj++)
                {
                    IList <IFCAnyHandle> polyLoopHandles = null;
                    if (ii == 0)
                    {
                        polyLoopHandles = facetVertexHandles[faceIndex][jj];
                    }
                    else
                    {
                        int numHandles = facetVertexHandles[faceIndex][jj].Count;
                        polyLoopHandles = new List <IFCAnyHandle>(numHandles);
                        for (int kk = numHandles - 1; kk >= 0; kk--)
                        {
                            polyLoopHandles.Add(facetVertexHandles[faceIndex][jj][kk]);
                        }
                    }

                    IFCAnyHandle polyLoop  = IFCInstanceExporter.CreatePolyLoop(file, polyLoopHandles);
                    IFCAnyHandle faceBound = (jj == 0) ?
                                             IFCInstanceExporter.CreateFaceOuterBound(file, polyLoop, true) :
                                             IFCInstanceExporter.CreateFaceBound(file, polyLoop, true);
                    faceBounds.Add(faceBound);
                }

                IFCAnyHandle face = IFCInstanceExporter.CreateFace(file, faceBounds);
                facetHnds.Add(face);
            }

            return(facetHnds);
        }
예제 #4
0
        /// <summary>
        /// Creates a simple swept solid from a list of curve loops.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="profileName">The profile name.</param>
        /// <param name="profileCurveLoops">The profile curve loops.</param>
        /// <param name="normal">The normal of the plane that the path lies on.</param>
        /// <param name="directrix">The path curve.</param>
        /// <returns>The swept solid handle.</returns>
        public static IFCAnyHandle CreateSimpleSweptSolid(ExporterIFC exporterIFC, string profileName, IList <CurveLoop> profileCurveLoops,
                                                          XYZ normal, Curve directrix)
        {
            // see definition of IfcSurfaceCurveSweptAreaSolid from
            // http://www.buildingsmart-tech.org/ifc/IFC2x4/rc4/html/schema/ifcgeometricmodelresource/lexical/ifcsurfacecurvesweptareasolid.htm

            IFCAnyHandle simpleSweptSolidHnd = null;

            if (!CanCreateSimpleSweptSolid(profileCurveLoops, normal, directrix))
            {
                return(simpleSweptSolidHnd);
            }

            bool   isBound            = directrix.IsBound;
            double originalStartParam = isBound ? directrix.GetEndParameter(0) : 0.0;

            Transform axisLCS, profileLCS;

            CreateAxisAndProfileCurveLCS(directrix, originalStartParam, out axisLCS, out profileLCS);

            IList <CurveLoop> curveLoops = null;

            try
            {
                // Check that curve loops are valid.
                curveLoops = ExporterIFCUtils.ValidateCurveLoops(profileCurveLoops, profileLCS.BasisZ);
            }
            catch (Exception)
            {
                return(null);
            }

            if (curveLoops == null || curveLoops.Count == 0)
            {
                return(simpleSweptSolidHnd);
            }

            double startParam = 0.0, endParam = 1.0;

            if (directrix is Arc)
            {
                // This effectively resets the start parameter to 0.0, and end parameter = length of curve.
                if (isBound)
                {
                    // Put the parameters in range of [0, 2*Pi]
                    double inRangeStarParam = (directrix.GetEndParameter(0) % (2 * Math.PI));
                    double inRangeEndParam  = (directrix.GetEndParameter(1) % (2 * Math.PI));
                    // We want the angle direction is anti-clockwise (+ direction), therefore we will always start with the smaller one
                    if (inRangeEndParam < inRangeStarParam)
                    {
                        double tmp = inRangeStarParam;
                        inRangeStarParam = inRangeEndParam;
                        inRangeEndParam  = tmp;
                    }
                    // If start param is negative, we will reset it to 0 and shift the end accordingly
                    if (inRangeStarParam < 0)
                    {
                        double parRange = inRangeEndParam - inRangeStarParam;
                        inRangeStarParam = 0.0;
                        inRangeEndParam  = parRange;
                    }
                    endParam = UnitUtil.ScaleAngle(inRangeEndParam);
                    //endParam = UnitUtil.ScaleAngle(MathUtil.PutInRange(directrix.GetEndParameter(1), Math.PI, 2 * Math.PI) -
                    //   MathUtil.PutInRange(originalStartParam, Math.PI, 2 * Math.PI));
                }
                else
                {
                    endParam = 2.0 * Math.PI;
                }
            }

            // Start creating IFC entities.

            IFCAnyHandle sweptArea = ExtrusionExporter.CreateSweptArea(exporterIFC, profileName, curveLoops, profileLCS, profileLCS.BasisZ);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(sweptArea))
            {
                return(simpleSweptSolidHnd);
            }

            IFCAnyHandle curveHandle            = null;
            IFCAnyHandle referenceSurfaceHandle = ExtrusionExporter.CreateSurfaceOfLinearExtrusionFromCurve(exporterIFC, directrix, axisLCS, 1.0, 1.0,
                                                                                                            out curveHandle);

            // Should this be moved up?  Check.
            XYZ scaledOrigin = ExporterIFCUtils.TransformAndScalePoint(exporterIFC, axisLCS.Origin);
            XYZ scaledXDir   = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, axisLCS.BasisX).Normalize();
            XYZ scaledNormal = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, axisLCS.BasisZ).Normalize();

            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle solidAxis = ExporterUtil.CreateAxis(file, scaledOrigin, scaledNormal, scaledXDir);

            simpleSweptSolidHnd = IFCInstanceExporter.CreateSurfaceCurveSweptAreaSolid(file, sweptArea, solidAxis, curveHandle, startParam,
                                                                                       endParam, referenceSurfaceHandle);
            return(simpleSweptSolidHnd);
        }
예제 #5
0
        // return null if parent should be completely clipped.
        // TODO: determine whether or not to use face boundary.
        private static IFCAnyHandle ProcessClippingFace(ExporterIFC exporterIFC, CurveLoop outerBoundary, Plane boundaryPlane,
                                                        Plane extrusionBasePlane, XYZ extrusionDirection, IFCRange range, bool useFaceBoundary, IFCAnyHandle bodyItemHnd)
        {
            if (outerBoundary == null || boundaryPlane == null)
            {
                throw new Exception("Invalid face boundary.");
            }

            double clippingSlant = boundaryPlane.Normal.DotProduct(extrusionDirection);

            if (useFaceBoundary)
            {
                if (MathUtil.IsAlmostZero(clippingSlant))
                {
                    return(bodyItemHnd);
                }
            }

            bool clipCompletely;

            if (!IsInRange(range, outerBoundary, boundaryPlane, extrusionDirection, out clipCompletely))
            {
                return(clipCompletely ? null : bodyItemHnd);
            }

            if (MathUtil.IsAlmostZero(clippingSlant))
            {
                throw new Exception("Can't create clipping perpendicular to extrusion.");
            }

            IFCFile file = exporterIFC.GetFile();

            XYZ scaledOrig = ExporterIFCUtils.TransformAndScalePoint(exporterIFC, boundaryPlane.Origin);
            XYZ scaledNorm = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, boundaryPlane.Normal);
            XYZ scaledXDir = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, boundaryPlane.XVec);

            IFCAnyHandle planeAxisHnd = ExporterUtil.CreateAxis(file, scaledOrig, scaledNorm, scaledXDir);
            IFCAnyHandle surfHnd      = IFCInstanceExporter.CreatePlane(file, planeAxisHnd);

            IFCAnyHandle clippedBodyItemHnd = null;
            IFCAnyHandle halfSpaceHnd       = null;

            if (useFaceBoundary)
            {
                IFCAnyHandle boundedCurveHnd;
                if (boundaryPlane != null)
                {
                    XYZ projScaledOrigin = ExporterIFCUtils.TransformAndScalePoint(exporterIFC, extrusionBasePlane.Origin);
                    XYZ projScaledX      = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, extrusionBasePlane.XVec);
                    XYZ projScaledY      = ExporterIFCUtils.TransformAndScaleVector(exporterIFC, extrusionBasePlane.YVec);
                    XYZ projScaledNorm   = projScaledX.CrossProduct(projScaledY);

                    Plane projScaledPlane = new Plane(projScaledX, projScaledY, projScaledOrigin);

                    IList <UV> polylinePts = TransformAndProjectCurveLoopToPlane(exporterIFC, outerBoundary, projScaledPlane);
                    polylinePts.Add(polylinePts[0]);
                    boundedCurveHnd = ExporterUtil.CreatePolyline(file, polylinePts);

                    IFCAnyHandle boundedAxisHnd = ExporterUtil.CreateAxis(file, projScaledOrigin, projScaledNorm, projScaledX);

                    halfSpaceHnd = IFCInstanceExporter.CreatePolygonalBoundedHalfSpace(file, boundedAxisHnd, boundedCurveHnd, surfHnd, false);
                }
                else
                {
                    throw new Exception("Can't create non-polygonal face boundary.");
                }
            }
            else
            {
                halfSpaceHnd = IFCInstanceExporter.CreateHalfSpaceSolid(file, surfHnd, false);
            }

            if (halfSpaceHnd == null)
            {
                throw new Exception("Can't create clipping.");
            }

            clippedBodyItemHnd = IFCInstanceExporter.CreateBooleanClippingResult(file, IFCBooleanOperator.Difference,
                                                                                 bodyItemHnd, halfSpaceHnd);
            return(clippedBodyItemHnd);
        }