Coder Social home page Coder Social logo

meshzoo's People

Contributors

nschloe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meshzoo's Issues

meshzoo.cube cells have 4 vertices

When generating a cube as in the readme:

points, cells = meshzoo.cube(
    xmin=0.0, xmax=1.0,
    ymin=0.0, ymax=1.0,
    zmin=0.0, zmax=1.0,
    nx=11, ny=11, nz=11
)

I noticed that the cells array contains 4 points.

>>> cells.shape
(5000, 4)

In the picture from the readme it seems to be made up of triangles.

Is there a version of meshzoo.cube that meshes the cube in terms of triangles?

Sorry if I am misunderstanding,
thanks

Insert mid-nodes for quadratic elements?

Hi Nico,

nice zoo 🐺 🐸 🐯 🐨 🐻.

Does meshzoo support the generation of higher-order quadratic (edge-based) meshes? With "quadratic" I mean e.g. the (bi-) quadratic quads, triangles, hexahedrons or tetrahedrons from VTK. Or do you know any open source python package that can handle this task? Ideally not only the creation of mid-side nodes but also some kind of removing duplicated nodes. I just wanted to ask before doing it myself.

Thanks!

Best regards,
Andreas

icosa_sphere vertex adjacencies?

Hello,

Thank you for meshzoo. It's a very cool library.

For my project I am building an array of vertex adjacencies for an icosa_sphere and I was wondering if there is any structure or pattern with the order of vertex indices in the cells array in relation to a vertex's neighbors. (Aside from the 3 verts in each cell winding counter-clockwise, that is.)

In other words, given any vertex index on a sphere of any level of subdivision, could there be a simple function to get the indices of its 5 or 6 neighbors in either a consistent clockwise or consistent counter-clockwise manner?

