Skip to content
Snippets Groups Projects
Commit 0fc83258 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

fix api_demos

parent c4d5c13f
Branches
Tags
No related merge requests found
...@@ -263,7 +263,7 @@ class GFace : public GEntity ...@@ -263,7 +263,7 @@ class GFace : public GEntity
// points are at most maxDist apart // points are at most maxDist apart
bool fillPointCloud(double maxDist, bool fillPointCloud(double maxDist,
std::vector<SPoint3> *points, std::vector<SPoint3> *points,
std::vector<SPoint2> *uvpoints, std::vector<SPoint2> *uvpoints=0,
std::vector<SVector3> *normals=0); std::vector<SVector3> *normals=0);
// apply Lloyd's algorithm to the mesh // apply Lloyd's algorithm to the mesh
......
...@@ -14,8 +14,10 @@ project(api_demos CXX) ...@@ -14,8 +14,10 @@ project(api_demos CXX)
add_subdirectory(../.. "${CMAKE_CURRENT_BINARY_DIR}/gmsh") add_subdirectory(../.. "${CMAKE_CURRENT_BINARY_DIR}/gmsh")
include_directories(../../Common ../../Numeric ../../Geo ../../Mesh include_directories(../../Common ../../Numeric ../../Geo ../../Mesh
../../Solver ../../Post ../../Plugin ../../Graphics ../../contrib/ANN/include ../../Solver ../../Post ../../Plugin ../../Graphics
../../contrib/DiscreteIntegration ${GMSH_EXTERNAL_INCLUDE_DIRS} ../../contrib/ANN/include ../../contrib/MathEx ../../contrib/kbipack
../../contrib/DiscreteIntegration
${GMSH_EXTERNAL_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}/gmsh/Common) ${CMAKE_CURRENT_BINARY_DIR}/gmsh/Common)
if(APPLE) if(APPLE)
...@@ -37,14 +39,11 @@ add_executable(mainElasticity mainElasticity.cpp) ...@@ -37,14 +39,11 @@ add_executable(mainElasticity mainElasticity.cpp)
target_link_libraries(mainElasticity shared) target_link_libraries(mainElasticity shared)
add_executable(mainGlut mainGlut.cpp) add_executable(mainGlut mainGlut.cpp)
target_link_libraries(mainGlut lib ${GMSH_EXTERNAL_LIBRARIES} ${glut}) target_link_libraries(mainGlut shared ${glut})
add_executable(mainHomology mainHomology.cpp) add_executable(mainHomology mainHomology.cpp)
target_link_libraries(mainHomology shared) target_link_libraries(mainHomology shared)
add_executable(mainLevelset mainLevelset.cpp)
target_link_libraries(mainLevelset shared)
add_executable(mainOcc mainOcc.cpp) add_executable(mainOcc mainOcc.cpp)
target_link_libraries(mainOcc shared) target_link_libraries(mainOcc shared)
......
// //
// A simple example on how to build a GUI frontend to Gmsh using GLUT // A simple example on how to build a GUI frontend to Gmsh using GLUT
// //
...@@ -6,133 +5,43 @@ ...@@ -6,133 +5,43 @@
#if defined(__APPLE__) #if defined(__APPLE__)
# include <GLUT/glut.h> # include <GLUT/glut.h>
#else #else
# include <GL/gl.h>
# include <GL/glut.h> # include <GL/glut.h>
# include <GL/glu.h>
#endif #endif
#include "Gmsh.h" #include "Gmsh.h"
#include <stdio.h>
#include "string.h"
#include "GModel.h" #include "GModel.h"
#include "MElement.h" #include "MElement.h"
#include "Context.h"
#include "drawContext.h" #include "drawContext.h"
#include "Trackball.h"
#include "Camera.h"
typedef struct {
double r,g,b;
} COLOUR;
typedef struct {
unsigned char r,g,b,a;
} PIXELA;
using namespace std;
drawContext *ctx = 0; drawContext *ctx = 0;
Camera *camera;
mouseAndKeyboard mouseandkeys;
static int xprev = 0, yprev = 0, specialkey = 0;
class drawContextGlut : public drawContextGlobal{ class drawContextGlut : public drawContextGlobal{
public: public:
void draw(){ ctx->draw3d(); ctx->draw2d(); } void draw(){ ctx->draw3d(); ctx->draw2d(); }
const char *getFontName(int index){ return "Helvetica"; } const char *getFontName(int index){ return "Helvetica"; }
int getFontSize(){ return 12; } int getFontSize(){ return 18; }
double getStringWidth(const char *str) double getStringWidth(const char *str)
{ {
return glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)str); return glutBitmapLength(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)str);
} }
int getStringHeight(){ return 12; } int getStringHeight(){ return 18; }
int getStringDescent(){ return 6; } int getStringDescent(){ return 6; }
void drawString(const char *str) void drawString(const char *str)
{ {
for (int i = 0; i < strlen(str); i++) for (int i = 0; i < strlen(str); i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
} }
}; };
// GLUT callbacks // GLUT callbacks
void display() void display()
{ {
if (!camera->stereoEnable) {
glViewport(ctx->viewport[0], ctx->viewport[1],
ctx->viewport[2], ctx->viewport[3]);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
camera->giveViewportDimension(ctx->viewport[2],ctx->viewport[3]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(camera->glFleft,camera->glFright,camera->glFbottom,camera->glFtop,camera->glFnear,camera->glFfar);
glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(camera->position.x, camera->position.y, camera->position.z,
camera->target.x, camera->target.y, camera->target.z,
camera->up.x, camera->up.y, camera->up.z);
ctx->draw3d();
ctx->draw2d();
glutSwapBuffers();
}
else {
// cout<<" display3D();"<<endl;
glViewport(ctx->viewport[0], ctx->viewport[1], glViewport(ctx->viewport[0], ctx->viewport[1],
ctx->viewport[2], ctx->viewport[3]); ctx->viewport[2], ctx->viewport[3]);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
camera->giveViewportDimension(ctx->viewport[2],ctx->viewport[3]); drawContext::global()->draw();
//right eye
XYZ eye =camera->eyesep / 2.0* camera->right;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double left = - camera->screenratio * camera->wd2 - 0.5 * camera->eyesep * camera->ndfl;
double right = camera->screenratio * camera->wd2 - 0.5 * camera->eyesep * camera->ndfl;
double top = camera->wd2;
double bottom = - camera->wd2;
glFrustum(left,right,bottom,top,camera->glFnear,camera->glFfar);
glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(camera->position.x+eye.x, camera->position.y+eye.y, camera->position.z+eye.z,
camera->target.x+eye.x, camera->target.y+eye.y, camera->target.z+eye.z,
camera->up.x, camera->up.y, camera->up.z);
ctx->draw3d();
ctx->draw2d();
//left eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
left = - camera->screenratio * camera->wd2 + 0.5 * camera->eyesep * camera->ndfl;
right = camera->screenratio * camera->wd2 + 0.5 * camera->eyesep * camera->ndfl;
top = camera->wd2;
bottom = - camera->wd2;
glFrustum(left,right,bottom,top,camera->glFnear,camera->glFfar);
glMatrixMode(GL_MODELVIEW);
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(camera->position.x-eye.x, camera->position.y-eye.y, camera->position.z-eye.z,
camera->target.x-eye.x, camera->target.y-eye.y, camera->target.z-eye.z,
camera->up.x, camera->up.y, camera->up.z);
ctx->draw3d();
ctx->draw2d();
glutSwapBuffers(); glutSwapBuffers();
} }
}
void reshape(int w, int h) void reshape(int w, int h)
{ {
ctx->viewport[2] = w; ctx->viewport[2] = w;
...@@ -140,239 +49,74 @@ void reshape(int w, int h) ...@@ -140,239 +49,74 @@ void reshape(int w, int h)
display(); display();
} }
void keyboard(unsigned char key, int x, int y)
{
switch(key){
case '1': GModel::current()->mesh(1); break;
case '2': GModel::current()->mesh(2); break;
case '3': GModel::current()->mesh(3); break;
}
display();
}
void keyboard(unsigned char key, int x, int y) { display();} static int xprev = 0, yprev = 0, specialkey = 0;
void motion(int x, int y) void motion(int x, int y)
{ {
int w = (ctx->viewport[2] - ctx->viewport[0]); int w = ctx->viewport[2];
int h = (ctx->viewport[3] - ctx->viewport[1]); int h = ctx->viewport[3];
//rotate if(specialkey == GLUT_ACTIVE_SHIFT){
if (mouseandkeys.button_left_down && (mouseandkeys.mode!= GLUT_ACTIVE_CTRL) ){ double dx = x - xprev;
double x_r = 2.*(1.*x - w/2.)/w;
double y_r = 2.*(-1.*y + h/2.)/h;
double xprev_r=2.*(1.*xprev - w/2.)/w;
double yprev_r=2.*(-1.*yprev + h/2.)/h;
double q[4];
trackball(q,xprev_r,yprev_r,x_r,y_r);
camera->rotate(q);
xprev = x;
yprev = y;
}
//zoom
if (mouseandkeys.button_middle_down ){
double dy = y - yprev; double dy = y - yprev;
double factor =( CTX::instance()->zoomFactor * fabs(dy) +(double) h) / (double)h; if(fabs(dy) > fabs(dx)) {
factor = ((dy > 0) ? factor : 1./factor); double fact = (4. * fabs(dy) + h) / (double)h;
camera->distance=fabs(1./factor*camera->ref_distance); ctx->s[0] *= ((dy > 0) ? fact : 1. / fact);
camera->position.x=camera->target.x-camera->distance*camera->view.x; ctx->s[1] = ctx->s[0];
camera->position.y=camera->target.y-camera->distance*camera->view.y; ctx->s[2] = ctx->s[0];
camera->position.z=camera->target.z-camera->distance*camera->view.z;
} }
// translate
if (mouseandkeys.button_right_down ){
double x_r = 2.*(1.*x - w/2.)/w;
double y_r = 2.*(1.*y - h/2.)/h;
double xprev_r=2.*(1.*xprev - w/2.)/w;
double yprev_r=2.*(1.*yprev - h/2.)/h;
double theta_x=camera->aperture*(x_r-xprev_r)*0.0174532925/2. ;
double theta_y=camera->aperture*(y_r-yprev_r)*0.0174532925/2. ;
camera->moveRight(theta_x);
camera->moveUp(theta_y);
xprev = x;
yprev = y;
} }
if (!mouseandkeys.button_middle_down ){ else{
ctx->addQuaternion((2. * xprev - w) / w, (h - 2. * yprev) / h,
(2. * x - w) / w, (h - 2. * y) / h);
}
xprev = x; xprev = x;
yprev = y; yprev = y;
}
display(); display();
} }
void mouse(int button, int state, int x, int y) void mouse(int button, int state, int x, int y)
{ {
specialkey = glutGetModifiers(); specialkey = glutGetModifiers();
xprev = x; xprev = x;
yprev = y; yprev = y;
if (button == GLUT_LEFT_BUTTON) {
mouseandkeys.button_left_down=!state;
}
else if (button == GLUT_MIDDLE_BUTTON) {
mouseandkeys.button_middle_down=!state;
}
else {
mouseandkeys.button_right_down=!state;
}
camera->ref_distance=camera->distance;
}
void processSpecialKeys(int key, int x, int y) {
mouseandkeys.mode = glutGetModifiers();
if (mouseandkeys.mode == GLUT_ACTIVE_CTRL) {
switch(key){
case 100 : /* 'left' */
display();
camera->focallength=camera->focallength*.99;
camera->eyesep=(camera->focallength/camera->distance)*camera->distance*camera->screenratio;
break;
case 102 : /* 'right' */
camera->focallength=camera->focallength*1.01;
camera->eyesep=(camera->focallength/camera->distance)*camera->distance*camera->screenratio;
display();
break;
}
}
else{
switch(key){
mouseandkeys.key= key ;
case 101 : /* 'up' */
camera->focallength*=1.1;
break;
case 103 : /* 'down' */
camera->focallength*=0.9;
break;
case 100 : /* 'left' */
camera->eyesep*=.9;
break;
case 102 : /* 'right' */
camera->eyesep*=1.1;
break;
}
}
camera->update();
display();
cout<<"eyesep = "<< camera->eyesep<<" / focallength = "<< camera->focallength<<" / screenratio = ";
cout<< camera->screenratio<<" / distance = "<< camera->distance<<" / closeness = "<< camera->closeness<<endl;
mouseandkeys.mode = 0;
} }
void processNormalKeys(unsigned char key, int x, int y) {
double def;
if (key != 0) {
mouseandkeys.key= key ;
mouseandkeys.mode = glutGetModifiers();
if (mouseandkeys.mode == GLUT_ACTIVE_CTRL && key==17) exit(0);
}
switch(key){
case 49: GModel::current()->mesh(1); break; /* '1' */
case 50: GModel::current()->mesh(2); break; /* '2' */
case 51: GModel::current()->mesh(3); break; /* '3' */
case 48 : /* '0' */
camera->lookAtCg();
display();
break;
case 114 : /* 'R' */
camera->init();
display();
break;
case 'f' : /* 'F' */
camera->screenwidth=ctx->viewport[2];
camera->screenheight=ctx->viewport[3];
glutFullScreen();
display();
break;
case 27 : /* 'ech' */
glutReshapeWindow(camera->screenwidth ,camera->screenheight );
//glutReshapeWindow(500,500 );
display();
break;
case 100 : ; /* 'D' */
GmshSetOption("View","VectorType",5.);
display();
break;
case 43 : /* '+' */
GmshGetOption("View", "DisplacementFactor", def);
def*=2.;
GmshSetOption("View","DisplacementFactor",def);
display();
break;
case 45 : ; /* '-' */
GmshGetOption("View", "DisplacementFactor", def);
def*=.5;
GmshSetOption("View","DisplacementFactor",def);
display();
break;
}
}
//*******************************************************
//*******************************************************
//*******************************************************
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
GmshInitialize(argc, argv); GmshInitialize(argc, argv);
GmshSetOption("General", "Terminal", 1.); GmshSetOption("General", "Terminal", 1.);
GmshSetOption("General", "Stereo", 0.); GmshSetOption("View", "IntervalsType", 1.);
GmshSetOption("General", "Camera", 1.); GmshSetOption("View", "AdaptVisualizationGrid", 1.);
GmshSetOption("General", "Orthographic", 0.); GmshSetOption("View", "TargetError", 0.00001);
GmshSetOption("General", "TrackballHyperbolicSheet", 0.); GmshSetOption("View", "MaxRecursionLevel", 3.);
if (strstr(argv[1],"-s") != NULL){
camera->stereoEnable = true;
cout<<"mode STEREO"<<endl;
GmshSetOption("General", "Stereo", 1.);
}
for(int i = 1; i < argc; i++) GmshMergeFile(argv[i]); for(int i = 1; i < argc; i++) GmshMergeFile(argv[i]);
ctx = new drawContext(); ctx = new drawContext();
drawContext::setGlobal(new drawContextGlut); drawContext::setGlobal(new drawContextGlut);
camera= &(ctx->camera);
camera->init();
glutInit(&argc, argv); glutInit(&argc, argv);
if (camera->stereoEnable) { glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STEREO);
}
else {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
}
glutInitWindowSize(ctx->viewport[2], ctx->viewport[3]); glutInitWindowSize(ctx->viewport[2], ctx->viewport[3]);
glutInitWindowPosition(400,10); glutInitWindowPosition(100, 100);
glutInitWindowSize(800,800);
glutCreateWindow("GLUT Gmsh Viewer"); glutCreateWindow("GLUT Gmsh Viewer");
glutDisplayFunc(display); glutDisplayFunc(display);
glutReshapeFunc(reshape); glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard); glutKeyboardFunc(keyboard);
glutMotionFunc(motion); glutMotionFunc(motion);
glutMouseFunc(mouse); glutMouseFunc(mouse);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
cout<<"-------------------------------------"<<endl;
cout<<" SHORTCUTS "<<endl;
cout<<"-------------------------------------"<<endl;
cout<<" Ctrl+Q Quit "<<endl;
cout<<" 1 mesh line "<<endl;
cout<<" 2 mesh surface "<<endl;
cout<<" 3 mesh volume "<<endl;
cout<<" R resize "<<endl;
cout<<" 0 origine "<<endl;
cout<<" option -s stereo on "<<endl;
cout<<" F full screen on "<<endl;
cout<<" ech full screen off"<<endl;
cout<<" D displacement field"<<endl;
cout<<" + deformed +"<<endl;
cout<<" - deformed -"<<endl;
cout<<" up focal length +"<<endl;
cout<<" down focal length -"<<endl;
cout<<" left eye sep -"<<endl;
cout<<" right eye sep +"<<endl;
cout<<"-------------------------------------"<<endl;
glutMainLoop(); glutMainLoop();
GmshFinalize(); GmshFinalize();
return 0; return 0;
} }
...@@ -28,9 +28,10 @@ int main(int argc, char **argv) ...@@ -28,9 +28,10 @@ int main(int argc, char **argv)
// (relative to subdomain). // (relative to subdomain).
std::vector<int> domain; std::vector<int> domain;
std::vector<int> subdomain; std::vector<int> subdomain;
std::vector<int> physicalIm;
// initialize // initialize
Homology* homology = new Homology(m, domain, subdomain); Homology* homology = new Homology(m, domain, subdomain, physicalIm);
// find homology basis elements // find homology basis elements
homology->findHomologyBasis(); homology->findHomologyBasis();
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment