-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJVtkLib.h
201 lines (157 loc) · 9.32 KB
/
JVtkLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//HEAD_DSCODES
/*
<DUALSPHYSICS> Copyright (c) 2020 by Dr Jose M. Dominguez et al. (see http://dual.sphysics.org/index.php/developers/).
EPHYSLAB Environmental Physics Laboratory, Universidade de Vigo, Ourense, Spain.
School of Mechanical, Aerospace and Civil Engineering, University of Manchester, Manchester, U.K.
This file is part of DualSPHysics.
DualSPHysics is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
DualSPHysics is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with DualSPHysics. If not, see <http://www.gnu.org/licenses/>.
*/
//:#############################################################################
//:# Cambios:
//:# =========
//:# - Clase para generacion de ficheros VTK de particulas o formas. (10-12-2019)
//:# - Permite compilar sin libreria de VTK. (13-12-2019)
//:# - Nuevas funciones AddShapePolyLine(). (23-12-2019)
//:# - Parametro creatpath que por defecto es true. (27-12-2019)
//:#############################################################################
/// \file JVtkLib.h \brief Declares the class \ref JVtkLib.
#ifndef _JVtkLib_
#define _JVtkLib_
#include "TypesDef.h"
#include "JObject.h"
#include "JDataArrays.h"
#include <string>
#include <cstring>
#include <string>
#include <vector>
#include "JVtkLibDef.h" //Defines DISABLE_VTKLIB to compile without VTK library.
//-Defines for normal exceptions for static methods.
#ifndef Run_ExceptioonSta
#define Run_ExceptioonSta(msg) RunExceptioonStatic(__FILE__,__LINE__,__func__,msg)
#endif
#ifndef Run_ExceptioonFileSta
#define Run_ExceptioonFileSta(msg,file) RunExceptioonStatic(__FILE__,__LINE__,__func__,msg,file)
#endif
class JShapeVtk;
//##############################################################################
//# JVtkLib
//##############################################################################
/// \brief Saves VTK files with particle data and shapes.
#ifdef DISABLE_VTKLIB
#include "JVtkLibUndef.h"
#else
class JVtkLib : protected JObject
{
public:
/// Modes to define the normals (for CHRONO coupling).
typedef enum{ NorNULL,NorOriginal,NorInvert,NorTwoFace }TpModeNormal;
private:
JShapeVtk *Shapes;
public:
JVtkLib();
~JVtkLib();
void Reset();
/// Returns true when this feature is available.
static bool Available(){ return(true); }
//==============================================================================
/// Throws exception related to a file from a static method.
//==============================================================================
static void RunExceptioonStatic(const std::string &srcfile,int srcline
,const std::string &method
,const std::string &msg,const std::string &file="");
//==============================================================================
// Different functions to create special VTK files.
//==============================================================================
/// Stores particle data in VTK file.
static void SaveVtkData(std::string fname,const JDataArrays &arrays,std::string posfield,bool createpath=true);
/// Stores particle and grid data in VTK file.
static void SaveVtkGridData(std::string fname,const JDataArrays &arrays,std::string posfield,const JDataArrays &arrays2,bool createpath=true);
/// Generates a VTK file with map cells.
static void SaveVtkCells(const std::string &fname,const tfloat3 &posmin,const tuint3 &cells,float scell,bool createpath=true);
/// Generates a VTK file with boxes.
static void SaveVtkBoxes(const std::string &fname,unsigned nbox,const tfloat3 *vbox,float sizemin=0,bool createpath=true);
/// Generates a VTK file with boxes.
static void SaveVtkBoxes(const std::string &fname,unsigned nbox,const tdouble3 *vbox,float sizemin=0,bool createpath=true);
//==============================================================================
// Functions to create VTK files with shapes.
//==============================================================================
/// Generates a VTK file with shapes.
void SaveShapeVtk(std::string file,std::string varname,bool createpath=true);
/// Adds shape line.
void AddShapeLine(const tfloat3 &pt1,const tfloat3 &pt2,int value);
/// Adds shape line.
void AddShapeLine(const tdouble3 &pt1,const tdouble3 &pt2,int value);
/// Adds shape polyline.
void AddShapePolyLine(unsigned np,const tfloat3 *vp,int value);
/// Adds shape polyline.
void AddShapePolyLine(unsigned np,const tdouble3 *vp,int value);
/// Adds shape quad using 4 points.
void AddShapeQuad(const tfloat3 &pt1,const tfloat3 &pt2,const tfloat3 &pt3,const tfloat3 &pt4,int value);
/// Adds shape quad using 4 points.
void AddShapeQuad(const tdouble3 &pt1,const tdouble3 &pt2,const tdouble3 &pt3,const tdouble3 &pt4,int value);
/// Adds shape quad using an orthogonal vector.
void AddShapeQuad(const tfloat3 &pt,const tfloat3 &vec,float size,int value);
/// Adds shape quad using an orthogonal vector.
void AddShapeQuad(const tdouble3 &pt,const tdouble3 &vec,double size,int value);
/// Adds shape lines of quad using 4 points.
void AddShapeQuadWire(const tfloat3 &pt1,const tfloat3 &pt2,const tfloat3 &pt3,const tfloat3 &pt4,int value);
/// Adds shape lines of quad using 4 points.
void AddShapeQuadWire(const tdouble3 &pt1,const tdouble3 &pt2,const tdouble3 &pt3,const tdouble3 &pt4,int value);
/// Adds shape lines of quad using an orthogonal vector.
void AddShapeQuadWire(const tfloat3 &pt,const tfloat3 &vec,float size,int value);
/// Adds shape lines of quad using an orthogonal vector.
void AddShapeQuadWire(const tdouble3 &pt,const tdouble3 &vec,double size,int value);
/// Adds shape box (1pt + 3x vec3).
void AddShapeBox(const tfloat3 &pt1,const tfloat3 &vx,const tfloat3 &vy,const tfloat3 &vz,int value);
/// Adds shape box (1pt + 3x vec3).
void AddShapeBox(const tdouble3 &pt1,const tdouble3 &vx,const tdouble3 &vy,const tdouble3 &vz,int value);
/// Adds shape box (1pt + size).
void AddShapeBoxSize(const tfloat3 &pt1,const tfloat3 &size,int value);
/// Adds shape box (1pt + 3x vec3).
void AddShapeBoxSize(const tdouble3 &pt1,const tdouble3 &size,int value);
/// Adds shape box (4pt front + 4pt back).
void AddShapeBoxFront(const tfloat3 &p,const tfloat3 &px,const tfloat3 &pxz,const tfloat3 &pz
,const tfloat3 &py,const tfloat3 &pyx,const tfloat3 &pyxz,const tfloat3 &pyz,int value);
/// Adds shape box (4pt front + 4pt back).
void AddShapeBoxFront(const tdouble3 &p,const tdouble3 &px,const tdouble3 &pxz,const tdouble3 &pz
,const tdouble3 &py,const tdouble3 &pyx,const tdouble3 &pyxz,const tdouble3 &pyz,int value);
/// Adds shape sphere using quads.
void AddShapeSphere(const tfloat3 &p,float radius,int nside,int value);
/// Adds shape sphere using quads.
void AddShapeSphere(const tdouble3 &p,double radius,int nside,int value);
/// Adds shape cylinder.
void AddShapeCylinder(const tfloat3 &p1,const tfloat3 &p2,float radius,int nside,int value,unsigned maskfaceshide=0);
/// Adds shape cylinder.
void AddShapeCylinder(const tdouble3 &p1,const tdouble3 &p2,double radius,int nside,int value,unsigned maskfaceshide=0);
/// Adds lines to create a cross.
void AddShapeCross(const tfloat3 &pt,float radius,int value);
/// Adds lines to create a cross.
void AddShapeCross(const tdouble3 &pt,double radius,int value);
/// Adds spring using lines.
/// \param cornersout Size of corner.
/// \param cornersin Size of corner (inside).
/// \param radius Spring radius.
/// \param revlength Length for each revolution.
/// \param nsides Number of sections for each revolution.
void AddShapeSpring(const tfloat3 &p1,const tfloat3 &p2,float restlength,float scalesize
,float cornersout,float cornersin,float radius,float revlength,int nsides,int value);
/// Adds spring using lines.
void AddShapeSpring(const tdouble3 &p1,const tdouble3 &p2,double restlength,double scalesize
,double cornersout,double cornersin,double radius,double revlength,int nsides,int value);
//==============================================================================
// Functions to create OBJ files starting from VTK files (for CHRONO coupling).
//==============================================================================
/// Creates object with geometry (triangles and quads) and mk data from VTK files.
static void* CreateMkShapes(const std::vector<std::string> &vtkfiles);
/// Frees object with geometry and mk data from VTK files.
static void DeleteMkShapes(void* ptr_vtksimple);
/// Creates OBJ file with MK geometry in VTK file. Returns not zero in case of error.
static void CreateOBJsByMk(void* ptr_vtksimple,std::string filein,std::string filesout
,const std::vector<unsigned> &mkbounds,unsigned mkboundfirst,TpModeNormal normalmode);
};
#endif
#endif