Update of /cvsroot/cgkit/cgkit2/wrappers
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26330/wrappers
Modified Files:
py_wrapper.cpp
Added Files:
py_polyhedrongeom.cpp
Log Message:
Added a Polyhedron object (which is not yet finished but already usable)
--- NEW FILE: py_polyhedrongeom.cpp ---
/*
Polyhedron geom
*/
#include <boost/python.hpp>
#include "polyhedrongeom.h"
#include "common_exceptions.h"
using namespace boost::python;
using namespace support3d;
/*
getLoop() wrapper method which returns the loop as list
*/
list getLoop(PolyhedronGeom* self, int poly, int loop)
{
list res;
std::vector<int> vloop = self->getLoop(poly, loop);
for(unsigned int i=0; i<vloop.size(); i++)
{
res.append(vloop[i]);
}
return res;
}
/*
setLoop() wrapper method
*/
void setLoop(PolyhedronGeom* self, int poly, int loop, object vloop)
{
std::vector<int> vloop2;
for(int i=0; i<vloop.attr("__len__")(); i++)
{
int v = extract<int>(vloop[i]);
vloop2.push_back(v);
}
self->setLoop(poly, loop, vloop2);
}
/*
Get a polygon.
*/
list getPoly(PolyhedronGeom* self, int poly)
{
if ((poly<0) || (poly>=self->getNumPolys()))
throw EIndexError("Poly index out of range.");
list res;
int loops = self->getNumLoops(poly);
// Iterate over the loops...
for(int i=0; i<loops; i++)
{
res.append(getLoop(self, poly, i));
}
return res;
}
/*
Set a polygon.
polydef must be a sequence of loops. A loop must be a sequence of
vertex indices.
*/
void setPoly(PolyhedronGeom* self, int poly, object polydef)
{
if ((poly<0) || (poly>=self->getNumPolys()))
throw EIndexError("Poly index out of range.");
int loops = extract<int>(polydef.attr("__len__")());
self->setNumLoops(poly, loops);
// Iterate over the loops...
for(int i=0; i<loops; i++)
{
setLoop(self, poly, i, polydef[i]);
}
}
//////////////////////////////////////////////////////////////////////
void class_PolyhedronGeom()
{
class_<PolyhedronGeom, bases<GeomObject> >("PolyhedronGeom",
"A simple polyhedron class.", init<>())
// The xyz_slot is the same than xyz because they're arrays
.def_readonly("verts_slot", &PolyhedronGeom::verts)
.def_readonly("verts", &PolyhedronGeom::verts)
// .add_property("cog", getCog)
// .add_property("inertiatensor", getInertiaTensor)
// .def_readonly("cog_slot", &PolyhedronGeom::cog)
// .def_readonly("inertiatensor_slot", &PolyhedronGeom::inertiatensor)
// .def("calcMassProperties", &PolyhedronGeom::calcMassProperties)
.def("getNumPolys", &PolyhedronGeom::getNumPolys,
"getNumPolys() -> int\n\n"
"Return the number of polygons.")
.def("getNumLoops", &PolyhedronGeom::getNumLoops, (arg("poly")),
"getNumLoops(poly) -> int\n\n"
"Return the number of vertex loops in the given polygon. poly is the\n\n"
"index of the polygon.")
.def("setNumPolys", &PolyhedronGeom::setNumPolys, (arg("num")),
"setNumPolys(num)\n\n"
"Allocate space for num polygons.")
.def("setNumLoops", &PolyhedronGeom::setNumLoops, (arg("poly"), arg("num")),
"setNumLoops(poly, num)\n\n"
"Allocate space for num loops in polygon with index poly.")
.def("getLoop", getLoop, (arg("poly"), arg("loop")),
"getLoop(poly, loop) -> Loop\n\n"
"Return a loop from a poly.")
.def("setLoop", setLoop, (arg("poly"), arg("loop"), arg("vloop")),
"setLoop(poly, loop, vloop)\n\n"
"Set new poly loop.")
.def("getPoly", getPoly, (arg("poly")),
"getPoly(poly) -> polydef\n\n"
"Return a polygon.")
.def("setPoly", setPoly, (arg("poly"), arg("polydef")),
"setPoly(poly, polydef)\n\n"
"Set a polygon.")
;
}
Index: py_wrapper.cpp
===================================================================
RCS file: /cvsroot/cgkit/cgkit2/wrappers/py_wrapper.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** py_wrapper.cpp 20 Dec 2004 16:35:04 -0000 1.2
--- py_wrapper.cpp 20 Feb 2005 18:30:42 -0000 1.3
***************
*** 89,92 ****
--- 89,95 ----
void class_TriMeshGeom();
+ // py_polyhedrongeom
+ void class_PolyhedronGeom();
+
// py_drawgeom
void class_DrawGeom();
***************
*** 302,305 ****
--- 305,311 ----
class_TriMeshGeom();
+ // PolyhedronGeom
+ class_PolyhedronGeom();
+
// DrawGeom
class_DrawGeom();
|