Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r964 - in trunk: SwigInterface UserInterface
- Date: Thu, 2 Mar 2006 14:28:00 -0700 (MST)
Author: bigler
Date: Thu Mar 2 14:27:59 2006
New Revision: 964
Modified:
trunk/SwigInterface/runmanta.py
trunk/UserInterface/XWindowUI.cc
trunk/UserInterface/XWindowUI.h
Log:
SwigInterface/runmanta.py
Added # on blank lines to help when you copy and paste code into the
python shell. The blanks indicate the end of the scope when pasting
in the shell, which isn't what you want to do.
Wrapped some of the more common engine things into functions, so
that you can call them more than once in an interactive shell.
UserInterface/XWindowUI.cc
Fixed indentation.
Added shutdown function which passes a TOKEN_SHUTDOWN to the event
loop that closes the X display and returns from the thread.
Register shutdown() with the termination functions for the manta
engine.
UserInterface/XWindowUI.h
Added shutdown() function.
Modified: trunk/SwigInterface/runmanta.py
==============================================================================
--- trunk/SwigInterface/runmanta.py (original)
+++ trunk/SwigInterface/runmanta.py Thu Mar 2 14:27:59 2006
@@ -14,7 +14,7 @@
checker2 = manta_new(CheckerTexture_ColorComponent(0.2, 0.5,
Vector(1,0,0),
Vector(0,1,0)))
plane_matl = manta_new(Phong(checker1, constant_color1, 32, checker2))
-
+ #
world = manta_new(Group())
floor = manta_new(Parallelogram(plane_matl, Vector(-20,-20,0),
Vector(40,0,0), Vector(0,40,0)))
@@ -23,14 +23,14 @@
world.add(floor)
world.add(manta_new(Sphere(red, Vector(0,0,1.2), 1.0)))
scene.setObject(world)
-
+ #
lights = manta_new(LightSet())
lights.add(manta_new(PointLight(Vector(0,5,8),
Color(RGBColor(.6,.1,.1)))))
lights.add(manta_new(PointLight(Vector(5,0,8),
Color(RGBColor(.1,.6,.1)))))
lights.add(manta_new(PointLight(Vector(5,5,2),
Color(RGBColor(.2,.2,.2)))))
lights.setAmbientLight(manta_new(ConstantAmbient(Color.black())))
print lights
-
+ #
scene.setLights(lights)
scene.getRenderParameters().maxDepth = 5
return scene
@@ -47,11 +47,10 @@
# We can't add the plane to objs, because it doesn't have a proper
# bounding box.
world.add(manta_new(Plane(groundmatl, Vector(0,0,1), Vector(0,0,2.5))))
-
# Metal sphere
ball_matl = manta_new(MetalMaterial(Color(RGBColor(0.8, 0.8, 0.8)), 100))
objs.add(manta_new(Sphere(ball_matl, Vector(-6, 3.5, 3.5), 1.0)))
-
+ #
lenscale = 2.5
glass = Color(RGBColor(pow(0.80, lenscale), pow(0.93, lenscale),
pow(0.87, lenscale)))
for i in range(4):
@@ -61,7 +60,7 @@
corner = Vector(i*1.3 - 4, -3, 2.5+1.e-4);
size = Vector(0.20, 2.5, 1.4);
objs.add(manta_new(Cube(transp_matl, corner, corner+size)))
-
+ #
# Line of rings
ringmatl = manta_new(Lambertian(Color(RGBColor(.6, .6, .9))))
r = .30
@@ -73,45 +72,60 @@
center+offset*i,
Vector(0.2, -1, -0.2),
inner_radius, r-inner_radius)))
-
+ #
# Create a BVH
world.add(manta_new(RealisticBvh(objs.get_objs(), objs.size())))
scene.setObject(world)
-
+ #
lights = manta_new(LightSet())
lights.add(manta_new(PointLight(Vector(20, 30, 100),
Color(RGBColor(.9,.9,.9)))))
lights.add(manta_new(PointLight(Vector(-40, -30, 50),
Color(RGBColor(.3,.1,.1)))))
lights.setAmbientLight(manta_new(ConstantAmbient(Color(RGBColor(.4, .4,
.4)))))
print lights
-
+ #
scene.setLights(lights)
scene.getRenderParameters().maxDepth = 25
scene.getRenderParameters().importanceCutoff = 0.01
-
+ #
return scene
-engine = createManta()
-engine.changeNumWorkers(1)
-engine.selectImageType("rgba8")
-engine.selectLoadBalancer("workqueue")
-engine.selectImageTraverser("tiled")
-engine.selectPixelSampler("singlesample")
-#engine.selectPixelSampler("jittersample(-numberOfSamples 4)")
-engine.selectRenderer("raytracer")
-engine.selectShadowAlgorithm("hard")
-currentCamera = engine.createCamera("pinhole(-eye 3 3 2 -lookat 0 0 0.3 -up
0 0 1 -fov 60)")
-#currentCamera = engine.createCamera("pinhole(-eye 8 -18 8.5 -lookat -4.7
2.5 2.5 -up 0 0 1 -fov 15)")
-xres = 512
-yres = 512
-xinterface = engine.createUserInterface("X")
-xinterface.startup()
-engine.createChannel("opengl", currentCamera, False, xres, yres)
-
-
-#engine.setScene(createDefaultScene())
-engine.setScene(createDefaultScenePython())
-#engine.setScene(createDielectricTestScene())
+def setupDefaultEngine(numworkers):
+ engine = createManta()
+ engine.changeNumWorkers(numworkers)
+ engine.selectImageType("rgba8")
+ engine.selectLoadBalancer("workqueue")
+ engine.selectImageTraverser("tiled")
+ engine.selectPixelSampler("singlesample")
+ #engine.selectPixelSampler("jittersample(-numberOfSamples 4)")
+ engine.selectRenderer("raytracer")
+ engine.selectShadowAlgorithm("hard")
+ #
+ return engine
+
+def addXInterface(engine, camera, xres, yres):
+ xinterface = engine.createUserInterface("X")
+ xinterface.startup()
+ engine.createChannel("opengl", camera, False, xres, yres)
+
+def addNullInterface(engine, camera, xres, yres):
+ ui = engine.createUserInterface("null")
+ ui.startup()
+ engine.createChannel("null", camera, False, xres, yres)
+
+
+engine = setupDefaultEngine(2)
+
+defaultCamera = engine.createCamera("pinhole(-eye 3 3 2 -lookat 0 0 0.3 -up
0 0 1 -fov 60)")
+#defaultCamera = engine.createCamera("pinhole(-eye 8 -18 8.5 -lookat -4.7
2.5 2.5 -up 0 0 1 -fov 15)")
+
+addXInterface(engine, defaultCamera, 512, 512)
+#addNullInterface(engine, defaultCamera, 512, 512)
+
+# scene = createDefaultScene()
+scene = createDefaultScenePython()
+# scene = createDielectricTestScene()
+engine.setScene(scene)
# if __name__ == "__main__":
Modified: trunk/UserInterface/XWindowUI.cc
==============================================================================
--- trunk/UserInterface/XWindowUI.cc (original)
+++ trunk/UserInterface/XWindowUI.cc Thu Mar 2 14:27:59 2006
@@ -39,6 +39,7 @@
#define TOKEN_NOOP 1
#define TOKEN_LOCK 2
+#define TOKEN_SHUTDOWN 3
using namespace Manta;
using namespace SCIRun;
@@ -76,6 +77,7 @@
register_default_mouse();
rtrt_interface->registerSetupCallback(this);
rtrt_interface->registerSerialAnimationCallback(Callback::create(this,
&XWindowUI::animation_callback));
+ rtrt_interface->registerTerminationCallback(Callback::create(this,
&XWindowUI::shutdown));
// Open the display and setup file descriptors for threads
if(pipe(xpipe) == -1){
@@ -111,6 +113,15 @@
t->detach();
}
+void XWindowUI::shutdown(MantaInterface*)
+{
+ int token = TOKEN_SHUTDOWN;
+ ssize_t s = write(xpipe[1], &token, sizeof(int));
+ if(s != sizeof(int)){
+ throw ErrnoException("XWindowUI write 3", errno, __FILE__, __LINE__ );
+ }
+}
+
void XWindowUI::setupBegin(const SetupContext&, int numChannels)
{
if(numChannels > static_cast<int>(windows.size())){
@@ -170,7 +181,7 @@
for(vector<int>::iterator iter = xfds.begin(); iter != xfds.end();
iter++){
FD_SET(*iter, &readfds);
if(*iter > max)
- max = *iter;
+ max = *iter;
}
int s;
do {
@@ -188,12 +199,16 @@
__FILE__, __LINE__ );
switch(token){
case TOKEN_NOOP:
- break;
+ break;
case TOKEN_LOCK:
- xlock.unlock();
- xsema.down();
- xlock.lock();
- break;
+ xlock.unlock();
+ xsema.down();
+ xlock.lock();
+ break;
+ case TOKEN_SHUTDOWN:
+ XCloseDisplay(dpy);
+ return;
+ break;
default:
throw InternalError("XWindowUI::Unknown token in pipe",
__FILE__, __LINE__ );
@@ -208,9 +223,9 @@
}
if(have_some){
while(XEventsQueued(dpy, QueuedAfterReading)){
- XEvent e;
- XNextEvent(dpy, &e);
- handle_event(e);
+ XEvent e;
+ XNextEvent(dpy, &e);
+ handle_event(e);
}
}
}
@@ -252,9 +267,9 @@
atts.event_mask=StructureNotifyMask|ExposureMask|ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask|KeyReleaseMask;
Window parent = RootWindow(dpy, screen);
window->window = XCreateWindow(dpy, parent, 0, 0,
- window->xres, window->yres, 0,
- DefaultDepth(dpy, screen), InputOutput,
- DefaultVisual(dpy, screen), flags, &atts);
+ window->xres, window->yres, 0,
+ DefaultDepth(dpy, screen), InputOutput,
+ DefaultVisual(dpy, screen), flags, &atts);
XTextProperty tp;
ostringstream title;
@@ -283,9 +298,9 @@
}
void XWindowUI::register_key(unsigned int state, unsigned long key,
- const string& description,
- KeyEventCallbackType* press,
- KeyEventCallbackType* release)
+ const string& description,
+ KeyEventCallbackType* press,
+ KeyEventCallbackType* release)
{
// cerr << description << ": " << (void*)key << '\n';
if(key == 0)
@@ -382,20 +397,20 @@
void XWindowUI::register_default_keys()
{
register_key(0, XStringToKeysym("h"),
- "print help message to stderr",
- Callback::create(this, &XWindowUI::helpkey));
+ "print help message to stderr",
+ Callback::create(this, &XWindowUI::helpkey));
register_key(0, XStringToKeysym("q"),
- "quit after this frame, press again to immediately quit",
- Callback::create(this, &XWindowUI::quitkey));
+ "quit after this frame, press again to immediately quit",
+ Callback::create(this, &XWindowUI::quitkey));
register_key(0, XStringToKeysym("question"),
- "print help message to stderr",
- Callback::create(this, &XWindowUI::helpkey));
+ "print help message to stderr",
+ Callback::create(this, &XWindowUI::helpkey));
register_key(0, XStringToKeysym("p"),
- "increase/decrease number of processors",
- Callback::create(this, &XWindowUI::prockey));
+ "increase/decrease number of processors",
+ Callback::create(this, &XWindowUI::prockey));
register_key(0, XStringToKeysym("P"),
- "increase/decrease number of processors",
- Callback::create(this, &XWindowUI::prockey));
+ "increase/decrease number of processors",
+ Callback::create(this, &XWindowUI::prockey));
register_key(0, XStringToKeysym("v"),
"autoview",
Callback::create(this, &XWindowUI::autoview));
@@ -403,8 +418,8 @@
"output camera",
Callback::create(this, &XWindowUI::output_camera));
register_key(0, XStringToKeysym("Escape"),
- "quit after this frame, press again to immediately quit",
- Callback::create(this, &XWindowUI::quitkey));
+ "quit after this frame, press again to immediately quit",
+ Callback::create(this, &XWindowUI::quitkey));
}
void XWindowUI::register_default_mouse()
@@ -448,7 +463,7 @@
if(key == XStringToKeysym("P"))
value = -1;
rtrt_interface->addTransaction("numWorkers",
- rtrt_interface->numWorkers(),
+ rtrt_interface->numWorkers(),
changeProcs(value));
}
@@ -618,46 +633,46 @@
unsigned long key = XKeycodeToKeysym(dpy, e.xkey.keycode, 0);
e.xkey.state &= ShiftMask|ControlMask|Mod1Mask;
if(e.xkey.state & ShiftMask){
- unsigned long key2 = XKeycodeToKeysym(dpy, e.xkey.keycode, 1);
- if(key2 != key){
- key = key2;
- e.xkey.state &= ~ShiftMask;
- }
+ unsigned long key2 = XKeycodeToKeysym(dpy, e.xkey.keycode, 1);
+ if(key2 != key){
+ key = key2;
+ e.xkey.state &= ~ShiftMask;
+ }
}
for(vector<KeyTab>::iterator iter = keys.begin();
- iter != keys.end(); iter++){
- if(key == iter->key && e.xkey.state == iter->state){
- if(iter->press){
- matched=true;
- iter->press->call(e.xkey.state, key, channel);
- }
- }
+ iter != keys.end(); iter++){
+ if(key == iter->key && e.xkey.state == iter->state){
+ if(iter->press){
+ matched=true;
+ iter->press->call(e.xkey.state, key, channel);
+ }
+ }
}
if(!matched){
- if(IsModifierKey(key)){
- // Don't print help for these keys
- } else {
- cerr << "Unknown key: ";
- char* s = XKeysymToString(key);
- if(!s)
- cerr << "Unknown keysym: " << key;
- else
- cerr << s << " (" << key << ")";
- if(e.xkey.state){
- cerr << " (";
- if(e.xkey.state & Mod1Mask)
- cerr << "Alt ";
- if(e.xkey.state & ControlMask)
- cerr << "Control ";
- if(e.xkey.state & ShiftMask)
- cerr << "Shift ";
+ if(IsModifierKey(key)){
+ // Don't print help for these keys
+ } else {
+ cerr << "Unknown key: ";
+ char* s = XKeysymToString(key);
+ if(!s)
+ cerr << "Unknown keysym: " << key;
+ else
+ cerr << s << " (" << key << ")";
+ if(e.xkey.state){
+ cerr << " (";
+ if(e.xkey.state & Mod1Mask)
+ cerr << "Alt ";
+ if(e.xkey.state & ControlMask)
+ cerr << "Control ";
+ if(e.xkey.state & ShiftMask)
+ cerr << "Shift ";
if(e.xkey.state & ~(Mod1Mask|ControlMask|ShiftMask))
cerr << "OtherModifier ";
- cerr << ")";
+ cerr << ")";
}
- cerr << '\n';
- helpkey(e.xkey.state, key, channel);
- }
+ cerr << '\n';
+ helpkey(e.xkey.state, key, channel);
+ }
}
}
break;
@@ -665,11 +680,11 @@
{
unsigned long key = XKeycodeToKeysym(dpy, e.xkey.keycode, 0);
for(vector<KeyTab>::iterator iter = keys.begin();
- iter != keys.end(); iter++){
- if(key == iter->key && e.xkey.state == iter->state){
- if(iter->release)
- iter->release->call(e.xkey.state, key, channel);
- }
+ iter != keys.end(); iter++){
+ if(key == iter->key && e.xkey.state == iter->state){
+ if(iter->release)
+ iter->release->call(e.xkey.state, key, channel);
+ }
}
}
break;
@@ -734,8 +749,8 @@
XWindow* window = windows[channel];
if(new_xres != window->xres || new_yres != window->yres)
rtrt_interface->addOneShotCallback(MantaInterface::Relative, 0,
- Callback::create(this,
&XWindowUI::changeResolution,
- channel, new_xres, new_yres));
+ Callback::create(this,
&XWindowUI::changeResolution,
+ channel,
new_xres, new_yres));
} // case ConfigureNotify
break;
case Expose:
Modified: trunk/UserInterface/XWindowUI.h
==============================================================================
--- trunk/UserInterface/XWindowUI.h (original)
+++ trunk/UserInterface/XWindowUI.h Thu Mar 2 14:27:59 2006
@@ -59,6 +59,9 @@
// This is the callback function used to notify the engine that we
// want a resize.
void changeResolution(int, int, int channel, int new_xres, int new_yres);
+
+ void shutdown(MantaInterface*);
+
protected:
void register_default_keys();
void register_default_mouse();
- [MANTA] r964 - in trunk: SwigInterface UserInterface, bigler, 03/02/2006
Archive powered by MHonArc 2.6.16.