AC3DsurfaceFormatCore.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "AC3DsurfaceFormatCore.H"
27 #include "clock.H"
28 #include "IFstream.H"
29 #include "IStringStream.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
34 (
35  IFstream& is,
36  string& cmd,
37  string& args
38 )
39 {
40  if (is.good())
41  {
42  string line;
43  is.getLine(line);
44 
45  string::size_type space = line.find(' ');
46 
47  if (space != string::npos)
48  {
49  cmd = line.substr(0, space);
50  args = line.substr(space+1);
51 
52  return true;
53  }
54  }
55  return false;
56 }
57 
58 
59 // Read up to line starting with cmd. Sets args to rest of line.
60 // Returns true if found, false if stream is not good anymore.
62 (
63  IFstream& is,
64  const string& cmd,
65  string& args
66 )
67 {
68  while (is.good())
69  {
70  string line;
71  is.getLine(line);
72 
73  string::size_type space = line.find(' ');
74 
75  if (space != string::npos)
76  {
77  if (line.substr(0, space) == cmd)
78  {
79  args = line.substr(space+1);
80 
81  return true;
82  }
83  }
84  }
85  return false;
86 }
87 
88 
89 // Similar to cueTo(), but throws error if cmd not found
91 (
92  IFstream& is,
93  const string& cmd,
94  const string& errorMsg
95 )
96 {
97  string args;
98  if (!cueTo(is, cmd, args))
99  {
101  (
102  "fileFormats::AC3DsurfaceFormat::read(const fileName&)"
103  )
104  << "Cannot find command " << cmd
105  << " " << errorMsg
106  << exit(FatalError);
107  }
108 
109  return args;
110 }
111 
112 
114 (
115  Ostream& os,
116  const UList<surfZone>& zoneLst
117 )
118 {
119  // Write with zones as separate objects under "world" object.
120  // Header is taken over from sample file.
121  // Defines separate materials for all zones. Recycle colours.
122 
123  // Define 8 standard colours as r,g,b components
124  static scalar colourMap[] =
125  {
126  1, 1, 1,
127  1, 0, 0,
128  0, 1, 0,
129  0, 0, 1,
130  1, 1, 0,
131  0, 1, 1,
132  1, 0, 1,
133  0.5, 0.5, 1
134  };
135 
136  // Write header. Define materials.
137  os << "AC3Db" << nl;
138 
139  forAll(zoneLst, zoneI)
140  {
141  label colourI = zoneI % 8;
142  label colourCompI = 3 * colourI;
143 
144  os << "MATERIAL \"" << zoneLst[zoneI].name() << "Mat\" rgb "
145  << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
146  << ' ' << colourMap[colourCompI+2]
147  << " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
148  << " trans 0"
149  << nl;
150  }
151 
152  os << "OBJECT world" << nl
153  << "kids " << zoneLst.size() << endl;
154 }
155 
156 
157 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling character strings derived from std::string.
Definition: string.H:74
static string cueToOrDie(IFstream &, const string &cmd, const string &errorMsg=string::null)
Cue up to cmd, reading args or exit with a FatalError.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static void writeHeader(Ostream &, const UList< surfZone > &)
Write header with materials.
Input from file stream.
Definition: IFstream.H:81
A line primitive.
Definition: line.H:56
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
static bool readCmd(IFstream &, string &cmd, string &args)
Read cmd, args from IFstream.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
ISstream & getLine(string &)
Raw, low-level getline into a string function.
Definition: ISstreamI.H:77
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Foam::argList args(argc, argv)
error FatalError
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static bool cueTo(IFstream &, const string &cmd, string &args)
Cue up to cmd, reading args.