Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "gtrl_triangulation.h"
00010 #include <vcl_compiler.h>
00011
00012
00013 #ifdef VCL_WIN32
00014 #define NO_TIMER
00015 #endif
00016
00017
00018 extern "C" {
00019 #ifdef SINGLE
00020 #define REAL float
00021 #else
00022 #define REAL double
00023 #endif
00024
00025 #include <triangle.h>
00026 }
00027
00028
00029 gtrl_triangulation::gtrl_triangulation( gtrl_polygon poly)
00030 : poly_( poly)
00031 {
00032 }
00033
00034 void gtrl_triangulation::run()
00035 {
00036 REAL *points= new REAL[poly_.size()*2];
00037 int *markers= new int[poly_.size()];
00038
00039
00040
00041 const int offset = 100;
00042
00043 vcl_vector<gtrl_vertex_sptr> pointlist;
00044
00045 for (int i=0; i< poly_.size(); i++)
00046 {
00047 gtrl_vertex_sptr p= poly_[i];
00048 pointlist.push_back( p);
00049
00050 points[i*2] = p->x();
00051 points[i*2+1]= p->y();
00052 markers[i]= i+offset;
00053 }
00054
00055
00056 triangulateio in;
00057 in.numberofpoints= poly_.size();
00058 in.pointlist= points;
00059 in.pointmarkerlist= markers;
00060 in.numberofpointattributes= 0;
00061 in.numberofholes= 0;
00062 in.trianglelist= 0;
00063
00064
00065 triangulateio out;
00066 out.pointlist= 0;
00067 out.trianglelist= 0;
00068 out.pointmarkerlist= 0;
00069 out.numberofpointattributes= 0;
00070 out.numberofholes= 0;
00071 out.numberoftriangleattributes= 0;
00072
00073
00074 triangulate( "-z -i -q", &in, &out, 0);
00075
00076
00077 for (int i=0; i< out.numberofpoints; i++)
00078 {
00079 if (out.pointmarkerlist[i]< offset)
00080 {
00081 pointlist.push_back( new gtrl_vertex( out.pointlist[i*2],
00082 out.pointlist[i*2+1]));
00083
00084 out.pointmarkerlist[i]= pointlist.size()-1+ offset;
00085 }
00086 }
00087
00088
00089 tris_.clear();
00090
00091
00092 for (int i=0; i< out.numberoftriangles; i++)
00093 {
00094 gtrl_triangle_sptr triangle= new gtrl_triangle( pointlist[ out.pointmarkerlist[ out.trianglelist[i*3]]- offset],
00095 pointlist[ out.pointmarkerlist[ out.trianglelist[i*3+1]]- offset],
00096 pointlist[ out.pointmarkerlist[ out.trianglelist[i*3+2]]- offset]);
00097
00098 if (poly_.inside( triangle->mid_point()))
00099 tris_.push_back( triangle);
00100 }
00101
00102 pts_= pointlist;
00103
00104
00105 delete[] out.pointlist;
00106 delete[] out.pointmarkerlist;
00107 delete[] out.trianglelist;
00108 delete[] points;
00109 delete[] markers;
00110 }