← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1889: 1. Don't call CreateIndex in Materia::Material (see https://bugs.launchpad.net/yade/+bug/495437)

 

------------------------------------------------------------
revno: 1889
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-12-11 12:38:18 +0100
message:
  1. Don't call CreateIndex in Materia::Material (see https://bugs.launchpad.net/yade/+bug/495437)
  2. Add dipl and rot methods to body, for querying displacement and rotation relative to reference position and orientation (moved from the python wrapper).
  3. Add .classIndices to return list of class indices from the instance up to the top-level indexable from python.
modified:
  core/Dispatcher.hpp
  core/Material.hpp
  core/State.hpp
  py/yadeWrapper/yadeWrapper.cpp


--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'core/Dispatcher.hpp'
--- core/Dispatcher.hpp	2009-12-09 16:43:25 +0000
+++ core/Dispatcher.hpp	2009-12-11 11:38:18 +0000
@@ -75,7 +75,7 @@
 {
 
 	public :
-		void dump(){ DynLibDispatcher<TYPELIST_1(baseClass),FunctorType,FunctorReturnType,FunctorArguments,autoSymmetry>::dumpDispatchMatrix1D(std::cerr); }
+		void dump(){ DynLibDispatcher<TYPELIST_1(baseClass),FunctorType,FunctorReturnType,FunctorArguments,autoSymmetry>::dumpDispatchMatrix1D(std::cout); }
 		virtual void add(FunctorType* eu){ add(shared_ptr<FunctorType>(eu)); }
 		virtual void add(shared_ptr<FunctorType> eu){
 			storeFunctorName(eu->get1DFunctorType1(),eu->getClassName(),eu);
@@ -145,7 +145,7 @@
 				>
 {
 	public :
-		void dump(){ DynLibDispatcher<TYPELIST_2(baseClass1,baseClass2),FunctorType,FunctorReturnType,FunctorArguments,autoSymmetry>::dumpDispatchMatrix2D(std::cerr); }
+		void dump(){ DynLibDispatcher<TYPELIST_2(baseClass1,baseClass2),FunctorType,FunctorReturnType,FunctorArguments,autoSymmetry>::dumpDispatchMatrix2D(std::cout); }
 		/* add functor by pointer: this is convenience for calls like foo->add(new SomeFunctor); */
 		virtual void add(FunctorType* eu){ add(shared_ptr<FunctorType>(eu)); }
 		/* add functor by shared pointer */

=== modified file 'core/Material.hpp'
--- core/Material.hpp	2009-12-06 22:02:12 +0000
+++ core/Material.hpp	2009-12-11 11:38:18 +0000
@@ -14,7 +14,7 @@
 */
 class Material: public Serializable, public Indexable{
 	public:
-		Material(): id(-1), density(-1){ createIndex(); }
+		Material(): id(-1), density(-1){ }
 		~Material();
 		//! global id of the material; if >= 0, the material is shared and can be found under this index in Scene::materials
 		//! (necessary since yade::serialization doesn't track shared pointers)

=== modified file 'core/State.hpp'
--- core/State.hpp	2009-11-30 12:50:41 +0000
+++ core/State.hpp	2009-12-11 11:38:18 +0000
@@ -59,6 +59,19 @@
 		//! Setter of blockedDOFs from list of strings (['x','rx','rz'] → DOF_X | DOR_RX | DOF_RZ)
 		void blockedDOFs_vec_set(const std::vector<std::string>& dofs);
 
+		//! Return displacement (current-reference position)
+		Vector3r displ() const {return pos-refPos;}
+		//! Return rotation (current-reference orientation, as Vector3r)
+		Vector3r rot() const { Quaternionr relRot=refOri.Conjugate()*ori; Vector3r axis; Real angle; relRot.ToAxisAngle(axis,angle); return axis*angle; }
+
+		// python access functions: pos and ori are references to inside Se3r and cannot be pointed to directly
+		Vector3r pos_get() const {return pos;}
+		void pos_set(const Vector3r& p) {pos=p;}
+		Quaternionr ori_get() const {return ori; }
+		void ori_set(const Quaternionr& o){ori=o;}
+
+
+
 	State(): se3(Vector3r::ZERO,Quaternionr::IDENTITY),pos(se3.position),vel(Vector3r::ZERO),accel(Vector3r::ZERO),mass(0.),ori(se3.orientation),angVel(Vector3r::ZERO),angAccel(Vector3r::ZERO),angMom(Vector3r::ZERO),inertia(Vector3r::ZERO),refPos(Vector3r::ZERO),refOri(Quaternionr::IDENTITY),blockedDOFs(DOF_NONE){}
 
 	REGISTER_CLASS_AND_BASE(State,Serializable);

=== modified file 'py/yadeWrapper/yadeWrapper.cpp'
--- py/yadeWrapper/yadeWrapper.cpp	2009-12-11 07:27:29 +0000
+++ py/yadeWrapper/yadeWrapper.cpp	2009-12-11 11:38:18 +0000
@@ -624,7 +624,22 @@
 
 template<typename someIndexable>
 int Indexable_getClassIndex(const shared_ptr<someIndexable> i){return i->getClassIndex();}
-
+//template<typename someIndexable>
+//int Indexable_getBaseClassIndex(const shared_ptr<someIndexable> i){return i->getBaseClassIndex(1);}
+template<typename someIndexable>
+vector<int> Indexable_getClassIndices(const shared_ptr<someIndexable> i){
+	int depth=1; vector<int> ret;
+	ret.push_back(i->getClassIndex());
+	while(true){
+		//cerr<<"depth="<<depth;
+		int idx=i->getBaseClassIndex(depth);
+		//cerr<<", idx="<<idx<<endl;
+		if(idx<0) return ret;
+		ret.push_back(idx);
+		depth++;
+	}
+}
+		
 // ParallelEngine
 void ParallelEngine_slaves_set(shared_ptr<ParallelEngine> self, const python::list& slaves){
 	int len=python::len(slaves);
@@ -648,16 +663,6 @@
 }
 shared_ptr<ParallelEngine> ParallelEngine_ctor_list(const python::list& slaves){ shared_ptr<ParallelEngine> instance(new ParallelEngine); ParallelEngine_slaves_set(instance,slaves); return instance; }
 
-// injected methods
-Vector3r State_displ_get(const shared_ptr<State>& pp){return pp->pos-pp->refPos;}
-Vector3r State_rot_get  (const shared_ptr<State>& pp){Quaternionr relRot=pp->refOri.Conjugate()*pp->ori; Vector3r axis; Real angle; relRot.ToAxisAngle(axis,angle); return axis*angle;  }
-Vector3r State_pos_get(const shared_ptr<State>& pp){return pp->pos;}
-Quaternionr State_ori_get(const shared_ptr<State>& pp){return pp->ori;}
-void State_pos_set(const shared_ptr<State>& pp, const Vector3r& p){ pp->pos=p; }
-void State_ori_set(const shared_ptr<State>& pp, const Quaternionr& p){ pp->ori=p; }
-//Vector3r State_refPos_get(const shared_ptr<State>& pp){return pp->refPos;}
-//void State_refPos_set(const shared_ptr<State>& pp, const Vector3r& p){ pp->refPos=p; }
-
 shared_ptr<Shape> Body_shape_deprec_get(const shared_ptr<Body>& b){ LOG_WARN("Body().mold and Body().geom attributes are deprecated, use 'shape' instead."); return b->shape; }
 void Body_shape_deprec_set(const shared_ptr<Body>& b, shared_ptr<Shape> ig){ LOG_WARN("Body().mold and Body().geom attributes are deprecated, use 'shape' instead."); b->shape=ig; }
 
@@ -850,7 +855,7 @@
 	#define EXPOSE_CXX_CLASS_RENAMED(cxxName,pyName) python::class_<cxxName,shared_ptr<cxxName>, python::bases<Serializable>, noncopyable>(#pyName).def("__init__",python::raw_constructor(Serializable_ctor_kwAttrs<cxxName>))
 	#define EXPOSE_CXX_CLASS(className) EXPOSE_CXX_CLASS_RENAMED(className,className)
 	// expose indexable class, with access to the index
-	#define EXPOSE_CXX_CLASS_IX(className) EXPOSE_CXX_CLASS(className).add_property("classIndex",&Indexable_getClassIndex<className>)
+	#define EXPOSE_CXX_CLASS_IX(className) EXPOSE_CXX_CLASS(className).add_property("classIndex",&Indexable_getClassIndex<className>,"Return class index of this instance.").add_property("classIndices",&Indexable_getClassIndices<className>,"Return list of indices of base classes, starting from the class instance itself, then immediate parent and so on to the top-level indexable at last.")
 
 	EXPOSE_CXX_CLASS(Body)
 		// mold and geom are deprecated:
@@ -876,11 +881,11 @@
 		;
 	EXPOSE_CXX_CLASS(State)
 		.add_property("blockedDOFs",&State::blockedDOFs_vec_get,&State::blockedDOFs_vec_set)
-		.add_property("pos",&State_pos_get,&State_pos_set)
-		.add_property("ori",&State_ori_get,&State_ori_set)
+		.add_property("pos",&State::pos_get,&State::pos_set)
+		.add_property("ori",&State::ori_get,&State::ori_set)
 		.def_readwrite("refPos",&State::refPos)
-		.add_property("displ",&State_displ_get)
-		.add_property("rot",&State_rot_get);
+		.add_property("displ",&State::displ)
+		.add_property("rot",&State::rot);
 	// deprecated
 	#ifdef YADE_PHYSPAR
 	EXPOSE_CXX_CLASS_IX(PhysicalParameters)