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 //#ifdef VTK_VERSION_LESS_THAN_6_1
25 //#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
27 //#include <vtkAutoInit.h>
28 //VTK_MODULE_INIT(vtkRenderingOpenGL);
31 #include <QMessageBox>
35 #include <QApplication>
37 #include <vtkSmartPointer.h>
38 #include <vtkLongArray.h>
39 #include <vtkLongLongArray.h>
40 #include <vtkIntArray.h>
41 #include <vtkDoubleArray.h>
44 #include "math/mathvector.h"
45 #include "math/smallsquarematrix.h"
46 #include "geometrytools.h"
47 #include "containertricks.h"
49 // #include "engrid_version.h" //Moved this to the only place where it was being used for now...
52 typedef vtkLongLongArray vtkLongArray_t
;
56 #if ( __WORDSIZE == 64 )
57 typedef vtkLongArray vtkLongArray_t
;
59 typedef vtkLongLongArray vtkLongArray_t
;
64 #define EG_ERR_RETURN(TXT) \
67 line.setNum(__LINE__); \
68 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
71 err.setType(Error::ExitOperation); \
72 QApplication::restoreOverrideCursor(); \
76 #define EG_ERR_DISPLAY(TXT) \
79 line.setNum(__LINE__); \
80 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
83 err.setType(Error::ExitOperation); \
91 line.setNum(__LINE__); \
92 QString txt = "This seems to be a bug in enGrid"; \
93 txt += QString("\n\nfile: ") + __FILE__ + "\nline:" + line + "\n\n"; \
101 line.setNum(__LINE__); \
102 QString txt = "This seems to be a bug in enGrid"; \
103 txt += QString("\n\nfile: ") + __FILE__ + "\nline:" + line + "\n\n"; \
106 err.setType(Error::ExitOperation); \
112 #define EG_ERR_STOP(TXT) \
115 line.setNum(__LINE__); \
116 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
119 err.setType(Error::ExitProgram); \
123 #define EG_VTKSP(TYPE,VAR) vtkSmartPointer<TYPE> VAR = vtkSmartPointer<TYPE>::New();
126 * Get an automatically casted pointer to a cell data array of a grid
127 * (vtkUnstructuredGrid).
128 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
129 * @param VAR the name for the C++ pointer variable
130 * @param GRID a pointer to the vtkUnstructuredGrid
131 * @param NAME the sybolic name of the data array; for example "cell_index"
133 #define EG_VTKDCC(TYPE,VAR,GRID,NAME) \
135 if (GRID->GetCellData()->GetScalars(NAME)) { \
136 VAR = dynamic_cast<TYPE*>(GRID->GetCellData()->GetScalars(NAME)); \
138 QString msg = "type mismatch ("; \
139 int t = GRID->GetCellData()->GetScalars(NAME)->GetDataType(); \
140 if (t == VTK_VOID) msg += "VTK_VOID"; \
141 if (t == VTK_BIT) msg += "VTK_BIT"; \
142 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
143 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
144 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
145 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
146 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
147 if (t == VTK_INT) msg += "VTK_INT"; \
148 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
149 if (t == VTK_LONG) msg += "VTK_LONG"; \
150 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
151 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
152 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
153 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
154 if (t == VTK_STRING) msg += "VTK_STRING"; \
155 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
156 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
157 if (t == VTK___INT64) msg += "VTK___INT64"; \
158 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
160 EG_ERR_RETURN(msg); \
163 QString msg = QString("array '") + NAME + "' does not exist."; \
164 EG_ERR_RETURN(msg); \
168 * Get an automatically casted pointer to a node data array of a grid
169 * (vtkUnstructuredGrid).
170 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
171 * @param VAR the name for the C++ pointer variable
172 * @param GRID a pointer to the vtkUnstructuredGrid
173 * @param NAME the sybolic name of the data array; for example "node_index"
175 #define EG_VTKDCN(TYPE,VAR,GRID,NAME) \
177 if (GRID->GetPointData()->GetScalars(NAME)) { \
178 VAR = dynamic_cast<TYPE*>(GRID->GetPointData()->GetScalars(NAME)); \
180 QString msg = "type mismatch ("; \
181 int t = GRID->GetPointData()->GetScalars(NAME)->GetDataType(); \
182 if (t == VTK_VOID) msg += "VTK_VOID"; \
183 if (t == VTK_BIT) msg += "VTK_BIT"; \
184 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
185 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
186 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
187 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
188 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
189 if (t == VTK_INT) msg += "VTK_INT"; \
190 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
191 if (t == VTK_LONG) msg += "VTK_LONG"; \
192 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
193 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
194 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
195 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
196 if (t == VTK_STRING) msg += "VTK_STRING"; \
197 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
198 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
199 if (t == VTK___INT64) msg += "VTK___INT64"; \
200 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
202 EG_ERR_RETURN(msg); \
205 QString msg = QString("array '") + NAME + "' does not exist."; \
206 EG_ERR_RETURN(msg); \
209 #define EG_STDINTERSLOT(OPER) \
213 } catch (Error err) { \
219 if(m_Grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
223 #define EG_STDSLOT(OPER) \
227 } catch (Error err) { \
231 oper->setLockGui(); \
237 #define EG_STDREADERSLOT(OPER) \
238 OPER *oper = new OPER(); \
241 if(m_Grid->GetNumberOfPoints()) updateBoundaryCodes(true); \
246 #define EG_STDCONNECT(OPER) \
247 connect(ui.action ## OPER, SIGNAL(triggered()), this, SLOT(call ## OPER ()));
249 #define DUMMY_VAR(X) X = X
252 * Perform a loop over all cells of a grid.
253 * @param ID_CELL the cell index iteration variable
254 * @param GRID a pointer to the vtkUnstructuredGrid
256 #define EG_FORALL_CELLS(ID_CELL, GRID) for (vtkIdType ID_CELL = 0; ID_CELL < GRID->GetNumberOfCells(); ++ID_CELL)
259 * Perform a loop over all nodes of a grid.
260 * @param ID_NODE the node index iteration variable
261 * @param GRID a pointer to the vtkUnstructuredGrid
263 #define EG_FORALL_NODES(ID_NODE, GRID) for (vtkIdType ID_NODE = 0; ID_NODE < GRID->GetNumberOfPoints(); ++ID_NODE)
266 * Get the type and the nodes of a cell.
267 * The following variables are created:
268 * - num_pts (number of points)
269 * - pts (array with the points)
270 * - type_cell (VTK type of the cell)
271 * @param ID_CELL the cell index
272 * @param GRID a pointer to the vtkUnstructuredGrid
274 #define EG_GET_CELL(ID_CELL, GRID) \
275 vtkIdType num_pts, *pts; \
276 vtkIdType type_cell = GRID->GetCellType(ID_CELL); \
277 GRID->GetCellPoints(ID_CELL, num_pts, pts);
279 #define EG_LARGE_REAL 1e99
281 #define EG_STOPDATE(STOP_DATE) \
282 QDate stop_date = QDate::fromString(STOP_DATE, "yyyy-MM-dd"); \
283 if (stop_date <= QDate::currentDate()) { \
284 EG_ERR_RETURN(QString("This feature is not supported after ") + STOP_DATE); \
287 inline double sqr(double x) { return x*x; }
290 inline T
sign1(T t
) {
291 if (t
>= 0) return 1;
295 inline int factorial_rec(int num
)
299 return factorial_rec(num
-1)*num
; // recursive call
302 inline int factorial_it(int num
)
305 for (int i
=1; i
<=num
; ++i
)
310 inline int N_Combinations(int N
,int k
)
312 return(factorial_rec(N
)/(factorial_rec(N
-k
)*factorial_rec(k
)));
315 inline int N_Permutations(int N
,int k
)
317 return(factorial_rec(N
)/(factorial_rec(N
-k
)));
320 #define LINE_STR "=================" << endl;
329 SortedPair(T v1
, T v2
);
330 bool operator==(const SortedPair
<T
>& P
) const{ return (v1
== P
.v1
) && (v2
== P
.v2
); }
331 bool operator<(const SortedPair
<T
>& P
) const;
332 bool operator>(const SortedPair
<T
>& P
) const { return !operator<(P
); }
337 SortedPair
<T
>::SortedPair(T v1
, T v2
)
349 SortedPair
<T
>::SortedPair()
356 bool SortedPair
<T
>::operator<(const SortedPair
<T
>& P
) const
360 } else if (v1
== P
.v1
) {
367 inline uint
qHash(const SortedPair
<T
> &P
)
369 uint h1
= qHash(P
.v1
);
370 uint h2
= qHash(P
.v2
);
371 return ((h1
<< 16) | (h1
>> 16)) ^ h2
;