drufat / triangle

Python bindings to the triangle library
GNU Lesser General Public License v3.0
224 stars 53 forks source link

point attributes not properly implemented #6

Closed jfloyd99 closed 4 years ago

jfloyd99 commented 8 years ago

A couple of changes needed to work with vertex attributes fully. This allows an attribute such as depth to be attached to a vertex and on each extra vertex insertion the attribute is interpolated by triangle. Not working at the moment. The example I worked with was 'A'. It (not sure why) ignored the attributes. Didnt realise till I made changes to the 2013 code that there was a git repository. These dont seem to be fixed in that repository.

Other wise this is a great way to access triangle through python.

need to add to the fields variable in init

          ('pointattributelist', 'vertex_attributes', 'double', 1),

so that attributes are passed in. We also need to skip the dimension test part later because attributes can be any dimension * no_of_points. Flattened arrays are passed backwards and forwards.

for n0, n1, _, d in fields:
    try:
        value = np.array(getattr(b, n0))
    except ValueError:
        continue
    print 'output reshape',n1,value.shape
    if n1=='vertex_attributes':                                           <<<<<< this skips an upfront definition - could be hard coded as 'variable' in fields.

        d=value.shape[0]/len(r['vertices'])
    r[n1] = value.reshape((-1,d))

return r

In core.pyx need to modify the definition property pointattributelist: def get(self): return <double[:self.c.numberofpoints*self.c.numberofpointattributes]> self.c.pointattributelist def set(self, double[:] value):

assert value.size == self.c.numberofpoints

        replace_d(&(self.c.pointattributelist), value)
        self.c.numberofpointattributes = value.size/self.c.numberofpoints

This latter modification allows multi attributes at each vertex. It deals with total size of the attribute which will be self.c.numberofpoints*self.c.numberofpointattributes.

drufat commented 8 years ago

Thanks for the bug report. I am currently quite busy, but feel free to submit a merge request with your proposed changes.

drufat commented 4 years ago

I think this issues has been addressed in the latest release. Feel free to reopen if not.