Beispiel #1
0
    def solve(self, niter):
        s = shapeopPython.shapeop_create()

        # Doesn't seem that we could just create a doubleArray that references the
        # same underlying data
        array = shapeopPython.doubleArray(self.data.shape[0] * self.npoints)
        for y in xrange(self.data.shape[0]):
            for x in xrange(self.npoints):
                array[self.data.shape[0] * x + y] = self.data[y, x]
        shapeopPython.shapeop_setPoints(s, array, self.npoints)

        for c, w in self.constraints:
            ids = shapeopPython.intArray(len(c.args))
            for i in xrange(len(c.args)):
                ids[i] = c.args[i]
            shapeopPython.shapeop_addConstraint(s, c.__cname__, ids,
                                                len(c.args), w)

        shapeopPython.shapeop_init(s)
        shapeopPython.shapeop_solve(s, niter)
        shapeopPython.shapeop_getPoints(s, array, self.npoints)
        shapeopPython.shapeop_delete(s)

        # np might be more willing to convert from raw memory, but we'll just
        # copy it back to the data manually
        for y in xrange(self.data.shape[0]):
            for x in xrange(self.npoints):
                self.data[y, x] = array[self.data.shape[0] * x + y]
Beispiel #2
0
def main():
  #create points with the swig doubleArray proxy
  #http://www.swig.org/Doc3.0/SWIGDocumentation.html#Library_carrays
  p = shapeopPython.doubleArray(12) #column major
  p[0] = 0.; p[3] = 0.5; p[6] = 0.5; p[9] = 0.;
  p[1] = 0.; p[4] = 0.; p[7] = 1.; p[10] = 1.;
  p[2] = 0.; p[5] = 1.; p[8] = 0.; p[11] = 1.;
  print "Input points:"
  printArray(p, 4)
  s=shapeopPython.shapeop_create()
  shapeopPython.shapeop_setPoints(s, p, 4)
  weight = 1.
  #add a plane constraint to all the vertices.
  ids = shapeopPython.intArray(4)
  ids[0] = 0; ids[1] = 1; ids[2] = 2; ids[3] = 3;
  shapeopPython.shapeop_addConstraint(s, "Plane", ids, 4, weight)
  #add a closeness constraint to the 1st vertex.
  ids = shapeopPython.intArray(1)
  ids[0] = 0;
  shapeopPython.shapeop_addConstraint(s, "Closeness", ids, 1, weight)
  #add a closeness constraint to the 4th vertex.
  ids = shapeopPython.intArray(1)
  ids[0] = 3;
  shapeopPython.shapeop_addConstraint(s, "Closeness", ids, 1, weight)
  shapeopPython.shapeop_init(s)
  shapeopPython.shapeop_solve(s, 10)
  shapeopPython.shapeop_getPoints(s, p, 4)
  shapeopPython.shapeop_delete(s)
  print "Output points:"
  printArray(p, 4)
Beispiel #3
0
def main():
    #create points with the swig doubleArray proxy
    #http://www.swig.org/Doc3.0/SWIGDocumentation.html#Library_carrays
    p = shapeopPython.doubleArray(12)  #column major
    p[0] = 0.
    p[3] = 0.5
    p[6] = 0.5
    p[9] = 0.
    p[1] = 0.
    p[4] = 0.
    p[7] = 1.
    p[10] = 1.
    p[2] = 0.
    p[5] = 1.
    p[8] = 0.
    p[11] = 1.
    print "Input points:"
    printArray(p, 4)
    s = shapeopPython.shapeop_create()
    shapeopPython.shapeop_setPoints(s, p, 4)
    weight = 1.
    #add a plane constraint to all the vertices.
    ids = shapeopPython.intArray(4)
    ids[0] = 0
    ids[1] = 1
    ids[2] = 2
    ids[3] = 3
    shapeopPython.shapeop_addConstraint(s, "Plane", ids, 4, weight)
    #add a closeness constraint to the 1st vertex.
    ids = shapeopPython.intArray(1)
    ids[0] = 0
    shapeopPython.shapeop_addConstraint(s, "Closeness", ids, 1, weight)
    #add a closeness constraint to the 4th vertex.
    ids = shapeopPython.intArray(1)
    ids[0] = 3
    shapeopPython.shapeop_addConstraint(s, "Closeness", ids, 1, weight)
    shapeopPython.shapeop_init(s)
    shapeopPython.shapeop_solve(s, 10)
    shapeopPython.shapeop_getPoints(s, p, 4)
    shapeopPython.shapeop_delete(s)
    print "Output points:"
    printArray(p, 4)
Beispiel #4
0
 def add_closeness_constraint(self, vertex, weight):
     vertices_array = int_array([vertex])
     return shapeopPython.shapeop_addConstraint(self.solver, 'Closeness', vertices_array, 1, weight)
Beispiel #5
0
 def add_circle_constraint(self, vertices, weight):
     vertices_array = int_array(vertices)
     return shapeopPython.shapeop_addConstraint(self.solver, 'Circle', vertices_array, len(vertices), weight)
Beispiel #6
0
 def add_plane_constraint(self, vertices, weight):
     vertices_array = int_array(vertices)
     constraint_id = shapeopPython.shapeop_addConstraint(self.solver, 'Plane', vertices_array, len(vertices), weight)
     return constraint_id