improved settingssheet saving: it now saves as current_filename+.sp. Loading and...
[engrid.git] / engrid.h
blob28316f1842dbd696c482342e3e6c1fe278ad667c
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
47 typedef vtkLongArray vtkLongArray_t;
48 #endif
50 #define EG_ERR_RETURN(TXT) \
51 { \
52 QString line; \
53 line.setNum(__LINE__); \
54 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
55 Error err; \
56 err.setText(txt); \
57 err.setType(Error::ExitOperation); \
58 throw err; \
61 #ifdef QT_DEBUG
62 #define EG_BUG \
63 abort();
64 #else
65 #define EG_BUG \
66 { \
67 QString line; \
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"; \
71 Error err; \
72 err.setText(txt); \
73 err.setType(Error::ExitOperation); \
74 throw err; \
76 #endif
79 #define EG_ERR_STOP(TXT) \
80 { \
81 QString line; \
82 line.setNum(__LINE__); \
83 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
84 Error err; \
85 err.setText(txt); \
86 err.setType(Error::ExitProgram); \
87 throw err; \
90 #define EG_VTKSP(TYPE,VAR) vtkSmartPointer<TYPE> VAR = vtkSmartPointer<TYPE>::New();
92 /**
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) \
101 TYPE *VAR = NULL; \
102 if (GRID->GetCellData()->GetScalars(NAME)) { \
103 VAR = dynamic_cast<TYPE*>(GRID->GetCellData()->GetScalars(NAME)); \
104 if (!VAR) { \
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"; \
126 msg += ")"; \
127 EG_ERR_RETURN(msg); \
128 }; \
129 } else { \
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) \
143 TYPE *VAR = NULL; \
144 if (GRID->GetPointData()->GetScalars(NAME)) { \
145 VAR = dynamic_cast<TYPE*>(GRID->GetPointData()->GetScalars(NAME)); \
146 if (!VAR) { \
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"; \
168 msg += ")"; \
169 EG_ERR_RETURN(msg); \
170 }; \
171 } else { \
172 QString msg = QString("array '") + NAME + "' does not exist."; \
173 EG_ERR_RETURN(msg); \
176 #define EG_STDINTERSLOT(OPER) \
177 OPER *oper = new OPER(); \
178 (*oper)(); \
179 oper->del(); \
180 if(grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
181 updateActors(); \
183 #define EG_STDSLOT(OPER) \
184 OPER *oper = new OPER(); \
185 oper->setGui(); \
186 (*oper)(); \
187 oper->del(); \
188 if(grid->GetNumberOfPoints()) updateBoundaryCodes(false); \
189 updateActors(); \
191 #define EG_STDREADERSLOT(OPER) \
192 OPER *oper = new OPER(); \
193 (*oper)(); \
194 oper->del(); \
195 if(grid->GetNumberOfPoints()) updateBoundaryCodes(true); \
196 updateActors(); \
197 updateStatusBar(); \
198 zoomAll();
200 #define EG_STDCONNECT(OPER) \
201 connect(ui.action ## OPER, SIGNAL(activated()), this, SLOT(call ## OPER ()));
203 #define EG_GETPTS(PTS,CELLID,GRID) \
204 vtkIdType *PTS; \
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)
212 if (num<=1)
213 return 1;
214 return factorial_rec(num-1)*num; // recursive call
217 inline int factorial_it(int num)
219 int result=1;
220 for (int i=1; i<=num; ++i)
221 result=result*i;
222 return result;
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;
237 #define USE(X) X=X
239 #endif