GithubHelp home page GithubHelp logo

Comments (4)

andyward avatar andyward commented on August 19, 2024

Can't really advise without seeing an example. Can you supply some example code and this test model?

from xbimgeometry.

ar98nau avatar ar98nau commented on August 19, 2024

Hi @andyward, thank you for giving this issue a try.
Here you have the IFC file of the screenshots above, hope it helps.
EN-04.zip.

To put into context I may explain the scope of the project. The initial IFC model has all solids spread in the space in a random position from the origin, I need to move those solids to a desired position and make some other transformations in their axis, all while maintaining the relative position between solids. Once I have this, I need the collisions between all solids with the name CAVITAT and those with the name XPS since I want those parts that are in touch with XPS solids. To do so without altering the original model I generate several new IfcStores along the way and put inside the modifications and transformations done to the elements. It's here when, after some translations and although being visible and identical to the original solid (only transformed) in the new IfcStore model, the Boolean operations start to fail for some random solids.

Here is an example of how I transform my solids:

var solidSet = geomEngine.CreateSolidSet();
solidSet.Add(solid);
var newTransform = new XbimMatrix3D();
newTransform.RotateAroundYAxis((180.0 * Math.PI) / 180.0);
var transformFlip = (IXbimSolidSet)solidSet.Transform(newTransform);

Here is how I create an object into a new IfcStore from the solid obtained after doing some transformations:

private static void CreateIfcGeometriesFromSolids(IfcStore model, IfcSpatialStructureElement parent, IXbimSolid shapeGeometry, IfcBuildingElement element, CustomXYZ position, string materialName, bool toMillimetres)
{
    double milli = toMillimetres ? 1000 : 1;

    var ifcFacetedBrep = model.Instances.New<IfcFacetedBrep>();
    var shell = model.Instances.New<IfcClosedShell>();

    foreach (var face in shapeGeometry.Faces)
    {
        var ifcFace = model.Instances.New<IfcFace>();
        var outerbound = model.Instances.New<IfcFaceOuterBound>();
        var polyloop = model.Instances.New<IfcPolyLoop>();

        List<IXbimVertex> vertices = face.OuterBound.Edges.SelectMany(e =>
        {
            List<IXbimVertex> verticesE = new List<IXbimVertex>
                    {
                        e.EdgeStart,
                        e.EdgeEnd
                    };
            return verticesE;
        }).ToList();
        vertices = vertices.Distinct().ToList();

        foreach (IXbimVertex vertice in vertices)
        {

            double x = vertice.VertexGeometry.X * milli;
            double y = vertice.VertexGeometry.Y * milli;
            double z = vertice.VertexGeometry.Z * milli;

            var cartesianPoint = model.Instances.New<IfcCartesianPoint>();
            cartesianPoint.SetXYZ(x, y, z);
            polyloop.Polygon.Add(cartesianPoint);
        }

        outerbound.Bound = polyloop;
        ifcFace.Bounds.Add(outerbound);
        shell.CfsFaces.Add(ifcFace);
    }

    CreateStructure(model, element, ifcFacetedBrep, shell);

    AddMaterial(model, element, materialName);

    SetPosition(position * milli, model, parent, element);
}

private static void CreateStructure(IfcStore model, IfcBuildingElement element, IfcFacetedBrep ifcFacetedBrep, IfcClosedShell shell)
{
	ifcFacetedBrep.Outer = shell;
	var shapeRepresentation = model.Instances.New<IfcShapeRepresentation>();
	var modelContext = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
	shapeRepresentation.ContextOfItems = modelContext;
	shapeRepresentation.RepresentationType = "Brep";
	shapeRepresentation.RepresentationIdentifier = "Body";
	shapeRepresentation.Items.Add(ifcFacetedBrep);
	var productDefinitionShape = model.Instances.New<IfcProductDefinitionShape>();
	productDefinitionShape.Representations.Add(shapeRepresentation);
	element.Representation = productDefinitionShape;
}

