Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting cell data #105

Open
adofarsi opened this issue Apr 2, 2021 · 2 comments
Open

Supporting cell data #105

adofarsi opened this issue Apr 2, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@adofarsi
Copy link

adofarsi commented Apr 2, 2021

Similarly to point data, could you also support cell data?
It would be great if when loading a mesh from memory, I could manually pass cell data, i.e. data associated with the tetrahedra for a tetrahedral mesh. For instance if I wanted to colour my mesh with the element id number, this is something that I cannot do with point data. Similarly, when importing a vtk file that includes both point and cell data, being able to import both and visualise cell data would be amazing.

Thanks a lot for your time!

Best,

Ado

@martinRenou
Copy link
Collaborator

That would be nice indeed :)

@martinRenou martinRenou added the enhancement New feature or request label Apr 2, 2021
@dschwoerer
Copy link

dschwoerer commented Jun 1, 2021

With this small script you can plot cell data:

import meshio
import ipygany
import numpy as np


def readcelldata(fn):
    msh = meshio.read(fn)
    indices = msh.cells[0]
    shp = indices.data.shape
    indices = indices.data.flatten()
    assert len(shp) == 2
    length = shp[0] * shp[1]
    indnew = np.arange(length, dtype=int)
    vert = np.empty((length, 3))
    datas = np.empty((length, len(msh.cell_data)))
    datold = np.array(list(msh.cell_data.values()))[:, 0, :]
    for i in range(length):
        vert[i] = msh.points[indices[i]]
        datas[i] = datold[:, i // shp[1]]
    datnew = {
        v: [ipygany.Component(name="value", array=datas[:, i])]
        for i, v in enumerate(msh.cell_data.keys())
    }
    return ipygany.PolyMesh(vert, indnew.reshape(shp), datnew)

However, proper support would be nice, because it isn't very efficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants