← Back to team overview

yade-dev team mailing list archive

[svn] r1819 - in trunk: core pkg/common/RenderingEngine/OpenGLRenderingEngine

 

Author: cosurgi
Date: 2009-06-27 00:32:40 +0200 (Sat, 27 Jun 2009)
New Revision: 1819

Modified:
   trunk/core/PhysicalParameters.hpp
   trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp
   trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.hpp
Log:
Add an option to display DOFs and body IDs in the OpenGL window



Modified: trunk/core/PhysicalParameters.hpp
===================================================================
--- trunk/core/PhysicalParameters.hpp	2009-06-26 12:35:07 UTC (rev 1818)
+++ trunk/core/PhysicalParameters.hpp	2009-06-26 22:32:40 UTC (rev 1819)
@@ -23,6 +23,13 @@
 		static const unsigned DOF_ALL=DOF_X|DOF_Y|DOF_Z|DOF_RX|DOF_RY|DOF_RZ; //! shorthand for all DOFs blocked
 		static const unsigned DOF_XYZ=DOF_X|DOF_Y|DOF_Z; //! shorthand for all displacements blocked
 		static const unsigned DOF_RXRYRZ=DOF_RX|DOF_RY|DOF_RZ; //! shorthand for all rotations blocked
+		void setDOFfromVector3r(Vector3r disp,Vector3r rot=Vector3r(0,0,0))
+		{
+			//! set DOFs according to two Vector3r arguments (blocked is when disp[i]==1.0 or rot[i]==1.0)
+			blockedDOFs = ((disp[0]==1.0)?DOF_X :0)|((disp[1]==1.0)?DOF_Y :0)|((disp[2]==1.0)?DOF_Z :0)|
+			              ((rot [0]==1.0)?DOF_RX:0)|((rot [1]==1.0)?DOF_RY:0)|((rot [2]==1.0)?DOF_RZ:0);
+			//Vector3<bool> would be actually better, I'm not checking now if it would work.
+		};
 		static unsigned axisDOF(int axis, bool rotationalDOF=false){return 1<<(axis+(rotationalDOF?3:0));} //! Return DOF_* constant for given axis∈{0,1,2} and rotationalDOF∈{false(default),true}; e.g. axisDOF(0,true)==DOF_RX
 
 	REGISTER_ATTRIBUTES(/*no base*/,(se3)(refSe3)(blockedDOFs));

Modified: trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp
===================================================================
--- trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp	2009-06-26 12:35:07 UTC (rev 1818)
+++ trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.cpp	2009-06-26 22:32:40 UTC (rev 1819)
@@ -16,6 +16,8 @@
 size_t OpenGLRenderingEngine::selectBodyLimit=500;
 
 OpenGLRenderingEngine::OpenGLRenderingEngine() : RenderingEngine(), clipPlaneNum(3){
+	Show_DOF = false;
+	Show_ID = false;
 	Body_state = false;
 	Body_bounding_volume = false;
 	Body_interacting_geom = false;
@@ -164,6 +166,7 @@
 	// set displayed Se3 of body (scaling) and isDisplayed (clipping)
 	setBodiesDispSe3(rootBody);
 
+	if (Show_DOF || Show_ID) renderDOF_ID(rootBody);
 	if (Body_geometrical_model){
 		if (Cast_shadows){	
 			if (Fast_shadow_volume) renderSceneUsingFastShadowVolumes(rootBody,Light_position);
@@ -356,6 +359,47 @@
 	else shadowVolumeDispatcher(rootBody->geometricalModel,rootBody->physicalParameters,Light_position);
 }
 
+void OpenGLRenderingEngine::renderDOF_ID(const shared_ptr<MetaBody>& rootBody){	
+	const GLfloat ambientColorSelected[4]={10.0,0.0,0.0,1.0};	
+	const GLfloat ambientColorUnselected[4]={0.5,0.5,0.5,1.0};	
+	if((rootBody->geometricalModel || Draw_inside) && Draw_inside) {
+		FOREACH(const shared_ptr<Body> b, *rootBody->bodies){
+			if(b->geometricalModel && ((b->getGroupMask() & Draw_mask) || b->getGroupMask()==0)){
+				if(b->physicalParameters && !b->physicalParameters->isDisplayed) continue;
+				if(!Show_ID && b->physicalParameters->blockedDOFs==0) continue;
+				const Se3r& se3=b->physicalParameters->dispSe3;
+				glPushMatrix();
+				glTranslatef(se3.position[0],se3.position[1],se3.position[2]);
+				if(current_selection==b->getId()){glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientColorSelected);}
+				{ // write text
+					glColor3f(1.0-Background_color[0],1.0-Background_color[1],1.0-Background_color[2]);
+					unsigned DOF = b->physicalParameters->blockedDOFs;
+					std::string dof = std::string("") 
+					                  + (((DOF & PhysicalParameters::DOF_X )!=0)?"X":" ")
+					                  + (((DOF & PhysicalParameters::DOF_Y )!=0)?"Y":" ")
+					                  + (((DOF & PhysicalParameters::DOF_Z )!=0)?"Z":" ")
+					                  + (((DOF & PhysicalParameters::DOF_RX)!=0)?"RX":"  ")
+					                  + (((DOF & PhysicalParameters::DOF_RY)!=0)?"RY":"  ")
+					                  + (((DOF & PhysicalParameters::DOF_RZ)!=0)?"RZ":"  ");
+					std::string id = boost::lexical_cast<std::string>(b->getId());
+					std::string str("");
+					if(Show_DOF && Show_ID) id += " ";
+					if(Show_ID) str += id;
+					if(Show_DOF) str += dof;
+					glPushMatrix();
+					glRasterPos2i(0,0);
+					for(unsigned int i=0;i<str.length();i++)
+						glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]);
+					glPopMatrix();
+				}
+				if(current_selection == b->getId()){glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientColorUnselected);}
+				glPopMatrix();
+			}
+		}
+	}
+	if(rootBody->geometricalModel) geometricalModelDispatcher(rootBody->geometricalModel,rootBody->physicalParameters,Body_wire);
+}
+
 void OpenGLRenderingEngine::renderGeometricalModel(const shared_ptr<MetaBody>& rootBody){	
 	const GLfloat ambientColorSelected[4]={10.0,0.0,0.0,1.0};	
 	const GLfloat ambientColorUnselected[4]={0.5,0.5,0.5,1.0};
@@ -487,6 +531,8 @@
 	
 	REGISTER_ATTRIBUTE(Body_wire);
 
+	REGISTER_ATTRIBUTE(Show_DOF);
+	REGISTER_ATTRIBUTE(Show_ID);
 	REGISTER_ATTRIBUTE(Body_state);
 	REGISTER_ATTRIBUTE(Body_bounding_volume);
 	REGISTER_ATTRIBUTE(Body_interacting_geom);

Modified: trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.hpp
===================================================================
--- trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.hpp	2009-06-26 12:35:07 UTC (rev 1818)
+++ trunk/pkg/common/RenderingEngine/OpenGLRenderingEngine/OpenGLRenderingEngine.hpp	2009-06-26 22:32:40 UTC (rev 1819)
@@ -14,7 +14,7 @@
 {	
 	public :
 		Vector3r Light_position,Background_color;
-		bool Body_state,Body_bounding_volume,Body_interacting_geom,Body_geometrical_model,Cast_shadows,Shadow_volumes,Fast_shadow_volume,Body_wire,Interaction_wire,Draw_inside,Interaction_geometry,Interaction_physics;
+		bool Show_DOF,Show_ID,Body_state,Body_bounding_volume,Body_interacting_geom,Body_geometrical_model,Cast_shadows,Shadow_volumes,Fast_shadow_volume,Body_wire,Interaction_wire,Draw_inside,Interaction_geometry,Interaction_physics;
 		body_id_t current_selection;
 		int Draw_mask;
 
@@ -79,6 +79,7 @@
 		virtual void renderWithNames(const shared_ptr<MetaBody>& );
 	
 	private :
+		void renderDOF_ID(const shared_ptr<MetaBody>& rootBody);
 		void renderGeometricalModel(const shared_ptr<MetaBody>& rootBody);
 		void renderInteractionPhysics(const shared_ptr<MetaBody>& rootBody);
 		void renderInteractionGeometry(const shared_ptr<MetaBody>& rootBody);