Subject: CGAL users discussion list
List archive
- From:
- To:
- Subject: Re: [cgal-discuss] Polyhedron rending with OpenGL
- Date: Wed, 6 Jun 2018 01:40:48 -0700 (MST)
- Arc-authentication-results: i=1; mx.google.com; spf=fail (google.com: domain of does not designate 162.253.133.72 as permitted sender)
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:content-transfer-encoding:mime-version:subject:message-id:to :from:arc-authentication-results; bh=xob/vwz/ePTQ/UgDUdh/qoLyKM6s37GZhCoWC1z+HIk=; b=whhF89K/Qxr20yjc4iSu6HmO141lvkxBiTqe23ax0l8nwYu3wKwxtx1zQnxDaetJnB PPfdajClxnI5Pfz5l1yEVnwqJ8Nm4fezWYshVh7XsqPaZeVkx7UBZ12yCCJzFZqJq41k eWrbR4xNJ+cSDLYQ7/bKaLl7m4os1Hb+61uZ0qC05Db/8iLhryWHml0OU6bHJt6081w7 SURU4LNcVC8bWSxm56blgtIegJsqr5yjR7xGaJH0EXPeD5Ylk/dquXoGW4uErobLPjnV lshm7AOI6Oa/v0WlwOpW7STtWc7Vpcd98pDwRFCOUmGBiC5fgoFTvKyZBnIH8K/XWBCi PCSg==
- Arc-seal: i=1; a=rsa-sha256; t=1528274449; cv=none; d=google.com; s=arc-20160816; b=un785GrODDP+pScLCU7NFDjNfp1oybDOqq0fT5JHPH6njEZdxNlXRUtso0ZaVS4sal hwLLMr6LHSttpgejzVCl+8ytkAgIfja9xQJZ0Y1zg01MdhS+oaGg+hJiz2z6Lk5xaW2M fIzD0r4nGJf2jRHNfX/Oo6vXCnnalFocy4VlmQtVmgBTeqW8GOkyA1KRDVj6ymbJvYBs vwkjapotCLoCDehCpvymDIhFvCfLsWOC3gsTXN3azgXr24tn1clmizgvUvkb2bEsKDuz +QxRDr3Odfx8CNjSq5ag4Qo1m2yfMIfZzx2KKAknT35ecZbmRBRlhicoUsOttkVhwKhw Z1FQ==
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf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IZq2ux5oQdDa9GtxpJkyYZTznhdJSP30Nu188SbG31A3aeWcNPDC5WKdvtXkAFIu6ANKbFciWi7ub0XLjR8wEViV9ElmJVEzQWcCBUvYIZjiVJ5Y4wDMBXLmlDYQm0EP37VOo+/9cNuPRvxYgm9f7ztEsvr/ckBgz8Xp/CMHPizjQHVExpXsBQnoN5I46oUF5zQ3dg61xgvgdCsYLov0QDVh8OpnbwOh3Tdv1X1CZcw==
- Resent-date: Wed, 6 Jun 2018 13:36:04 +0200
- Resent-from: "Sebastien Loriot (GeometryFactory)" <>
- Resent-message-id: <>
- Resent-to:
- Resent-user-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0
sorry it's my first time to reply and i'm not sure is this the right way to
reply to you
thanks for you advice and here is my complete code:
#define CGAL_EIGEN3_ENABLED
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/poisson_surface_reconstruction.h>
#include <CGAL/IO/read_xyz_points.h>
#include<gl/freeglut.h>
#include<gl/glut.h>
#include<GL/GL.H>
#include<gl/GLU.H>
#include <vector>
#include <fstream>
float xx;
float yy;
float zz;
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;
typedef std::pair<Point, Vector> Pwn;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef boost::graph_traits<Polyhedron>::vertex_descriptor
vertex_descriptor;
typedef boost::graph_traits<Polyhedron>::face_descriptor face_descriptor;
const float g_ambDiff[4] = { 1.0f, 0.5f, 0.0f, 1.0f };//value of lighting
const float g_lightPos[] = { 10.0f, 10.0f, 10.0f, 0.0f };
const float g_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const float g_shininess[] = { 50.0f };
Kernel::Vector_3 n;
Polyhedron P;
std::map<face_descriptor, Vector> fnormals;
std::map<vertex_descriptor, Vector> vnormals;
Polyhedron::Vertex_iterator v;
void gl_draw_facet(Polyhedron::Facet_iterator f){
Polyhedron::Halfedge_around_facet_circulator he = f->facet_begin();
do{
const Point& p = he->vertex()->point();
glVertex3d(p.x(), p.y(), p.z());
} while (++he != f->facet_begin());
}
void getPoint()
{
std::vector<Pwn> points;
std::ifstream stream("data/kitten.xyz");
if (!stream ||
!CGAL::read_xyz_points(
stream,
std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>()).
normal_map(CGAL::Second_of_pair_property_map<Pwn>())))
{
std::cerr << "Error: cannot read file data/kitten.xyz" <<
std::endl;
}
double average_spacing =
CGAL::compute_average_spacing<CGAL::Sequential_tag>
(points, 6,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>()));
CGAL::poisson_surface_reconstruction_delaunay
(points.begin(), points.end(),
CGAL::First_of_pair_property_map<Pwn>(),
CGAL::Second_of_pair_property_map<Pwn>(),
P, average_spacing);
}
void drawPoint(){
Polyhedron::Vertex_iterator v;
Polyhedron::Facet_iterator f;
Polyhedron::Edge_iterator eit;
Polyhedron::Halfedge_handle h_handle;
double x, y, z;
CGAL::Polygon_mesh_processing::compute_normals(P,
boost::make_assoc_property_map(vnormals),
boost::make_assoc_property_map(fnormals));
glBegin(GL_TRIANGLES);
for (f = P.facets_begin(); f != P.facets_end(); f++){
xx = fnormals[f].x() /
sqrt((fnormals[f].x()*fnormals[f].x()) +
(fnormals[f].y()*fnormals[f].y()) + (fnormals[f].z()*fnormals[f].z()));
yy = fnormals[f].y() /
sqrt((fnormals[f].x()*fnormals[f].x()) +
(fnormals[f].y()*fnormals[f].y()) + (fnormals[f].z()*fnormals[f].z()));
zz = fnormals[f].z() /
sqrt((fnormals[f].x()*fnormals[f].x()) +
(fnormals[f].y()*fnormals[f].y()) + (fnormals[f].z()*fnormals[f].z()));
glNormal3f(xx, yy, zz);
gl_draw_facet(f);
}
glEnd();
}
void init(){
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
drawPoint();
glFlush();
glutSwapBuffers();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("points");
init();
getPoint();
glutDisplayFunc(display);
glutKeyboardFunc(key);
glClearColor(0.2, 0.55, 1.0, 1);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, g_lightPos);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, g_ambDiff);
glMaterialfv(GL_FRONT, GL_SPECULAR, g_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, g_shininess);
glutMainLoop();
return 0;
}
the data "kitten.xyz" comes from the cgal examples
"Poisson_surface_reconstruction_3" or you can see it from here
https://doc.cgal.org/latest/Poisson_surface_reconstruction_3/Poisson_surface_reconstruction_3_2poisson_reconstruction_function_8cpp-example.html
<quote author='Sebastien Loriot (GeometryFactory)'>
I don't see any error here.
Try posting a minimal complete example showing the error
so that we can reproduce it. Maybe the error is not where
you think it is and selected parts are not relevant.
Sebastien
On 06/06/2018 10:02 AM, Lettuce wrote:
> Hello,
> firstly i use CGAL::poisson_suface_reconstruction_delaunay to creat a mesh
> here is the code
>
> CGAL::poisson_surface_reconstruction_delaunay
> (points.begin(), points.end(),
> CGAL::First_of_pair_property_map<Pwn>(),
> CGAL::Second_of_pair_property_map<Pwn>(),
> P, average_spacing);
>
> then i want to use opengl to rending it and the code is
>
> void gl_draw_facet(Polyhedron::Facet_iterator f){
> Polyhedron::Halfedge_around_facet_circulator he = f->facet_begin();
> do{
> const Point& p = he->vertex()->point();
> glVertex3d(p.x(), p.y(), p.z());
> } while (++he != f->facet_begin());
> }
>
> void drawPoint(){
> Polyhedron::Vertex_iterator v;
> Polyhedron::Facet_iterator f;
> Polyhedron::Edge_iterator eit;
> Polyhedron::Halfedge_handle h_handle;
> double x, y, z;
>
> CGAL::Polygon_mesh_processing::compute_normals(P,
> boost::make_assoc_property_map(vnormals),
> boost::make_assoc_property_map(fnormals));
>
> glBegin(GL_TRIANGLES);
> for (f = P.facets_begin(); f != P.facets_end(); f++){
> xx = fnormals[f].x() /
> sqrt((fnormals[f].x()*fnormals[f].x()) +
> (fnormals[f].y()*fnormals[f].y()) + (fnormals[f].z()*fnormals[f].z()));
> yy = fnormals[f].y() /
> sqrt((fnormals[f].x()*fnormals[f].x()) +
> (fnormals[f].y()*fnormals[f].y()) + (fnormals[f].z()*fnormals[f].z()));
> zz = fnormals[f].z() /
> sqrt((fnormals[f].x()*fnormals[f].x()) +
> (fnormals[f].y()*fnormals[f].y()) + (fnormals[f].z()*fnormals[f].z()));
> glNormal3f(xx, yy, zz);
> gl_draw_facet(f);
> }
> glEnd();
> }
> but the result shows there is something wrong with the normals. here is
> the
> result
> <http://cgal-discuss.949826.n4.nabble.com/file/t375948/cat.png>
>
> i dont know what's wrong with my code.
>
> need help,thank you.
>
>
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.nabble.com/
>
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss
</quote>
Quoted from:
http://cgal-discuss.949826.n4.nabble.com/Polyhedron-rending-with-OpenGL-tp4663546p4663547.html
_____________________________________
Sent from http://cgal-discuss.949826.n4.nabble.com
- [cgal-discuss] Polyhedron rending with OpenGL, Lettuce, 06/06/2018
- Re: [cgal-discuss] Polyhedron rending with OpenGL, Sebastien Loriot (GeometryFactory), 06/06/2018
- Re: [cgal-discuss] Polyhedron rending with OpenGL, Lettuce, 06/06/2018
- <Possible follow-up(s)>
- Re: [cgal-discuss] Polyhedron rending with OpenGL, jm55480, 06/06/2018
- Re: [cgal-discuss] Polyhedron rending with OpenGL, Sebastien Loriot (GeometryFactory), 06/06/2018
Archive powered by MHonArc 2.6.18.