Exemplo n.º 1
0
 def __init__(self, func=None, nx=10, ny=10, extraVars=()):
     self.function = ParametrizedFunction(func, extraVars)
     if self.function.argCount() < 2:
         raise (TypeError, "function %s needs at least 2 arguments" % func)
     self.vectorFieldFunc = None
     self.coordinates = SoCoordinate3()
     self.mesh = make_hideable(SoQuadMesh())
     self.mesh.verticesPerColumn = nx
     self.mesh.verticesPerRow = ny
     normal_binding = SoNormalBinding()
     normal_binding.value = SoNormalBinding.PER_VERTEX_INDEXED
     ## ============================
     self.scale = SoScale()
     self.lineSetX = make_hideable(SoLineSet(), show=False)
     self.lineSetY = make_hideable(SoLineSet(), show=False)
     self.linesetYcoor = SoCoordinate3()
     self.lineColor = SoMaterial()
     self.lineColor.diffuseColor = (1, 0, 0)
     ## ============================
     self.root = SoSeparator()
     self.root.addChild(normal_binding)
     self.root.addChild(self.scale)
     self.root.addChild(self.coordinates)
     self.root.addChild(self.mesh.root)
     self.root.addChild(self.lineColor)
     self.root.addChild(self.lineSetX.root)
     self.root.addChild(self.linesetYcoor)
     self.root.addChild(self.lineSetY.root)
Exemplo n.º 2
0
 def __init__(self, func=None, nx=10, ny=10, extraVars=()):
     self.function = ParametrizedFunction(func, extraVars)
     if self.function.argCount() < 2:
         raise (TypeError, "function %s needs at least 2 arguments" % func)
     self.vectorFieldFunc = None
     self.coordinates = SoCoordinate3()
     self.mesh = make_hideable(SoQuadMesh())
     self.mesh.verticesPerColumn = nx
     self.mesh.verticesPerRow = ny
     normal_binding = SoNormalBinding()
     normal_binding.value = SoNormalBinding.PER_VERTEX_INDEXED
     ## ============================
     self.scale = SoScale()
     self.lineSetX = make_hideable(SoLineSet(), show=False)
     self.lineSetY = make_hideable(SoLineSet(), show=False)
     self.linesetYcoor = SoCoordinate3()
     self.lineColor = SoMaterial()
     self.lineColor.diffuseColor = (1, 0, 0)
     ## ============================
     self.root = SoSeparator()
     self.root.addChild(normal_binding)
     self.root.addChild(self.scale)
     self.root.addChild(self.coordinates)
     self.root.addChild(self.mesh.root)
     self.root.addChild(self.lineColor)
     self.root.addChild(self.lineSetX.root)
     self.root.addChild(self.linesetYcoor)
     self.root.addChild(self.lineSetY.root)
Exemplo n.º 3
0
class Quad(object):
    """A Mesh"""
    def __init__(self, func=None, nx=10, ny=10, extraVars=()):
        self.function = ParametrizedFunction(func, extraVars)
        if self.function.argCount() < 2:
            raise (TypeError, "function %s needs at least 2 arguments" % func)
        self.vectorFieldFunc = None
        self.coordinates = SoCoordinate3()
        self.mesh = make_hideable(SoQuadMesh())
        self.mesh.verticesPerColumn = nx
        self.mesh.verticesPerRow = ny
        normal_binding = SoNormalBinding()
        normal_binding.value = SoNormalBinding.PER_VERTEX_INDEXED
        ## ============================
        self.scale = SoScale()
        self.lineSetX = make_hideable(SoLineSet(), show=False)
        self.lineSetY = make_hideable(SoLineSet(), show=False)
        self.linesetYcoor = SoCoordinate3()
        self.lineColor = SoMaterial()
        self.lineColor.diffuseColor = (1, 0, 0)
        ## ============================
        self.root = SoSeparator()
        self.root.addChild(normal_binding)
        self.root.addChild(self.scale)
        self.root.addChild(self.coordinates)
        self.root.addChild(self.mesh.root)
        self.root.addChild(self.lineColor)
        self.root.addChild(self.lineSetX.root)
        self.root.addChild(self.linesetYcoor)
        self.root.addChild(self.lineSetY.root)

    def getLinesVisible(self):
        return self.lineSetX.visible

    def setLinesVisible(self, visible):
        self.lineSetX.visible = visible
        self.lineSetY.visible = visible

    linesVisible = property(getLinesVisible, setLinesVisible)

    @property
    def verticesPerColumn(self):
        return self.mesh.verticesPerColumn.getValue()

    @property
    def verticesPerRow(self):
        return self.mesh.verticesPerRow.getValue()

    def addVectorField(self, func):
        self.vectorFieldFunc = func

    def update(self, rangeX, rangeY):
        vertices = range(len(rangeX) * len(rangeY))
        malla(vertices, self.function, rangeX.min, rangeX.dt, len(rangeX),
              rangeY.min, rangeY.dt, len(rangeY))
        self.coordinates.point.setValues(0, len(vertices), vertices)
        ## ============================
        ## the lines
        vpc = self.verticesPerColumn
        vpr = self.verticesPerRow
        lstX = tuple(itertools.repeat(vpr, vpc))
        lstY = tuple(itertools.repeat(vpc, vpr))
        self.lineSetX.numVertices.setValues(
            lstX)  # we need the "transpose of the first list
        verticesY = []
        for i in range(vpr):
            for j in range(vpc):
                verticesY.append(vertices[j * vpr + i])
        self.linesetYcoor.point.setValues(0, len(verticesY), verticesY)
        self.lineSetY.numVertices.setValues(lstY)
