/// <summary>
        /// Calculates net surface area.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            double areaSum = 0;
            SolidMeshGeometryInfo geomInfo = GeometryUtil.GetSolidMeshGeometry(element);

            if (geomInfo.SolidsCount() > 0)
            {
                for (int ii = 0; ii < geomInfo.SolidsCount(); ++ii)
                {
                    foreach (Face f in geomInfo.GetSolids()[ii].Faces)
                    {
                        areaSum += f.Area;
                    }
                }
            }

            if (geomInfo.MeshesCount() > 0)
            {
                for (int jj = 0; jj < geomInfo.MeshesCount(); ++jj)
                {
                    Mesh geomMesh      = geomInfo.GetMeshes()[jj];
                    XYZ  arbitraryOrig = geomMesh.Vertices[0];
                    for (int ii = 0; ii < geomMesh.NumTriangles; ++ii)
                    {
                        MeshTriangle meshTri = geomMesh.get_Triangle(ii);
                        double       a       = meshTri.get_Vertex(1).DistanceTo(meshTri.get_Vertex(0));
                        double       b       = meshTri.get_Vertex(2).DistanceTo(meshTri.get_Vertex(1));
                        double       c       = meshTri.get_Vertex(0).DistanceTo(meshTri.get_Vertex(2));
                        areaSum += (a + b + c) / 2.0;
                    }
                }
            }

            m_Area = UnitUtil.ScaleArea(areaSum);
            if (m_Area < MathUtil.Eps() * MathUtil.Eps() || m_Area < MathUtil.Eps())
            {
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcQtyNetSurfaceArea", out m_Area) == null)
                {
                    if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcNetSurfaceArea", out m_Area) == null)
                    {
                        ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "NetSurfaceArea", out m_Area);
                    }
                }
                m_Area = UnitUtil.ScaleArea(m_Area);
                if (m_Area < MathUtil.Eps() * MathUtil.Eps() || m_Area < MathUtil.Eps())
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
Exemple #2
0
        /// <summary>
        /// Calculates net volume.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            double vol = 0;
            SolidMeshGeometryInfo geomInfo = GeometryUtil.GetSolidMeshGeometry(element);

            if (geomInfo.SolidsCount() > 0)
            {
                for (int ii = 0; ii < geomInfo.SolidsCount(); ++ii)
                {
                    vol += geomInfo.GetSolids()[ii].Volume;
                }
            }

            if (geomInfo.MeshesCount() > 0)
            {
                for (int jj = 0; jj < geomInfo.MeshesCount(); ++jj)
                {
                    Mesh geomMesh      = geomInfo.GetMeshes()[jj];
                    XYZ  arbitraryOrig = geomMesh.Vertices[0];
                    for (int i = 0; i < geomMesh.NumTriangles; ++i)
                    {
                        MeshTriangle meshTri = geomMesh.get_Triangle(i);
                        XYZ          v1      = meshTri.get_Vertex(0) - arbitraryOrig;
                        XYZ          v2      = meshTri.get_Vertex(1) - arbitraryOrig;
                        XYZ          v3      = meshTri.get_Vertex(2) - arbitraryOrig;
                        vol += v1.DotProduct(v2.CrossProduct(v3)) / 6.0f;
                    }
                }
            }

            m_Volume = UnitUtil.ScaleVolume(vol);
            if (m_Volume < MathUtil.Eps() * MathUtil.Eps() || m_Volume < MathUtil.Eps())
            {
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcQtyNetVolume", out m_Volume) == null)
                {
                    if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcNetVolume", out m_Volume) == null)
                    {
                        ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "NetVolume", out m_Volume);
                    }
                }
                m_Volume = UnitUtil.ScaleVolume(m_Volume);
                if (m_Volume < MathUtil.Eps())
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }