Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r377 - in swig: Interface Model/AmbientLights SwigInterface
- Date: Fri, 10 Jun 2005 18:37:24 -0600 (MDT)
Author: bigler
Date: Fri Jun 10 18:37:20 2005
New Revision: 377
Modified:
swig/Interface/AmbientLight.h
swig/Interface/LightSet.cc
swig/Interface/LightSet.h
swig/Model/AmbientLights/ArcAmbient.cc
swig/Model/AmbientLights/ArcAmbient.h
swig/Model/AmbientLights/ConstantAmbient.cc
swig/Model/AmbientLights/ConstantAmbient.h
swig/SwigInterface/CMakeLists.txt
swig/SwigInterface/manta-run.py
swig/SwigInterface/manta.i
Log:
Updates for converting some classes to strings. Changed void
printme() to std::string toString(). Made some extenstions to make
these functions available in Python.
Interface/AmbientLight.h
Interface/LightSet.cc
Interface/LightSet.h
Model/AmbientLights/ArcAmbient.h
Model/AmbientLights/ConstantAmbient.h
printme to toString.
Model/AmbientLights/ArcAmbient.cc
Model/AmbientLights/ConstantAmbient.cc
printme to toString. Better printing of colors.
SwigInterface/CMakeLists.txt
Some CMakes really do want you to call
SET_SOURCE_FILES_PROPERTIES for SWIG_FLAGS with something. I
wanted that to be "", but this caused the CMake I use at SCI
to break, so I came up with something that won't cause it to
break, I hope.
SwigInterface/manta-run.py
Use the cool new manta_new python function that acts like C's
new.
SwigInterface/manta.i
Add some extenstions for LightSet and AmbientLight to map
__str__ to toString(). I also added hints that the memory
allocated needs to be deleted after SWIG hands it off to
Python.
Added manta_new and manta_delete Python functions for managing
pointers of classes created by Python.
Modified: swig/Interface/AmbientLight.h
==============================================================================
--- swig/Interface/AmbientLight.h (original)
+++ swig/Interface/AmbientLight.h Fri Jun 10 18:37:20 2005
@@ -2,6 +2,10 @@
#ifndef Manta_Interface_AmbientLight_h
#define Manta_Interface_AmbientLight_h
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <sgi_stl_warnings_on.h>
+
namespace Manta {
class PreprocessContext;
class RenderContext;
@@ -14,7 +18,9 @@
virtual void preprocess(const PreprocessContext& context) = 0;
virtual void computeAmbient(const RenderContext& context, RayPacket&
rays) const = 0;
- virtual void printme() const = 0;
+ // This function will return a newly allocated pointer of a string
+ // representation of the object. You should delete it yourself.
+ virtual std::string toString() const = 0;
private:
AmbientLight(const AmbientLight&);
AmbientLight& operator=(const AmbientLight&);
Modified: swig/Interface/LightSet.cc
==============================================================================
--- swig/Interface/LightSet.cc (original)
+++ swig/Interface/LightSet.cc Fri Jun 10 18:37:20 2005
@@ -6,6 +6,7 @@
#include <sgi_stl_warnings_off.h>
#include <iostream>
+#include <sstream>
#include <sgi_stl_warnings_on.h>
using namespace Manta;
@@ -30,8 +31,6 @@
{
// This won't work in many of the shadow algorithms
ASSERT(static_cast<int>(lights.size()) <= RayPacket::MaxSize);
- cerr << "LightSet::preprocess\n";
- printme();
if(ambientLight){
AmbientLight* test = dynamic_cast<AmbientLight*>(ambientLight);
if (test)
@@ -46,12 +45,15 @@
}
}
-void LightSet::printme() {
- cerr << "ambientLight = "<<ambientLight<<"\n";
- if (ambientLight) ambientLight->printme();
- cerr << "Num lights = "<<lights.size()<<"\n";
+string LightSet::toString() {
+ ostringstream out;
+ out << "ambientLight = "<<ambientLight<<"\n";
+ if (ambientLight)
+ out << ambientLight->toString();
+ out << "Num lights = "<<lights.size()<<"\n";
for(int i = 0; i < static_cast<int>(lights.size()); i++) {
- cerr << "lights["<<i<<"] = "<<lights[i]<<"\n";
+ out << "lights["<<i<<"] = "<<lights[i]<<"\n";
// if (lights[i]) lights[i]->printme();
}
+ return out.str();
}
Modified: swig/Interface/LightSet.h
==============================================================================
--- swig/Interface/LightSet.h (original)
+++ swig/Interface/LightSet.h Fri Jun 10 18:37:20 2005
@@ -3,8 +3,10 @@
#define Manta_Interface_LightSet_h
#include <Interface/RayPacket.h>
+
#include <sgi_stl_warnings_off.h>
#include <vector>
+#include <string>
#include <sgi_stl_warnings_on.h>
namespace Manta {
@@ -53,7 +55,7 @@
void preprocess(const PreprocessContext&);
- void printme();
+ string toString();
Point centers[RayPacket::MaxSize];
Color colors[RayPacket::MaxSize];
Modified: swig/Model/AmbientLights/ArcAmbient.cc
==============================================================================
--- swig/Model/AmbientLights/ArcAmbient.cc (original)
+++ swig/Model/AmbientLights/ArcAmbient.cc Fri Jun 10 18:37:20 2005
@@ -3,7 +3,7 @@
#include <Interface/RayPacket.h>
#include <sgi_stl_warnings_off.h>
-#include <iostream>
+#include <sstream>
#include <sgi_stl_warnings_on.h>
using namespace Manta;
@@ -43,11 +43,13 @@
}
}
-void ArcAmbient::printme() const {
- cerr << "-------- ArcAmbient ---------\n";
-// RGB cu(cup), cd(cdown);
-// cerr << "(cup, cdown) = ";
-// cerr << "("<<cu.r()<<", "<<cu.g()<<", "<<cu.b()<<"), ";
-// cerr << "("<<cd.r()<<", "<<cd.g()<<", "<<cd.b()<<")\n";
- cerr << "up = "<<up<<"\n";
+string ArcAmbient::toString() const {
+ ostringstream out;
+ out << "-------- ArcAmbient ---------\n";
+ RGB cu(cup.convertRGB()), cd(cdown.convertRGB());
+ out << "(cup, cdown) = ";
+ out << "("<<cu.r()<<", "<<cu.g()<<", "<<cu.b()<<"), ";
+ out << "("<<cd.r()<<", "<<cd.g()<<", "<<cd.b()<<")\n";
+ out << "up = "<<up<<"\n";
+ return out.str();
}
Modified: swig/Model/AmbientLights/ArcAmbient.h
==============================================================================
--- swig/Model/AmbientLights/ArcAmbient.h (original)
+++ swig/Model/AmbientLights/ArcAmbient.h Fri Jun 10 18:37:20 2005
@@ -6,6 +6,10 @@
#include <Core/Color/Color.h>
#include <Core/Geometry/PointVector.h>
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <sgi_stl_warnings_on.h>
+
namespace Manta {
class ArcAmbient : public AmbientLight {
@@ -17,7 +21,7 @@
virtual void preprocess(const PreprocessContext&);
virtual void computeAmbient(const RenderContext& context, RayPacket&
rays) const;
- virtual void printme() const;
+ virtual std::string toString() const;
private:
Color cup;
Color cdown;
Modified: swig/Model/AmbientLights/ConstantAmbient.cc
==============================================================================
--- swig/Model/AmbientLights/ConstantAmbient.cc (original)
+++ swig/Model/AmbientLights/ConstantAmbient.cc Fri Jun 10 18:37:20 2005
@@ -3,7 +3,7 @@
#include <Interface/RayPacket.h>
#include <sgi_stl_warnings_off.h>
-#include <iostream>
+#include <sstream>
#include <sgi_stl_warnings_on.h>
using namespace Manta;
@@ -29,8 +29,10 @@
rays.get(i).ambientLight = color;
}
-void ConstantAmbient::printme() const {
- cerr << "-------- ConstantAmbient ---------\n";
- // RGB c(color);
- // cerr << "color = ("<<c.r()<<", "<<c.g()<<", "<<c.b()<<")\n";
+string ConstantAmbient::toString() const {
+ ostringstream out;
+ out << "-------- ConstantAmbient ---------\n";
+ RGB c(color.convertRGB());
+ out << "color = ("<<c.r()<<", "<<c.g()<<", "<<c.b()<<")\n";
+ return out.str();
}
Modified: swig/Model/AmbientLights/ConstantAmbient.h
==============================================================================
--- swig/Model/AmbientLights/ConstantAmbient.h (original)
+++ swig/Model/AmbientLights/ConstantAmbient.h Fri Jun 10 18:37:20 2005
@@ -5,6 +5,10 @@
#include <Interface/AmbientLight.h>
#include <Core/Color/Color.h>
+#include <sgi_stl_warnings_off.h>
+#include <string>
+#include <sgi_stl_warnings_on.h>
+
namespace Manta{
class ConstantAmbient : public AmbientLight {
public:
@@ -14,7 +18,7 @@
virtual void preprocess(const PreprocessContext&);
virtual void computeAmbient(const RenderContext& context, RayPacket&
rays) const;
- virtual void printme() const;
+ virtual std::string toString() const;
private:
Color color;
};
Modified: swig/SwigInterface/CMakeLists.txt
==============================================================================
--- swig/SwigInterface/CMakeLists.txt (original)
+++ swig/SwigInterface/CMakeLists.txt Fri Jun 10 18:37:20 2005
@@ -12,13 +12,13 @@
# parameter. You can't use a variable set to "", because that will
# get replaced with a null string and the SET_SOURCE_FILES_PROPERTIES
# macro will barf.
-SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES SWIG_FLAGS "")
+SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES SWIG_FLAGS "`echo \"\"`")
SWIG_ADD_MODULE(example python
example.i example.cc)
SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES})
SET_SOURCE_FILES_PROPERTIES(manta.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(manta.i PROPERTIES SWIG_FLAGS "")
+SET_SOURCE_FILES_PROPERTIES(manta.i PROPERTIES SWIG_FLAGS "`echo \"\"`")
SWIG_ADD_MODULE(manta python manta.i manta.cc)
Modified: swig/SwigInterface/manta-run.py
==============================================================================
--- swig/SwigInterface/manta-run.py (original)
+++ swig/SwigInterface/manta-run.py Fri Jun 10 18:37:20 2005
@@ -34,21 +34,15 @@
uniformmap = UniformMapper()
floor.setTexCoordMapper(uniformmap)
world.add(floor)
-sphere = Sphere(red, Point(0,0,1.2), 1.0)
-world.add(sphere)
+world.add(manta_new(Sphere(red, Point(0,0,1.2), 1.0)))
scene.setObject(world)
lights = LightSet()
-light1 = PointLight(Point(0,5,8), Color(RGBColor(.6,.1,.1)))
-light2 = PointLight(Point(5,0,8), Color(RGBColor(.1,.6,.1)))
-light3 = PointLight(Point(5,5,2), Color(RGBColor(.2,.2,.2)))
-lights.add(light1);
-lights.add(light2);
-lights.add(light3);
-ambientLight = ConstantAmbient(Color.black())
-ambientLight.thisown = 0
-lights.setAmbientLight(ambientLight)
-lights.printme()
+lights.add(manta_new(PointLight(Point(0,5,8), Color(RGBColor(.6,.1,.1)))))
+lights.add(manta_new(PointLight(Point(5,0,8), Color(RGBColor(.1,.6,.1)))))
+lights.add(manta_new(PointLight(Point(5,5,2), Color(RGBColor(.2,.2,.2)))))
+lights.setAmbientLight(manta_new(ConstantAmbient(Color.black())))
+print lights
scene.setLights(lights);
scene.getRenderParameters().maxDepth = 1;
Modified: swig/SwigInterface/manta.i
==============================================================================
--- swig/SwigInterface/manta.i (original)
+++ swig/SwigInterface/manta.i Fri Jun 10 18:37:20 2005
@@ -142,6 +142,22 @@
%include <Model/TexCoordMappers/UniformMapper.h>
namespace Manta {
+ // This tells SWIG to deallocate the memory from toString functions.
+ // %newobject *::toString();
+ %extend LightSet {
+ %newobject __str__;
+ char* __str__() {
+ return strdup(self->toString().c_str());
+ }
+ };
+
+ %extend AmbientLight {
+ %newobject __str__;
+ char* __str__() {
+ return strdup(self->toString().c_str());
+ }
+ };
+
// Definition for CheckerTexture<Color>
%template(Texture_Color) Texture<Color>;
%template(CheckerTexture_Color) CheckerTexture<Color>;
@@ -150,3 +166,19 @@
%template(Constant_Color) Constant<Color>;
}
+%pythoncode %{
+# This code is to do crazy stuff like
+# myobj = CoolThing(new Stuff());
+#
+# myobj = CoolThing(manta_new(Stuff()))
+
+def manta_new(obj):
+ obj.thisown = 0
+ return obj
+
+def manta_delete(obj):
+ obj.thisown = 1
+ return obj
+
+
+%}
- [MANTA] r377 - in swig: Interface Model/AmbientLights SwigInterface, bigler, 06/10/2005
Archive powered by MHonArc 2.6.16.