Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1824 - in trunk: Core/Color Core/Persistent Interface Model/AmbientLights Model/Backgrounds Model/Materials Model/Primitives Model/Textures


Chronological Thread 
  • From: sparker@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1824 - in trunk: Core/Color Core/Persistent Interface Model/AmbientLights Model/Backgrounds Model/Materials Model/Primitives Model/Textures
  • Date: Mon, 5 Nov 2007 23:03:18 -0700 (MST)

Author: sparker
Date: Mon Nov  5 23:03:16 2007
New Revision: 1824

Modified:
   trunk/Core/Color/ColorDB.cc
   trunk/Core/Color/ColorDB.h
   trunk/Core/Color/ColorSpace.h
   trunk/Core/Color/RGBTraits.cc
   trunk/Core/Color/RGBTraits.h
   trunk/Core/Persistent/MantaRTTI.h
   trunk/Core/Persistent/XMLArchive.cc
   trunk/Interface/InterfaceRTTI.h
   trunk/Model/AmbientLights/ConstantAmbient.cc
   trunk/Model/AmbientLights/ConstantAmbient.h
   trunk/Model/Backgrounds/ConstantBackground.cc
   trunk/Model/Backgrounds/ConstantBackground.h
   trunk/Model/Materials/LitMaterial.cc
   trunk/Model/Primitives/Parallelogram.cc
   trunk/Model/Primitives/PrimitiveCommon.cc
   trunk/Model/Textures/CheckerTexture.h
   trunk/Model/Textures/Constant.h
Log:
Fix linux build by avoiding static intialization order problems
Fix scalar build by adding rtti for double
Added rtti/persistence for a few new classes
Rework reading of color
Allow forward references
Make some classes a little more friendly to hand-generated XML


Modified: trunk/Core/Color/ColorDB.cc
==============================================================================
--- trunk/Core/Color/ColorDB.cc (original)
+++ trunk/Core/Color/ColorDB.cc Mon Nov  5 23:03:16 2007
@@ -775,7 +775,7 @@
   {"yellow4", 139, 139, 0},
 };
 
-Color ColorDB::getNamedColor(const std::string& name)
+bool ColorDB::getNamedColor(RGBColor& result, const std::string& name)
 {
   // A simple binary search of our namedColors array.
   int l = 0;
@@ -789,11 +789,20 @@
     }
   }
   if(name != namedColors[l].name)
-    throw UnknownColor(name);
+    return false;
 
   float scale = 1.f/255.f;
   RGBData& nc = namedColors[l];