Exemplo n.º 4
0
class Quad(object):
    """A Mesh"""

    def __init__(self, func=None, nx=10, ny=10, extraVars=()):
        self.function = ParametrizedFunction(func, extraVars)
        if self.function.argCount() < 2:
            raise (TypeError, "function %s needs at least 2 arguments" % func)
        self.vectorFieldFunc = None
        self.coordinates = SoCoordinate3()
        self.mesh = make_hideable(SoQuadMesh())
        self.mesh.verticesPerColumn = nx
        self.mesh.verticesPerRow = ny
        normal_binding = SoNormalBinding()
        normal_binding.value = SoNormalBinding.PER_VERTEX_INDEXED
        ## ============================
        self.scale = SoScale()
        self.lineSetX = make_hideable(SoLineSet(), show=False)
        self.lineSetY = make_hideable(SoLineSet(), show=False)
        self.linesetYcoor = SoCoordinate3()
        self.lineColor = SoMaterial()
        self.lineColor.diffuseColor = (1, 0, 0)
        ## ============================
        self.root = SoSeparator()
        self.root.addChild(normal_binding)
        self.root.addChild(self.scale)
        self.root.addChild(self.coordinates)
        self.root.addChild(self.mesh.root)
        self.root.addChild(self.lineColor)
        self.root.addChild(self.lineSetX.root)
        self.root.addChild(self.linesetYcoor)
        self.root.addChild(self.lineSetY.root)

    def getLinesVisible(self):
        return self.lineSetX.visible

    def setLinesVisible(self, visible):
        self.lineSetX.visible = visible
        self.lineSetY.visible = visible

    linesVisible = property(getLinesVisible, setLinesVisible)

    @property
    def verticesPerColumn(self):
        return self.mesh.verticesPerColumn.getValue()

    @property
    def verticesPerRow(self):
        return self.mesh.verticesPerRow.getValue()

    def addVectorField(self, func):
        self.vectorFieldFunc = func

    def update(self, rangeX, rangeY):
        vertices = range(len(rangeX) * len(rangeY))
        malla(vertices, self.function, rangeX.min, rangeX.dt, len(rangeX), rangeY.min, rangeY.dt, len(rangeY))
        self.coordinates.point.setValues(0, len(vertices), vertices)
        ## ============================
        ## the lines
        vpc = self.verticesPerColumn
        vpr = self.verticesPerRow
        lstX = tuple(itertools.repeat(vpr, vpc))
        lstY = tuple(itertools.repeat(vpc, vpr))
        self.lineSetX.numVertices.setValues(lstX)  # we need the "transpose of the first list
        verticesY = []
        for i in range(vpr):
            for j in range(vpc):
                verticesY.append(vertices[j * vpr + i])
        self.linesetYcoor.point.setValues(0, len(verticesY), verticesY)
        self.lineSetY.numVertices.setValues(lstY)