.gitignore changes
[engrid.git] / engrid.h
blob98f50b43094e40f9d77d9794d1eaaa9347b1d829
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef engrid_H
24 #define engrid_H
26 #include <QMessageBox>
27 #include <QtDebug>
28 #include <QString>
30 #include <vtkSmartPointer.h>
31 #include <vtkLongArray.h>
32 #include <vtkLongLongArray.h>
33 #include <vtkIntArray.h>
34 #include <vtkDoubleArray.h>
36 #include "error.h"
37 #include "math/mathvector.h"
38 #include "math/smallsquarematrix.h"
39 #include "geometrytools.h"
40 #include "containertricks.h"
42 #define ENGRID_VERSION "CVS"
44 #ifdef WIN32
45 typedef vtkLongLongArray vtkLongArray_t;
46 #else
48 #include <limits.h>
49 #if ( __WORDSIZE == 64 )
50 typedef vtkLongArray vtkLongArray_t;
51 #else
52 typedef vtkLongLongArray vtkLongArray_t;
53 #endif
55 #endif
57 #define EG_ERR_RETURN(TXT) \
58 { \
59 QString line; \
60 line.setNum(__LINE__); \
61 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
62 Error err; \
63 err.setText(txt); \
64 err.setType(Error::ExitOperation); \
65 throw err; \
68 #ifdef QT_DEBUG
69 #define EG_BUG \
70 abort();
71 #else
72 #define EG_BUG \
73 { \
74 QString line; \
75 line.setNum(__LINE__); \
76 QString txt = "This seems to be a bug in enGrid"; \
77 txt += QString("\n\nfile: ") + __FILE__ + "\nline:" + line + "\n\n"; \
78 Error err; \
79 err.setText(txt); \
80 err.setType(Error::ExitOperation); \
81 throw err; \
83 #endif
86 #define EG_ERR_STOP(TXT) \
87 { \
88 QString line; \
89 line.setNum(__LINE__); \
90 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
91 Error err; \
92 err.setText(txt); \
93 err.setType(Error::ExitProgram); \
94 throw err; \
97 #define EG_VTKSP(TYPE,VAR) vtkSmartPointer<TYPE> VAR = vtkSmartPointer<TYPE>::New();
99 /**
100 * Get an automatically casted pointer to a cell data array of a grid
101 * (vtkUnstructuredGrid).
102 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
103 * @param VAR the name for the C++ pointer variable
104 * @param GRID a pointer to the vtkUnstructuredGrid
105 * @param NAME the sybolic name of the data array; for example "cell_index"
107 #define EG_VTKDCC(TYPE,VAR,GRID,NAME) \
108 TYPE *VAR = NULL; \
109 if (GRID->GetCellData()->GetScalars(NAME)) { \
110 VAR = dynamic_cast<TYPE*>(GRID->GetCellData()->GetScalars(NAME)); \
111 if (!VAR) { \
112 QString msg = "type mismatch ("; \
113 int t = GRID->GetCellData()->GetScalars(NAME)->GetDataType(); \
114 if (t == VTK_VOID) msg += "VTK_VOID"; \
115 if (t == VTK_BIT) msg += "VTK_BIT"; \
116 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
117 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
118 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
119 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
120 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
121 if (t == VTK_INT) msg += "VTK_INT"; \
122 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
123 if (t == VTK_LONG) msg += "VTK_LONG"; \
124 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
125 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
126 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
127 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
128 if (t == VTK_STRING) msg += "VTK_STRING"; \
129 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
130 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
131 if (t == VTK___INT64) msg += "VTK___INT64"; \
132 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
133 msg += ")"; \
134 EG_ERR_RETURN(msg); \
135 }; \
136 } else { \
137 QString msg = QString("array '") + NAME + "' does not exist."; \
138 EG_ERR_RETURN(msg); \
142 * Get an automatically casted pointer to a node data array of a grid
143 * (vtkUnstructuredGrid).
144 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
145 * @param VAR the name for the C++ pointer variable
146 * @param GRID a pointer to the vtkUnstructuredGrid
147 * @param NAME the sybolic name of the data array; for example "node_index"
149 #define EG_VTKDCN(TYPE,VAR,GRID,NAME) \
150 TYPE *VAR = NULL; \
151 if (GRID->GetPointData()->GetScalars(NAME)) { \
152 VAR = dynamic_cast<TYPE*>(GRID->GetPointData()->GetScalars(NAME)); \
153 if (!VAR) { \
154 QString msg = "type mismatch ("; \
155 int t = GRID->GetPointData()->GetScalars(NAME)->GetDataType(); \
156 if (t == VTK_VOID) msg += "VTK_VOID"; \
157 if (t == VTK_BIT) msg += "VTK_BIT"; \
158 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
159 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
160 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
161 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
162 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
163 if (t == VTK_INT) msg += "VTK_INT"; \
164 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
165 if (t == VTK_LONG) msg += "VTK_LONG"; \
166 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
167 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
168 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
169 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
170 if (t == VTK_STRING) msg += "VTK_STRING"; \
171 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
172 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
173 if (t == VTK___INT64) msg += "VTK___INT64"; \
174 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
175 msg += ")"; \
176 EG_ERR_RETURN(msg); \
177 }; \
178 } else { \
179 QString msg = QString("array '") + NAME + "' does not exist."; \
180 EG_ERR_RETURN(msg); \
183 #define EG_STDINTERSLOT(OPER) \
184 OPER *oper = new OPER(); \
185 (*oper)(); \
186 oper->del(); \
187 if(grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
188 updateActors(); \
190 #define EG_STDSLOT(OPER) \
191 OPER *oper = new OPER(); \
192 oper->setGui(); \
193 (*oper)(); \
194 oper->del(); \
195 if(grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
196 updateActors(); \
198 #define EG_STDREADERSLOT(OPER) \
199 OPER *oper = new OPER(); \
200 (*oper)(); \
201 oper->del(); \
202 if(grid->GetNumberOfPoints()) updateBoundaryCodes(true); \
203 updateActors(); \
204 updateStatusBar(); \
205 zoomAll();
207 #define EG_STDCONNECT(OPER) \
208 connect(ui.action ## OPER, SIGNAL(activated()), this, SLOT(call ## OPER ()));
210 #define EG_GETPTS(PTS,CELLID,GRID) \
211 vtkIdType *PTS; \
212 vtkIdType N ## PTS; \
213 GRID->GetCellPoints(CELLID, N ## PTS, PTS);
215 inline double sqr(double x) { return x*x; };
217 inline int factorial_rec(int num)
219 if (num<=1)
220 return 1;
221 return factorial_rec(num-1)*num; // recursive call
224 inline int factorial_it(int num)
226 int result=1;
227 for (int i=1; i<=num; ++i)
228 result=result*i;
229 return result;
232 inline int N_Combinations(int N,int k)
234 return(factorial_rec(N)/(factorial_rec(N-k)*factorial_rec(k)));
237 inline int N_Permutations(int N,int k)
239 return(factorial_rec(N)/(factorial_rec(N-k)));
242 #define LINE "========================================================================" << endl;
244 #define USE(X) X=X
246 #endif