-  return Color(RGBColor(nc.r*scale, nc.g*scale, nc.b*scale));
+  result = RGBColor(nc.r*scale, nc.g*scale, nc.b*scale);
+  return true;
+}
+
+Color ColorDB::getNamedColor(const std::string& name)
+{
+  RGBColor result;
+  if(!getNamedColor(result, name))
+    throw UnknownColor(name);
+  return Color(result);
 }
 
 bool ColorDB::getNamedColor( unsigned char result[3], const std::string 
&name ) {

Modified: trunk/Core/Color/ColorDB.h
==============================================================================
--- trunk/Core/Color/ColorDB.h  (original)
+++ trunk/Core/Color/ColorDB.h  Mon Nov  5 23:03:16 2007
@@ -8,9 +8,11 @@
 #include <sgi_stl_warnings_on.h>
 
 namespace Manta {
+  class RGBColor;
   class ColorDB {
   public:
     static Color getNamedColor(const std::string& name);
+    static bool getNamedColor(RGBColor& result, const std::string& name);
     static bool  getNamedColor(unsigned char result[3], const std::string 
&name);
 
     // Tests to make sure the namedColors array is sorted properly and

Modified: trunk/Core/Color/ColorSpace.h
==============================================================================
--- trunk/Core/Color/ColorSpace.h       (original)
+++ trunk/Core/Color/ColorSpace.h       Mon Nov  5 23:03:16 2007
@@ -11,10 +11,8 @@
 #include <Core/Persistent/MantaRTTI.h>
 
 #include <sgi_stl_warnings_off.h>
-#include <sstream>
 #include <string>
 #include <sgi_stl_warnings_on.h>
-#include <ctype.h>
 
 namespace Manta {
   template<typename Traits> class ColorSpace {
@@ -280,61 +278,16 @@
     static std::string getPublicClassname() {
       return "Color";
     }
-    static inline int hexvalue(char c){
-      if(c >= '0' && c <= '9')
-        return c-'0';
-      else if(c >= 'a' && c <= 'f')
-        return c-'a';
-      else if(c >= 'A' && c <= 'F')
-        return c-'A';
-      else
-        return 0;
-    }
     static void readwrite(ArchiveElement* archive, ColorSpace<Traits>& data) 
{
       if(archive->reading()){
         // Read a number of different color representations
         std::string str;
         archive->readwrite("data", str);
-        if(str[0] == '#'){
-          // Parse html style hex string
-          std::string::size_type idx = 1;
-          while(idx < str.size() && ((str[idx] >= '0' && str[idx] <= '9') || 
(str[idx] >= 'a' && str[idx] <= 'f') || (str[idx] >= 'A' && str[idx] <= 'F')))
-            idx++;
-
-          int r, g, b;
-          if(idx == 7){
-            r = (hexvalue(str[1])<<4) + hexvalue(str[2]);
-            g = (hexvalue(str[3])<<4) + hexvalue(str[4]);
-            b = (hexvalue(str[5])<<4) + hexvalue(str[6]);
-          } else if(idx == 4){
-            r = (hexvalue(str[1])<<4) + hexvalue(str[1]);
-            g = (hexvalue(str[2])<<4) + hexvalue(str[2]);
-            b = (hexvalue(str[3])<<4) + hexvalue(str[3]);
-          } else {
-            throw SerializationError("Error parsing rgb triple: " + str);
-          }
-          while(idx < str.size() && !isspace(str[idx]))
-            idx++;
-          if(idx != str.size())
-            throw SerializationError("Error parsing rgb triple: " + str);
-
-          Traits::convertFrom(data.data, RGB(r/255., g/255., b/255.));
-        } else if(str.substr(0, 4) == "rgb:"){
-          // RGB triple
-          std::istringstream in(str.substr(4));
-          float r,g,b;
-          in >> r >> g >> b;
-          if(!in)
-            throw SerializationError("Error parsing rgb value: " + str);
-          Traits::convertFrom(data.data, RGB(r, g, b));
+        RGBColor rgb;
+        if(RGBTraits::parseColor(rgb, str)){
+          Traits::convertFrom(data.data, rgb);
         } else {
-          // Try to parse as an rgb triple
-          std::istringstream in(str);
-          float r,g,b;
-          in >> r >> g >> b;
-          if(!in)
-            throw SerializationError("Unknown color value: " + str);
-          Traits::convertFrom(data.data, RGB(r, g, b));
+          throw SerializationError("Unknown color value: " + str);
         }
       } else {
         Traits::readwrite(archive, data.data);

Modified: trunk/Core/Color/RGBTraits.cc
==============================================================================
--- trunk/Core/Color/RGBTraits.cc       (original)
+++ trunk/Core/Color/RGBTraits.cc       Mon Nov  5 23:03:16 2007
@@ -1,15 +1,17 @@
 
 #include <Core/Color/RGBTraits.h>
 #include <Core/Color/ColorSpace.h>
+#include <Core/Color/ColorDB.h>
 #include <Core/Persistent/ArchiveElement.h>
 #include <sstream>
 #include <iomanip>
+#include <ctype.h>
 
 using namespace Manta;
 using namespace std;
 
 template<>
-bool MantaRTTI<ColorSpace<RGBTraits> >::force_initialize = 
MantaRTTI<ColorSpace<RGBTraits> >::registerClass("Color");
+bool MantaRTTI<ColorSpace<RGBTraits> >::force_initialize = 
MantaRTTI<ColorSpace<RGBTraits> >::registerClass();
 
 void RGBTraits::readwrite(ArchiveElement* archive, ComponentType data[3])
 {
@@ -40,3 +42,64 @@
   archive->readwrite("rgb", repstring);
 }
 
+static inline int hexvalue(char c){
+  if(c >= '0' && c <= '9')
+    return c-'0';
+  else if(c >= 'a' && c <= 'f')
+    return c-'a';
+  else if(c >= 'A' && c <= 'F')
+    return c-'A';
+  else
+    return 0;
+}
+
+bool RGBTraits::parseColor(RGBColor& result, const std::string& str)
+{
+  if(str[0] == '#'){
+    // Parse html style hex string
+    std::string::size_type idx = 1;
+    while(idx < str.size() && ((str[idx] >= '0' && str[idx] <= '9') || 
(str[idx] >= 'a' && str[idx] <= 'f') || (str[idx] >= 'A' && str[idx] <= 'F')))
+      idx++;
+
+    int r, g, b;
+    if(idx == 7){
+      r = (hexvalue(str[1])<<4) + hexvalue(str[2]);
+      g = (hexvalue(str[3])<<4) + hexvalue(str[4]);
+      b = (hexvalue(str[5])<<4) + hexvalue(str[6]);
+    } else if(idx == 4){
+      r = (hexvalue(str[1])<<4) + hexvalue(str[1]);
+      g = (hexvalue(str[2])<<4) + hexvalue(str[2]);
+      b = (hexvalue(str[3])<<4) + hexvalue(str[3]);
+    } else {
+      return false;
+    }
+    while(idx < str.size() && !isspace(str[idx]))
+      idx++;
+    if(idx != str.size())
+      return false;
+
+    result = RGBColor(r/255., g/255., b/255.);
+    return true;
+  } else if(str.substr(0, 4) == "rgb:"){
+    // RGB triple
+    std::istringstream in(str.substr(4));
+    float r,g,b;
+    in >> r >> g >> b;
+    if(!in)
+      return false;
+    result = RGBColor(r, g, b);
+    return true;
+  } else if(ColorDB::getNamedColor(result, str)){
+    // A named color
+    return true;
+  } else {
+    // Try to parse as an rgb triple
+    std::istringstream in(str);
+    float r,g,b;
+    in >> r >> g >> b;
+    if(!in)
+      return false;
+    result = RGBColor(r, g, b);
+    return true;
+  }
+}

Modified: trunk/Core/Color/RGBTraits.h
==============================================================================
--- trunk/Core/Color/RGBTraits.h        (original)
+++ trunk/Core/Color/RGBTraits.h        Mon Nov  5 23:03:16 2007
@@ -43,7 +43,7 @@
     }
 
     static void readwrite(ArchiveElement* archive, ComponentType data[3]);
-
+    static bool parseColor(RGBColor& result, const std::string& str);
   };
 }
 

Modified: trunk/Core/Persistent/MantaRTTI.h
==============================================================================
--- trunk/Core/Persistent/MantaRTTI.h   (original)
+++ trunk/Core/Persistent/MantaRTTI.h   Mon Nov  5 23:03:16 2007
@@ -359,13 +359,7 @@
   template<class T>
   class MantaRTTI_BaseClass {
   public:
-    static std::string getPublicClassname() {
-      if(!classname){
-        throw SCIRun::InternalError(std::string("Class: ") + 
typeid(T).name() + " is not registered", __FILE__, __LINE__);
-      }
-      return *classname;
-    }
-    static bool registerClass(const std::string& _classname);
+    static bool registerClass();
 
     template<class C>
     static void registerClassAndParents(const std::string& classname) {
@@ -383,19 +377,12 @@
     }
   private:
     MantaRTTI_BaseClass();
-    static std::string* classname;
   };
-  template<class T> std::string* MantaRTTI_BaseClass<T>::classname;
 
   template<class T, class Parent>
   class MantaRTTI_DerivedClass {
   public:
-    static std::string getPublicClassname() {
-      if(!classname)
-        throw SCIRun::InternalError(std::string("Class: ") + 
typeid(T).name() + " is not registered", __FILE__, __LINE__);
-      return *classname;
-    }
-    static bool registerClass(const std::string& _classname);
+    static bool registerClass();
 
     template<class C>
     static void registerClassAndParents(const std::string& classname) {
@@ -415,28 +402,19 @@
   private:
     MantaRTTI_DerivedClass();
     // This is a string* instead of a string to avoid initialization order 
issues
-    static std::string* classname;
   };
-  template<class T, class Parent> std::string* MantaRTTI_DerivedClass<T, 
Parent>::classname;
 
   template<class T, class Parent>
-    bool MantaRTTI_DerivedClass<T, Parent>::registerClass(const std::string& 
_classname)
+    bool MantaRTTI_DerivedClass<T, Parent>::registerClass()
   {
-    if(!classname)
-      classname = new std::string(_classname);
-    registerClassAndParents<T>(_classname);
+    registerClassAndParents<T>(MantaRTTI<T>::getPublicClassname());
     return MantaRTTI<Parent>::force_initialize;
   }
 
   template<class T, class Parent1, class Parent2>
   class MantaRTTI_DerivedClass2 {
   public:
-    static std::string getPublicClassname() {
-      if(!classname)
-        throw SCIRun::InternalError(std::string("Class: ") + 
typeid(T).name() + " is not registered", __FILE__, __LINE__);
-      return *classname;
-    }
-    static bool registerClass(const std::string& _classname);
+    static bool registerClass();
 
     template<class C>
     static void registerClassAndParents(const std::string& classname) {
@@ -456,25 +434,19 @@
   private:
     MantaRTTI_DerivedClass2();
     // This is a string* instead of a string to avoid initialization order 
issues
-    static std::string* classname;
   };
-  template<class T, class Parent1, class Parent2> std::string* 
MantaRTTI_DerivedClass2<T, Parent1, Parent2>::classname;
 
   template<class T, class Parent1, class Parent2>
-    bool MantaRTTI_DerivedClass2<T, Parent1, Parent2>::registerClass(const 
std::string& _classname)
+    bool MantaRTTI_DerivedClass2<T, Parent1, Parent2>::registerClass()
   {
-    if(!classname)
-      classname = new std::string(_classname);
-    registerClassAndParents<T>(_classname);
+    registerClassAndParents<T>(MantaRTTI<T>::getPublicClassname());
     return MantaRTTI<Parent1>::force_initialize | 
MantaRTTI<Parent2>::force_initialize;
   }
 
   template<class T>
-  bool MantaRTTI_BaseClass<T>::registerClass(const std::string& _classname)
+  bool MantaRTTI_BaseClass<T>::registerClass()
   {
-    if(!classname)
-      classname = new std::string(_classname);
-    registerClassAndParents<T>(_classname);
+    registerClassAndParents<T>(MantaRTTI<T>::getPublicClassname());
     return true;
   }
 
@@ -485,8 +457,17 @@
       return "float";
     }
   };
+
+  template<>
+  class MantaRTTI<double> {
+  public:
+    static std::string getPublicClassname() {
+      return "double";
+    }
+  };
 }
 
+
 // Convenience macros
 #define MANTA_DECLARE_RTTI_DERIVEDCLASS(declclass, baseclass, classtype, 
rwtype)  \
 template<>\
@@ -496,6 +477,10 @@
 { \
  public: \
   static bool force_initialize; \
+  static std::string getPublicClassname() \
+  { \
+    return #declclass; \
+  } \
 }
 
 #define MANTA_DECLARE_RTTI_DERIVEDCLASS2(declclass, baseclass1, baseclass2, 
classtype, rwtype) \
@@ -506,6 +491,10 @@
 { \
  public: \
   static bool force_initialize; \
+  static std::string getPublicClassname() \
+  { \
+    return #declclass; \
+  } \
 }
 
 #define MANTA_DECLARE_RTTI_BASECLASS(declclass, classtype, rwtype)  \
@@ -516,10 +505,14 @@
 { \
  public: \
   static bool force_initialize; \
+  static std::string getPublicClassname() \
+  { \
+    return #declclass; \
+  } \
 }
 
 
 #define MANTA_REGISTER_CLASS(classname) \
-bool MantaRTTI<classname>::force_initialize = 
MantaRTTI<classname>::registerClass(#classname)
+bool MantaRTTI<classname>::force_initialize = 
MantaRTTI<classname>::registerClass()
 
 #endif

Modified: trunk/Core/Persistent/XMLArchive.cc
==============================================================================
--- trunk/Core/Persistent/XMLArchive.cc (original)
+++ trunk/Core/Persistent/XMLArchive.cc Mon Nov  5 23:03:16 2007
@@ -67,7 +67,6 @@
     virtual bool nextContainerElement();
 
     virtual bool hasField(const std::string& fieldname) const;
-    typedef std::map<std::string, PointerWrapperInterface*> pointermaptype;
   protected:
     XMLArchive* archive;
     xmlNodePtr node;
@@ -85,6 +84,8 @@
 
   typedef std::map<void*, RefInfo> refmaptype;
   typedef std::map<std::string, int> countmaptype;
+  typedef std::map<std::string, PointerWrapperInterface*> pointermaptype;
+  typedef std::map<std::string, xmlNodePtr> assetmaptype;
 
   class XMLArchive : public Archive {
   public:
@@ -96,10 +97,12 @@
 
     refmaptype refmap;
     countmaptype countmap;
-    XMLArchiveElement::pointermaptype pointermap;
+    pointermaptype pointermap;
+    assetmaptype assetmap;
   private:
     std::string filename;
     xmlDocPtr doc;
+    void scanPointers(xmlNodePtr node);
 
     static bool force_initialize;
   };
@@ -229,10 +232,27 @@
   xmlFreeDoc(doc);
 }
 
+void XMLArchive::scanPointers(xmlNodePtr node)
+{
+  xmlChar* id = xmlGetProp(node, to_xml_ch_ptr("id"));
+  if(id){
+    string sid = to_char_ptr(id);
+    assetmaptype::iterator iter = assetmap.find(sid);
+    if(iter != assetmap.end())
+      throw SerializationError("Pointer: " + sid + " defined twice");
+    assetmap.insert(std::make_pair(sid, node));
+  }
+  for(xmlNodePtr child = node->children; child != 0; child = child->next){
+    if(child->type == XML_ELEMENT_NODE)
+      scanPointers(child);
+  }
+}
+
 ArchiveElement* XMLArchive::getRoot()
 {
   if(reading()){
     xmlNodePtr root = xmlDocGetRootElement(doc);
+    scanPointers(root);
     return new XMLArchiveElement(this, root, XMLArchiveElement::RootElement);
   } else {
     xmlNodePtr top = xmlNewNode(0, to_xml_ch_ptr("Manta"));
@@ -644,7 +664,7 @@
       xmlChar* prop = xmlGetProp(node, to_xml_ch_ptr(fieldname.c_str()));
       xmlNodePtr child = node->children;
       if((prop && strcmp(to_char_ptr(prop), "null") == 0)
-         || (!prop && strcmp(to_char_ptr(child->name), "null") == 0)){
+         || (!prop && child && strcmp(to_char_ptr(child->name), "null") == 
0)){
         if(!isPointer)
           throw SerializationError("Cannot read a reference to a null 
pointer");
         ptr.setNull();
@@ -705,11 +725,28 @@
       } else {
         string pointername = to_char_ptr(prop);
         pointermaptype::iterator iter = 
archive->pointermap.find(pointername);
-        if(iter == archive->pointermap.end())
-          throw SerializationError("Unknown pointer: " + pointername + " 
while reading field: " + fieldname + " (forward references not yet 
supported)");
-        if(!iter->second->upcast(&ptr)){
-          iter->second->upcast(&ptr);
-          throw SerializationError("Pointer type mismatch while reading 
field: " + fieldname);
+        if(iter != archive->pointermap.end()){
+          // Have pointer already
+          if(!iter->second->upcast(&ptr))
+            throw SerializationError("Pointer type mismatch while reading 
field: " + fieldname);
+        } else {
+          // Find pointer elsewhere in the file.  Usually this is either a 
forward
+          // reference, or something in the Assets section
+          assetmaptype::iterator iter = archive->assetmap.find(pointername);
+          if(iter == archive->assetmap.end())
+            throw SerializationError("Unknown pointer: " + pointername + " 
while reading field: " + fieldname);
+          
+          if(isPointer){
+            string classname = get_classname(iter->second, fieldname);
+            PointerWrapperInterface* newobj;
+            if(!ptr.createObject(classname, &newobj))
+              throw SerializationError("Cannot instantiate class: " + 
classname + " for field: " + fieldname);
+            if(archive->pointermap.find(iter->first) != 
archive->pointermap.end())
+              throw SerializationError("Pointer: " + iter->first + " defined 
twice while reading field: " + fieldname + " in class: " + classname);
+            archive->pointermap.insert(std::make_pair(iter->first, newobj));
+          }
+          XMLArchiveElement subelement(archive, iter->second, NormalElement);
+          ptr.readwrite(&subelement);
         }
         return;
       }

Modified: trunk/Interface/InterfaceRTTI.h
==============================================================================
--- trunk/Interface/InterfaceRTTI.h     (original)
+++ trunk/Interface/InterfaceRTTI.h     Mon Nov  5 23:03:16 2007
@@ -36,10 +36,13 @@
   class MantaRTTI<Texture<ValueType> > : public 
MantaRTTI_DerivedClass<Texture<ValueType>, Interpolable>, public 
MantaRTTI_AbstractClass<Texture<ValueType> >, public 
MantaRTTI_readwriteNone<Texture<ValueType> > {
   public:
     static bool force_initialize;
+    static std::string getPublicClassname() {
+      return "Texture<"+MantaRTTI<ValueType>::getPublicClassname()+">";
+    }
   };
 
   template<class ValueType>
-    bool MantaRTTI<Texture<ValueType> >::force_initialize = 
MantaRTTI<Texture<ValueType> 
>::registerClass("Texture<"+MantaRTTI<ValueType>::getPublicClassname()+">");
+    bool MantaRTTI<Texture<ValueType> >::force_initialize = 
MantaRTTI<Texture<ValueType> >::registerClass();
 }
 
 #endif

Modified: trunk/Model/AmbientLights/ConstantAmbient.cc
==============================================================================
--- trunk/Model/AmbientLights/ConstantAmbient.cc        (original)
+++ trunk/Model/AmbientLights/ConstantAmbient.cc        Mon Nov  5 23:03:16 
2007
@@ -1,6 +1,8 @@
 
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Interface/RayPacket.h>
+#include <Interface/InterfaceRTTI.h>
+#include <Core/Persistent/ArchiveElement.h>
 #include <MantaSSE.h>
 
 #include <sgi_stl_warnings_off.h>
@@ -10,6 +12,10 @@
 using namespace Manta;
 using namespace std;
 
+ConstantAmbient::ConstantAmbient()
+{
+}
+
 ConstantAmbient::ConstantAmbient(const Color& color)
   : color(color)
 {
@@ -65,4 +71,15 @@
   RGB c(color.convertRGB());
   out << "color = ("<<c.r()<<", "<<c.g()<<", "<<c.b()<<")\n";
   return out.str();
+}
+
+namespace Manta {
+MANTA_DECLARE_RTTI_DERIVEDCLASS(ConstantAmbient, AmbientLight, 
ConcreteClass, readwriteMethod);
+MANTA_REGISTER_CLASS(ConstantAmbient);
+}
+
+void ConstantAmbient::readwrite(ArchiveElement* archive)
+{
+  MantaRTTI<AmbientLight>::readwrite(archive, *this);
+  archive->readwrite("color", color);
 }

Modified: trunk/Model/AmbientLights/ConstantAmbient.h
==============================================================================
--- trunk/Model/AmbientLights/ConstantAmbient.h (original)
+++ trunk/Model/AmbientLights/ConstantAmbient.h Mon Nov  5 23:03:16 2007
@@ -12,6 +12,7 @@
 namespace Manta{
   class ConstantAmbient : public AmbientLight {
   public:
+    ConstantAmbient();
     ConstantAmbient(const Color& color);
     virtual ~ConstantAmbient();
 
@@ -19,6 +20,7 @@
     virtual void computeAmbient(const RenderContext& context, RayPacket& 
rays, ColorArray ambient) const;
 
     virtual std::string toString() const;
+    virtual void readwrite(ArchiveElement*);
   private:
     Color color;
   };

Modified: trunk/Model/Backgrounds/ConstantBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/ConstantBackground.cc       (original)
+++ trunk/Model/Backgrounds/ConstantBackground.cc       Mon Nov  5 23:03:16 
2007
@@ -1,5 +1,7 @@
 
 #include <Model/Backgrounds/ConstantBackground.h>
+#include <Core/Persistent/ArchiveElement.h>
+#include <Interface/InterfaceRTTI.h>
 #include <Interface/RayPacket.h>
 #include <MantaSSE.h>
 
@@ -10,6 +12,10 @@
 {
 }
 
+ConstantBackground::ConstantBackground()
+{
+}
+
 ConstantBackground::~ConstantBackground()
 {
 }
@@ -47,4 +53,15 @@
       rays.setColor(i, bgcolor);
     }
 #endif
+}
+
+namespace Manta {
+MANTA_DECLARE_RTTI_DERIVEDCLASS(ConstantBackground, Background, 
ConcreteClass, readwriteMethod);
+MANTA_REGISTER_CLASS(ConstantBackground);
+}
+
+void ConstantBackground::readwrite(ArchiveElement* archive)
+{
+  MantaRTTI<Background>::readwrite(archive, *this);
+  archive->readwrite("color", bgcolor);
 }

Modified: trunk/Model/Backgrounds/ConstantBackground.h
==============================================================================
--- trunk/Model/Backgrounds/ConstantBackground.h        (original)
+++ trunk/Model/Backgrounds/ConstantBackground.h        Mon Nov  5 23:03:16 
2007
@@ -4,15 +4,19 @@
 
 #include <Interface/Background.h>
 #include <Core/Color/Color.h>
+#include <Core/Persistent/MantaRTTI.h>
 
 namespace Manta{
   class ConstantBackground : public Background {
   public:
+    ConstantBackground();
     ConstantBackground(const Color& color);
     virtual ~ConstantBackground();
 
     virtual void preprocess(const PreprocessContext& context);
     virtual void shade(const RenderContext& context, RayPacket& rays) const;
+
+    void readwrite(ArchiveElement* archive);
   private:
     Color bgcolor;
   };

Modified: trunk/Model/Materials/LitMaterial.cc
==============================================================================
--- trunk/Model/Materials/LitMaterial.cc        (original)
+++ trunk/Model/Materials/LitMaterial.cc        Mon Nov  5 23:03:16 2007
@@ -43,6 +43,14 @@
 void LitMaterial::readwrite(ArchiveElement* archive)
 {
   MantaRTTI<OpaqueShadower>::readwrite(archive, *this);
-  archive->readwrite("localLights", localLights);
-  archive->readwrite("localLightsOverrideGlobal", localLightsOverrideGlobal);
+  if(archive->hasField("localLights")){
+    archive->readwrite("localLights", localLights);
+  } else {
+    localLights = 0;
+  }
+  if(archive->hasField("localLightsOverrideGlobal")){
+    archive->readwrite("localLightsOverrideGlobal", 
localLightsOverrideGlobal);
+  } else {
+    localLightsOverrideGlobal = false;
+  }
 }

Modified: trunk/Model/Primitives/Parallelogram.cc
==============================================================================
--- trunk/Model/Primitives/Parallelogram.cc     (original)
+++ trunk/Model/Primitives/Parallelogram.cc     Mon Nov  5 23:03:16 2007
@@ -630,14 +630,21 @@
 {
   MantaRTTI<PrimitiveCommon>::readwrite(archive, *this);
   MantaRTTI<TexCoordMapper>::readwrite(archive, *this);
-  archive->readwrite("anchor", anchor);
-  archive->readwrite("v1", v1);
-  archive->readwrite("v2", v2);
-  archive->readwrite("normal", normal);
-  archive->readwrite("offset", d);
-  if(archive->reading()){
-    double len = normal.normalize();
-    d *= len;
+  if(archive->reading() && archive->hasField("p0") && 
archive->hasField("p1") && archive->hasField("p2")){
+    Vector p0, p1, p2;
+    archive->readwrite("p0", p0);
+    archive->readwrite("p1", p1);
+    archive->readwrite("p2", p2);
+    changeGeometry(p0, p1-p0, p2-p0);
+  } else {
+    archive->readwrite("anchor", anchor);
+    archive->readwrite("v1", v1);
+    archive->readwrite("v2", v2);
+    archive->readwrite("normal", normal);
+    archive->readwrite("offset", d);
+    if(archive->reading()){
+      double len = normal.normalize();
+      d *= len;
+    }
   }
 }
-

Modified: trunk/Model/Primitives/PrimitiveCommon.cc
==============================================================================
--- trunk/Model/Primitives/PrimitiveCommon.cc   (original)
+++ trunk/Model/Primitives/PrimitiveCommon.cc   Mon Nov  5 23:03:16 2007
@@ -78,5 +78,8 @@
 {
   MantaRTTI<Primitive>::readwrite(archive, *this);
   archive->readwrite("material", material);
-  archive->readwrite("tex", tex);
+  if(archive->hasField("tex"))
+    archive->readwrite("tex", tex);
+  else
+    tex = &default_map;
 }

Modified: trunk/Model/Textures/CheckerTexture.h
==============================================================================
--- trunk/Model/Textures/CheckerTexture.h       (original)
+++ trunk/Model/Textures/CheckerTexture.h       Mon Nov  5 23:03:16 2007
@@ -91,10 +91,13 @@
   template<class ValueType>
     class MantaRTTI<CheckerTexture<ValueType> > : public 
MantaRTTI_DerivedClass<CheckerTexture<ValueType>, Texture<ValueType> >, 
public MantaRTTI_ConcreteClass<CheckerTexture<ValueType> >, public 
MantaRTTI_readwriteMethod<CheckerTexture<ValueType> > {
   public:
+    static std::string getPublicClassname() {
+      return 
"CheckerTexture<"+MantaRTTI<ValueType>::getPublicClassname()+">";
+    }
     class Initializer {
     public:
       Initializer() {
-        MantaRTTI<CheckerTexture<ValueType> 
>::registerClass("CheckerTexture<"+MantaRTTI<ValueType>::getPublicClassname()+">");
+        MantaRTTI<CheckerTexture<ValueType> >::registerClass();
       }
       void forceinit() {
       }

Modified: trunk/Model/Textures/Constant.h
==============================================================================
--- trunk/Model/Textures/Constant.h     (original)
+++ trunk/Model/Textures/Constant.h     Mon Nov  5 23:03:16 2007
@@ -36,10 +36,13 @@
   template<class ValueType>
     class MantaRTTI<Constant<ValueType> > : public 
MantaRTTI_DerivedClass<Constant<ValueType>, Texture<ValueType> >, public 
MantaRTTI_ConcreteClass<Constant<ValueType> >, public 
MantaRTTI_readwriteMethod<Constant<ValueType> > {
   public:
+    static std::string getPublicClassname() {
+      return "Constant<"+MantaRTTI<ValueType>::getPublicClassname()+">";
+    }
     class Initializer {
     public:
       Initializer() {
-        MantaRTTI<Constant<ValueType> 
>::registerClass("Constant<"+MantaRTTI<ValueType>::getPublicClassname()+">");
+        MantaRTTI<Constant<ValueType> >::registerClass();
       }
       void forceinit() {
       }




  • [Manta] r1824 - in trunk: Core/Color Core/Persistent Interface Model/AmbientLights Model/Backgrounds Model/Materials Model/Primitives Model/Textures, sparker, 11/06/2007

Archive powered by MHonArc 2.6.16.

Top of page