OGS
FileIO::Gocad Namespace Reference

Namespaces

namespace  GocadAsciiReader

Classes

class  CoordinateSystem
class  GocadNode
class  GocadSGridReader
class  GocadSplitNode
class  IndexCalculator
struct  Layer
struct  Property
struct  Region

Typedefs

using Bitset = boost::dynamic_bitset<>

Enumerations

enum class  DataType {
  UNDEFINED , VSET , PLINE , TSURF ,
  MODEL3D , ALL
}
enum class  FaceDirection : char { U , V , W }

Functions

std::string parseName (std::string const &str)
std::ostream & operator<< (std::ostream &os, CoordinateSystem const &c)
void generateFaceSets (GocadSGridReader const &reader, std::string const &path)
std::string dataType2String (DataType const t)
 Given a Gocad DataType this returns the appropriate string.
std::string dataType2ShortString (DataType const t)
 Given a Gocad DataType this returns the appropriate short form.
bool operator<= (GocadNode const &n0, GocadNode const &n1)
Bitset readBits (std::ifstream &in, const std::size_t bits)
std::ostream & operator<< (std::ostream &os, Layer const &l)
Layer parseLayer (std::string const &line, std::vector< Region > const &regions)
std::ostream & operator<< (std::ostream &os, Property const &p)
Property parseGocadPropertyMetaData (std::string &line, std::istream &in, std::string const &path)
std::ostream & operator<< (std::ostream &os, Region const &r)
Region parseRegion (std::string const &line)

Typedef Documentation

◆ Bitset

using FileIO::Gocad::Bitset = boost::dynamic_bitset<>

Definition at line 23 of file FileIO/GocadIO/GocadSGridReader.cpp.

Enumeration Type Documentation

◆ DataType

enum class FileIO::Gocad::DataType
strong
Enumerator
UNDEFINED 
VSET 
PLINE 
TSURF 
MODEL3D 
ALL 

Definition at line 12 of file GocadEnums.h.

◆ FaceDirection

enum class FileIO::Gocad::FaceDirection : char
strong
Enumerator

Definition at line 17 of file GocadNode.h.

Function Documentation

◆ dataType2ShortString()

std::string FileIO::Gocad::dataType2ShortString ( DataType const t)

Given a Gocad DataType this returns the appropriate short form.

Definition at line 35 of file GocadEnums.cpp.

36{
37 if (t == DataType::UNDEFINED)
38 {
39 return "[undefined]";
40 }
41 if (t == DataType::VSET)
42 {
43 return "vertices";
44 }
45 if (t == DataType::PLINE)
46 {
47 return "line";
48 }
49 if (t == DataType::TSURF)
50 {
51 return "surface";
52 }
53 if (t == DataType::MODEL3D)
54 {
55 return "model";
56 }
57 return "[all data]";
58}

References MODEL3D, PLINE, TSURF, UNDEFINED, and VSET.

Referenced by FileIO::Gocad::GocadAsciiReader::createMesh().

◆ dataType2String()

std::string FileIO::Gocad::dataType2String ( DataType const t)

Given a Gocad DataType this returns the appropriate string.

Definition at line 10 of file GocadEnums.cpp.

11{
12 if (t == DataType::UNDEFINED)
13 {
14 return "[Undefined Type]";
15 }
16 if (t == DataType::VSET)
17 {
18 return "GOCAD VSet";
19 }
20 if (t == DataType::PLINE)
21 {
22 return "GOCAD PLine";
23 }
24 if (t == DataType::TSURF)
25 {
26 return "GOCAD TSurf";
27 }
28 if (t == DataType::MODEL3D)
29 {
30 return "GOCAD Model3d";
31 }
32 return "[all types]";
33}

References MODEL3D, PLINE, TSURF, UNDEFINED, and VSET.

Referenced by FileIO::Gocad::GocadAsciiReader::isKeyword(), and FileIO::Gocad::GocadAsciiReader::readFile().

◆ generateFaceSets()

void FileIO::Gocad::generateFaceSets ( GocadSGridReader const & reader,
std::string const & path )

Definition at line 13 of file GenerateFaceSetMeshes.cpp.

14{
15 for (std::size_t l(0); l < 128; l++)
16 {
17 std::unique_ptr<MeshLib::Mesh> face_set(reader.getFaceSetMesh(l));
18
19 if (!face_set)
20 {
21 continue;
22 }
23 INFO("Face set mesh created. #nodes: {:d}, #elements: {:d}",
24 face_set->getNumberOfNodes(),
25 face_set->getNumberOfElements());
26
27 std::string const mesh_out_fname(path + face_set->getName() + ".vtu");
28 INFO("Writing face set mesh to '{:s}'.", mesh_out_fname);
29 MeshLib::IO::writeMeshToFile(*face_set, mesh_out_fname);
30 }
31}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)

References FileIO::Gocad::GocadSGridReader::getFaceSetMesh(), INFO(), and MeshLib::IO::writeMeshToFile().

Referenced by main().

◆ operator<<() [1/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream & os,
CoordinateSystem const & c )

Definition at line 105 of file Applications/FileIO/GocadIO/CoordinateSystem.cpp.

106{
107 os << "Gocad CoordinateSystem " << c.name
108 << "\nAxis names: " << c.axis_name_u << ", " << c.axis_name_v << ", "
109 << c.axis_name_w << "\nAxis units: " << c.axis_unit_u << ", "
110 << c.axis_unit_v << ", " << c.axis_unit_w << "\nZ-orientation: ";
112 {
113 os << "downwards";
114 }
115 else
116 {
117 os << "upwards";
118 }
119 os << "\n";
120 return os;
121}

References FileIO::Gocad::CoordinateSystem::Depth.

◆ operator<<() [2/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream & os,
Layer const & l )

Definition at line 16 of file Layer.cpp.

17{
18 std::copy(l.regions.begin(), l.regions.end(),
19 std::ostream_iterator<Region>(os, " "));
20 return os;
21}

References FileIO::Gocad::Layer::regions.

◆ operator<<() [3/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream & os,
Property const & p )

Definition at line 17 of file Applications/FileIO/GocadIO/Property.cpp.

18{
19 return os << "'" << p._property_name << "' '" << p._property_id << "' '"
20 << p._property_data_type << "' '" << p._property_data_fname
21 << "'";
22}

References FileIO::Gocad::Property::_property_data_fname, FileIO::Gocad::Property::_property_data_type, FileIO::Gocad::Property::_property_id, and FileIO::Gocad::Property::_property_name.

◆ operator<<() [4/4]

std::ostream & FileIO::Gocad::operator<< ( std::ostream & os,
Region const & r )

Definition at line 15 of file Region.cpp.

16{
17 return os << "(" << r.name << "|" << r.bit << ")";
18}

References FileIO::Gocad::Region::bit, and FileIO::Gocad::Region::name.

◆ operator<=()

bool FileIO::Gocad::operator<= ( GocadNode const & n0,
GocadNode const & n1 )

Definition at line 10 of file GocadNode.cpp.

11{
12 for (std::size_t k(0); k < 3; k++)
13 {
14 if (n0[0] > n1[0])
15 {
16 return false;
17 }
18 if (n0[0] < n1[0])
19 {
20 return true;
21 }
22 // => n0[k] == n1[k]
23 }
24
25 return n0.getLayerTransitionIndex() <= n1.getLayerTransitionIndex();
26}

References FileIO::Gocad::GocadNode::getLayerTransitionIndex().

◆ parseGocadPropertyMetaData()

Property FileIO::Gocad::parseGocadPropertyMetaData ( std::string & line,
std::istream & in,
std::string const & path )

Definition at line 24 of file Applications/FileIO/GocadIO/Property.cpp.

