1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
26 #include <QMessageBox>
31 #include <vtkSmartPointer.h>
32 #include <vtkLongArray.h>
33 #include <vtkLongLongArray.h>
34 #include <vtkIntArray.h>
35 #include <vtkDoubleArray.h>
38 #include "math/mathvector.h"
39 #include "math/smallsquarematrix.h"
40 #include "geometrytools.h"
41 #include "containertricks.h"
43 // #include "engrid_version.h" //Moved this to the only place where it was being used for now...
46 typedef vtkLongLongArray vtkLongArray_t
;
50 #if ( __WORDSIZE == 64 )
51 typedef vtkLongArray vtkLongArray_t
;
53 typedef vtkLongLongArray vtkLongArray_t
;
58 #define EG_ERR_RETURN(TXT) \
61 line.setNum(__LINE__); \
62 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
65 err.setType(Error::ExitOperation); \
69 #define EG_ERR_DISPLAY(TXT) \
72 line.setNum(__LINE__); \
73 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
76 err.setType(Error::ExitOperation); \
84 line.setNum(__LINE__); \
85 QString txt = "This seems to be a bug in enGrid"; \
86 txt += QString("\n\nfile: ") + __FILE__ + "\nline:" + line + "\n\n"; \
94 line.setNum(__LINE__); \
95 QString txt = "This seems to be a bug in enGrid"; \
96 txt += QString("\n\nfile: ") + __FILE__ + "\nline:" + line + "\n\n"; \
99 err.setType(Error::ExitOperation); \
105 #define EG_ERR_STOP(TXT) \
108 line.setNum(__LINE__); \
109 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
112 err.setType(Error::ExitProgram); \
116 #define EG_VTKSP(TYPE,VAR) vtkSmartPointer<TYPE> VAR = vtkSmartPointer<TYPE>::New();
119 * Get an automatically casted pointer to a cell data array of a grid
120 * (vtkUnstructuredGrid).
121 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
122 * @param VAR the name for the C++ pointer variable
123 * @param GRID a pointer to the vtkUnstructuredGrid
124 * @param NAME the sybolic name of the data array; for example "cell_index"
126 #define EG_VTKDCC(TYPE,VAR,GRID,NAME) \
128 if (GRID->GetCellData()->GetScalars(NAME)) { \
129 VAR = dynamic_cast<TYPE*>(GRID->GetCellData()->GetScalars(NAME)); \
131 QString msg = "type mismatch ("; \
132 int t = GRID->GetCellData()->GetScalars(NAME)->GetDataType(); \
133 if (t == VTK_VOID) msg += "VTK_VOID"; \
134 if (t == VTK_BIT) msg += "VTK_BIT"; \
135 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
136 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
137 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
138 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
139 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
140 if (t == VTK_INT) msg += "VTK_INT"; \
141 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
142 if (t == VTK_LONG) msg += "VTK_LONG"; \
143 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
144 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
145 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
146 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
147 if (t == VTK_STRING) msg += "VTK_STRING"; \
148 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
149 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
150 if (t == VTK___INT64) msg += "VTK___INT64"; \
151 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
153 EG_ERR_RETURN(msg); \
156 QString msg = QString("array '") + NAME + "' does not exist."; \
157 EG_ERR_RETURN(msg); \
161 * Get an automatically casted pointer to a node data array of a grid
162 * (vtkUnstructuredGrid).
163 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
164 * @param VAR the name for the C++ pointer variable
165 * @param GRID a pointer to the vtkUnstructuredGrid
166 * @param NAME the sybolic name of the data array; for example "node_index"
168 #define EG_VTKDCN(TYPE,VAR,GRID,NAME) \
170 if (GRID->GetPointData()->GetScalars(NAME)) { \
171 VAR = dynamic_cast<TYPE*>(GRID->GetPointData()->GetScalars(NAME)); \
173 QString msg = "type mismatch ("; \
174 int t = GRID->GetPointData()->GetScalars(NAME)->GetDataType(); \
175 if (t == VTK_VOID) msg += "VTK_VOID"; \
176 if (t == VTK_BIT) msg += "VTK_BIT"; \
177 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
178 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
179 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
180 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
181 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
182 if (t == VTK_INT) msg += "VTK_INT"; \
183 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
184 if (t == VTK_LONG) msg += "VTK_LONG"; \
185 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
186 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
187 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
188 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
189 if (t == VTK_STRING) msg += "VTK_STRING"; \
190 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
191 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
192 if (t == VTK___INT64) msg += "VTK___INT64"; \
193 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
195 EG_ERR_RETURN(msg); \
198 QString msg = QString("array '") + NAME + "' does not exist."; \
199 EG_ERR_RETURN(msg); \
202 #define EG_STDINTERSLOT(OPER) \
206 } catch (Error err) { \
212 if(m_Grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
216 #define EG_STDSLOT(OPER) \
220 } catch (Error err) { \
224 oper->setLockGui(); \
230 #define EG_STDREADERSLOT(OPER) \
231 OPER *oper = new OPER(); \
234 if(m_Grid->GetNumberOfPoints()) updateBoundaryCodes(true); \
239 #define EG_STDCONNECT(OPER) \
240 connect(ui.action ## OPER, SIGNAL(triggered()), this, SLOT(call ## OPER ()));
242 #define DUMMY_VAR(X) X = X
245 * Perform a loop over all cells of a grid.
246 * @param ID_CELL the cell index iteration variable
247 * @param GRID a pointer to the vtkUnstructuredGrid
249 #define EG_FORALL_CELLS(ID_CELL, GRID) for (vtkIdType ID_CELL = 0; ID_CELL < GRID->GetNumberOfCells(); ++ID_CELL)
252 * Perform a loop over all nodes of a grid.
253 * @param ID_NODE the node index iteration variable
254 * @param GRID a pointer to the vtkUnstructuredGrid
256 #define EG_FORALL_NODES(ID_NODE, GRID) for (vtkIdType ID_NODE = 0; ID_NODE < GRID->GetNumberOfPoints(); ++ID_NODE)
259 * Get the type and the nodes of a cell.
260 * The following variables are created:
261 * - num_pts (number of points)
262 * - pts (array with the points)
263 * - type_cell (VTK type of the cell)
264 * @param ID_CELL the cell index
265 * @param GRID a pointer to the vtkUnstructuredGrid
267 #define EG_GET_CELL(ID_CELL, GRID) \
268 vtkIdType num_pts, *pts; \
269 vtkIdType type_cell = GRID->GetCellType(ID_CELL); \
270 GRID->GetCellPoints(ID_CELL, num_pts, pts);
272 #define EG_LARGE_REAL 1e99
274 #define EG_STOPDATE(STOP_DATE) \
275 QDate stop_date = QDate::fromString(STOP_DATE, "yyyy-MM-dd"); \
276 if (stop_date <= QDate::currentDate()) { \
277 EG_ERR_RETURN(QString("This feature is not supported after ") + STOP_DATE); \
280 inline double sqr(double x) { return x*x; }
283 inline T
sign1(T t
) {
284 if (t
>= 0) return 1;
288 inline int factorial_rec(int num
)
292 return factorial_rec(num
-1)*num
; // recursive call
295 inline int factorial_it(int num
)
298 for (int i
=1; i
<=num
; ++i
)
303 inline int N_Combinations(int N
,int k
)
305 return(factorial_rec(N
)/(factorial_rec(N
-k
)*factorial_rec(k
)));
308 inline int N_Permutations(int N
,int k
)
310 return(factorial_rec(N
)/(factorial_rec(N
-k
)));
313 #define LINE_STR "=================" << endl;
322 SortedPair(T v1
, T v2
);
323 bool operator==(const SortedPair
<T
>& P
) const{ return (v1
== P
.v1
) && (v2
== P
.v2
); }
324 bool operator<(const SortedPair
<T
>& P
) const;
325 bool operator>(const SortedPair
<T
>& P
) const { return !operator<(P
); }
330 SortedPair
<T
>::SortedPair(T v1
, T v2
)
342 SortedPair
<T
>::SortedPair()
349 bool SortedPair
<T
>::operator<(const SortedPair
<T
>& P
) const
353 } else if (v1
== P
.v1
) {
360 inline uint
qHash(const SortedPair
<T
> &P
)
362 uint h1
= qHash(P
.v1
);
363 uint h2
= qHash(P
.v2
);
364 return ((h1
<< 16) | (h1
>> 16)) ^ h2
;