5#include "hydrodynamics/Mesh.hpp"
9#define MSMSLINESIZE 180
20 std::istream* faceFile_;
21 std::istream* vertFile_;
22 std::vector<Vector3d> vertices_;
23 std::vector<Vector3d> normals_;
26 MSMSFormat::MSMSFormat(
const std::string& msmsRoot) {
32 std::string faceFileName = prefix +
".face";
33 std::string vertFileName = prefix +
".vert";
35 faceFile_ =
new std::ifstream(faceFileName.c_str(),
36 ifstream::in | ifstream::binary);
38 if (faceFile_->fail()) {
39 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
40 "MSMSFormat: Cannot open facet file: %s\n",
41 faceFileName.c_str());
46 vertFile_ =
new std::ifstream(vertFileName.c_str(),
47 ifstream::in | ifstream::binary);
49 if (vertFile_->fail()) {
50 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
51 "MSMSFormat: Cannot open vertex file: %s\n",
52 vertFileName.c_str());
61 MSMSFormat::~MSMSFormat() {
67 Mesh* MSMSFormat::ReadShape() {
68 char inbuf[MSMSLINESIZE];
74 while (vertFile_->getline(inbuf, MSMSLINESIZE)) {
76 if (inbuf[0] !=
'#') {
78 StringTokenizer tokenizer(line);
80 if (tokenizer.countTokens() >= 3) {
83 vertex[0] = tokenizer.nextTokenAsDouble();
84 vertex[1] = tokenizer.nextTokenAsDouble();
85 vertex[2] = tokenizer.nextTokenAsDouble();
86 vertices_.push_back(vertex);
88 if (tokenizer.countTokens() >= 6) {
90 normal[0] = tokenizer.nextTokenAsDouble();
91 normal[1] = tokenizer.nextTokenAsDouble();
92 normal[2] = tokenizer.nextTokenAsDouble();
93 normals_.push_back(normal);
103 while (faceFile_->getline(inbuf, MSMSLINESIZE)) {
105 if (inbuf[0] !=
'#') {
107 StringTokenizer tokenizer(line);
109 if (tokenizer.countTokens() >= 3) {
112 v0 = tokenizer.nextTokenAsInt();
113 v1 = tokenizer.nextTokenAsInt();
114 v2 = tokenizer.nextTokenAsInt();
120 mesh_->add(vertices_[v0], vertices_[v1], vertices_[v2]);
124 std::cerr <<
"MSMS files have " << vertices_.size() <<
" vertices and ";
125 std::cerr << mesh_->size() <<
" facets\n";
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)