Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1396 - in branches/persistent: . Core/Color Core/Geometry Core/Reflection Interface Model/Groups Model/Lights Model/Materials Model/Primitives Model/TexCoordMappers Model/Textures


Chronological Thread 
  • From: sparker@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1396 - in branches/persistent: . Core/Color Core/Geometry Core/Reflection Interface Model/Groups Model/Lights Model/Materials Model/Primitives Model/TexCoordMappers Model/Textures
  • Date: Tue, 22 May 2007 23:05:34 -0600 (MDT)

Author: sparker
Date: Tue May 22 23:04:58 2007
New Revision: 1396

Modified:
   branches/persistent/Core/Color/ColorSpace.h
   branches/persistent/Core/Color/RGBTraits.cc
   branches/persistent/Core/Geometry/Vector.cc
   branches/persistent/Core/Reflection/Archive.cc
   branches/persistent/Core/Reflection/Archive.h
   branches/persistent/Core/Reflection/ClassInfo.h
   branches/persistent/Core/Reflection/XMLArchive.cc
   branches/persistent/Core/Reflection/XMLArchive.h
   branches/persistent/Interface/Object.h
   branches/persistent/Interface/Scene.cc
   branches/persistent/Interface/Scene.h
   branches/persistent/Interface/TexCoordMapper.h
   branches/persistent/Interface/Texture.h
   branches/persistent/Model/Groups/Group.cc
   branches/persistent/Model/Lights/PointLight.cc
   branches/persistent/Model/Lights/PointLight.h
   branches/persistent/Model/Materials/MetalMaterial.cc
   branches/persistent/Model/Materials/MetalMaterial.h
   branches/persistent/Model/Primitives/Heightfield.cc
   branches/persistent/Model/Primitives/Parallelogram.cc
   branches/persistent/Model/Primitives/Parallelogram.h
   branches/persistent/Model/Primitives/PrimitiveCommon.cc
   branches/persistent/Model/Primitives/Sphere.cc
   branches/persistent/Model/Primitives/Triangle.cc
   branches/persistent/Model/TexCoordMappers/UniformMapper.cc
   branches/persistent/Model/TexCoordMappers/UniformMapper.h
   branches/persistent/Model/Textures/CheckerTexture.h
   branches/persistent/Model/Textures/Constant.h
   branches/persistent/TODO
Log:
Persistent writes largely working


Modified: branches/persistent/Core/Color/ColorSpace.h
==============================================================================
--- branches/persistent/Core/Color/ColorSpace.h (original)
+++ branches/persistent/Core/Color/ColorSpace.h Tue May 22 23:04:58 2007
@@ -7,6 +7,7 @@
 #include <Core/Color/RGBColor.h>
 #include <Core/Color/RGBTraits.h>
 #include <Core/Math/Expon.h>
+#include <Core/Reflection/Archive.h>
 #include <Core/Reflection/ClassInfo.h>
 
 #include <sgi_stl_warnings_off.h>
@@ -275,7 +276,12 @@
       return "Color";
     }
     static void readwrite(Archive* archive, ColorSpace<Traits>& data) {
-      Traits::readwrite(archive, data.data);
+      if(archive->reading()){
+        // Read a number of different color representations
+        NOT_FINISHED("ColorSpace::readwrite");
+      } else {
+        Traits::readwrite(archive, data.data);
+      }
     }
     static bool force_initialize;
   };

Modified: branches/persistent/Core/Color/RGBTraits.cc
==============================================================================
--- branches/persistent/Core/Color/RGBTraits.cc (original)
+++ branches/persistent/Core/Color/RGBTraits.cc Tue May 22 23:04:58 2007
@@ -1,11 +1,38 @@
 
 #include <Core/Color/RGBTraits.h>
-#include <Core/Util/NotFinished.h>
+#include <Core/Reflection/Archive.h>
+#include <sstream>
+#include <iomanip>
 
 using namespace Manta;
+using namespace std;
 
 void RGBTraits::readwrite(Archive* archive, ComponentType data[3])
 {
-  NOT_FINISHED("RGBTraits::readwrite");
+  // Only used for writing...
+
+  // First, see if we can approximate the color with an rgb that is 
divisible by 256 so that
+  // we can use the HTML hex notation
+  bool hexworks = true;
+  int hex[3];
+  for(int i=0;i<3;i++){
+    if(data[i] < 0 || data[i] > 1){
+      hexworks = false;
+    } else {
+      hex[i] = (int)(data[0]*255 + 0.5);
+      if(hex[i]/255.0 != data[i])
+        hexworks = false;
+    }
+  }
+  ostringstream rep;
+  if(hexworks){
+    rep << "#";
+    for(int i=0;i<3;i++)
+      rep << setfill('0') << setbase(16) << setw(2) << hex[i];
+  } else {
+    rep << "rgb: " << data[0] << " " << data[1] << " " << data[2];
+  }
+  string repstring = rep.str();
+  archive->readwrite(0, repstring);
 }
 

Modified: branches/persistent/Core/Geometry/Vector.cc
==============================================================================
--- branches/persistent/Core/Geometry/Vector.cc (original)
+++ branches/persistent/Core/Geometry/Vector.cc Tue May 22 23:04:58 2007
@@ -56,6 +56,6 @@
 
 void Vector::readwrite(Archive* archive)
 {
-  archive->readwrite("data", data, 3);
+  archive->readwrite(0, data, 3);
 }
 

Modified: branches/persistent/Core/Reflection/Archive.cc
==============================================================================
--- branches/persistent/Core/Reflection/Archive.cc      (original)
+++ branches/persistent/Core/Reflection/Archive.cc      Tue May 22 23:04:58 
2007
@@ -72,3 +72,4 @@
 Archive::~Archive()
 {
 }
+

Modified: branches/persistent/Core/Reflection/Archive.h
==============================================================================
--- branches/persistent/Core/Reflection/Archive.h       (original)
+++ branches/persistent/Core/Reflection/Archive.h       Tue May 22 23:04:58 
2007
@@ -25,6 +25,7 @@
     virtual void readwrite(const char* fieldname, float& data) = 0;
     virtual void readwrite(const char* fieldname, float* data, int 
numElements) = 0;
     virtual void readwrite(const char* fieldname, int& data) = 0;
+    virtual void readwrite(const char* fieldname, std::string& data) = 0;
 
     bool reading() const {
       return isreading;
@@ -42,7 +43,13 @@
     virtual Archive* createFieldForClass(const std::string& fieldname, const 
std::string& classname) = 0;
     //virtual Archive* addSequence(const std::string& sequencename);
     virtual bool isNullPointer() const = 0;
-    virtual void writeNullPointer() = 0;
+    virtual void writeNullPointer(const std::string& fieldname) = 0;
+
+    virtual bool haveReference(void* ptr, std::string& refname) = 0;
+    virtual void saveReference(void* ptr, const std::string& classname) = 0;
+    virtual void writeObjectReference(const std::string& fieldname,
+                                      const std::string& classname,
+                                      const std::string& refname) = 0;
 
     virtual ~Archive();
   protected:
@@ -57,7 +64,7 @@
   void Archive::readwrite(const char* fieldname, T& data)
   {
     if(writing() && typeid(T) != typeid(data))
-      throw SerializationError("Error, cannot serialize reference to derived 
class");
+      throw SerializationError("Cannot serialize reference to derived 
class");
 
     Archive* subArchive;
     if(reading()){
@@ -93,27 +100,42 @@
     } else {
       // Writing
       if(!data){
-        Archive* subArchive = fieldname?createField(fieldname):this;
-        subArchive->writeNullPointer();
-        if(fieldname)
-          delete subArchive;
+        writeNullPointer(fieldname?fieldname:"");
         return;
       }
       if(typeid(T) == typeid(*data)){
         std::string classname = ClassInfo<T>::getPublicClassname();
-        Archive* subArchive = fieldname?createFieldForClass(fieldname, 
classname):createClass(classname);
-        ClassInfo<T>::readwrite(subArchive, *data);
-        delete subArchive;
+        // Check to see if this pointer has already been emitted.
+        std::string refname;
+        if(haveReference(static_cast<void*>(data), refname)){
+          writeObjectReference(fieldname?fieldname:"", classname, refname);
+        } else {
+          Archive* subArchive = fieldname?createFieldForClass(fieldname, 
classname):createClass(classname);
+          subArchive->saveReference(static_cast<void*>(data), classname);
+          ClassInfo<T>::readwrite(subArchive, *data);
+          delete subArchive;
+        }
       } else {
         typename ClassDatabase<T>::Entry* dbentry = 
ClassDatabase<T>::getEntry(typeid(*data));;
         if(!dbentry){
           std::string classname = typeid(*data).name();
           throw SerializationError("Cannot locate serializer for class: " + 
classname + " due to missing ClassInfo");
         }
+        // Check to see if this pointer has already been emitted.
+        // To avoid issues with pointer uniqueness under multiple
+        // inheritance, we always convert it to void the the most
+        // derived class using the class database
         std::string classname = dbentry->getPublicClassname();
-        Archive* subArchive = fieldname?createFieldForClass(fieldname, 
classname):createClass(classname);
-        dbentry->readwrite(subArchive, data);
-        delete subArchive;
+        void* ptrvalue = dbentry->getPointerValue(data);
+        std::string refname;
+        if(haveReference(static_cast<void*>(ptrvalue), refname)){
+          writeObjectReference(fieldname?fieldname:"", classname, refname);
+        } else {
+          Archive* subArchive = fieldname?createFieldForClass(fieldname, 
classname):createClass(classname);
+          subArchive->saveReference(static_cast<void*>(data), classname);
+          dbentry->readwrite(subArchive, data);
+          delete subArchive;
+        }
       }
     }
   }

Modified: branches/persistent/Core/Reflection/ClassInfo.h
==============================================================================
--- branches/persistent/Core/Reflection/ClassInfo.h     (original)
+++ branches/persistent/Core/Reflection/ClassInfo.h     Tue May 22 23:04:58 
2007
@@ -5,7 +5,6 @@
 #include <Core/Exceptions/SerializationError.h>
 #include <Core/Exceptions/InternalError.h>
 #include <Core/Util/NotFinished.h>
-#include <iostream>
 #include <map>
 #include <string>
 #include <typeinfo>
@@ -36,6 +35,7 @@
       virtual std::string getPublicClassname() const = 0;
       virtual void readwrite(Archive* archive, T* ptr) const = 0;
       virtual const std::type_info& get_typeinfo() const = 0;
+      virtual void* getPointerValue(T* ptr) const = 0;
     };
 
   private:
@@ -43,7 +43,7 @@
     class ConcreteEntry : public Entry {
     public:
       virtual ~ConcreteEntry() {}
-      virtual Class* createInstance() const {
+      virtual T* createInstance() const {
         return ClassInfo<Class>::createInstance();
       }
       virtual std::string getPublicClassname() const {
@@ -62,12 +62,15 @@
       virtual const std::type_info& get_typeinfo() const {
         return typeid(Class);
       }
+      virtual void* getPointerValue(T* ptr) const {
+        Class* derivedptr = dynamic_cast<Class*>(ptr);
+        return static_cast<void*>(derivedptr);
+      }
     };
 
   public:
     template<class C>
     static void registerClass(const std::string& name) {
-      std::cerr << "register: " << name << '\n';
       ClassDatabase<T>* db = singleton();
       ConcreteEntry<C>* entry = new ConcreteEntry<C>();
       std::pair<typename namedb_type::iterator, bool> result;
@@ -237,6 +240,38 @@
     return true;
   }
 
+  template<class T, class Parent1, class Parent2>
+  class ClassInfo_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);
+
+    template<class C>
+    static void registerClassAndParents(const std::string& classname) {
+      ClassDatabase<T>::template registerClass<C>(classname);
+      ClassInfo<Parent1>::template registerClassAndParents<C>(classname);
+      ClassInfo<Parent2>::template registerClassAndParents<C>(classname);
+    }
+  private:
+    ClassInfo_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* 
ClassInfo_DerivedClass2<T, Parent1, Parent2>::classname;
+
+  template<class T, class Parent1, class Parent2>
+    bool ClassInfo_DerivedClass2<T, Parent1, Parent2>::registerClass(const 
std::string& _classname)
+  {
+    if(!classname)
+      classname = new std::string(_classname);
+    registerClassAndParents<T>(_classname);
+    return true;
+  }
+
   template<>
   class ClassInfo<float> {
   public:
@@ -250,6 +285,15 @@
 #define DECLARE_CLASSINFO_DERIVEDCLASS(declclass, baseclass, classtype, 
rwtype)  \
 template<>\
 class ClassInfo<declclass> : public ClassInfo_DerivedClass<declclass, 
baseclass>, \
+                             public ClassInfo_##classtype<declclass>, \
+                             public ClassInfo_##rwtype<declclass> \
+{ \
+  static bool force_initialize; \
+}
+
+#define DECLARE_CLASSINFO_DERIVEDCLASS2(declclass, baseclass1, baseclass2, 
classtype, rwtype) \
+template<>\
+class ClassInfo<declclass> : public ClassInfo_DerivedClass2<declclass, 
baseclass1, baseclass2>, \
                              public ClassInfo_##classtype<declclass>, \
                              public ClassInfo_##rwtype<declclass> \
 { \

Modified: branches/persistent/Core/Reflection/XMLArchive.cc
==============================================================================
--- branches/persistent/Core/Reflection/XMLArchive.cc   (original)
+++ branches/persistent/Core/Reflection/XMLArchive.cc   Tue May 22 23:04:58 
2007
@@ -29,7 +29,7 @@
   if (doc == 0)
     throw InputError("Error reading file: "+filename);
 
-  return new XMLArchive(doc, xmlDocGetRootElement(doc), true);
+  return new XMLArchive(doc);
 }
 
 static Archive* writeopener(const std::string& filename)
@@ -43,10 +43,7 @@
     suffix = filename.substr(dot+1);
   }
   if(suffix == "xml" || suffix == "rtml"){
-    LIBXML_TEST_VERSION;
-  
-    xmlDocPtr doc = xmlNewDoc(to_xml_ch_ptr("1.0"));
-    return new XMLArchive(doc, 0, strdup(filename.c_str()));
+    return new XMLArchive(filename);
   } else {
     return 0;
   }
@@ -54,44 +51,69 @@
 
 bool XMLArchive::force_initialize = Archive::registerArchiveType("xml", 
readopener, writeopener);
 
-XMLArchive::XMLArchive(xmlDocPtr doc, xmlNodePtr node, bool ownsDoc)
-  : Archive(true), doc(doc), node(node), filename(0), ownsDoc(ownsDoc)
-{
-}
-
-XMLArchive::XMLArchive(xmlDocPtr doc, xmlNodePtr node, char* filename)
-  : Archive(false), doc(doc), node(node), filename(filename), ownsDoc(0)
+XMLArchive::XMLArchive(xmlDocPtr doc)
+  : Archive(true)
 {
+  node = 0;
+  ownsDoc = true;
+  docinfo = new DocInfo;
+  docinfo->doc = doc;
+}
+
+XMLArchive::XMLArchive(const std::string& infilename)
+  : Archive(false)
+{
+  node = 0;
+  ownsDoc = true;
+  docinfo = new DocInfo;
+  docinfo->doc = xmlNewDoc(to_xml_ch_ptr("1.0"));
+  docinfo->filename = infilename;
 }
 
 XMLArchive::XMLArchive(XMLArchive* copy, xmlNodePtr node)
-  : Archive(copy->isreading), doc(copy->doc), node(node), filename(0), 
ownsDoc(0)
+  : Archive(copy->isreading), node(node), docinfo(copy->docinfo), 
ownsDoc(false)
 {
 }
 
 XMLArchive::~XMLArchive()
 {
-  if(filename){
-    xmlKeepBlanksDefault(0);
-    xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1);
-    free(filename);
+  if(ownsDoc){
+    if(writing()){
+      xmlKeepBlanksDefault(0);
+      xmlSaveFormatFileEnc(docinfo->filename.c_str(), docinfo->doc, "UTF-8", 
1);
+    } else {
+    }
+    xmlFreeDoc(docinfo->doc);
+    delete docinfo;
   }
-
-  if(ownsDoc)
-    xmlFreeDoc(doc);
 }
 
 void XMLArchive::writeProperty(const char* fieldname, const std::string& 
value)
 {
-  if(xmlHasProp(node, to_xml_ch_ptr(fieldname))){
-    ostringstream msg;
-    msg << "Writing duplicate field (" << fieldname << ")";
-    const char* cl = to_char_ptr(xmlGetProp(node, to_xml_ch_ptr("class")));
-    if(cl)
-      msg << " in writing class " << cl << '\n';
-    throw SerializationError(msg.str());
+  if(!fieldname){
+    // Write the value as a property of the parent node
+    if(xmlHasProp(node->parent, node->name)){
+      ostringstream msg;
+      msg << "Writing duplicate anonymous field in writing class " << 
to_char_ptr(node->name);
+      throw SerializationError(msg.str());
+    }
+    if(node->children){
+      ostringstream msg;
+      msg << "Using anonymous (single) field when there are other XML 
children in writing class " << to_char_ptr(node->name);
+      throw SerializationError(msg.str());
+    }
+    xmlSetProp(node->parent, node->name, to_xml_ch_ptr(value.c_str()));
+    xmlUnlinkNode(node);
+    xmlFreeNode(node);
+    node = 0;
+  } else {
+    if(xmlHasProp(node, to_xml_ch_ptr(fieldname))){
+      ostringstream msg;
+      msg << "Writing duplicate field (" << fieldname << ") in writing class 
" << to_char_ptr(node->name);
+      throw SerializationError(msg.str());
+    }
+    xmlSetProp(node, to_xml_ch_ptr(fieldname), to_xml_ch_ptr(value.c_str()));
   }
-  xmlSetProp(node, to_xml_ch_ptr(fieldname), to_xml_ch_ptr(value.c_str()));
 }
 
 void XMLArchive::readwrite(const char* fieldname, bool& data)
@@ -154,6 +176,15 @@
   }
 }
 
+void XMLArchive::readwrite(const char* fieldname, std::string& data)
+{
+  if(reading()){
+    NOT_FINISHED("XMLArchive::readwrite");
+  } else {
+    writeProperty(fieldname, data);
+  }
+}
+
 std::string XMLArchive::getClassname() const
 {
   return to_char_ptr(node->name);
@@ -171,7 +202,7 @@
   if(node)
     xmlAddChild(node, child);
   else
-    xmlDocSetRootElement(doc, child);
+    xmlDocSetRootElement(docinfo->doc, child);
   return new XMLArchive(this, child);
 }
 
@@ -197,7 +228,67 @@
   return false;
 }
 
-void XMLArchive::writeNullPointer()
+void XMLArchive::writeNullPointer(const std::string& fieldname)
 {
-  NOT_FINISHED("XMLArchive::writeNullPointer");
+  xmlNodePtr field;
+  if(fieldname == ""){
+    field = xmlNewNode(0, to_xml_ch_ptr("null"));
+  } else {
+    field = xmlNewNode(0, to_xml_ch_ptr(fieldname.c_str()));
+  }
+}
+
+void XMLArchive::writeObjectReference(const std::string& fieldname,
+                                      const std::string& classname,
+                                      const std::string& refname)
+{
+  if(fieldname == ""){
+    NOT_FINISHED("XMLArchive::writeObjectReference");
+  } else {
+    xmlSetProp(node, to_xml_ch_ptr(fieldname.c_str()), 
to_xml_ch_ptr(refname.c_str()));
+  }
+}
+
+bool XMLArchive::haveReference(void* ptr, std::string& refname)
+{
+  refmaptype::iterator iter = docinfo->refmap.find(ptr);
+  if(iter == docinfo->refmap.end()){
+    return false;
+  } else {
+    RefInfo& ri = iter->second;
+    if(!ri.used){
+      // Append the count to make it unique
+      countmaptype::iterator citer = docinfo->countmap.find(ri.refname);
+      int count;
+      if(citer == docinfo->countmap.end()){
+        count = 0;
+        docinfo->countmap.insert(make_pair(ri.refname, 1));
+      } else {
+        count = citer->second++;
+      }
+
+      ostringstream str;
+      str << ri.refname << count;
+      ri.refname = str.str();
+      xmlSetProp(ri.node, to_xml_ch_ptr("id"), 
to_xml_ch_ptr(ri.refname.c_str()));
+      ri.used = true;
+    }
+    refname = ri.refname;
+    return true;
+  }
+}
+
+void XMLArchive::saveReference(void* ptr, const std::string& classname)
+{
+  refmaptype::iterator iter = docinfo->refmap.find(ptr);
+  if(iter != docinfo->refmap.end())
+    throw SerializationError("Pointer writen twice (reference id " + 
iter->second.refname);
+
+
+  RefInfo ri;
+  ri.node = node;
+  ri.refname = classname; // Will be appended with unique ID later
+  ri.used = false;
+
+  docinfo->refmap.insert(make_pair(ptr, ri));
 }

