Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2003 - in trunk: Engine/Factory scenes


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2003 - in trunk: Engine/Factory scenes
  • Date: Thu, 24 Jan 2008 17:14:37 -0700 (MST)

Author: boulos
Date: Thu Jan 24 17:14:35 2008
New Revision: 2003

Added:
   trunk/scenes/externalObject.cc
      - copied, changed from r2002, trunk/scenes/macbeth.cc
Modified:
   trunk/Engine/Factory/Factory.cc
   trunk/scenes/CMakeLists.txt
Log:
Engine/Factory/Factory.cc

 Making the Plugin class exclusive (getting rid of if1/0 stuff).

 Allocating Plugins on the heap to avoid dlclose at destruction; while
 this leaks memory, it allows external plugins to define their own
 symbols and not have them disappear after scene creation. 

scenes/CMakeLists.txt
scenes/externalObject.cc

 Adding a scene to stress test the new bug introduced in the switch to Plugin 
(by Carson).


Modified: trunk/Engine/Factory/Factory.cc
==============================================================================
--- trunk/Engine/Factory/Factory.cc     (original)
+++ trunk/Engine/Factory/Factory.cc     Thu Jan 24 17:14:35 2008
@@ -46,7 +46,6 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-//#include <dlfcn.h>
 #include <stdio.h>
 
 
@@ -485,44 +484,24 @@
     }
   }
 
-#if 1
   typedef Scene* (*MakerType)(const ReadContext&, const vector<string>&);
-  Plugin<MakerType> scene_file(fullname.c_str());
+  Plugin<MakerType>* scene_file = new Plugin<MakerType>(fullname.c_str());
 
-  if (!scene_file.loadSymbol("make_scene")) {
+  if (!scene_file->loadSymbol("make_scene")) {
     return NULL;
   }
 
-  MakerType make_scene = scene_file.function;
+  MakerType make_scene = scene_file->function;
   // Call the make_scene function.
   ReadContext context(manta_interface);
   Scene* scene=(*make_scene)(context, args);
   if(!scene){
+    delete scene_file;
     throw InputError( "make_scene returned null" );
   }
-#else
-  // Attempt to open the file name.
-  void* handle=dlopen(fullname.c_str(), RTLD_NOW);
-  if(!handle){
-    throw InputError( dlerror() );
-  }
-
-  // Look up the scene function.
-  void* scene_fn=dlsym(handle, "make_scene");
-  if(!scene_fn){
-    throw InputError( "Could not find \"make_scene\" function.\n" );
-  }
-
-  typedef Scene* (*MakerType)(const ReadContext&, const vector<string>&);
-  MakerType make_scene = (MakerType)(scene_fn);
-
-  // Call the make_scene function.
-  ReadContext context(manta_interface);
-  Scene* scene=(*make_scene)(context, args);
-  if(!scene){
-    throw InputError( "make_scene returned null" );
-  }
-#endif
+  // NOTE(boulos): Don't delete scene_file here because we need the
+  // symbols to stay around if they're not linked into the binary
+  // itself. (like a class defined in an external module)
 
   return scene;
 
@@ -548,45 +527,19 @@
     }
   }
 
-#if 1
   typedef void (*MakerType)(ReadContext &, const vector<string>&);
-  Plugin<MakerType> make_stack(fullname.c_str());
-  if (!make_stack.loadSymbol("make_stack")) {
+  Plugin<MakerType>* make_stack = new Plugin<MakerType>(fullname.c_str());
+  if (!make_stack->loadSymbol("make_stack")) {
     if(printErrors){
       cerr << "Stack configuration file found, but make_stack() function not 
found\n";
     }
+    delete make_stack;
     return;
   }
   ReadContext context(manta_interface);
-  MakerType make_stack_function = make_stack.function;
+  MakerType make_stack_function = make_stack->function;
   // Call the function.
   (*make_stack_function)(context, args);
-#else
-  // Open the file.
-  void* handle=dlopen(fullname.c_str(), RTLD_NOW);
-  if(!handle){
-    throw InputError( "Could not load stack" );
-  }
-
-  // Access the make_stack symbol
-  void* stack_fn=dlsym(handle, "make_stack");
-  if(!stack_fn){
-    if(printErrors){
-      cerr << "Stack configuration file found, but make_stack() function not 
found\n";
-    }
-    return;
-  }
-
-  ///////////////////////////////////////////////////////////////////////////
-  // Invoke the function.
-  typedef void (*MakerType)(ReadContext &, const vector<string>&);
-  MakerType make_stack = (MakerType)(stack_fn);
-  ReadContext context(manta_interface);
-
-  // Call the function.
-  (*make_stack)(context, args);
-#endif
-
 }
 
 UserInterface* Factory::createUserInterface(const string& spec)

Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Thu Jan 24 17:14:35 2008
@@ -132,3 +132,10 @@
    ADD_LIBRARY(scene_macbeth macbeth.cc)
    TARGET_LINK_LIBRARIES(scene_macbeth ${MANTA_SCENE_LINK})
 ENDIF(SCENE_MACBETH)
