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 29 of file GocadSGridReader.cpp.

Enumeration Type Documentation

◆ DataType

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

Definition at line 19 of file GocadEnums.h.

◆ FaceDirection

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

Definition at line 23 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 42 of file GocadEnums.cpp.

43{
44 if (t == DataType::UNDEFINED)
45 {
46 return "[undefined]";
47 }
48 if (t == DataType::VSET)
49 {
50 return "vertices";
51 }
52 if (t == DataType::PLINE)
53 {
54 return "line";
55 }
56 if (t == DataType::TSURF)
57 {
58 return "surface";
59 }
60 if (t == DataType::MODEL3D)
61 {
62 return "model";
63 }
64 return "[all data]";
65}

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 17 of file GocadEnums.cpp.

18{
19 if (t == DataType::UNDEFINED)
20 {
21 return "[Undefined Type]";
22 }
23 if (t == DataType::VSET)
24 {
25 return "GOCAD VSet";
26 }
27 if (t == DataType::PLINE)
28 {
29 return "GOCAD PLine";
30 }
31 if (t == DataType::TSURF)
32 {
33 return "GOCAD TSurf";
34 }
35 if (t == DataType::MODEL3D)
36 {
37 return "GOCAD Model3d";
38 }
39 return "[all types]";
40}

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 19 of file GenerateFaceSetMeshes.cpp.

20{
21 for (std::size_t l(0); l < 128; l++)
22 {
23 std::unique_ptr<MeshLib::Mesh> face_set(reader.getFaceSetMesh(l));
24
25 if (!face_set)
26 {
27 continue;
28 }
29 INFO("Face set mesh created. #nodes: {:d}, #elements: {:d}",
30 face_set->getNumberOfNodes(),
31 face_set->getNumberOfElements());
32
33 std::string const mesh_out_fname(path + face_set->getName() + ".vtu");
34 INFO("Writing face set mesh to '{:s}'.", mesh_out_fname);
35 MeshLib::IO::writeMeshToFile(*face_set, mesh_out_fname);
36 }
37}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
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 111 of file CoordinateSystem.cpp.

112{
113 os << "Gocad CoordinateSystem " << c.name
114 << "\nAxis names: " << c.axis_name_u << ", " << c.axis_name_v << ", "
115 << c.axis_name_w << "\nAxis units: " << c.axis_unit_u << ", "
116 << c.axis_unit_v << ", " << c.axis_unit_w << "\nZ-orientation: ";
118 {
119 os << "downwards";
120 }
121 else
122 {
123 os << "upwards";
124 }
125 os << "\n";
126 return os;
127}

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

◆ operator<<() [2/4]

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

Definition at line 22 of file Layer.cpp.

23{
24 std::copy(l.regions.begin(), l.regions.end(),
25 std::ostream_iterator<Region>(os, " "));
26 return os;
27}

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

◆ operator<<() [3/4]

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

Definition at line 23 of file Property.cpp.

24{
25 return os << "'" << p._property_name << "' '" << p._property_id << "' '"
26 << p._property_data_type << "' '" << p._property_data_fname
27 << "'";
28}

◆ operator<<() [4/4]

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

Definition at line 21 of file Region.cpp.

22{
23 return os << "(" << r.name << "|" << r.bit << ")";
24}

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

◆ operator<=()

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

Definition at line 16 of file GocadNode.cpp.

17{
18 for (std::size_t k(0); k < 3; k++)
19 {
20 if (n0[0] > n1[0])
21 {
22 return false;
23 }
24 if (n0[0] < n1[0])
25 {
26 return true;
27 }
28 // => n0[k] == n1[k]
29 }
30
31 return n0.getLayerTransitionIndex() <= n1.getLayerTransitionIndex();
32}

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

◆ parseGocadPropertyMetaData()

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

Definition at line 30 of file Property.cpp.

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

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

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 22 of file CoordinateSystem.cpp.

23{
24 std::string name;
25 std::size_t const start = str.find_first_of('\"');
26 if (start != std::string::npos)
27 {
28 std::size_t const end = str.find_last_of('\"');
29 name = str.substr(start + 1, end - start - 1);
30 }
31 else
32 {
33 name = str.substr(str.find_first_of(' '), str.length());
34 }
35 boost::algorithm::trim(name);
36 return name;
37}

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

◆ parseRegion()

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

Definition at line 26 of file Region.cpp.

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

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 393 of file GocadSGridReader.cpp.

394{
395 using block_t = Bitset::block_type;
396 auto const bytes = static_cast<std::size_t>(std::ceil(bits / 8.));
397 std::size_t const blocks =
398 bytes + 1 < sizeof(block_t) ? 1 : (bytes + 1) / sizeof(block_t);
399
400 std::vector<block_t> data;
401 data.resize(blocks);
402 std::fill_n(data.data(), blocks, 0);
403 in.read(reinterpret_cast<char*>(data.data()), bytes);
404
405 return Bitset(data.begin(), data.end());
406}
boost::dynamic_bitset<> Bitset

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