################################################################################
# 3. Object is not compatible and cannot convert himself to a compatible one.
# In this case, we define an adapter and register it.
# Once registered, Viewer can use it automatically
# Here, adapter is defined and register in module but that could be done via plugins.
################################################################################

# Define and register adapter. (generally defined in a separated plugin)
from openalea.oalab.service.geometry import register_shape3d


def to_shape3d(obj):
    if isinstance(obj, PlantFrame):
        return pf.plot(gc=True, display=False)
register_shape3d(PlantFrame, to_shape3d)

# Create object (small tree)
g = MTG(data / 'noylum2.mtg')
dressing_data = dresser.DressingData(DiameterUnit=10)
pf = PlantFrame(g, TopDiameter='TopDia', DressingData=dressing_data)

# Add it to world
world['obj3'] = pf
world['obj3'].displayed = True
world['obj3'].repr = 'geom'

world['i1'] = 1


def init():
Esempio n. 2
0

class MyObject(object):
    def __init__(self, n):
        self.points = numpy.random.randn(n, 3) * 100
        self.colors = zip(
            numpy.random.randint(0, 255, n).tolist(),
            numpy.random.randint(0, 255, n).tolist(),
            numpy.random.randint(0, 255, n).tolist())


def myobjectIn3d(obj):
    return PointSet(obj.points, colorList=Color4Array(map(Color4, obj.colors)))


register_shape3d(MyObject, myobjectIn3d)

if __name__ == '__main__':

    from openalea.vpltk.qt import QtGui
    instance = QtGui.QApplication.instance()
    if instance is None:
        app = QtGui.QApplication([])
    else:
        app = instance

    t = MyObject(100)
    Viewer.display(to_shape3d(t))

    if instance is None:
        app.exec_()
Esempio n. 3
0
from openalea.plantgl.all import Viewer, PointSet, Color4Array, Color4
import numpy

from openalea.oalab.service.geometry import to_shape3d, register_shape3d

class MyObject(object):
    def __init__(self, n):
        self.points = numpy.random.randn(n, 3) * 100
        self.colors = zip(numpy.random.randint(0, 255, n).tolist(),
                          numpy.random.randint(0, 255, n).tolist(),
                          numpy.random.randint(0, 255, n).tolist())

def myobjectIn3d(obj):
    return PointSet(obj.points, colorList=Color4Array(map(Color4, obj.colors)))

register_shape3d(MyObject, myobjectIn3d)

if __name__ == '__main__':

    from openalea.vpltk.qt import QtGui
    instance = QtGui.QApplication.instance()
    if instance is None :
        app = QtGui.QApplication([])
    else :
        app = instance

    t = MyObject(100)
    Viewer.display(to_shape3d(t))

    if instance is None :
        app.exec_()
Esempio n. 4
0
# Add it to world
world['obj2'] = b

################################################################################
# 3. Object is not compatible and cannot convert himself to a compatible one.
# In this case, we define an adapter and register it.
# Once registered, Viewer can use it automatically
# Here, adapter is defined and register in module but that could be done via plugins.
################################################################################

# Define and register adapter. (generally defined in a separated plugin)
from openalea.oalab.service.geometry import register_shape3d
def to_shape3d(obj):
    if isinstance(obj, PlantFrame):
        return pf.plot(gc=True, display=False)
register_shape3d(PlantFrame, to_shape3d)

# Create object (small tree)
g = MTG(data / 'noylum2.mtg')
dressing_data = dresser.DressingData(DiameterUnit=10)
pf = PlantFrame(g, TopDiameter='TopDia', DressingData=dressing_data)

# Add it to world
world['obj3'] = pf
world['obj3'].displayed = True
world['obj3'].repr = 'geom'

world['i1'] = 1

def init():
  del world['i1'], world['obj1'], world['obj2'], world['obj3']