X-Git-Url: http://pileus.org/git/?p=~andy%2Fcs275-proj;a=blobdiff_plain;f=src%2Ftest.py;fp=src%2Ftest.py;h=3332487c9620a384858bdfef0beef88bc66c1f52;hp=0000000000000000000000000000000000000000;hb=3ce798e5876d96b2d121973a3d41181504659174;hpb=425aef5873feebdbd0fe0614a86788a3194ca053 diff --git a/src/test.py b/src/test.py new file mode 100755 index 0000000..3332487 --- /dev/null +++ b/src/test.py @@ -0,0 +1,95 @@ +#!/bin/env python + +# Dependencies: +# PyQt4 + +import sys + +from OpenGL.GL import * + +from PyQt4.Qt import QApplication, QMainWindow, QLabel +from PyQGLViewer import QGLViewer, Vec + +from openalea.lpy import Lsystem +from openalea.plantgl.all import Discretizer, GLRenderer + +# Qt Plant Viewer +class Viewer(QGLViewer): + def __init__(self, lfile): + QGLViewer.__init__(self) + + center = Vec(0.16104, 0.00831, 2.53128) + position = Vec(4.74832, 4.66647, 8.79487) + + self.discretizer = Discretizer() + self.renderer = GLRenderer(self.discretizer) + self.lsystem = Lsystem(lfile) + self.scene = self.lsystem.sceneInterpretation(self.lsystem.iterate()) + + camera = self.camera() + camera.setRevolveAroundPoint(center) + camera.setPosition(position) + camera.setUpVector(Vec(0,0,1)) + camera.lookAt(center) + camera.setSceneRadius(7) + + def draw(self): + light_pos = list(self.camera().position())+[1.0] + light_dir = list(self.camera().viewDirection())+[1.0] + + glEnable(GL_LIGHTING) + glEnable(GL_LIGHT0) + + glLightfv(GL_LIGHT0, GL_POSITION, light_pos) + glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_dir) + glLightfv(GL_LIGHT0, GL_AMBIENT, (0.6,0.6,0.6,1.0)) + glLightfv(GL_LIGHT0, GL_DIFFUSE, (1.0,1.0,1.0,1.0)) + glLightfv(GL_LIGHT0, GL_SPECULAR, (1.0,1.0,1.0,1.0)) + + if self.renderer.beginSceneList(): + glEnable(GL_RESCALE_NORMAL) + self.scene.apply(self.renderer) + self.renderer.endSceneList() + +# Test Qt +class TestQt: + def __init__(self, args): + self.args = args; + + def run(self): + app = QApplication(self.args) + win = QMainWindow() + btn = QLabel("Hello, World"); + + win.setCentralWidget(btn) + win.resize(800,600) + win.show() + + app.exec_() + +# Test PlantGL +class TestPlantGL: + def __init__(self, args): + self.args = args; + + def run(self): + app = QApplication(self.args) + win = QMainWindow() + view = Viewer("plant.lpy"); + + win.setCentralWidget(view) + win.resize(800,600) + win.show() + + app.exec_() + +# Main +for test in sys.argv[1:]: + + if test == 'qt': + qt = TestQt(sys.argv) + qt.run() + + if test == 'plantgl' or test == 'pgl': + pgl = TestPlantGL(sys.argv) + pgl.run()