rheolef  6.6
geo_seq_visu_vtk_mayavi.cc
Go to the documentation of this file.
1 #include "rheolef/geo.h"
2 #include "rheolef/piola.h"
3 #include "rheolef/rheostream.h"
4 #include "rheolef/iorheo.h"
5 #include "rheolef/iofem.h"
6 using namespace std;
7 namespace rheolef {
8 
9 
10 template<class T>
11 static
12 std::string
13 python (const point_basic<T>& x, size_t d=3)
14 {
15  std::ostringstream os;
16  os << "[" << x[0];
17  for (size_t i = 1; i < d; i++)
18  os << ", " << x[i];
19  os << "]" << std::flush;
20  string buffer = os.str();
21  return buffer;
22 }
23 template <class T> odiststream& geo_put_vtk (odiststream&, const geo_basic<T,sequential>&);
24 
25 template <class T>
26 odiststream&
28 {
29  using namespace std;
31  typedef point_basic<size_type> ilat;
32  ostream& os = ops.os();
33  bool verbose = iorheo::getverbose(os);
34  bool clean = iorheo::getclean(os);
35  bool execute = iorheo::getexecute(os);
36  bool fill = iorheo::getfill(os); // isocontours or color fill
37  bool elevation = iorheo::getelevation(os);
38  bool color = iorheo::getcolor(os);
39  bool gray = iorheo::getgray(os);
40  bool black_and_white = iorheo::getblack_and_white(os);
41  bool stereo = iorheo::getstereo(os);
42  bool full = iorheo::getfull(os);
43  bool iso = iorheo::getiso(os);
44  bool cut = iorheo::getcut(os);
45  bool volume = iorheo::getvolume(os);
46  bool grid = iorheo::getgrid(os);
47  bool ball = iorheo::getball(os);
48  bool lattice = iorheo::getlattice(os);
49  bool shrink = iorheo::getshrink(os);
50  bool tube = iorheo::gettube(os);
51  string format = iorheo::getimage_format(os);
52  string basename = iorheo::getbasename(os);
53  point_basic<T> origin = iofem::getorigin(os);
54  point_basic<T> normal = iofem::getnormal(os);
55  string outfile_fmt = "";
56  string tmp = get_tmpdir() + "/";
57  if (!clean) tmp = "";
58 
59  size_type dim = omega.dimension();
60  size_type map_dim = omega.map_dimension();
61  size_type nv = omega.sizes().ownership_by_dimension[0].size();
62  size_type nedg = omega.sizes().ownership_by_dimension[1].size();
63  size_type nfac = omega.sizes().ownership_by_dimension[2].size();
64  size_type nvol = omega.sizes().ownership_by_dimension[3].size();
65  size_type ne = omega.sizes().ownership_by_dimension[map_dim].size();
66  string filelist;
67  string filename = tmp+basename + ".vtk";
68  filelist = filelist + " " + filename;
69  ofstream vtk_os (filename.c_str());
70  odiststream vtk (vtk_os);
71  if (verbose) clog << "! file \"" << filename << "\" created.\n";
72  geo_put_vtk (vtk, omega);
73  vtk.close();
74  for (size_type idom = 0, ndom = omega.n_domain(); idom < ndom; ++idom) {
75  const geo_basic<T,sequential>& dom = omega.get_domain(idom);
76  string filename = tmp+basename + "." + dom.name() + ".vtk";
77  filelist = filelist + " " + filename;
78  ofstream vtk_os_dom (filename.c_str());
79  odiststream vtk_dom (vtk_os_dom);
80  if (verbose) clog << "! file \"" << filename << "\" created.\n";
81  geo_put_vtk (vtk_dom, dom);
82  vtk_dom.close();
83  }
84  std::string py_name = filename = tmp+basename + ".py";
85  filelist = filelist + " " + filename;
86  ofstream py (filename.c_str());
87  if (verbose) clog << "! file \"" << filename << "\" created.\n";
88  py << "#!/usr/bin/env mayavi2" << endl
89  << "# This is a mayavi script for the visualization of " << basename << ".vtk" << endl
90  << "# automatically generated by rheolef." << endl
91  << endl
92  ;
93  py << "from sys import version_info" << endl
94  << "# mayavi2.py file has changed from directory since python 2.7:" << endl
95  << "if version_info[0] >= 2 and version_info[1] >= 7 and version_info[2] >= 2:" << endl
96  << " from mayavi.scripts import mayavi2" << endl
97  << "else:" << endl
98  << " from enthought.mayavi.scripts import mayavi2" << endl
99  << "mayavi2.standalone(globals()) # start mayvi2 graphic interface" << endl
100  << "from mayavi2_rheolef import * # load rheolef specific functions" << endl
101  << endl
102  ;
103  py << "d = [ '" << tmp+basename << "'";
104  for (size_type idom = 0, ndom = omega.n_domain(); idom < ndom; ++idom) {
105  const geo_basic<T,sequential>& dom = omega.get_domain(idom);;
106  py << ", '" << dom.name() << "'";
107  }
108  py << "]" << endl;
109 
110  bool has_origin = (origin[0] != numeric_limits<Float>::max());
111  bool view_2d = (omega.xmax()[2] - omega.xmin()[2] == 0);
112  py << "opt = { \\" << endl
113  << " 'label' : 1," << endl
114  << " 'axis' : 1," << endl
115  << " 'view_1d' : 0," << endl
116  << " 'view_2d' : " << view_2d << "," << endl
117  << " 'color' : '" << (color ? "color" : (gray ? "gray" : "black_and_white")) << "'," << endl
118  << " 'stereo' : " << stereo << ", \\" << endl
119  << " 'ball' : " << ball << ", \\" << endl
120  << " 'cut' : " << cut << ", \\" << endl
121  << " 'fill' : " << fill << ", \\" << endl
122  << " 'full' : " << full << ", \\" << endl
123  << " 'lattice' : " << lattice << ", \\" << endl
124  << " 'shrink' : " << shrink << ", \\" << endl
125  << " 'tube' : " << tube << ", \\" << endl
126  << " 'has_origin' : " << has_origin << ", \\" << endl
127  << " 'origin' : " << python(origin) << ", \\" << endl
128  << " 'normal' : " << python(normal) << ", \\" << endl
129  << " 'elevation' : 0 \\" << endl
130  << " }" << endl
131  << endl
132  ;
133  py << "mayavi2_geo(mayavi, opt, d)" << endl
134  << endl
135  ;
136  int status = 0;
137  string command;
138  if (execute) {
139  command = "LANG=C PYTHONPATH=" + string(_RHEOLEF_PKGDATADIR) + " mayavi2 -x " + py_name;
140  if (verbose) clog << "! " << command << endl;
141  status = system (command.c_str());
142  }
143  if (clean) {
144  command = "/bin/rm -f " + filelist;
145  if (verbose) clog << "! " << command << endl;
146  status = system (command.c_str());
147  }
148  return ops;
149 }
150 template odiststream& visu_vtk_mayavi<Float> (odiststream&, const geo_basic<Float,sequential>&);
151 
152 }// namespace rheolef
field_nonlinear_expr< field_expr_terminal_function< normal_pseudo_function< Float > > > normal()
Definition: operators2.h:22
const node_type & xmin() const
Definition: geo.h:919
size_type size(size_type ip) const
Definition: distributor.h:110
std::string get_tmpdir()
Definition: rheostream.cc:33
idiststream, odiststream - distributed interface for large data streams
Definition: diststream.h:68
verbose clean transpose logscale grid shrink ball stereo iso volume velocity elevation bezieradapt label black_and_white
geo_basic< T, sequential > get_domain(size_type i) const
point - vertex of a mesh
Definition: point.h:22
const geo_size & sizes() const
Definition: geo.h:924
STL namespace.
irheostream, orheostream - large data streams
Definition: compiler.h:7
verbose clean transpose logscale grid shrink ball stereo iso volume velocity elevation bezieradapt label color color
const node_type & xmax() const
Definition: geo.h:920
size_type dimension() const
Definition: geo.h:911
size_t d
size_type map_dimension() const
Definition: geo.h:912
#define _RHEOLEF_PKGDATADIR
Definition: config.h:402
distributor ownership_by_dimension[4]
Definition: geo_size.h:15
odiststream & visu_vtk_mayavi(odiststream &, const field_basic< T, sequential > &)
size_type n_domain() const
Definition: geo.h:953
template odiststream & visu_vtk_mayavi< Float >(odiststream &, const geo_basic< Float, sequential > &)
odiststream & geo_put_vtk(odiststream &ods, const geo_basic< T, sequential > &omega, const numbering< T, sequential > &my_numb, const array< point_basic< T >, sequential > &my_node, bool append_data)
boost::proto::result_of::make_expr< boost::proto::tag::function, vec_domain, const vec_detail::max_, const int &, const vec< T, M > & >::type max(const int &x, const vec< T, M > &y)
reference_element_H::size_type size_type
static std::string python(const point_basic< T > &x, size_t d=3)
std::ostream & os()
Definition: diststream.h:166
verbose clean transpose logscale grid shrink ball stereo iso volume velocity elevation bezieradapt label color color format format format format format format format format format format format format format format format format vtk
std::string name() const
Definition: geo.h:909