Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Simple Question

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Simple Question


Chronological Thread 
  • From: "Bo Schwarzstein" <>
  • To: <>
  • Subject: Re: [cgal-discuss] Simple Question
  • Date: Wed, 30 Jul 2008 17:34:29 +0800
  • Importance: Normal

Title: Simple Question
Here is a part of my code, generate polyhedron from a wavefront obj file, all the facet are triangles, learned from a example in manual.
 
#include "CCSubd.h"
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Subdivision_method_3.h>
#include <CGAL/Polyhedron_3.h>
#include <fstream>
#include <iostream>
#include <string>
#include <memory.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Polyhedron_VRML_1_ostream.h>
 
using namespace std;
 
template<class HDS>
class TriangleBuilder : public CGAL::Modifier_base<HDS>
{
public:
 TriangleBuilder( WavefrontObj* P=NULL) : _Obj(P)
 {
 }
 void operator()(HDS& H)
 {
  CGAL::Polyhedron_incremental_builder_3<HDS> B( H, true);
  if( _Obj->FacetCount == 0 )
  {
   cerr<<"CCSUBD ERROR : FacetCount < 1"<<endl;
   return;
  }
  B.begin_surface(_Obj->VertexCount, _Obj->FacetCount, 6);
  //cout<<"B.begin_surface"<<endl;
  typedef typename HDS::Vertex Vertex;
  typedef typename Vertex::Point Point;
  for( size_t i=0; i<_Obj->VertexCount; i++ )
  {
   size_t j=i*3;
   B.add_vertex( Point(_Obj->VertexPtr[j+0],_Obj->VertexPtr[j+1],_Obj->VertexPtr[j+2]) );
  }
  for( size_t i=0; i<_Obj->FacetCount; i++ )
  {
   B.begin_facet();
   size_t j=i*3;
   B.add_vertex_to_facet( _Obj->IndexPtr[j+0] );
   B.add_vertex_to_facet( _Obj->IndexPtr[j+1] );
   B.add_vertex_to_facet( _Obj->IndexPtr[j+2] );
   B.end_facet();
  }
  B.end_surface();
  //cout<<"B.end_surface"<<endl;
 }
private:
 WavefrontObj* _Obj;
};
 
After declare this class, we can use it like this
 
 typedef CGAL::Simple_cartesian<float> Kernel;
 typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
 typedef Polyhedron::HalfedgeDS HalfedgeDS;
 TriangleBuilder<HalfedgeDS> TB(pObj);
 Polyhedron P;
 P.delegate(TB);
 
if no error happened, the polyhedron is valid.
 

From:
Sent: Wednesday, July 30, 2008 5:22 PM
To:
Subject: [cgal-discuss] Simple Question

Hi All

How do I generate tetrahedrons/Polyhedron to be used in CSG Nef_Polyhedra for geometry primitives (Sphere,Cone,Cylinder)?

Please help. I haven’t received any reply for my previous emails. CGAL seems to be too complicated to work on without a good indepth tutorial, is there one?

Thanks

Sri




Archive powered by MHonArc 2.6.16.

Top of Page