1
// Copyright (C) 2006 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// Modified by Johan Jansson 2006.
5
// Modified by Ola Skavhaug 2006.
6
// Modified by Dag Lindbo 2008.
8
// First added: 2006-06-21
9
// Last changed: 2006-12-01
11
#include <dolfin/dolfin_log.h>
12
#include <dolfin/Array.h>
13
#include <dolfin/Mesh.h>
14
#include <dolfin/Facet.h>
15
#include <dolfin/Vertex.h>
16
#include <dolfin/Cell.h>
18
#include <dolfin/GTSInterface.h>
24
using namespace dolfin;
26
//-----------------------------------------------------------------------------
27
GTSInterface::GTSInterface(Mesh& m) : mesh(m), tree(0)
31
//-----------------------------------------------------------------------------
32
GTSInterface::~GTSInterface()
35
gts_bb_tree_destroy(tree, 1);
38
//-----------------------------------------------------------------------------
39
GtsBBox* GTSInterface::bboxCell(Cell& c)
48
bbox = gts_bbox_new(gts_bbox_class(), (void *)c.index(),
52
for(++v; !v.end(); ++v)
55
if (p.x() > bbox->x2) bbox->x2 = p.x();
56
if (p.x() < bbox->x1) bbox->x1 = p.x();
57
if (p.y() > bbox->y2) bbox->y2 = p.y();
58
if (p.y() < bbox->y1) bbox->y1 = p.y();
59
if (p.z() > bbox->z2) bbox->z2 = p.z();
60
if (p.z() < bbox->z1) bbox->z1 = p.z();
69
//-----------------------------------------------------------------------------
70
GtsBBox* GTSInterface::bboxPoint(const Point& p)
76
bbox = gts_bbox_new(gts_bbox_class(), (void *)0,
87
//-----------------------------------------------------------------------------
88
GtsBBox* GTSInterface::bboxPoint(const Point& p1, const Point& p2)
117
bbox = gts_bbox_new(gts_bbox_class(), (void *)0,
124
error("missing GTS");
128
//-----------------------------------------------------------------------------
129
void GTSInterface::buildCellTree()
134
warning("tree already initialized");
136
GSList* bboxes = NULL;
138
for(CellIterator ci(mesh); !ci.end(); ++ci)
141
bboxes = g_slist_prepend(bboxes, bboxCell(c));
144
tree = gts_bb_tree_new(bboxes);
145
g_slist_free(bboxes);
148
error("missing GTS");
151
//-----------------------------------------------------------------------------
152
void GTSInterface::overlap(Cell& c, Array<uint>& cells)
157
GSList* overlaps = 0, *overlaps_base;
160
CellType& type = mesh.type();
162
bbprobe = bboxCell(c);
164
overlaps = gts_bb_tree_overlap(tree, bbprobe);
165
overlaps_base = overlaps;
169
bb = (GtsBBox *)overlaps->data;
170
boundedcell = (uint)(long)bb->bounded;
172
Cell close(mesh, boundedcell);
174
if(type.intersects(c, close))
176
cells.push_back(boundedcell);
178
overlaps = overlaps->next;
181
g_slist_free(overlaps_base);
182
gts_object_destroy(GTS_OBJECT(bbprobe));
185
error("missing GTS");
188
//-----------------------------------------------------------------------------
189
void GTSInterface::overlap(Point& p, Array<uint>& cells)
194
GSList* overlaps = 0, *overlaps_base;
197
CellType& type = mesh.type();
199
bbprobe = bboxPoint(p);
201
overlaps = gts_bb_tree_overlap(tree, bbprobe);
202
overlaps_base = overlaps;
206
bb = (GtsBBox *)overlaps->data;
207
boundedcell = (uint)(long)bb->bounded;
209
Cell close(mesh, boundedcell);
211
if(type.intersects(close, p))
212
cells.push_back(boundedcell);
214
overlaps = overlaps->next;
217
g_slist_free(overlaps_base);
218
gts_object_destroy(GTS_OBJECT(bbprobe));
221
error("missing GTS");
224
//-----------------------------------------------------------------------------
225
void GTSInterface::overlap(Point& p1, Point& p2, Array<uint>& cells)
230
GSList* overlaps = 0,*overlaps_base;
233
bbprobe = bboxPoint(p1,p2);
235
overlaps = gts_bb_tree_overlap(tree, bbprobe);
236
overlaps_base = overlaps;
240
bb = (GtsBBox *)overlaps->data;
241
boundedcell = (uint)(long)bb->bounded;
243
cells.push_back(boundedcell);
245
overlaps = overlaps->next;
247
g_slist_free(overlaps_base);
248
gts_object_destroy(GTS_OBJECT(bbprobe));
251
error("missing GTS");
254
//-----------------------------------------------------------------------------