For example say we provide the index of vertex 38 as in the below screenshot, could we get its neighbors (starting from any neighbor, let's say vertex 2) from meshzoo's cells array and output like [2, 28, 12, 3, 23, 40] or like [2, 40, 23, 3, 12, 28]?

icosa_sphere with n == 2
image

Thanks.

p.s. Have you ever considered adding numba @jit / @njit decorators in meshzoo?

cube_quad?

Hello!

First, awesome project!

I was wondering if you had an idea of how to implement a cube_quad. I can think of a handful of ways, but none seem efficient.

This would really just be the outer shell of a cube, but still very useful!

Thanks again!

Cell order not consistent with normals

For a given cell (p1, p2, p3) with a normal n, then typical convention is that:

dot(cross(p2-p1, p3 - p2), n) > 0

The cell ordering is inconsistent for many of the functions such as tetra_sphere, octa_sphere, uv_sphere (from what I've tested) and possibly more.

Since all of the sphere normals are equal to the positions, then a simple fix would be:

fixed_cells = []
for cell in cells:
            p1 = points[cell[0], :]
            p2 = points[cell[1], :]
            p3 = points[cell[2], :]
            n = normals[cell[0], :]
            if np.dot(np.cross(p2 - p1, p3 - p2), n) < 0:
                fixed_cells.append([cell[2], cell[1], cell[0]])
            else:
                fixed_cells.append(cell[0], cell[1], cell[2])

Did you delete version from PyPI ?

I've been scratching my head on CI failure on napari, and realise that no version of meshzoo<0.10 are available on PyPI. I was just wondering if this was purposeful.

Some cells of tet meshes have negative volumes

If the cell volumes of a tet mesh are calculated by the triple product of edge vectors (see https://en.wikipedia.org/wiki/Tetrahedron#Volume) it seems that the cell connectivity of meshzoo leads to some negative cell volumes. Should this be fixed? Let's have a look at the following code snippet. First, I'll define a (nice and fast 😎) function for the volume calculation of tet cells.

import numpy as np

def cell_volumes_tetra(points, cells):
    "Calculate cell volumes of tetrahedrons."

    # extract point no. 0 of all cells and reshape
    p0 = points[cells][:, 0].reshape(len(cells), 1, 3)
    
    # calculate edge vectors "i" as v[:, i] for all cells
    edges = (points[cells] - np.repeat(p0, 4, axis=1))[:, 1:]
    
    # evaluate cell volumes by the triple product
    # cyclic permutations lead to identical results (0,1,2), (1,2,0), (2,0,1)
    cell_volumes = np.einsum("...i,...i->...", edges[:, 0], 
                             np.cross(edges[:, 1], edges[:, 2])) / 6

    return cell_volumes

Next, let's define a tet mesh.

import meshzoo

points, cells = meshzoo.cube_tetra(a0=(0,0,0), a1=(1,1,1), n=2)

and evaluate volumes...

volumes = cell_volumes_tetra(points, cells)

volumes
# >>> array([-0.16666667, -0.16666667, -0.33333333, -0.16666667, -0.16666667])

volumes.sum()
# >>> -0.9999999999999999

A simple fix would be to swap two colums of the cells array for cells with negative volumes.

# easy fix of negative volumes
# permute point entries for cells with volume < 0
cells[volumes < 0] = cells[volumes < 0][:, [0, 2, 1, 3]]

# check again
volumes = cell_volumes_tetra(points, cells)
# >>>array([0.16666667, 0.16666667, 0.33333333, 0.16666667, 0.16666667])

volumes
# >>> array([0.16666667, 0.16666667, 0.33333333, 0.16666667, 0.16666667])

volumes.sum()
# >>> .9999999999999999

What do you think @nschloe?

rectangle quad with ny > 1 result in incorrect faces

I was drawing some rectangles, but I ended up drawing the wrong edges. It turns out this is due to the a array in _rectangle.py needing to be incremented by the row number. I'll submit a PR promptly.

MWE

import meshzoo

points, cells = meshzoo.rectangle_quad((0.0, 0.0), (1.0, 1.0), n=2)

This results the following cells:

array([[0, 1, 4, 3],  # ok
       [2, 3, 6, 5],  # should be [3, 4, 7, 6]
       [1, 2, 5, 4],  # ok
       [3, 4, 7, 6]])  # should be [4, 5, 8, 7]

It's obvious something is wrong -- even without making a quick drawing. n=2 results in 9 vertices, but the highest index in cells is 7.

It's easily fixed by altering this line:

    a = np.add.outer(np.arange(nx), nx * np.arange(ny))

into

    a = np.add.outer(np.arange(nx), nx * np.arange(ny)) + np.arange(ny)

Meshing cuboid with higher aspect ratio not working

I wanted to create meshed cuboids (with hex and tet meshes) with "high" aspect ratios using meshzoo.cube_hexa() and meshzoo.cube_tetra(). But the meshes are flawed for those higher aspect ratios. Especially if the dimensions differ in all space directions.

I made a little working example:

import meshzoo  # Version 0.9.0
import meshio
import numpy as np

offset = [0.0, 0.0, 0.0]
size = [2.0, 6.0, 1.0]
mesh_size = 0.5

points, _cells = meshzoo.cube_hexa(
    np.linspace(offset[0], offset[0] + size[0], int(round(size[0] / mesh_size)) + 1),
    np.linspace(offset[1], offset[1] + size[1], int(round(size[1] / mesh_size)) + 1),
    np.linspace(offset[2], offset[2] + size[2], int(round(size[2] / mesh_size)) + 1),
)

cells = [("hexahedron", _cells)]

mesh = meshio.Mesh(points, cells)

meshio.vtk.write("cuboid.vtk", mesh)

Is it possible to extend the cube functionality to work with general cuboids?

Feature request: Non uniform structured meshes

I am doing some work to extend the grid options in a scientific code, but would like to
“Test out” structured nonuniform Cartesian, Cylindrical, and Spherical meshes. I haven’t looked deeply if meshzoo has those features but if that is of interest I would like to work on contributing that.

Saving with meshio from cube example doesn't work

I'm trying to use the cube example and then saving to a file like this:

import meshzoo
import numpy as np

points, cells = meshzoo.cube_tetra(
    np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11)
)

# this fails
meshio.write_points_cells("triangle.vtk", points, cells)

fails with

ValueError: too many values to unpack (expected 2)

which is too bad because this is a lovely module

unclear licensing & source code access

I appreciate this package and have been using it for testing some mesh-related stuff, but I am a bit concerned that I don't see any license information here, and no human-readable source-code either.

When I install meshzoo via pip, the module has some binary content which is interpreted via x21.__dex__ function, where x21 is distributed binary-only. Besides wanting to look into meshzoo code as the documentation is not always complete, I have obvious security concerns about binary-only module running on my machine.

I understand someone may not want to disclose sources for their package, yet have the conveniences of pypi as distribution platform, but then the documentation should be explicit about that.

Icosasphere refinement

Hi,
I recently installed your library and used the computed geometries with some differentiable renderers in a 3D object generation pipeline. In particular, I'm interested in the icosasphere as a symmetrical shape. The problem is that the rendered shape is actually an icosahedron with no refinement to obtain an icosasphere. Do you plan to add this refinement operation or have any idea on how to do it correctly?

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.