+
+# macbeth color checker scene
+SET(SCENE_EXTERNAL_OBJECT TRUE CACHE BOOL "Externally derived object unit 
test")
+IF(SCENE_EXTERNAL_OBJECT)
+   ADD_LIBRARY(scene_externalObject externalObject.cc)
+   TARGET_LINK_LIBRARIES(scene_externalObject ${MANTA_SCENE_LINK})
+ENDIF(SCENE_EXTERNAL_OBJECT)

Copied: trunk/scenes/externalObject.cc (from r2002, trunk/scenes/macbeth.cc)
==============================================================================
--- trunk/scenes/macbeth.cc     (original)
+++ trunk/scenes/externalObject.cc      Thu Jan 24 17:14:35 2008
@@ -9,8 +9,8 @@
 #include <Model/Backgrounds/ConstantBackground.h>
 #include <Model/Groups/Group.h>
 #include <Model/Lights/DirectionalLight.h>
-#include <Model/Materials/CopyTextureMaterial.h>
-#include <Model/Primitives/Parallelogram.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Primitives/Sphere.h>
 #include <Model/TexCoordMappers/LinearMapper.h>
 #include <Model/Textures/ImageTexture.h>
 
@@ -18,6 +18,13 @@
 
 using namespace Manta;
 
+class SphereTwoX : public Sphere {
+public:
+  SphereTwoX(Material* material, const Vector& center, Real radius)
+    : Sphere(material, center, radius * 2) {
+  }
+};
+
 void addLights( LightSet* lights)
 {
   lights->add(new DirectionalLight(Vector(0, 0, 1), Color::white()));
@@ -26,21 +33,6 @@
 MANTA_PLUGINEXPORT
 Scene* make_scene(const ReadContext&, const vector<string>& args)
 {
-  std::string filename;
-  for(size_t i = 0; i < args.size(); ++i) {
-    std::string arg = args[i];
-    if(arg == "-file") {
-      if(!getStringArg(i, args, filename))
-        throw IllegalArgument("scene macbeth -file", i , args);
-    } else {
-      std::cerr << "Unknown option: " << arg << "\n";
-    }
-  }
-
-  if (filename == "") {
-    throw InputError("Filename required for macbeth scene");
-  }
-
   Vector up( 0.0f, 1.0f, 0.0f );
   Vector right( 1.0f, 0.0f, 0.0f );
 
@@ -50,12 +42,8 @@
 
   scene->setBackground( new ConstantBackground( Color(RGB(.5, .5, .5) ) ) );
 
-  ImageTexture<Color>* texture = LoadColorImageTexture(filename, &std::cerr, 
true);
-  Material* image = new CopyTextureMaterial(texture);
-  Primitive* board = new Parallelogram(image, Vector(0, 0, 0), Vector(6, 0, 
0), Vector(0, 4, 0));
-  board->setTexCoordMapper( new LinearMapper( Vector(0, 0, 0), 
Vector(6,0,0), Vector(0, 4, 0), Vector(0,0,1)) );
-
-  group->add(board);
+  Material* red = new Lambertian(Color(RGBColor(.78, .1, .1)));
+  group->add(new SphereTwoX(red, Vector(0,0,1.2), 1.0));
   scene->setObject(group);
 
   LightSet* lights = new LightSet();
@@ -65,10 +53,7 @@
   scene->setLights(lights);
 
   // Add a default camera
-  Vector eye(3,2,-10);
-  Vector lookat(3,2,0);
-  Real   fov=45;
-  scene->addBookmark("default view", eye, lookat, up, fov, fov);
+  scene->addBookmark("default view", Vector(3, 3, 2), Vector(0, 0, 0.3), 
Vector(0, 0, 1), 60, 60);
 
   return scene;
 }




  • [Manta] r2003 - in trunk: Engine/Factory scenes, boulos, 01/24/2008

Archive powered by MHonArc 2.6.16.

Top of page