Code Monkey home page Code Monkey logo

Comments (4)

Grantim avatar Grantim commented on June 3, 2024

Hello!

Could you please provide meshes so we can reproduce the issue on our end?

from meshlib.

tobias-scheepers avatar tobias-scheepers commented on June 3, 2024

Sure thing. Please see the example below:

from meshlib import mrmeshpy as mm
from meshlib import mrmeshnumpy as mn

def get_inside(mesh_a, mesh_b):
    bOperation = mm.BooleanOperation.InsideA
    bResMapper = mm.BooleanResultMapper()
    bResult = mm.boolean(mesh_a, mesh_b, bOperation, None, bResMapper)

    inner_faces = bResMapper.map(mesh_a.topology.getValidFaces(), mm.BooleanResMapObj.A)
    inner_verts = bResMapper.map(mesh_a.topology.getValidVerts(), mm.BooleanResMapObj.A)
    
    return mn.getNumpyBitSet(inner_faces), mn.getNumpyBitSet(inner_verts)

torusIntersected = mm.makeTorusWithSelfIntersections(2, 1, 10, 10, None)
mm.fixSelfIntersections(torusIntersected, 0.1)

torus = mm.makeTorus(2, 1, 10, 10, None)

transVector = mm.Vector3f()
transVector.x = 0.5
transVector.y = 1
transVector.z = 1

diffXf = mm.AffineXf3f.translation(transVector)

torus2 = mm.makeTorus(2, 1, 10, 10, None)
torus2.transform(diffXf)

print(f"Valid faces: {torus.topology.getValidFaces().size()}")
print(f"Valid verts: {torus.topology.getValidVerts().size()}")

inside_faces, inside_verts = get_inside(mesh_a=torus, mesh_b=torus2)

print(f"Inside faces: {inside_faces.size}")
print(f"Inside verts: {inside_verts.size}")

print(inside_faces)
print(inside_verts)

Which outputs the following:

Valid faces: 200
Valid verts: 100
Inside faces: 154
Inside verts: 25
[ True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True]
[ True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True]

What I'd expected was the that the outputted bitsets would be the same length as that of getValidFaces and getValidVerts but with boolean values indicating if face or vertices comply with the boolean operation.

from meshlib.

Grantim avatar Grantim commented on June 3, 2024

Thanks!

Now I understand the problem, really BooleanResultMapper.map functions return BitSets of result mesh that correspond to given BitSet. As I understand you need to filter torus.topology.getValidFaces()

There are maps that allow to do it in c++

auto validFaces = torus.topology.getValidFaces();
const auto& cut2originMap = mapper.maps[int(BooleanResultMapper::MapObject::A)].cut2origin;
const auto& cut2newMap = mapper.maps[int(BooleanResultMapper::MapObject::A)].cut2newFaces;
for ( int i = 0; i < cut2originMap.size(); ++i )
{
    auto orgFace = cut2originMap[FaceId(i)];
    if ( !orgFace.valid() )
        continue;
    if ( !cut2newMap[FaceId(i)].valid() )
        validFaces.reset( orgFace );
} 

Unfortunately these maps are not exposed to python yet, we will expose them, an maybe add special functions in Mapper class.

For now there is workaround

def get_inside(mesh_a, mesh_b):
    bOperation = mm.BooleanOperation.InsideA
    bResMapper = mm.BooleanResultMapper()
    bResult = mm.boolean(mesh_a, mesh_b, bOperation, None, bResMapper)

    inner_faces = mesh_a.topology.getValidFaces()
    for f in inner_faces:
        bs = mm.FaceBitSet()
        bs.resize( f.get()+1)
        bs.set(f)
        if (bResMapper.map(bs, mm.BooleanResMapObj.A).count() == 0):
            inner_faces.set(f,False)
    inner_verts = mesh_a.topology.getValidVerts()
    for v in inner_verts:
        bs = mm.VertBitSet()
        bs.resize( v.get()+1)
        bs.set(v)
        if (bResMapper.map(bs, mm.BooleanResMapObj.A).count() == 0):
            inner_verts.set(v,False)
    
    return mn.getNumpyBitSet(inner_faces), mn.getNumpyBitSet(inner_verts)

surely it will do a lot of excessive computations, but it is easiest way to implement it right now

from meshlib.

tobias-scheepers avatar tobias-scheepers commented on June 3, 2024

Got it! Indeed see where this is coming from now!

from meshlib.

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.