00001
#ifndef _DELAUNAYMESHGENERATOR_H_
00002
#define _DELAUNAYMESHGENERATOR_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#include <qptrlist.h>
00026
#include <qxml.h>
00027
00028
#include "Vertex.h"
00029
#include "Edge.h"
00030
#include "Triangle.h"
00031
00032
#include "Mesh.h"
00033
00034
00035
00036
00037
00038
#define CEps 1e-8
00039
00040
00041
00043
00050 class DelaunayMeshGenerator :
public QXmlDefaultHandler
00051 {
00052
00053
public:
00054
00055
00065
DelaunayMeshGenerator(
const QString& filename,
bool verbose =
false);
00066
00067
00068
00078
DelaunayMeshGenerator(QIODevice& iodevice,
bool verbose =
false);
00079
00080
00081
00090
~DelaunayMeshGenerator();
00091
00092
00093
00100
void generate();
00101
00102
00103
00107 Mesh*
mesh()
const {
return _mesh; }
00108
00109
00110
00115
bool startElement(
const QString&,
const QString&,
00116
const QString& qName,
const QXmlAttributes& );
00117
00118
00119
00128
void write_XML(QTextStream& cout);
00129
00130
00131
00132
protected:
00133
00134
00135
void add_vertex(
Vertex* v);
00136
00137
00138
void add_edge(
Edge* e) { _edges.append(e); }
00139
00140
00141
Vertex* vertex(
const QString&
id)
00142 {
00143
for(
Vertex* v = _vertices.first(); v; v = _vertices.next()) {
00144
if(v->
ID() ==
id)
return v;
00145 }
00146
return 0;
00147 }
00148
00149
00150
00151
private:
00152
00153 QPtrList<Vertex> _vertices;
00154 QPtrList<Vertex> _active_vertices;
00155
00156 QPtrList<Edge> _edges;
00157 QPtrList<Edge> _active_edges;
00158
00159 QPtrList<Triangle> _triangles;
00160
00161
bool _verbose;
00162
00163
double minX, minY, maxX, maxY;
00164
double box_minX, box_minY, box_maxX, box_maxY;
00165
00166
double u_alt;
00167
00168
int _count_ID;
00169
00170
00171 QString createID() {
00172 QString str;
00173 str.sprintf(
"id_%d", _count_ID++);
00174
return str;
00175 }
00176
00177
00178
Mesh* _mesh;
00179
00180
00181
void init();
00182
00183
void reset();
00184
00185
00186
void open(QIODevice& iodevice)
00187 {
00188 QXmlInputSource source( &iodevice );
00189 QXmlSimpleReader reader;
00190 reader.setContentHandler(
this);
00191 reader.parse( source );
00192 }
00193
00194
00195
00196
bool test_intersection(
Vertex* v1,
Vertex* v2);
00197
00198
00199
bool is_voronoi_triangle(
Edge* edge,
Vertex* v);
00200
00201
00202
void create_triangle(
Edge* basisedge,
Vertex* vertex);
00203
00204 };
00205
00206
00207
#endif