2014-10-06 22:36:17 +06:00
|
|
|
from netgen.csg import *
|
|
|
|
import netgen.meshing as meshing
|
2014-10-10 17:18:51 +06:00
|
|
|
import libvisual
|
2014-10-06 22:36:17 +06:00
|
|
|
|
|
|
|
from OpenGL.GL import *
|
|
|
|
from OpenGL.GLU import *
|
|
|
|
from OpenGL.GLUT import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sp1 = Sphere (Pnt(0,0,0), 0.2)
|
|
|
|
sp2 = Sphere (Pnt(0.5,0,0), 0.2)
|
|
|
|
|
2014-10-10 17:18:51 +06:00
|
|
|
all = sp1+sp2
|
2014-10-06 22:36:17 +06:00
|
|
|
|
|
|
|
|
|
|
|
geom = CSGeometry()
|
|
|
|
geom.Add (all)
|
|
|
|
|
|
|
|
|
2014-10-10 17:18:51 +06:00
|
|
|
param = meshing.MeshingParameters()
|
|
|
|
param.maxh = 0.1
|
|
|
|
m1 = GenerateMesh (geom, param)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vismesh = libvisual.meshvis.VS(m1)
|
|
|
|
|
2014-10-06 22:36:17 +06:00
|
|
|
vis = VS(geom)
|
|
|
|
# vis.Draw()
|
|
|
|
|
|
|
|
|
|
|
|
window = 0 # glut window number
|
|
|
|
width, height = 500, 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mydraw():
|
|
|
|
vis.Draw()
|
|
|
|
glutSwapBuffers()
|
|
|
|
|
2014-10-07 02:01:44 +06:00
|
|
|
|
2014-10-06 22:36:17 +06:00
|
|
|
xold = -1;
|
|
|
|
yold = -1;
|
|
|
|
mode = 'r'
|
|
|
|
|
|
|
|
def myMotionHandler( x, y ):
|
|
|
|
global xold, yold
|
|
|
|
MouseMove(vis,xold,yold, x,y, mode) # 'm','z'
|
|
|
|
xold = x
|
|
|
|
yold = y
|
2014-10-10 17:18:51 +06:00
|
|
|
glutPostRedisplay()
|
|
|
|
# mydraw()
|
2014-10-06 22:36:17 +06:00
|
|
|
|
|
|
|
def myPassiveMotionHandler( x, y ):
|
|
|
|
global xold, yold
|
|
|
|
xold = x
|
|
|
|
yold = y
|
|
|
|
|
|
|
|
def myMouseHandler( button, state, x, y ):
|
|
|
|
print(button,state,x,y)
|
|
|
|
modes = {0:'r', 1:'m', 2:'z'}
|
|
|
|
global mode
|
|
|
|
if button<3:
|
|
|
|
if state==0:
|
|
|
|
mode = modes[button]
|
|
|
|
else:
|
|
|
|
mode = 'r'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glutInit("mainwin") # initialize glut
|
|
|
|
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
|
|
|
|
glutInitWindowSize(width, height) # set window size
|
|
|
|
glutInitWindowPosition(0, 0) # set window position
|
|
|
|
window = glutCreateWindow(b"ngs") # create window with title
|
2014-10-07 02:01:44 +06:00
|
|
|
|
2014-10-06 22:36:17 +06:00
|
|
|
glutMotionFunc(myMotionHandler)
|
|
|
|
glutMouseFunc(myMouseHandler)
|
|
|
|
glutPassiveMotionFunc(myPassiveMotionHandler)
|
|
|
|
glutDisplayFunc(mydraw) # set draw function callback
|
2014-10-07 02:01:44 +06:00
|
|
|
# glutIdleFunc(mydraw) # draw all the time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
pnear = 0.1;
|
|
|
|
pfar = 10;
|
|
|
|
gluPerspective(20.0, 1.0*width / height, pnear, pfar);
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-10 17:18:51 +06:00
|
|
|
glutMainLoop()
|
|
|
|
|
|
|
|
|
|
|
|
# import threading
|
|
|
|
# threading.start_new_thread (glutMainLoop, [])
|
|
|
|
|
|
|
|
|
|
|
|
# from threading import Thread
|
|
|
|
# thread = Thread(target = glutMainLoop)
|
|
|
|
# thread.start()
|
|
|
|
# thread.join()
|
2014-10-06 22:36:17 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# param = meshing.MeshingParameters(maxh=0.2)
|
|
|
|
# mesh = GenerateMesh (geom, param)
|
|
|
|
# mesh.Save ("test.vol")
|
|
|
|
|