msbGrid  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mfileswriter.hh
Go to the documentation of this file.
1 /*****************************************************************************
2 * This program is part of the msbGrid software *
3 * *
4 * msbGrid stands for multi-structured block Grid generator *
5 * *
6 * msbGrid is a 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. *
10 * *
11 * msbGrid 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. *
15 * *
16 * See the file COPYING for full copying permissions. *
17 *****************************************************************************/
24 #ifndef _M_FILES_WRITER_HH
25 #define _M_FILES_WRITER_HH
26 
27 #include <fstream>
28 #include <iomanip>
29 #include <cstdlib>
30 
31 namespace msbGrid
32 {
33 class MFilesWriter;
34 }
35 
36 class msbGrid :: MFilesWriter
37 {
38 public:
42 
43 private:
45  std :: ofstream outputFile_;
46 
47 public:
48 
49  MFilesWriter(const InputData * inputData)
50  {
51  inputData_ = inputData;
52  }
53 
55 
56  void openFile(const std :: string &name)
57  {
58  std :: string fileName = inputData_->outputPath() + "m/" + name + ".m";
59 #if VERBOSE_LEVEL >= 2
60  std :: cout << "fileName = " << fileName << "\n";
61 #endif
62  outputFile_.open(fileName.c_str(), std :: ios :: out);
63  if ( !outputFile_ ) {
64  std :: cerr << "Can't open output file" << fileName << std :: endl;
65  std :: exit(1);
66  }
67 
68  outputFile_ << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
69  outputFile_ << "%% This file was generated by msbGrid software %%\n";
70  outputFile_ << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n";
71  outputFile_ << "clear all; close all; clc; hold on; axis square;\n\n";
73  }
74 
75  void closeFile()
76  { outputFile_.close(); }
77 
79  {
80  outputFile_ << "%% command line options : ";
81  outputFile_ << " --outputPath=\"" << inputData_->outputPath() << "\""
82  << " --outputDirName=\"" << inputData_->outputDirName() << "\""
83  << " --xMin=\"" << inputData_->xMin() << "\""
84  << " --xMax=\"" << inputData_->xMax() << "\""
85  << " --bnCx=\"" << inputData_->blockNumberController() [ 0 ] << "\""
86  << " --bnCy=\"" << inputData_->blockNumberController() [ 1 ] << "\""
87  << " --dr=\"" << inputData_->dr() << "\""
88  << " --rafC=\"" << inputData_->rafCoeff() << "\""
89  << " --bCId=\"" << inputData_->blockCenterRandSeqId() << "\""
90  << " --bAId=\"" << inputData_->blockAngleRandSeqId() << "\""
91  << " --bCPC=\"" << inputData_->blockCenterPertCoeff() << "\""
92  << " --d2bC=\"" << inputData_->dist2BoundCoeff() << "\""
93  << " --intbC=\"" << inputData_->interBlockDistCoeff() << "\""
94  << "\n\n";
95  }
96 
97  void write(const std :: string &texte)
98  { outputFile_ << texte; }
99 
100  void write(const Point &pt0, const bool &writeText)
101  {
102 #if !( ( DEV_MOD == 1 ) && ( CHECK_MARKED_POINTS == 1 ) )
103  if ( pt0.mark() ) {
104  return;
105  }
106 
107 #endif
108 
109  outputFile_ << std :: setw(1)
110  << std :: fixed
111  << "iPt = " << pt0.Id() << "; "
112  << "x(iPt) = " << pt0.pos() [ 0 ] << "; "
113  << "y(iPt) = " << pt0.pos() [ 1 ] << "; "
114  << "plot(x(iPt),y(iPt)," << pt0.marker().symbol
115  << ",'MarkerSize'," << pt0.marker().size
116  << ",'MarkerEdgeColor'," << colorSymbol(pt0.marker().edgeColor)
117  << ",'MarkerFaceColor'," << colorSymbol(pt0.marker().faceColor)
118  << "); ";
119 
120  if ( writeText ) {
121  outputFile_ << "text(x(iPt), y(iPt), num2str(iPt));";
122  }
123 
124  outputFile_ << std :: endl;
125  }
126 
127  void write(const msbGrid :: Edge &ed0, const bool &writeText)
128  {
129  if ( ed0.mark() ) {
130  return;
131  }
132 
133  outputFile_ << std :: setw(1)
134  << std :: fixed
135  << "iEd = " << ed0.Id() << "; "
136  << "u = [x(" << ed0.vPt() [ 0 ]->Id() << ") x(" << ed0.vPt() [ 1 ]->Id() << ")]; "
137  << "v = [y(" << ed0.vPt() [ 0 ]->Id() << ") y(" << ed0.vPt() [ 1 ]->Id() << ")]; "
138  << "plot(u,v," << colorSymbol( ed0.color() ) << "); ";
139 
140  if ( writeText ) {
141  outputFile_ << "xbc(iEd) = " << ed0.pos() [ 0 ] << "; "
142  << "ybc(iEd) = " << ed0.pos() [ 1 ] << "; "
143  << "text(xbc(iEd), ybc(iEd), num2str(iEd));";
144  }
145 
146  outputFile_ << std :: endl;
147  }
148 
149  void write(const msbGrid :: Triangle &tr0, const bool &writeText)
150  {
151  if ( tr0.mark() ) {
152  return;
153  }
154 
155  const int &Id0 = tr0.vPt() [ 0 ]->Id();
156  const int &Id1 = tr0.vPt() [ 1 ]->Id();
157  const int &Id2 = tr0.vPt() [ 2 ]->Id();
158 
159  outputFile_ << std :: setw(1)
160  << std :: fixed
161  << "iTr =" << tr0.Id() << "; "
162  << "u = [x(" << Id0 << ") x(" << Id1 << ") x(" << Id2 << ") x(" << Id0 << ")]; "
163  << "v = [y(" << Id0 << ") y(" << Id1 << ") y(" << Id2 << ") y(" << Id0 << ")]; "
164  << "plot(u, v, 'k'); ";
165 
166  if ( tr0.color() != Color :: Black ) {
167  outputFile_ << "fill(u,v," << colorSymbol( tr0.color() ) << "); ";
168  }
169 
170  if ( writeText ) {
171  outputFile_ << "xbc(iTr) = ( " << tr0.pos() [ 0 ] << "); "
172  << "ybc(iTr) = ( " << tr0.pos() [ 1 ] << "); "
173  << "text(xbc(iTr), ybc(iTr), num2str(iTr));";
174  }
175 
176  outputFile_ << std :: endl;
177  }
178 
179  void write(const msbGrid :: Quadrangle &qd0, const bool &writeText)
180  {
181  if ( qd0.mark() ) {
182  return;
183  }
184 
185  const int &Id0 = qd0.vPt() [ 0 ]->Id();
186  const int &Id1 = qd0.vPt() [ 1 ]->Id();
187  const int &Id2 = qd0.vPt() [ 2 ]->Id();
188  const int &Id3 = qd0.vPt() [ 3 ]->Id();
189 
190 #if 0
191  if ( qd0.Id() == 44 ) {
192  std :: cout << "Id0 = " << Id0 << " , "
193  << "Id1 = " << Id1 << " , "
194  << "Id2 = " << Id2 << " , "
195  << "Id3 = " << Id3 << "\n";
196  }
197 
198 #endif
199 
200  outputFile_ << std :: setw(1)
201  << std :: fixed
202  << "iQd =" << qd0.Id() << "; "
203  << "u = [x(" << Id0 << ") x(" << Id1 << ") x(" << Id2 << ") x(" << Id3 << ") x(" << Id0 << ")]; "
204  << "v = [y(" << Id0 << ") y(" << Id1 << ") y(" << Id2 << ") y(" << Id3 << ") y(" << Id0 << ")]; "
205  << "plot(u, v, 'k'); ";
206 
207  if ( qd0.color() != Color :: Black ) {
208  outputFile_ << "fill(u,v," << colorSymbol( qd0.color() ) << "); ";
209  }
210 
211  if ( writeText ) {
212  outputFile_ << "xbc(iQd) = ( " << qd0.pos() [ 0 ] << "); "
213  << "ybc(iQd) = ( " << qd0.pos() [ 1 ] << "); "
214  << "text(xbc(iQd), ybc(iQd), num2str(iQd));";
215  }
216 
217  outputFile_ << std :: endl;
218  }
219 
220  template< typename EntityT >
221  void write(const msbGrid :: Block< EntityT > &bl0, const bool &writeText = false)
222  {
223  if ( bl0.size() == 0 ) {
224  return;
225  }
226 
227  for ( int iEnt = 0; iEnt < bl0.size(); ++iEnt ) {
228  write(bl0.vEnt() [ iEnt ], writeText);
229  }
230  }
231 };
232 
233 #endif /* #ifndef _M_FILES_WRITER_HH */