2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26 #include <QMessageBox>
30 #include <vtkSmartPointer.h>
31 #include <vtkLongArray.h>
32 #include <vtkLongLongArray.h>
33 #include <vtkIntArray.h>
34 #include <vtkDoubleArray.h>
37 #include "math/mathvector.h"
38 #include "math/smallsquarematrix.h"
39 #include "geometrytools.h"
40 #include "containertricks.h"
42 #define ENGRID_VERSION "CVS"
45 typedef vtkLongLongArray vtkLongArray_t
;
47 typedef vtkLongArray vtkLongArray_t
;
50 #define EG_ERR_RETURN(TXT) \
53 line.setNum(__LINE__); \
54 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
57 err.setType(Error::ExitOperation); \
68 line.setNum(__LINE__); \
69 QString txt = "This seems to be a bug in enGrid"; \
70 txt += QString("\n\nfile: ") + __FILE__ + "\nline:" + line + "\n\n"; \
73 err.setType(Error::ExitOperation); \
79 #define EG_ERR_STOP(TXT) \
82 line.setNum(__LINE__); \
83 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
86 err.setType(Error::ExitProgram); \
90 #define EG_VTKSP(TYPE,VAR) vtkSmartPointer<TYPE> VAR = vtkSmartPointer<TYPE>::New();
93 * Get an automatically casted pointer to a cell data array of a grid
94 * (vtkUnstructuredGrid).
95 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
96 * @param VAR the name for the C++ pointer variable
97 * @param GRID a pointer to the vtkUnstructuredGrid
98 * @param NAME the sybolic name of the data array; for example "cell_index"
100 #define EG_VTKDCC(TYPE,VAR,GRID,NAME) \
102 if (GRID->GetCellData()->GetScalars(NAME)) { \
103 VAR = dynamic_cast<TYPE*>(GRID->GetCellData()->GetScalars(NAME)); \
105 QString msg = "type mismatch ("; \
106 int t = GRID->GetCellData()->GetScalars(NAME)->GetDataType(); \
107 if (t == VTK_VOID) msg += "VTK_VOID"; \
108 if (t == VTK_BIT) msg += "VTK_BIT"; \
109 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
110 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
111 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
112 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
113 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
114 if (t == VTK_INT) msg += "VTK_INT"; \
115 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
116 if (t == VTK_LONG) msg += "VTK_LONG"; \
117 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
118 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
119 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
120 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
121 if (t == VTK_STRING) msg += "VTK_STRING"; \
122 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
123 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
124 if (t == VTK___INT64) msg += "VTK___INT64"; \
125 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
127 EG_ERR_RETURN(msg); \
130 QString msg = QString("array '") + NAME + "' does not exist."; \
131 EG_ERR_RETURN(msg); \
135 * Get an automatically casted pointer to a node data array of a grid
136 * (vtkUnstructuredGrid).
137 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
138 * @param VAR the name for the C++ pointer variable
139 * @param GRID a pointer to the vtkUnstructuredGrid
140 * @param NAME the sybolic name of the data array; for example "node_index"
142 #define EG_VTKDCN(TYPE,VAR,GRID,NAME) \
144 if (GRID->GetPointData()->GetScalars(NAME)) { \
145 VAR = dynamic_cast<TYPE*>(GRID->GetPointData()->GetScalars(NAME)); \
147 QString msg = "type mismatch ("; \
148 int t = GRID->GetPointData()->GetScalars(NAME)->GetDataType(); \
149 if (t == VTK_VOID) msg += "VTK_VOID"; \
150 if (t == VTK_BIT) msg += "VTK_BIT"; \
151 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
152 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
153 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
154 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
155 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
156 if (t == VTK_INT) msg += "VTK_INT"; \
157 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
158 if (t == VTK_LONG) msg += "VTK_LONG"; \
159 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
160 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
161 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
162 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
163 if (t == VTK_STRING) msg += "VTK_STRING"; \
164 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
165 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
166 if (t == VTK___INT64) msg += "VTK___INT64"; \
167 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
169 EG_ERR_RETURN(msg); \
172 QString msg = QString("array '") + NAME + "' does not exist."; \
173 EG_ERR_RETURN(msg); \
176 #define EG_STDINTERSLOT(OPER) \
177 OPER *oper = new OPER(); \
180 if(grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
183 #define EG_STDSLOT(OPER) \
184 OPER *oper = new OPER(); \
188 if(grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
191 #define EG_STDREADERSLOT(OPER) \
192 OPER *oper = new OPER(); \
195 if(grid->GetNumberOfPoints()) updateBoundaryCodes(true); \
200 #define EG_STDCONNECT(OPER) \
201 connect(ui.action ## OPER, SIGNAL(activated()), this, SLOT(call ## OPER ()));
203 #define EG_GETPTS(PTS,CELLID,GRID) \
205 vtkIdType N ## PTS; \
206 GRID->GetCellPoints(CELLID, N ## PTS, PTS);
208 inline double sqr(double x
) { return x
*x
; };
210 inline int factorial_rec(int num
)
214 return factorial_rec(num
-1)*num
; // recursive call
217 inline int factorial_it(int num
)
220 for (int i
=1; i
<=num
; ++i
)
225 inline int N_Combinations(int N
,int k
)
227 return(factorial_rec(N
)/(factorial_rec(N
-k
)*factorial_rec(k
)));
230 inline int N_Permutations(int N
,int k
)
232 return(factorial_rec(N
)/(factorial_rec(N
-k
)));
235 #define LINE "========================================================================" << endl;