Nektar++
TriangleInterface.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: TriangleInterface.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Interface to triangle mesher
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
36 
37 #include <sstream>
38 
39 using namespace std;
40 namespace Nektar
41 {
42 namespace NekMeshUtils
43 {
44 
45 void TriangleInterface::Mesh(bool Quality)
46 {
47  SetUp();
48 
49  int numPoints = 0;
50  int numSeg = 0;
51  for (int i = 0; i < m_boundingloops.size(); i++)
52  {
53  numSeg += m_boundingloops[i].size();
54  }
55  numPoints = numSeg + m_stienerpoints.size();
56 
57  stringstream ss;
58  ss << "3 points required for triangulation, " << numPoints << " provided";
59 
60  ASSERTL0(numPoints > 2, ss.str());
61 
62  dt.in.numberofpoints = numPoints;
63  dt.in.numberofpointattributes = 0;
64  dt.in.pointlist = new double[dt.in.numberofpoints * 2];
65 
66  int pointc = 0;
67 
68  for (int i = 0; i < m_boundingloops.size(); i++)
69  {
70  for (int j = 0; j < m_boundingloops[i].size(); j++, pointc++)
71  {
72  nodemap[pointc] = m_boundingloops[i][j];
73 
75  m_boundingloops[i][j]->GetCADSurfInfo(sid);
76  dt.in.pointlist[pointc * 2 + 0] = uv[0] * m_str;
77  dt.in.pointlist[pointc * 2 + 1] = uv[1];
78  }
79  }
80 
81  for (int i = 0; i < m_stienerpoints.size(); i++, pointc++)
82  {
83  nodemap[pointc] = m_stienerpoints[i];
84 
85  Array<OneD, NekDouble> uv = m_stienerpoints[i]->GetCADSurfInfo(sid);
86  dt.in.pointlist[pointc * 2 + 0] = uv[0] * m_str;
87  dt.in.pointlist[pointc * 2 + 1] = uv[1];
88  }
89 
90  dt.in.numberofsegments = numSeg;
91  dt.in.segmentlist = new int[dt.in.numberofsegments * 2];
92  pointc = 0;
93  for (int i = 0; i < m_boundingloops.size(); i++, pointc++)
94  {
95  int first = pointc;
96  for (int j = 0; j < m_boundingloops[i].size() - 1; j++, pointc++)
97  {
98  dt.in.segmentlist[pointc * 2 + 0] = pointc;
99  dt.in.segmentlist[pointc * 2 + 1] = pointc + 1;
100  }
101  dt.in.segmentlist[pointc * 2 + 0] = pointc;
102  dt.in.segmentlist[pointc * 2 + 1] = first;
103  }
104 
105  dt.in.numberofregions = 0;
106  dt.in.numberofholes = m_centers.size() - 1;
107  dt.in.holelist = new double[dt.in.numberofholes * 2];
108 
109  for (int i = 1; i < m_centers.size(); i++)
110  {
111  dt.in.holelist[(i - 1) * 2 + 0] = m_centers[i][0] * m_str;
112  dt.in.holelist[(i - 1) * 2 + 1] = m_centers[i][1];
113  }
114 
115  string cmd;
116  if (Quality)
117  {
118  cmd = "pqzQY";
119  }
120  else if (!Quality)
121  {
122  cmd = "pzQY";
123  }
124  char *cstr = new char[cmd.length() + 1];
125  strcpy(cstr, cmd.c_str());
126 
127  dt.Run(cstr);
128 }
129 
130 void TriangleInterface::SetUp()
131 {
132  dt.in.pointlist = (double *)NULL;
133  dt.in.pointattributelist = (double *)NULL;
134  dt.in.pointmarkerlist = (int *)NULL;
135  dt.in.numberofpoints = 0;
136  dt.in.numberofpointattributes = 0;
137  //
138  dt.in.trianglelist = (int *)NULL;
139  dt.in.triangleattributelist = (double *)NULL;
140  dt.in.trianglearealist = (double *)NULL;
141  dt.in.neighborlist = (int *)NULL;
142  dt.in.numberoftriangles = 0;
143  dt.in.numberofcorners = 0;
144  dt.in.numberoftriangleattributes = 0;
145  //
146  dt.in.segmentlist = (int *)NULL;
147  dt.in.segmentmarkerlist = (int *)NULL;
148  dt.in.numberofsegments = 0;
149  //
150  dt.in.holelist = (double *)NULL;
151  dt.in.numberofholes = 0;
152  //
153  dt.in.regionlist = (double *)NULL;
154  dt.in.numberofregions = 0;
155  //
156  dt.in.edgelist = (int *)NULL;
157  dt.in.edgemarkerlist = (int *)NULL;
158  dt.in.normlist = (double *)NULL;
159  dt.in.numberofedges = 0;
160  //
161  dt.out.pointlist = (double *)NULL;
162  dt.out.pointattributelist = (double *)NULL;
163  dt.out.pointmarkerlist = (int *)NULL;
164  dt.out.numberofpoints = 0;
165  dt.out.numberofpointattributes = 0;
166  //
167  dt.out.trianglelist = (int *)NULL;
168  dt.out.triangleattributelist = (double *)NULL;
169  dt.out.trianglearealist = (double *)NULL;
170  dt.out.neighborlist = (int *)NULL;
171  dt.out.numberoftriangles = 0;
172  dt.out.numberofcorners = 0;
173  dt.out.numberoftriangleattributes = 0;
174  //
175  dt.out.segmentlist = (int *)NULL;
176  dt.out.segmentmarkerlist = (int *)NULL;
177  dt.out.numberofsegments = 0;
178  //
179  dt.out.holelist = (double *)NULL;
180  dt.out.numberofholes = 0;
181  //
182  dt.out.regionlist = (double *)NULL;
183  dt.out.numberofregions = 0;
184  //
185  dt.out.edgelist = (int *)NULL;
186  dt.out.edgemarkerlist = (int *)NULL;
187  dt.out.normlist = (double *)NULL;
188  dt.out.numberofedges = 0;
189 }
190 
191 void TriangleInterface::Extract(
192  std::vector<std::vector<NodeSharedPtr> > &Connec)
193 {
194  Connec.clear();
195  for (int i = 0; i < dt.out.numberoftriangles; i++)
196  {
197  map<int, NodeSharedPtr>::iterator n1, n2, n3;
198  n1 = nodemap.find(dt.out.trianglelist[i * 3 + 0]);
199  n2 = nodemap.find(dt.out.trianglelist[i * 3 + 1]);
200  n3 = nodemap.find(dt.out.trianglelist[i * 3 + 2]);
201 
202  ASSERTL0(n1 != nodemap.end() && n2 != nodemap.end() &&
203  n3 != nodemap.end(),
204  "node index error");
205 
206  vector<NodeSharedPtr> tri(3);
207  tri[0] = n1->second;
208  tri[1] = n2->second;
209  tri[2] = n3->second;
210  Connec.push_back(tri);
211  }
212 }
213 }
214 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
STL namespace.