Modified: branches/persistent/Core/Reflection/XMLArchive.h
==============================================================================
--- branches/persistent/Core/Reflection/XMLArchive.h    (original)
+++ branches/persistent/Core/Reflection/XMLArchive.h    Tue May 22 23:04:58 
2007
@@ -4,12 +4,14 @@
 
 #include <Core/Reflection/Archive.h>
 #include <libxml/tree.h>
+#include <map>
+#include <string>
 
 namespace Manta {
   class XMLArchive : public Archive {
   public:
-    XMLArchive(xmlDocPtr doc, xmlNodePtr node, bool ownsDoc);
-    XMLArchive(xmlDocPtr doc, xmlNodePtr node, char* filename);
+    XMLArchive(xmlDocPtr doc);
+    XMLArchive(const std::string& filename);
     XMLArchive(XMLArchive* archive, xmlNodePtr node);
     virtual ~XMLArchive();
 
@@ -18,6 +20,7 @@
     virtual void readwrite(const char* fieldname, float& data);
     virtual void readwrite(const char* fieldname, float* data, int 
numElements);
     virtual void readwrite(const char* fieldname, int& data);
+    virtual void readwrite(const char* fieldname, std::string& data);
     
     virtual std::string getClassname() const;
 
@@ -26,11 +29,32 @@
     virtual Archive* createField(const std::string& fieldname);
     virtual Archive* createFieldForClass(const std::string& fieldname, const 
std::string& classname);
     virtual bool isNullPointer() const;
-    virtual void writeNullPointer();
+    virtual void writeNullPointer(const std::string& fieldname);
+
+    virtual bool haveReference(void* ptr, std::string& refname);
+    virtual void saveReference(void* ptr, const std::string& classname);
+    virtual void writeObjectReference(const std::string& fieldname,
+                                      const std::string& classname,
+                                      const std::string& refname);
+
   private:
-    xmlDocPtr doc;
     xmlNodePtr node;
-    char* filename;
+
+    struct RefInfo {
+      xmlNodePtr node;
+      std::string refname;
+      bool used;
+    };
+
+    typedef std::map<void*, RefInfo> refmaptype;
+    typedef std::map<std::string, int> countmaptype;
+    struct DocInfo {
+      refmaptype refmap;
+      countmaptype countmap;
+      xmlDocPtr doc;
+      std::string filename;
+    };
+    DocInfo* docinfo;
     bool ownsDoc;
 
     static bool force_initialize;

Modified: branches/persistent/Interface/Object.h
==============================================================================
--- branches/persistent/Interface/Object.h      (original)
+++ branches/persistent/Interface/Object.h      Tue May 22 23:04:58 2007
@@ -11,7 +11,7 @@
   class RayPacket;
   class RenderContext;
 
-  class Object : public Interpolable {
+  class Object : virtual public Interpolable {
   public:
     Object();
     virtual ~Object();

Modified: branches/persistent/Interface/Scene.cc
==============================================================================
--- branches/persistent/Interface/Scene.cc      (original)
+++ branches/persistent/Interface/Scene.cc      Tue May 22 23:04:58 2007
@@ -51,7 +51,18 @@
   archive->readwrite("bg", bg);
   archive->readwrite("lights", lights);
   archive->readwrite("renderParameters", renderParameters);
-  NOT_FINISHED("readwrite bookmarks");
-  //archive->readwrite("bookmarks", bookmarks);
+  archive->readwrite("bookmarks", bookmarks);
   archive->readwrite("currentBookmark", currentBookmark);
 }
+
+namespace Manta {
+  DECLARE_CLASSINFO_BASECLASS(Scene::Bookmark, ConcreteClass, 
readwriteMethod);
+  REGISTER_CLASS(Scene::Bookmark);
+}
+
+void Scene::Bookmark::readwrite(Archive* archive)
+{
+  archive->readwrite("name", name);
+  archive->readwrite("cameradata", cameradata);
+}
+

Modified: branches/persistent/Interface/Scene.h
==============================================================================
--- branches/persistent/Interface/Scene.h       (original)
+++ branches/persistent/Interface/Scene.h       Tue May 22 23:04:58 2007
@@ -75,15 +75,18 @@
     const BasicCameraData* nextBookmark();
 
     void readwrite(Archive*);
+    struct Bookmark {
+      void readwrite(Archive* archive);
+    private:
+      friend class Scene;
+      std::string name;
+      BasicCameraData cameradata;
+    };
   private:
     Object* object;
     Background* bg;
     LightSet* lights;
     RenderParameters renderParameters;
-    struct Bookmark {
-      std::string name;
-      BasicCameraData cameradata;
-    };
     std::vector<Bookmark*> bookmarks;
     int currentBookmark;
   };

Modified: branches/persistent/Interface/TexCoordMapper.h
==============================================================================
--- branches/persistent/Interface/TexCoordMapper.h      (original)
+++ branches/persistent/Interface/TexCoordMapper.h      Tue May 22 23:04:58 
2007
@@ -9,7 +9,7 @@
   class RayPacket;
   class RenderContext;
 
-  class TexCoordMapper : public Interpolable {
+  class TexCoordMapper : virtual public Interpolable {
   public:
     TexCoordMapper();
     virtual ~TexCoordMapper();

Modified: branches/persistent/Interface/Texture.h
==============================================================================
--- branches/persistent/Interface/Texture.h     (original)
+++ branches/persistent/Interface/Texture.h     Tue May 22 23:04:58 2007
@@ -9,7 +9,7 @@
   class RayPacket;
   class RenderContext;
   template<typename ValueType>
-  class Texture : public Interpolable {
+  class Texture : virtual public Interpolable {
   public:
     Texture() {};
     virtual ~Texture() {};

Modified: branches/persistent/Model/Groups/Group.cc
==============================================================================
--- branches/persistent/Model/Groups/Group.cc   (original)
+++ branches/persistent/Model/Groups/Group.cc   Tue May 22 23:04:58 2007
@@ -30,14 +30,14 @@
 {
   Group *copy;
   if (incoming)
-    copy = static_cast<Group*>(incoming);
+    copy = dynamic_cast<Group*>(incoming);
   else
     copy = new Group();
 
   for(vector<Object*>::iterator iter = objs.begin();
       iter != objs.end(); ++iter) {
     Object *obj = *iter;
-    copy->add(static_cast<Object*>(obj->clone(depth)));
+    copy->add(dynamic_cast<Object*>(obj->clone(depth)));
   }
   return copy;
 }

Modified: branches/persistent/Model/Lights/PointLight.cc
==============================================================================
--- branches/persistent/Model/Lights/PointLight.cc      (original)
+++ branches/persistent/Model/Lights/PointLight.cc      Tue May 22 23:04:58 
2007
@@ -1,9 +1,16 @@
 
 #include <Model/Lights/PointLight.h>
+#include <Core/Reflection/Archive.h>
+#include <Core/Reflection/ClassInfo.h>
+#include <Interface/InterfaceClassInfo.h>
 #include <MantaSSE.h>
 
 using namespace Manta;
 
+PointLight::PointLight()
+{
+}
+
 PointLight::PointLight(const Vector& position, const Color& color)
   : position(position), color(color)
 {
@@ -56,4 +63,16 @@
       destRays.setDirection(i, position - sourceRays.getHitPosition(i));
     }
 #endif
+}
+
+namespace Manta {
+  DECLARE_CLASSINFO_DERIVEDCLASS(PointLight, Light, ConcreteClass, 
readwriteMethod);
+  REGISTER_CLASS(PointLight);
+}
+
+void PointLight::readwrite(Archive* archive)
+{
+  ClassInfo<Light>::readwrite(archive, *this);
+  archive->readwrite("position", position);
+  archive->readwrite("color", color);
 }

Modified: branches/persistent/Model/Lights/PointLight.h
==============================================================================
--- branches/persistent/Model/Lights/PointLight.h       (original)
+++ branches/persistent/Model/Lights/PointLight.h       Tue May 22 23:04:58 
2007
@@ -7,8 +7,11 @@
 #include <Core/Color/Color.h>
 
 namespace Manta {
+  class Archive;
+
   class PointLight : public Light {
   public:
+    PointLight();
     PointLight(const Vector& position, const Color& color);
     virtual ~PointLight();
 
@@ -23,7 +26,8 @@
 
     Color getColor() const { return color; }
     void setColor(Color new_c) { color = new_c; }
-    
+
+    void readwrite(Archive* archive);
   private:
     Vector position;
     Color color;

Modified: branches/persistent/Model/Materials/MetalMaterial.cc
==============================================================================
--- branches/persistent/Model/Materials/MetalMaterial.cc        (original)
+++ branches/persistent/Model/Materials/MetalMaterial.cc        Tue May 22 
23:04:58 2007
@@ -1,6 +1,8 @@
 
 #include <Model/Materials/MetalMaterial.h>
 #include <Core/Math/ipow.h>
+#include <Core/Reflection/ClassInfo.h>
+#include <Core/Reflection/Archive.h>
 #include <Interface/Context.h>
 #include <Interface/Light.h>
 #include <Interface/LightSet.h>
@@ -13,6 +15,11 @@
 
 using namespace Manta;
 
+MetalMaterial::MetalMaterial()
+{
+  specular_reflectance = 0;
+}
+
 MetalMaterial::MetalMaterial(const Color& specular, int phong_exponent)
   : phong_exponent(phong_exponent)
 {
@@ -74,4 +81,16 @@
     for(int i=rays.begin();i<rays.end();i++) 
       rays.setColor(i, Color::black());
   }
+}
+
+namespace Manta {
+  DECLARE_CLASSINFO_DERIVEDCLASS(MetalMaterial, LitMaterial, ConcreteClass, 
readwriteMethod);
+  REGISTER_CLASS(MetalMaterial);
+}
+
+void MetalMaterial::readwrite(Archive* archive)
+{
+  ClassInfo<LitMaterial>::readwrite(archive, *this);
+  archive->readwrite("reflectance", specular_reflectance);
+  archive->readwrite("phong_exponent", phong_exponent);
 }

Modified: branches/persistent/Model/Materials/MetalMaterial.h
==============================================================================
--- branches/persistent/Model/Materials/MetalMaterial.h (original)
+++ branches/persistent/Model/Materials/MetalMaterial.h Tue May 22 23:04:58 
2007
@@ -7,17 +7,19 @@
 #include <Interface/Texture.h>
 
 namespace Manta{
+  class Archive;
   class LightSet;
 
   class MetalMaterial : public LitMaterial {
   public:
-
+    MetalMaterial();
     MetalMaterial(const Color& specular_reflectance, int phong_exponent = 
100);
     MetalMaterial(const Texture<Color>* specular_reflectance,
                  int phong_exponent = 100);
     virtual ~MetalMaterial();
   
     virtual void shade(const RenderContext& context, RayPacket& rays) const;
+    void readwrite(Archive* archive);
   private:
     const Texture<Color>* specular_reflectance;
     int phong_exponent;

Modified: branches/persistent/Model/Primitives/Heightfield.cc
==============================================================================
--- branches/persistent/Model/Primitives/Heightfield.cc (original)
+++ branches/persistent/Model/Primitives/Heightfield.cc Tue May 22 23:04:58 
2007
@@ -69,7 +69,7 @@
 {
   Heightfield *h;
   if (incoming)
-    h = static_cast<Heightfield*>(incoming);
+    h = dynamic_cast<Heightfield*>(incoming);
   else
     h = new Heightfield();
 

Modified: branches/persistent/Model/Primitives/Parallelogram.cc
==============================================================================
--- branches/persistent/Model/Primitives/Parallelogram.cc       (original)
+++ branches/persistent/Model/Primitives/Parallelogram.cc       Tue May 22 
23:04:58 2007
@@ -1,6 +1,9 @@
 
 #include <Model/Primitives/Parallelogram.h>
+#include <Interface/InterfaceClassInfo.h>
 #include <Interface/RayPacket.h>
+#include <Core/Reflection/Archive.h>
+#include <Core/Reflection/ClassInfo.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Math/MiscMath.h>
 #include <MantaSSE.h>
@@ -16,6 +19,10 @@
                _mm_or_ps(_mm_and_ps(mask, newD),                    \
                          _mm_andnot_ps(mask, _mm_load_ps(oldD))))
 
+Parallelogram::Parallelogram()
+{
+}
+
 Parallelogram::Parallelogram(Material* material, const Vector& anchor,
                              const Vector& in_v1, const Vector& in_v2)
   : PrimitiveCommon(material, this), anchor(anchor), v1(in_v1), v2(in_v2)
@@ -542,3 +549,21 @@
 #endif
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
+
+namespace Manta {
+  DECLARE_CLASSINFO_DERIVEDCLASS2(Parallelogram, PrimitiveCommon, 
TexCoordMapper, ConcreteClass, readwriteMethod);
+  REGISTER_CLASS(Parallelogram);
+}
+
+void Parallelogram::readwrite(Archive* archive)
+{
+  ClassInfo<PrimitiveCommon>::readwrite(archive, *this);
+  ClassInfo<TexCoordMapper>::readwrite(archive, *this);
+  archive->readwrite("anchor", anchor);
+  archive->readwrite("v1", v1);
+  archive->readwrite("v2", v2);
+  if(archive->reading()){
+    NOT_FINISHED("Parallelogram readwrite normal/d");
+  }
+}
+

Modified: branches/persistent/Model/Primitives/Parallelogram.h
==============================================================================
--- branches/persistent/Model/Primitives/Parallelogram.h        (original)
+++ branches/persistent/Model/Primitives/Parallelogram.h        Tue May 22 
23:04:58 2007
@@ -7,8 +7,11 @@
 #include <Core/Geometry/Vector.h>
 
 namespace Manta {
+  class Archive;
+
   class Parallelogram : public PrimitiveCommon, public TexCoordMapper {
   public:
+    Parallelogram();
     Parallelogram(Material* material, const Vector& anchor,
                   const Vector& v1, const Vector& v2);
     virtual ~Parallelogram();
@@ -21,6 +24,8 @@
                                   RayPacket& rays) const;
     virtual void computeTexCoords3(const RenderContext& context,
                                   RayPacket& rays) const;
+
+    void readwrite(Archive* archive);
   private:
     Vector anchor;
     Vector v1, v2;

Modified: branches/persistent/Model/Primitives/PrimitiveCommon.cc
==============================================================================
--- branches/persistent/Model/Primitives/PrimitiveCommon.cc     (original)
+++ branches/persistent/Model/Primitives/PrimitiveCommon.cc     Tue May 22 
23:04:58 2007
@@ -27,7 +27,7 @@
 {
   PrimitiveCommon *copy;
   assert (incoming); //PrimitiveCommon is an abstract base class, can't new 
it.
-  copy = static_cast<PrimitiveCommon*>(incoming);
+  copy = dynamic_cast<PrimitiveCommon*>(incoming);
   copy->material = material;
   copy->tex = tex;
   

Modified: branches/persistent/Model/Primitives/Sphere.cc
==============================================================================
--- branches/persistent/Model/Primitives/Sphere.cc      (original)
+++ branches/persistent/Model/Primitives/Sphere.cc      Tue May 22 23:04:58 
2007
@@ -33,7 +33,7 @@
 {
   Sphere *copy;
   if (incoming)
-    copy = static_cast<Sphere*>(incoming);
+    copy = dynamic_cast<Sphere*>(incoming);
   else
     copy = new Sphere();
 

Modified: branches/persistent/Model/Primitives/Triangle.cc
==============================================================================
--- branches/persistent/Model/Primitives/Triangle.cc    (original)
+++ branches/persistent/Model/Primitives/Triangle.cc    Tue May 22 23:04:58 
2007
@@ -27,7 +27,7 @@
 {
   Triangle *copy;
   if (incoming)
-    copy = static_cast<Triangle*>(incoming);
+    copy = dynamic_cast<Triangle*>(incoming);
   else
     copy = new Triangle();
 

Modified: branches/persistent/Model/TexCoordMappers/UniformMapper.cc
==============================================================================
--- branches/persistent/Model/TexCoordMappers/UniformMapper.cc  (original)
+++ branches/persistent/Model/TexCoordMappers/UniformMapper.cc  Tue May 22 
23:04:58 2007
@@ -1,5 +1,6 @@
 
 #include <Model/TexCoordMappers/UniformMapper.h>
+#include <Interface/InterfaceClassInfo.h>
 #include <Interface/RayPacket.h>
 
 using namespace Manta;
@@ -80,3 +81,12 @@
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
 
+namespace Manta {
+  DECLARE_CLASSINFO_DERIVEDCLASS(UniformMapper, TexCoordMapper, 
ConcreteClass, readwriteMethod);
+  REGISTER_CLASS(UniformMapper);
+};
+
+void UniformMapper::readwrite(Archive* archive)
+{
+  ClassInfo<TexCoordMapper>::readwrite(archive, *this);
+}

Modified: branches/persistent/Model/TexCoordMappers/UniformMapper.h
==============================================================================
--- branches/persistent/Model/TexCoordMappers/UniformMapper.h   (original)
+++ branches/persistent/Model/TexCoordMappers/UniformMapper.h   Tue May 22 
23:04:58 2007
@@ -5,6 +5,8 @@
 #include <Interface/TexCoordMapper.h>
 
 namespace Manta {
+  class Archive;
+
   class UniformMapper : public TexCoordMapper {
   public:
     UniformMapper();
@@ -14,6 +16,8 @@
                           RayPacket& rays) const;
     virtual void computeTexCoords3(const RenderContext& context,
                            RayPacket& rays) const;
+
+    void readwrite(Archive* archive);
   private:
     UniformMapper(const UniformMapper&);
     UniformMapper& operator=(const UniformMapper&);

Modified: branches/persistent/Model/Textures/CheckerTexture.h
==============================================================================
--- branches/persistent/Model/Textures/CheckerTexture.h (original)
+++ branches/persistent/Model/Textures/CheckerTexture.h Tue May 22 23:04:58 
2007
@@ -5,6 +5,8 @@
 #include <Interface/Texture.h>
 #include <Core/Color/Color.h>
 #include <Core/Geometry/Vector.h>
+#include <Core/Reflection/Archive.h>
+#include <Interface/InterfaceClassInfo.h>
 #include <Interface/RayPacket.h>
 #include <MantaSSE.h>
 
@@ -14,12 +16,14 @@
   template<typename ValueType>
   class CheckerTexture : public Texture<ValueType> {
   public:
+    CheckerTexture();
     CheckerTexture(const ValueType& value1,
                   const ValueType& value2,
                   const Vector& v1, const Vector& v2);
     virtual ~CheckerTexture();
 
     virtual void mapValues(Packet<ValueType>&, const RenderContext& context, 
RayPacket& rays) const;
+    void readwrite(Archive* archive);
   private:
     CheckerTexture(const CheckerTexture&);
     CheckerTexture& operator=(const CheckerTexture&);
@@ -31,6 +35,11 @@
   };
 
   template<class ValueType>
+  CheckerTexture<ValueType>::CheckerTexture()
+  {
+  }
+
+  template<class ValueType>
   CheckerTexture<ValueType>::CheckerTexture(const ValueType& value1,
                                            const ValueType& value2,
                                            const Vector& v1,
@@ -46,11 +55,6 @@
   }
   
   template<class ValueType>
-  CheckerTexture<ValueType>::~CheckerTexture()
-  {
-  }
-  
-  template<class ValueType>
     void CheckerTexture<ValueType>::mapValues(Packet<ValueType>& results,
                                               const RenderContext& context,
                                               RayPacket& rays) const
@@ -84,6 +88,52 @@
                                           RayPacket& rays) const;
 #endif
 
+  template<class ValueType>
+    class ClassInfo<CheckerTexture<ValueType> > : public 
ClassInfo_DerivedClass<CheckerTexture<ValueType>, Texture<ValueType> >, 
public ClassInfo_ConcreteClass<CheckerTexture<ValueType> >, public 
ClassInfo_readwriteMethod<CheckerTexture<ValueType> > {
+  public:
+    class Initializer {
+    public:
+      Initializer() {
+        ClassInfo<CheckerTexture<ValueType> 
>::registerClass("CheckerTexture<"+ClassInfo<ValueType>::getPublicClassname()+">");
+      }
+      void forceinit() {
+      }
+    };
+    static Initializer init;
+  };
+
+  template<class ValueType>
+  typename ClassInfo<CheckerTexture<ValueType> >::Initializer 
ClassInfo<CheckerTexture<ValueType> >::init;
+
+  template<class ValueType>
+  void CheckerTexture<ValueType>::readwrite(Archive* archive)
+  {
+    archive->readwrite("value1", values[0]);
+    archive->readwrite("value2", values[1]);
+    archive->readwrite("v1", v1);
+    archive->readwrite("v2", v2);
+    if(archive->reading()){
+      if(v1.z() == 0 && v2.z() == 0)
+        need_w = false;
+      else
+        need_w = true;
+    }
+  }
+
+  template<class ValueType>
+  CheckerTexture<ValueType>::~CheckerTexture()
+  {
+    ClassInfo<CheckerTexture<ValueType> >::init.forceinit();
+  }
+  
+  template<>
+    void CheckerTexture<Color>::mapValues(Packet<Color>& results,
+                                    const RenderContext& context,
+                                    RayPacket& rays) const;
+  template<>
+    void CheckerTexture<float>::mapValues(Packet<float>& results,
+                                    const RenderContext& context,
+                                    RayPacket& rays) const;
 }
 
 

Modified: branches/persistent/Model/Textures/Constant.h
==============================================================================
--- branches/persistent/Model/Textures/Constant.h       (original)
+++ branches/persistent/Model/Textures/Constant.h       Tue May 22 23:04:58 
2007
@@ -4,6 +4,7 @@
 
 #include <Interface/Texture.h>
 #include <Interface/RayPacket.h>
+#include <Interface/InterfaceClassInfo.h>
 #include <Core/Reflection/Archive.h>
 #include <MantaSSE.h>
 
@@ -32,22 +33,14 @@
   };
 
   template<class ValueType>
-  class ClassInfo<Constant<ValueType> > : public 
ClassInfo_ConcreteClass<Constant<ValueType> >, public 
ClassInfo_readwriteMethod<Constant<ValueType> > {
-  public:
-    static std::string getPublicClassname() {
-      init.forceinit();
-      return "Constant<" + ClassInfo<ValueType>::getPublicClassname() + ">";
-    }
-
+    class ClassInfo<Constant<ValueType> > : public 
ClassInfo_DerivedClass<Constant<ValueType>, Texture<ValueType> >, public 
ClassInfo_ConcreteClass<Constant<ValueType> >, public 
ClassInfo_readwriteMethod<Constant<ValueType> > {
   public:
     class Initializer {
     public:
       Initializer() {
-        std::cerr << "register class: " << getPublicClassname() << '\n';
-        ClassDatabase<Constant<ValueType> >::template 
registerClass<Constant<ValueType> >(getPublicClassname());
+        ClassInfo<Constant<ValueType> 
>::registerClass("Constant<"+ClassInfo<ValueType>::getPublicClassname()+">");
       }
       void forceinit() {
-        std::cerr << "forceinit\n";
       }
     };
     static Initializer init;
@@ -60,18 +53,17 @@
   Constant<ValueType>::Constant(const ValueType& value)
     : value(value)
   {
-    ClassInfo<Constant<ValueType> >::init.forceinit();
   }
   
   template<class ValueType>
   Constant<ValueType>::Constant()
   {
-    ClassInfo<Constant<ValueType> >::init.forceinit();
   }
   
   template<class ValueType>
   Constant<ValueType>::~Constant()
   {
+    ClassInfo<Constant<ValueType> >::init.forceinit();
   }
   
   template<class ValueType>

Modified: branches/persistent/TODO
==============================================================================
--- branches/persistent/TODO    (original)
+++ branches/persistent/TODO    Tue May 22 23:04:58 2007
@@ -1,12 +1,10 @@
+Fix tag names for templates values (is . legal?)
+instead of using precision 17, try different lengths of precision?  At least 
the default?
+Detect self references?
 Separate read for color (can read anything)
-Writer for color
-vector readwrite
-array readwrite
 specialize classinfo for pointers?  Then remove specialization from vector
-Error checking in xmlarchive
-Need to mark objects already emitted
-reference by id
-can backward references work?
+Error checking in xmlarchive (err codes from libxml2)
+can backward references work for reading?
 properly handlenamespaces in:
  - read
  - write




  • [MANTA] r1396 - in branches/persistent: . Core/Color Core/Geometry Core/Reflection Interface Model/Groups Model/Lights Model/Materials Model/Primitives Model/TexCoordMappers Model/Textures, sparker, 05/22/2007

Archive powered by MHonArc 2.6.16.

Top of page