for Doxygen
[engrid.git] / engrid.h
blob727897453bf224909efc8fcc71e5ab612241a948
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 #ifdef WIN32
43 typedef vtkLongLongArray vtkLongArray_t;
44 #else
45 typedef vtkLongArray vtkLongArray_t;
46 #endif
48 #define EG_ERR_RETURN(TXT) \
49 { \
50 QString line; \
51 line.setNum(__LINE__); \
52 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
53 Error err; \
54 err.setText(txt); \
55 err.setType(Error::ExitOperation); \
56 throw err; \
59 #ifdef QT_DEBUG
60 #define EG_BUG \
61 abort();
62 #else
63 #define EG_BUG \
64 { \
65 QString line; \
66 line.setNum(__LINE__); \
67 QString txt = "This seems to be a bug in enGrid"; \
68 txt += QString("\n\nfile: ") + __FILE__ + "\nline:" + line + "\n\n"; \
69 Error err; \
70 err.setText(txt); \
71 err.setType(Error::ExitOperation); \
72 throw err; \
74 #endif
77 #define EG_ERR_STOP(TXT) \
78 { \
79 QString line; \
80 line.setNum(__LINE__); \
81 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
82 Error err; \
83 err.setText(txt); \
84 err.setType(Error::ExitProgram); \
85 throw err; \
88 #define EG_VTKSP(TYPE,VAR) vtkSmartPointer<TYPE> VAR = vtkSmartPointer<TYPE>::New();
90 /**
91 * Get an automatically casted pointer to a cell data array of a grid
92 * (vtkUnstructuredGrid).
93 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
94 * @param VAR the name for the C++ pointer variable
95 * @param GRID a pointer to the vtkUnstructuredGrid
96 * @param NAME the sybolic name of the data array; for example "cell_index"
98 #define EG_VTKDCC(TYPE,VAR,GRID,NAME) \
99 TYPE *VAR = NULL; \
100 if (GRID->GetCellData()->GetScalars(NAME)) { \
101 VAR = dynamic_cast<TYPE*>(GRID->GetCellData()->GetScalars(NAME)); \
102 if (!VAR) { \
103 QString msg = "type mismatch ("; \
104 int t = GRID->GetCellData()->GetScalars(NAME)->GetDataType(); \
105 if (t == VTK_VOID) msg += "VTK_VOID"; \
106 if (t == VTK_BIT) msg += "VTK_BIT"; \
107 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
108 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
109 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
110 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
111 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
112 if (t == VTK_INT) msg += "VTK_INT"; \
113 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
114 if (t == VTK_LONG) msg += "VTK_LONG"; \
115 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
116 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
117 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
118 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
119 if (t == VTK_STRING) msg += "VTK_STRING"; \
120 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
121 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
122 if (t == VTK___INT64) msg += "VTK___INT64"; \
123 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
124 msg += ")"; \
125 EG_ERR_RETURN(msg); \
126 }; \
127 } else { \
128 QString msg = QString("array '") + NAME + "' does not exist."; \
129 EG_ERR_RETURN(msg); \
133 * Get an automatically casted pointer to a node data array of a grid
134 * (vtkUnstructuredGrid).
135 * @param TYPE the type to cast to; examples are: vtkLongArray_t, vtkDoubleArray, ...
136 * @param VAR the name for the C++ pointer variable
137 * @param GRID a pointer to the vtkUnstructuredGrid
138 * @param NAME the sybolic name of the data array; for example "node_index"
140 #define EG_VTKDCN(TYPE,VAR,GRID,NAME) \
141 TYPE *VAR = NULL; \
142 if (GRID->GetPointData()->GetScalars(NAME)) { \
143 VAR = dynamic_cast<TYPE*>(GRID->GetPointData()->GetScalars(NAME)); \
144 if (!VAR) { \
145 QString msg = "type mismatch ("; \
146 int t = GRID->GetPointData()->GetScalars(NAME)->GetDataType(); \
147 if (t == VTK_VOID) msg += "VTK_VOID"; \
148 if (t == VTK_BIT) msg += "VTK_BIT"; \
149 if (t == VTK_CHAR) msg += "VTK_CHAR"; \
150 if (t == VTK_SIGNED_CHAR) msg += "VTK_SIGNED_CHAR"; \
151 if (t == VTK_UNSIGNED_CHAR) msg += "VTK_UNSIGNED_CHAR"; \
152 if (t == VTK_SHORT) msg += "VTK_SHORT"; \
153 if (t == VTK_UNSIGNED_SHORT) msg += "VTK_UNSIGNED_SHORT"; \
154 if (t == VTK_INT) msg += "VTK_INT"; \
155 if (t == VTK_UNSIGNED_INT) msg += "VTK_UNSIGNED_INT"; \
156 if (t == VTK_LONG) msg += "VTK_LONG"; \
157 if (t == VTK_UNSIGNED_LONG) msg += "VTK_UNSIGNED_LONG"; \
158 if (t == VTK_FLOAT) msg += "VTK_FLOAT"; \
159 if (t == VTK_DOUBLE) msg += "VTK_DOUBLE"; \
160 if (t == VTK_ID_TYPE) msg += "VTK_ID_TYPE"; \
161 if (t == VTK_STRING) msg += "VTK_STRING"; \
162 if (t == VTK_LONG_LONG) msg += "VTK_LONG_LONG"; \
163 if (t == VTK_UNSIGNED_LONG_LONG) msg += "VTK_UNSIGNED_LONG_LONG"; \
164 if (t == VTK___INT64) msg += "VTK___INT64"; \
165 if (t == VTK_UNSIGNED___INT64) msg += "VTK_UNSIGNED___INT64"; \
166 msg += ")"; \
167 EG_ERR_RETURN(msg); \
168 }; \
169 } else { \
170 QString msg = QString("array '") + NAME + "' does not exist."; \
171 EG_ERR_RETURN(msg); \
174 #define EG_STDINTERSLOT(OPER) \
175 OPER *oper = new OPER(); \
176 (*oper)(); \
177 oper->del(); \
178 updateBoundaryCodes(false); \
179 updateActors(); \
181 #define EG_STDSLOT(OPER) \
182 OPER *oper = new OPER(); \
183 oper->setGui(); \
184 (*oper)(); \
185 oper->del(); \
186 updateBoundaryCodes(false); \
187 updateActors(); \
189 #define EG_STDREADERSLOT(OPER) \
190 OPER *oper = new OPER(); \
191 (*oper)(); \
192 oper->del(); \
193 updateBoundaryCodes(true); \
194 updateActors(); \
195 updateStatusBar(); \
196 zoomAll();
198 #define EG_STDCONNECT(OPER) \
199 connect(ui.action ## OPER, SIGNAL(activated()), this, SLOT(call ## OPER ()));
201 #define EG_GETPTS(PTS,CELLID,GRID) \
202 vtkIdType *PTS; \
203 vtkIdType N ## PTS; \
204 GRID->GetCellPoints(CELLID, N ## PTS, PTS);
206 inline double sqr(double x) { return x*x; };
208 #define LINE "========================================================================" << endl;
210 #define USE(X) X=X
212 #endif