private static void AddMaterial(IfcStore model, IfcBuildingElement element, string materialName)
{
	var material = model.Instances.New<IfcMaterial>();
	material.Name = materialName;
	var ifcRelAssociatesMaterial = model.Instances.New<IfcRelAssociatesMaterial>();
	ifcRelAssociatesMaterial.RelatingMaterial = material;
	ifcRelAssociatesMaterial.RelatedObjects.Add(element);
}

private static void SetPosition(CustomXYZ position, IfcStore model, IfcSpatialStructureElement parent, IfcBuildingElement element)
{
	var origin = model.Instances.New<IfcCartesianPoint>();
	origin.SetXYZ(position.x, position.y, position.z);
	var lp = model.Instances.New<IfcLocalPlacement>();
	var ax3D = model.Instances.New<IfcAxis2Placement3D>();
	ax3D.Location = origin;
	lp.RelativePlacement = ax3D;
	lp.PlacementRelTo = parent.ObjectPlacement;
	element.ObjectPlacement = lp;
}

This is the fragment of my code where I have issues after performing the Intersect boolean operation:

List<IfcBuildingElementProxy> XPSs = ifcModel.Instances.OfType<IfcBuildingElementProxy>().Where(i => ((IfcMaterial)i.Material).Name.Value.ToString().Contains(XPS_OBJECT_ID) && i.Representation != null).ToList();
List<IfcBuildingElementProxy> fresades = ifcModel.Instances.OfType<IfcBuildingElementProxy>().Where(i => ((IfcMaterial)i.Material).Name.Value.ToString().Contains(CAVITAT_OBJECT_ID) && i.Representation != null).ToList();

IXbimSolidSet xpsSolids = null;
foreach (IfcBuildingElementProxy xps in XPSs)
{
    var xpsBrep = xps.Representation.Representations.SelectMany(r => r.Items.OfType<IfcFacetedBrep>()).FirstOrDefault();
    var xpsGeom = geomEngine.CreateSolidSet(xpsBrep, _logger);
    XbimMatrix3D matrixXPS = geomEngine.ToMatrix3D(xps.ObjectPlacement, _logger);
    var xpsGeomTransform = (IXbimSolidSet)xpsGeom.Transform(matrixXPS);

    if (xpsSolids == null) xpsSolids = xpsGeomTransform;
    else xpsSolids.Add(xpsGeomTransform);
}

IXbimSolidSet resultsIntersect = null;
foreach (IfcBuildingElementProxy fresada in fresades)
{
    var fresadaBrep = fresada.Representation.Representations.SelectMany(r => r.Items.OfType<IfcFacetedBrep>()).FirstOrDefault();
    var fresadaGeom = geomEngine.CreateSolidSet(fresadaBrep, _logger);
    XbimMatrix3D matrixF = geomEngine.ToMatrix3D(fresada.ObjectPlacement, _logger);
    var fresadaGeomTransform = (IXbimSolidSet)fresadaGeom.Transform(matrixF);

    var fresadaIntersect = xpsSolids.Intersection(fresadaGeomTransform, 0, _logger);

    if (fresadaIntersect.Count > 0)
    {
        if (resultsIntersect == null)
            resultsIntersect = fresadaIntersect;
        else
            resultsIntersect.Add(fresadaIntersect);
    }
}

Also I've recently tried performing the intersect boolean operation between CAVITAT solids and XPS solids directly to the initial IFC model (without any transformation) and the result is slightly different, in this case, I only lose the two cylinders. So the behaviour is driving me mad since it seems totally random to me.
image

from xbimgeometry.

ar98nau avatar ar98nau commented on August 19, 2024

Hi @andyward ,
I was hoping to have some news about this issue. If there's something I can do or the information provided isn't enough just tell me.

Thanks in advance.

from xbimgeometry.

andyward avatar andyward commented on August 19, 2024

Sorry, this is too hard to diagnose from the above. It needs a solution someone can debug. I'd create a minimal working project demonstrating the issue. I.e. in this case select two elements that you expect to intersect but maybe don't. Perhaps build up some unit tests to check your assumptions?

from xbimgeometry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.