Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • openmesh-python openmesh-python
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenMeshOpenMesh
  • openmesh-pythonopenmesh-python
  • Issues
  • #16
Closed
Open
Issue created Mar 26, 2018 by Janis Born@bornMaintainer

convenience features for set_*_property_array methods

You need to call set_*_property_array in order to initialize a property as a 'numpy property', e.g.:

m.set_vertex_property_array('test', np.zeros(m.n_vertices(), 3))

Constructing the second argument can be a bit tedious and I'd like to simplify it by broadening the interface of the set_*_property_array methods a bit, allowing the following calls:

# the old interface: explicitly setting all values at once;
# data.shape[0] must be equal to the number of elements
m.set_vertex_property_array('test', data)

# setting the same value for each element, e.g. the vector [1,2,3]
m.set_vertex_property_array('test', element_value=[1,2,3])

# setting the same value for each element with a specific shape
# e.g. a 3x3 matrix filled with 4's
# (4 is broadcasted to the 3x3 shape to fill the matrix)
m.set_vertex_property_array('test', element_shape=(3,3), element_value=4)

# creating an uninitialized data array with a specific shape for each element:
m.set_vertex_property_array('test', element_shape=(3,3))

# creating an uninitialized data array with space for a scalar value for each element:
# (common use case)
m.set_vertex_property_array('test')

You can try out this interface by applying the following monkeypatch snippet:

orig_set_vertex_property_array = om.TriMesh.set_vertex_property_array

def svpa(self, prop_name, array=None, element_shape=None, element_value=None):
    if element_shape is None:
        if element_value is None:
            element_shape = ()
        else:
            element_shape = np.shape(element_value)
    if array is None:
        if element_value is None:
            orig_set_vertex_property_array(self, prop_name, np.empty((self.n_vertices(), *element_shape)))
        else:
            orig_set_vertex_property_array(self, prop_name, np.array(np.broadcast_to(element_value, (self.n_vertices(), *element_shape))))
    else:
        assert element_value is None, 'both array and element_value are set'
        orig_set_vertex_property_array(self, prop_name, np.reshape(array, (self.n_vertices(), *element_shape)))

om.TriMesh.set_vertex_property_array = svpa

I'm currently not sure whether it's better to implement this on the C++ or Python side. Python code likely makes it easier to use numpy features like broadcast_to and reshape but I don't know how to deduplicate the code for the different mesh types and mesh elements.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking