Commit e6da485b authored by Anton Gladky's avatar Anton Gladky
Browse files

Replace some "#define"(s) by functions.

It is a good practice not to use macroses
if it is not really necessary.

http://stackoverflow.com/questions/14041453/why-are-preprocessor-macros-evil-and-what-are-the-alternatives
parent e063ea12
......@@ -214,4 +214,18 @@ template< > inline void glMaterial< int > ( GLenum face, GLenum pname, int par
template< > inline void glMaterialv< Vector3r > ( GLenum face, GLenum pname, const Vector3r params ) { const GLfloat _p[3]={(float) params[0], (float) params[1], (float) params[2]}; glMaterialfv(face,pname,_p); };
template< > inline void glMaterialv< Vector3i > ( GLenum face, GLenum pname, const Vector3i params ) { glMaterialiv(face,pname,(int*)&params); };
template< typename Type > inline void glOneWire(Type & t, unsigned int a, unsigned int b) { glVertex3v(t->v[a]); glVertex3v(t->v[b]); }
template< typename Type > inline void glOneFace(Type & t, unsigned int a, unsigned int b, unsigned int c) {
const Vector3r center = (t->v[0]+t->v[1]+t->v[2]+t->v[3])*.25;
Vector3r n=(t->v[b]-t->v[a]).cross(t->v[c]-t->v[a]);
n.normalize();
const Vector3r faceCenter=(t->v[a]+t->v[b]+t->v[c])/3.;
if((faceCenter-center).dot(n)<0) n=-n;
glNormal3v(n);
glVertex3v(t->v[a]);
glVertex3v(t->v[b]);
glVertex3v(t->v[c]);
}
#undef LDOUBL
......@@ -281,8 +281,9 @@ void Bo1_Polyhedra_Aabb::go(const shared_ptr<Shape>& ig, shared_ptr<Bound>& bv,
/* Plotting */
#ifdef YADE_OPENGL
#include<lib/opengl/OpenGLWrapper.hpp>
#include <lib/opengl/OpenGLWrapper.hpp>
bool Gl1_Polyhedra::wire;
void Gl1_Polyhedra::go(const shared_ptr<Shape>& cm, const shared_ptr<State>&,bool wire2,const GLViewInfo&)
{
glMaterialv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,Vector3r(cm->color[0],cm->color[1],cm->color[2]));
......@@ -293,20 +294,33 @@ void Bo1_Polyhedra_Aabb::go(const shared_ptr<Shape>& ig, shared_ptr<Bound>& bv,
if (wire || wire2) {
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
#define __ONEWIRE(a,b) glVertex3v(t->v[a]);glVertex3v(t->v[b])
for(int tri=0; tri < (int) faceTri.size(); tri+=3) {__ONEWIRE(faceTri[tri],faceTri[tri+1]); __ONEWIRE(faceTri[tri],faceTri[tri+2]); __ONEWIRE(faceTri[tri+1],faceTri[tri+2]);}
#undef __ONEWIRE
for(int tri=0; tri < (int) faceTri.size(); tri+=3) {
glOneWire(t, faceTri[tri], faceTri[tri+1]);
glOneWire(t, faceTri[tri], faceTri[tri+2]);
glOneWire(t, faceTri[tri+1], faceTri[tri+2]);
}
glEnd();
}
else
{
Vector3r centroid = t->GetCentroid();
Vector3r faceCenter, n;
glDisable(GL_CULL_FACE); glEnable(GL_LIGHTING);
glBegin(GL_TRIANGLES);
#define __ONEFACE(a,b,c) n=(t->v[b]-t->v[a]).cross(t->v[c]-t->v[a]); n.normalize(); faceCenter=(t->v[a]+t->v[b]+t->v[c])/3.; if((faceCenter-centroid).dot(n)<0)n=-n; glNormal3v(n); glVertex3v(t->v[a]); glVertex3v(t->v[b]); glVertex3v(t->v[c]);
for(int tri=0; tri < (int) faceTri.size(); tri+=3) {__ONEFACE(faceTri[tri],faceTri[tri+1],faceTri[tri+2]);}
#undef __ONEFACE
for(int tri=0; tri < (int) faceTri.size(); tri+=3) {
const auto a = faceTri[tri+0];
const auto b = faceTri[tri+1];
const auto c = faceTri[tri+2];
Vector3r n=(t->v[b]-t->v[a]).cross(t->v[c]-t->v[a]);
n.normalize();
Vector3r faceCenter=(t->v[a]+t->v[b]+t->v[c])/3.;
if((faceCenter-centroid).dot(n)<0) n=-n;
glNormal3v(n);
glVertex3v(t->v[a]);
glVertex3v(t->v[b]);
glVertex3v(t->v[c]);
}
glEnd();
}
}
......
......@@ -12,15 +12,15 @@
//EMPRIRICAL CONSTANTS - ADJUST IF SEGMENTATION FAULT OCCUR, IT IS A PROBLEM OF CGAL. THESE ARE USED TO CHECK CGAL IMPUTS
//DISTANCE_LIMIT controls numerical issues in calculating intersection. It should be small enough to neglect only extremely
//small overlaps, but large enough to prevent errors during computation of convex hull
#define DISTANCE_LIMIT 2E-11//-11
const Real DISTANCE_LIMIT = 2E-11;
//MERGE_PLANES_LIMIT - if two facets of two intersecting polyhedron differ less, then they are treated ose one only
#define MERGE_PLANES_LIMIT 1E-18 //18
const Real MERGE_PLANES_LIMIT = 1E-18; //18
//SIMPLIFY_LIMIT - if two facets of one polyhedron differ less, then they are joint into one facet
#define SIMPLIFY_LIMIT 1E-19 //19
const Real SIMPLIFY_LIMIT = 1E-19; //19
//FIND_NORMAL_LIMIT - to determine which facet of intersection belongs to which polyhedron
#define FIND_NORMAL_LIMIT 1E-40
const Real FIND_NORMAL_LIMIT = 1E-40;
//SPLITTER_GAP - creates gap between splitted polyhedrons
#define SPLITTER_GAP 1E-8
const Real SPLITTER_GAP = 1E-8;
//**********************************************************************************
......
......@@ -981,7 +981,8 @@ void TetraVolumetricLaw::action()
}
#ifdef YADE_OPENGL
#include<lib/opengl/OpenGLWrapper.hpp>
#include <lib/opengl/OpenGLWrapper.hpp>
bool Gl1_Tetra::wire;
void Gl1_Tetra::go(const shared_ptr<Shape>& cm, const shared_ptr<State>&,bool wire2,const GLViewInfo&)
{
......@@ -991,22 +992,22 @@ void TetraVolumetricLaw::action()
if (wire && wire2) { // wireframe, as for Tetrahedron
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
#define __ONEWIRE(a,b) glVertex3v(t->v[a]);glVertex3v(t->v[b])
__ONEWIRE(0,1);__ONEWIRE(0,2);__ONEWIRE(0,3);__ONEWIRE(1,2);__ONEWIRE(1,3);__ONEWIRE(2,3);
#undef __ONEWIRE
glOneWire(t, 0, 1);
glOneWire(t, 0, 2);
glOneWire(t, 0, 3);
glOneWire(t, 1, 2);
glOneWire(t, 1, 3);
glOneWire(t, 2, 3);
glEnd();
}
else
{
Vector3r center = (t->v[0]+t->v[1]+t->v[2]+t->v[3])*.25, faceCenter, n;
glDisable(GL_CULL_FACE); glEnable(GL_LIGHTING);
glBegin(GL_TRIANGLES);
#define __ONEFACE(a,b,c) n=(t->v[b]-t->v[a]).cross(t->v[c]-t->v[a]); n.normalize(); faceCenter=(t->v[a]+t->v[b]+t->v[c])/3.; if((faceCenter-center).dot(n)<0)n=-n; glNormal3v(n); glVertex3v(t->v[a]); glVertex3v(t->v[b]); glVertex3v(t->v[c]);
__ONEFACE(0,2,1);
__ONEFACE(0,1,3);
__ONEFACE(1,2,3);
__ONEFACE(0,3,2);
#undef __ONEFACE
glOneFace (t, 0,2,1);
glOneFace (t, 0,1,3);
glOneFace (t, 1,2,3);
glOneFace (t, 0,3,2);
glEnd();
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment