Skip to content
Snippets Groups Projects
Commit 166376a9 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

Geometry and Mesh drawing on mobile

parent f8d8bcce
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,8 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(DEFAULT ON CACHE INTERNAL "Default value for enabled-by-default options")
if(APPLE)
option(ENABLE_BUILD_IOS "Build library for iOS (ARM)" OFF)
option(ENABLE_BUILD_IOS_EMULATOR "Build library for iOS emulator (x86)" ON)
option(ENABLE_BUILD_IOS "Build XCode project for iOS (ARM)" OFF)
option(ENABLE_BUILD_IOS_EMULATOR "Build XCode project for iOS emulator (x86)" ON)
option(ENABLE_BUILD_ANDROID "Build library for Android NDK (ARMv7)" OFF)
else(APPLE)
option(ENABLE_BUILD_ANDROID "Build library for Android NDK (ARMv7)" ON)
......@@ -57,6 +57,8 @@ if(ENABLE_BUILD_IOS_EMULATOR OR ENABLE_BUILD_IOS)
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/iOS/ic_launcher_retina.png ${CMAKE_CURRENT_BINARY_DIR}/Onelab/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawContext.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawContext.h ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawGeom.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawMesh.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawString.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawString.h ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Trackball.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/
......
......@@ -211,7 +211,7 @@ void drawContext::initView(int w, int h)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void drawArray(VertexArray *va, GLint type, bool colorArray=false)
void drawArray(VertexArray *va, GLint type, bool colorArray)
{
if(!va) return;
glEnable(GL_BLEND);
......@@ -465,21 +465,6 @@ void drawContext::drawScale()
glPopMatrix();
}
void drawContext::drawMesh()
{
GModel::current()->fillVertexArrays();
unsigned int col = CTX::instance()->color.mesh.line;
glColor4ub((GLubyte)CTX::instance()->unpackRed(col),
(GLubyte)CTX::instance()->unpackGreen(col),
(GLubyte)CTX::instance()->unpackBlue(col),
(GLubyte)CTX::instance()->unpackAlpha(col));
for(GModel::fiter it = GModel::current()->firstFace(); it != GModel::current()->lastFace(); it++){
if(_fillMesh) drawArray((*it)->va_triangles, GL_TRIANGLES);
else drawArray((*it)->va_lines, GL_LINES, true);
}
CTX::instance()->mesh.changed = 0;
}
void drawContext::drawPost()
{
if(PView::list.empty()) return ;
......@@ -490,39 +475,6 @@ void drawContext::drawPost()
}
}
void drawContext::drawGeom()
{
unsigned int col = CTX::instance()->color.geom.line;
glColor4ub((GLubyte)CTX::instance()->unpackRed(col),
(GLubyte)CTX::instance()->unpackGreen(col),
(GLubyte)CTX::instance()->unpackBlue(col),
(GLubyte)CTX::instance()->unpackAlpha(col));
//glLineWidth((GLfloat)CTX::instance()->geom.lineWidth); OpenGL Error -> GL_INVALID_VALUE​, 0x0501
for(GModel::eiter it = GModel::current()->firstEdge(); it != GModel::current()->lastEdge(); it++){
GEdge *e = *it;
int N = e->minimumDrawSegments() + 1; // e is sometime incorrect (e.g. 0x0000004f) when compute
Range<double> t_bounds = e->parBounds(0);
double t_min = t_bounds.low();
double t_max = t_bounds.high();
// Create a VA for this edge
GLfloat *edge = (GLfloat *) malloc(N*3*sizeof(GLfloat));
for(unsigned int i=0; i < N; i++) {
double t = t_min + (double)i / (double)(N-1) * (t_max - t_min);
GPoint p = e->point(t);
edge[i*3] = p.x(); edge[i*3+1] = p.y(); edge[i*3+2] = p.z();
}
// Then print the VA
glVertexPointer(3, GL_FLOAT, 0, edge);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, N);
glDisableClientState(GL_VERTEX_ARRAY);
free(edge);
}
glLineWidth(1);
}
void drawContext::drawAxes(float x0, float y0, float z0, float h)
{
glLineWidth(1.);
......
#if !defined(BUILD_ANDROID)
#define BUILD_IOS 1
#endif
#if defined(BUILD_IOS)
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#include <Gmsh/Gmsh.h>
#include <Gmsh/GModel.h>
#endif
#if defined(BUILD_ANDROID)
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <gmsh/Gmsh.h>
#include <gmsh/GModel.h>
#endif
#include "drawContext.h"
void drawGeomVertex(GVertex *v)
{
if(!v->getVisibility()) return;
if(v->geomType() == GEntity::BoundaryLayerPoint) return;
unsigned int col = CTX::instance()->color.geom.point;
glColor4ub((GLubyte)CTX::instance()->unpackRed(col),
(GLubyte)CTX::instance()->unpackGreen(col),
(GLubyte)CTX::instance()->unpackBlue(col),
(GLubyte)CTX::instance()->unpackAlpha(col));
const GLfloat p[] = {(GLfloat)v->x(), (GLfloat)v->y(), (GLfloat)v->z()};
glPointSize((GLfloat)(CTX::instance()->geom.pointSize>0)? 3:1);
glVertexPointer(3, GL_FLOAT, 0, p);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_POINTS, 0, 1);
glDisableClientState(GL_VERTEX_ARRAY);
glPointSize(1);
}
void drawGeomEdge(GEdge *e)
{
if(!e->getVisibility()) return;
if(e->geomType() == GEntity::DiscreteCurve) return;
if(e->geomType() == GEntity::PartitionCurve) return;
if(e->geomType() == GEntity::BoundaryLayerCurve) return;
unsigned int col = CTX::instance()->color.geom.line;
glColor4ub((GLubyte)CTX::instance()->unpackRed(col),
(GLubyte)CTX::instance()->unpackGreen(col),
(GLubyte)CTX::instance()->unpackBlue(col),
(GLubyte)CTX::instance()->unpackAlpha(col));
int N = e->minimumDrawSegments() + 1;
Range<double> t_bounds = e->parBounds(0);
double t_min = t_bounds.low();
double t_max = t_bounds.high();
// Create a VA for this edge
GLfloat *edge = (GLfloat *) malloc(N*3*sizeof(GLfloat));
for(unsigned int i=0; i < N; i++) {
double t = t_min + (double)i / (double)(N-1) * (t_max - t_min);
GPoint p = e->point(t);
edge[i*3] = p.x(); edge[i*3+1] = p.y(); edge[i*3+2] = p.z();
}
// Then print the VA
glVertexPointer(3, GL_FLOAT, 0, edge);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, N);
glDisableClientState(GL_VERTEX_ARRAY);
free(edge);
}
void drawGeomFace(GFace *f)
{
// TODO
}
void drawContext::drawGeom()
{
for(unsigned int i=0; i<GModel::list.size(); i++) {
GModel *m = GModel::list[i];
if(!m->getVisibility()) continue;
if(CTX::instance()->geom.points || CTX::instance()->geom.pointsNum)
std::for_each(m->firstVertex(), m->lastVertex(), drawGeomVertex);
if(CTX::instance()->geom.lines || CTX::instance()->geom.linesNum || CTX::instance()->geom.tangents)
std::for_each(m->firstEdge(), m->lastEdge(), drawGeomEdge);
if(CTX::instance()->geom.surfaces || CTX::instance()->geom.surfacesNum || CTX::instance()->geom.normals)
std::for_each(m->firstFace(), m->lastFace(), drawGeomFace);
}
}
#if !defined(BUILD_ANDROID)
#define BUILD_IOS 1
#endif
#if defined(BUILD_IOS)
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#include <Gmsh/Gmsh.h>
#include <Gmsh/GModel.h>
#include <Gmsh/GEdgeCompound.h>
#include <Gmsh/GFaceCompound.h>
#include <Gmsh/PView.h>
#include <Gmsh/PViewData.h>
#endif
#if defined(BUILD_ANDROID)
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <gmsh/Gmsh.h>
#include <gmsh/GModel.h>
#include <gmsh/GEdgeCompound.h>
#include <gmsh/GFaceCompound.h>
#include <gmsh/PView.h>
#include <gmsh/PViewData.h>
#endif
#include "drawContext.h"
// from GModelVertexArrays
extern unsigned int getColorByEntity(GEntity *e);
void drawMeshVertex(GVertex *e)
{
if(!CTX::instance()->mesh.points && !CTX::instance()->mesh.pointsNum) return;
std::vector<GLfloat> vertex;
std::vector<GLubyte> color;
for(unsigned int i = 0; i < e->mesh_vertices.size(); i++){
MVertex *v = e->mesh_vertices[i];
if(!v->getVisibility()) continue;
unsigned int col;
if(CTX::instance()->mesh.colorCarousel == 0 || CTX::instance()->mesh.volumesFaces || CTX::instance()->mesh.surfacesFaces) {
if(v->getPolynomialOrder() > 1)
col = CTX::instance()->color.mesh.vertexSup;
else
col = CTX::instance()->color.mesh.vertex;
}
else
col = getColorByEntity(e);
color.push_back((GLubyte)CTX::instance()->unpackRed(col));
color.push_back((GLubyte)CTX::instance()->unpackGreen(col));
color.push_back((GLubyte)CTX::instance()->unpackBlue(col));
color.push_back((GLubyte)CTX::instance()->unpackAlpha(col));
vertex.push_back(v->x());
vertex.push_back(v->y());
vertex.push_back(v->z());
}
glVertexPointer(3, GL_FLOAT, 0, &vertex.front());
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, color.size()/4, &color.front());
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, 0, vertex.size()/3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
void drawMeshEdge(GEdge *e)
{
if(!e->getVisibility()) {
if(e->getCompound()) {
if(!e->getCompound()->getVisibility()) return;
}
else
return;
}
drawArray(e->va_lines, GL_LINES, true);
}
void drawMeshFace(GFace *f)
{
if(!f->getVisibility()) {
if(f->getCompound()) {
if(!f->getCompound()->getVisibility()) return;
}
else
return;
}
drawArray(f->va_lines, GL_LINES, true);
}
void drawContext::drawMesh()
{
if(!CTX::instance()->mesh.draw) return;
if(CTX::instance()->mesh.changed)
for(unsigned int i = 0; i < GModel::list.size(); i++)
for(unsigned int j = 0; j < PView::list.size(); j++)
if(PView::list[j]->getData()->hasModel(GModel::list[i]))
PView::list[j]->setChanged(true);
unsigned int col = CTX::instance()->color.mesh.line;
glColor4ub((GLubyte)CTX::instance()->unpackRed(col),
(GLubyte)CTX::instance()->unpackGreen(col),
(GLubyte)CTX::instance()->unpackBlue(col),
(GLubyte)CTX::instance()->unpackAlpha(col));
for(unsigned int i = 0; i < GModel::list.size(); i++){
GModel *m = GModel::list[i];
m->fillVertexArrays();
if(!m->getVisibility()) continue;
int status = m->getMeshStatus();
if(status >= 0)
std::for_each(m->firstVertex(), m->lastVertex(), drawMeshVertex);
if(status >= 1)
std::for_each(m->firstEdge(), m->lastEdge(), drawMeshEdge);
if(status >= 2)
std::for_each(m->firstFace(), m->lastFace(), drawMeshFace);
}
CTX::instance()->mesh.changed = 0;
}
......@@ -40,6 +40,7 @@
}
}*/
self.delegate = detailViewController;
[self setPresentsWithGesture:NO];
}
-(void)viewDidAppear:(BOOL)animated
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment