Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expansion of GoCAD interface #2586

Merged
merged 15 commits into from
Aug 12, 2019
Merged

Expansion of GoCAD interface #2586

merged 15 commits into from
Aug 12, 2019

Conversation

rinkk
Copy link
Member

@rinkk rinkk commented Aug 1, 2019

Can now also parse GoCAD PLine data.

Also added a check if multiple data sets in the same file have the same name and if so append a UID, so files don't get overwritten on export.

parseLine(in, nodes, elems, node_id_map, mesh_prop);
return true;
}
else if (line == "END")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else after a return is not needed...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@@ -108,7 +160,21 @@ MeshLib::Mesh* GocadTSurfaceReader::readMesh(std::ifstream& in,
return nullptr;
}
}
else if (str[0] == "TFACE")
else if (type == GOCAD_DATA_TYPE::PLINE && str[0] == "ILINE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copy of the following if for TSURF. Please avoid code duplications.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplication is indeed resolved, but now the mesh creation logic is mixed up with the parsing of the cases. It is difficult to add new cases there.
It's up to you, but I'd have written something like

auto parse_mesh = [&](auto node_element_parser) {
    std::vector<MeshLib::Node*> nodes;
    std::vector<MeshLib::Element*> elems;
    std::map<std::size_t, std::size_t> node_id_map;
    if (!node_element_parser(in, nodes, elems, node_id_map, mesh_prop))
    {
        ERR(...);
        return nullptr;
    }
    return std::make_unique<MeshLib::Mesh>(mesh_name, ...);
};

And in the conditions:

if (type == TFACE)
{
    return parse_mesh(parseSurface);
}
if (type == PLINE)
{
    return parse_mesh(parseLine);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I have no idea what happens there. And I know that it's difficult to add cases now, that's why it was written before such that cases were independent of each other.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific, I'd very much prefer the code the way it was originally written. That'd be six lines of duplicate code, which isn't a big issue in my opinion if it means the code is easier to read.

std::map<std::size_t, std::size_t> const& node_id_map,
MeshLib::Properties& mesh_prop)
{
std::string keyword;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please constrain variables to minimum possible scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for data array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@endJunction
Copy link
Member

clang-format

WARN(
"GocadTSurfaceReader::parseNodes() - Unknown keyword found: %s",
line.c_str());
WARN("GocadTSurfaceReader::parseNodes() - Unknown keyword found: %s", line.c_str());
Copy link
Member

@TomFischer TomFischer Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GocadTSurfaceReader -> GocadAsciiReader?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

}
if (line.substr(0, 13) == "GOCAD Model3d")
else if (line.substr(0, 11) == "GOCAD PLine")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this string to enum conversion to the place where the enum is defined.

Also no else after return is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you suggest that I should implement a enum -> string conversion for this one use?

The return does not follow "else" but "while" and is required in case the end of the file is reached.

GocadAsciiReader::GocadAsciiReader()
: _export_type(GocadDataType::ALL) {}

GocadAsciiReader::GocadAsciiReader(GocadDataType const t)
Copy link
Member

@endJunction endJunction Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GocadAsciiReader::GocadAsciiReader(GocadDataType const t)
GocadAsciiReader::GocadAsciiReader(GocadDataType const t = GocadDataType::ALL)

... then the default ctor is not needed.
(Sorry, wrong place, goes into the header file)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

if (!skipToEND(in))
{
std::string const t = (type == GocadDataType::VSET) ? "VSet" : "Model3D";
ERR("Parsing of type %s is not implemented. Skipping section.", t);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ERR("Parsing of type %s is not implemented. Skipping section.", t);
ERR("Parsing of type %s is not implemented. Skipping section.", t.c_str());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@TomFischer
Copy link
Member

The file GocadEnums.h is missing.

GocadAsciiReader.h:15:10: fatal error: 'Applications/FileIO/GocadIO/GocadEnums.h' file not found

};

/// Given a Gocad DataType this returns the appropriate string.
std::string DataType2Str(DataType const t);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string DataType2Str(DataType const t);
std::string dataType2String(DataType const t);

{
return "model";
}
return "[all data]";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all data vs. all types above. Maybe wrong.

Copy link
Member

@endJunction endJunction left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomFischer when OK, merge.

@TomFischer TomFischer merged commit 1eb6d3c into ufz:master Aug 12, 2019
@rinkk rinkk deleted the GocadExpansion branch August 12, 2019 11:33
@ogsbot
Copy link
Member

ogsbot commented Jun 19, 2020

OpenGeoSys development has been moved to GitLab.

See this pull request on GitLab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants