2
/// This file is part of Rheolef.
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
6
/// Rheolef is free software; you can redistribute it and/or modify
7
/// it under the terms of the GNU General Public License as published by
8
/// the Free Software Foundation; either version 2 of the License, or
9
/// (at your option) any later version.
11
/// Rheolef is distributed in the hope that it will be useful,
12
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
/// GNU General Public License for more details.
16
/// You should have received a copy of the GNU General Public License
17
/// along with Rheolef; if not, write to the Free Software
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
/// =========================================================================
22
// visualisation of geometries using mayavi
25
// Pierre.Saramito@imag.fr
27
// date: 22 january 2006
30
// - a mayavi Module ClipPolyData with a customizale cut plane
31
// - how to cut all datas (boundfarie, ect) with the same plane in mayavi ??
33
#include "rheolef/georep.h"
34
#include "rheolef/geo-visu.h"
35
#include "rheolef/geo-visu-aux.h"
39
// define when using old mayavi python library:
40
#undef _RHEOLEF_USE_MAYAVI_1
43
georep::visu_mayavi (const geo_visu_option_type& opt) const
46
// output geometry for vtkUnstructuredGridReader
48
string vtk_name = opt.basename + ".vtk";
49
ofstream vtk (vtk_name.c_str());
50
if (opt.verbose) clog << "! file \"" << vtk_name << "\" created." << endl;
51
int digits10 = numeric_limits<Float>::digits10;
52
vtk << setprecision(digits10);
58
domlist_type::const_iterator iter = _domlist.begin();
59
domlist_type::const_iterator last = _domlist.end();
60
for (; iter != last; ++iter) {
61
const domain& dom = *iter;
62
string dom_name = opt.basename + "." + dom.name() + ".vtk";
63
vtk.open (dom_name.c_str());
64
if (opt.verbose) clog << "! file \"" << dom_name << "\" created." << endl;
65
dom.put_vtk (vtk, begin_node(), end_node());
69
// output python script for mayavi/vtk executable
71
string py_name = opt.basename + ".py";
72
ofstream py (py_name.c_str());
73
if (opt.verbose) clog << "! file \"" << py_name << "\" created." << endl;
75
py << "#!/usr/bin/env mayavi2" << endl
76
<< "# This is a mayavi script for the visualization of " << opt.basename << ".vtk" << endl
77
<< "# automatically generated by rheolef." << endl
80
#ifdef _RHEOLEF_USE_MAYAVI_1
81
// old mayavi python library
82
py << "import mayavi" << endl
83
<< "from mayavi_geo import *" << endl
87
// new mayavi2 python library
88
py << "from enthought.mayavi.scripts import mayavi2" << endl
89
<< "mayavi2.standalone(globals())" << endl
90
<< "from mayavi2_rheolef import *" << endl
94
iter = _domlist.begin();
95
last = _domlist.end();
96
py << "d = [ '" << opt.basename << "'";
97
for (; iter != last; ++iter) {
98
const domain& dom = *iter;
99
py << ", '" << dom.name() << "'";
103
size_t d = dimension();
104
bool has_origin = (opt.origin[0] != numeric_limits<Float>::max());
105
py << "opt = { \\" << endl
106
<< " 'label' : 1," << endl
107
<< " 'axis' : 1," << endl
108
<< " 'color' : '" << (opt.color ? "color" : (opt.gray ? "gray" : "black_and_white")) << "'," << endl
109
<< " 'stereo' : " << opt.stereo << ", \\" << endl
110
<< " 'ball' : " << opt.ball << ", \\" << endl
111
<< " 'cut' : " << opt.cut << ", \\" << endl
112
<< " 'fill' : " << opt.fill << ", \\" << endl
113
<< " 'full' : " << opt.full << ", \\" << endl
114
<< " 'lattice' : " << opt.lattice << ", \\" << endl
115
<< " 'shrink' : " << opt.shrink << ", \\" << endl
116
<< " 'tube' : " << opt.tube << ", \\" << endl
117
<< " 'has_origin' : " << has_origin << ", \\" << endl
118
<< " 'origin' : " << python(opt.origin) << ", \\" << endl
119
<< " 'normal' : " << python(-opt.normal) << " \\" << endl
123
#ifdef _RHEOLEF_USE_MAYAVI_1
124
py << "v = mayavi.mayavi()" << endl
125
<< "mayavi_geo(v, opt, d)" << endl
126
<< "v.Render()" << endl
127
<< "v.master.wait_window()" << endl
131
py << "mayavi2_geo(mayavi, opt, d)" << endl
141
command = "LANG=C PYTHONPATH=" + string(_RHEOLEF_PKGDATADIR) + " mayavi2 " + py_name;
142
if (opt.verbose) clog << "! " << command << endl;
143
status = system (command.c_str());
149
command = "/bin/rm -f " + opt.basename + ".vtk " + opt.basename + ".py";
150
if (opt.verbose) clog << "! " << command << endl;
151
status = system (command.c_str());
152
iter = _domlist.begin();
153
last = _domlist.end();
154
for (; iter != last; ++iter) {
155
const domain& dom = *iter;
156
command = "/bin/rm -f " + opt.basename + "." + dom.name() + ".vtk";
157
if (opt.verbose) clog << "! " << command << endl;
158
status = system (command.c_str());