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"
43 typedef vtkLongLongArray vtkLongArray_t
;
45 typedef vtkLongArray vtkLongArray_t
;
48 #define EG_ERR_RETURN(TXT) \
51 line.setNum(__LINE__); \
52 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
55 err.setType(Error::ExitOperation); \
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"; \
71 err.setType(Error::ExitOperation); \
77 #define EG_ERR_STOP(TXT) \
80 line.setNum(__LINE__); \
81 QString txt = QString(TXT) + "\n\nfile: " + __FILE__ + "\nline:" + line + "\n\n"; \
84 err.setType(Error::ExitProgram); \
88 #define EG_VTKSP(TYPE,VAR) vtkSmartPointer<TYPE> VAR = vtkSmartPointer<TYPE>::New();
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) \
100 if (GRID->GetCellData()->GetScalars(NAME)) { \
101 VAR = dynamic_cast<TYPE*>(GRID->GetCellData()->GetScalars(NAME)); \
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"; \
125 EG_ERR_RETURN(msg); \
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) \
142 if (GRID->GetPointData()->GetScalars(NAME)) { \
143 VAR = dynamic_cast<TYPE*>(GRID->GetPointData()->GetScalars(NAME)); \
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"; \
167 EG_ERR_RETURN(msg); \
170 QString msg = QString("array '") + NAME + "' does not exist."; \
171 EG_ERR_RETURN(msg); \
174 #define EG_STDINTERSLOT(OPER) \
175 OPER *oper = new OPER(); \
178 updateBoundaryCodes(false); \
181 #define EG_STDSLOT(OPER) \
182 OPER *oper = new OPER(); \
186 updateBoundaryCodes(false); \
189 #define EG_STDREADERSLOT(OPER) \
190 OPER *oper = new OPER(); \
193 updateBoundaryCodes(true); \
198 #define EG_STDCONNECT(OPER) \
199 connect(ui.action ## OPER, SIGNAL(activated()), this, SLOT(call ## OPER ()));
201 #define EG_GETPTS(PTS,CELLID,GRID) \
203 vtkIdType N ## PTS; \
204 GRID->GetCellPoints(CELLID, N ## PTS, PTS);
206 inline double sqr(double x
) { return x
*x
; };
208 #define LINE "========================================================================" << endl;