26{
27 boost::char_separator<char> sep("\t ");
28 boost::tokenizer<boost::char_separator<char>> tokens(line, sep);
29 auto tok_it(tokens.begin());
30 // A property section in Gocad file starts with a line
31 // PROPERTY id "property_name"
32 if (*tok_it != "PROPERTY")
33 {
34 ERR("Expected PROPERTY keyword but '{:s}' found.", tok_it->c_str());
35 throw std::runtime_error(
36 "In parseGocadPropertyMetaData() expected PROPERTY keyword not "
37 "found.");
38 }
39 tok_it++;
40
41 Property prop;
42 prop._property_id = std::stoul(*tok_it);
43 tok_it++;
44 prop._property_name = *tok_it;
45 tok_it++;
46 while (tok_it != tokens.end())
47 {
48 prop._property_name += " " + *tok_it;
49 tok_it++;
50 }
51 BaseLib::trim(prop._property_name, '\"');
52
53 auto checkPropertyID =
54 [](boost::tokenizer<boost::char_separator<char>>::iterator const&
55 tok_it,
56 Property const& prop)
57 {
58 if (!prop.checkID(*tok_it))
59 {
60 throw std::runtime_error(
61 "parseGocadPropertyMetaData(): id mismatch.");
62 }
63 };
64
65 while (std::getline(in, line))
66 {
67 if (line.empty())
68 {
69 continue;
70 }
71 if (line.back() == '\r')
72 {
73 line.pop_back();
74 }
75 tokens.assign(line);
76
77 tok_it = tokens.begin();
78 // this is the last entry of the property
79 if (*tok_it == "PROP_FILE")
80 {
81 checkPropertyID(++tok_it, prop);
82 tok_it++;
83 std::string tmp(*tok_it);
84 tok_it++;
85 while (tok_it != tokens.end())
86 {
87 tmp += " " + *tok_it;
88 tok_it++;
89 }
90 BaseLib::trim(tmp, '\"');
91 if (tmp.front() == ' ')
92 {
93 tmp.erase(tmp.begin());
94 }
95 prop._property_data_fname = path + tmp;
96 return prop;
97 }
98
99 if (*tok_it == "PROPERTY_CLASS")
100 {
101 checkPropertyID(++tok_it, prop);
102 tok_it++;
103 prop._property_class_name = *tok_it;
104 }
105
106 if (*tok_it == "PROPERTY_SUBCLASS")
107 {
108 checkPropertyID(++tok_it, prop);
109 tok_it++;
110 if (*tok_it != "QUANTITY" && *tok_it != "ENUM")
111 {
112 ERR("Expected keywords QUANTITY or ENUM, but found '{:s}'.",
113 tok_it->c_str());
114 throw std::runtime_error(
115 "parseGocadPropertyMetaData(): Expected keywords QUANTITY "
116 "or ENUM, but found '" +
117 *tok_it + "'.");
118 }
119 if (*tok_it == "QUANTITY")
120 {
121 tok_it++;
122 prop._property_data_type = *tok_it;
123 }
124 }
125
126 if (*tok_it == "PROP_UNIT" || *tok_it == "PROP_ORIGINAL_UNIT")
127 {
128 checkPropertyID(++tok_it, prop);
129 tok_it++;
130 prop._property_unit = *tok_it;
131 }
132
133 if (*tok_it == "PROP_NO_DATA_VALUE")
134 {
135 checkPropertyID(++tok_it, prop);
136 tok_it++;
137 prop._property_no_data_value = std::stoul(*tok_it);
138 }
139 }
140 return prop;
141}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void trim(std::string &str, char ch)

References FileIO::Gocad::Property::_property_class_name, FileIO::Gocad::Property::_property_data_fname, FileIO::Gocad::Property::_property_data_type, FileIO::Gocad::Property::_property_id, FileIO::Gocad::Property::_property_name, FileIO::Gocad::Property::_property_no_data_value, FileIO::Gocad::Property::_property_unit, FileIO::Gocad::Property::checkID(), ERR(), and BaseLib::trim().

Referenced by FileIO::Gocad::GocadSGridReader::GocadSGridReader().

◆ parseLayer()

Layer FileIO::Gocad::parseLayer ( std::string const & line,
std::vector< Region > const & regions )

Definition at line 23 of file Layer.cpp.

24{
25 std::istringstream iss(line);
26 std::istream_iterator<std::string> it(iss);
27 // Check first word is MODEL_LAYER.
28 if (*it != std::string("MODEL_LAYER"))
29 {
30 ERR("Expected MODEL_LAYER keyword but '{:s}' found.\n", it->c_str());
31 throw std::runtime_error(
32 "In parseRegion() expected MODEL_LAYER keyword not found.\n");
33 }
34 ++it;
35
36 Layer l;
37 while (it != std::istream_iterator<std::string>() && *it != "END")
38 {
39 auto const& region_it =
40 std::find_if(regions.begin(), regions.end(),
41 [&](Region const& r) { return r.name == *it; });
42 if (region_it != regions.end())
43 {
44 l.regions.push_back(*region_it);
45 }
46 ++it;
47 }
48
49 return l;
50}

References ERR(), and FileIO::Gocad::Layer::regions.

Referenced by FileIO::Gocad::GocadSGridReader::GocadSGridReader().

◆ parseName()

std::string FileIO::Gocad::parseName ( std::string const & str)

Definition at line 16 of file Applications/FileIO/GocadIO/CoordinateSystem.cpp.

17{
18 std::string name;
19 std::size_t const start = str.find_first_of('\"');
20 if (start != std::string::npos)
21 {
22 std::size_t const end = str.find_last_of('\"');
23 name = str.substr(start + 1, end - start - 1);
24 }
25 else
26 {
27 name = str.substr(str.find_first_of(' '), str.length());
28 }
29 boost::algorithm::trim(name);
30 return name;
31}

Referenced by FileIO::Gocad::CoordinateSystem::parse().

◆ parseRegion()

Region FileIO::Gocad::parseRegion ( std::string const & line)

Definition at line 20 of file Region.cpp.

21{
22 std::istringstream iss(line);
23 std::istream_iterator<std::string> it(iss);
24 // Check first word is REGION or MODEL_REGION.
25 if (*it != std::string("REGION") && *it != std::string("MODEL_REGION"))
26 {
27 ERR("Expected REGION or MODEL_REGION keyword but '{:s}' found.\n",
28 it->c_str());
29 throw std::runtime_error(
30 "In parseRegion() expected REGION or MODEL_REGION keyword not "
31 "found.\n");
32 }
33 ++it;
34
35 Region r;
36 r.name = *it;
37 ++it;
38 r.bit = atoi(it->c_str());
39
40 return r;
41}

References FileIO::Gocad::Region::bit, ERR(), and FileIO::Gocad::Region::name.

Referenced by FileIO::Gocad::GocadSGridReader::GocadSGridReader().

◆ readBits()

Bitset FileIO::Gocad::readBits ( std::ifstream & in,
const std::size_t bits )

Definition at line 386 of file FileIO/GocadIO/GocadSGridReader.cpp.

387{
388 using block_t = Bitset::block_type;
389 auto const bytes = static_cast<std::size_t>(std::ceil(bits / 8.));
390 std::size_t const blocks =
391 bytes + 1 < sizeof(block_t) ? 1 : (bytes + 1) / sizeof(block_t);
392
393 std::vector<block_t> data;
394 data.resize(blocks);
395 std::fill_n(data.data(), blocks, 0);
396 in.read(reinterpret_cast<char*>(data.data()), bytes);
397
398 return Bitset(data.begin(), data.end());
399}
boost::dynamic_bitset<> Bitset

Referenced by FileIO::Gocad::GocadSGridReader::readRegionFlagsBinary().