| 95 | |
| 96 | |
| 97 | bool Foam::fileFormats::OBJedgeFormat::read(const fileName& filename) |
| 98 | { |
| 99 | clear(); |
| 100 | |
| 101 | IFstream is(filename); |
| 102 | if (!is.good()) |
| 103 | { |
| 104 | FatalErrorInFunction |
| 105 | << "Cannot read file " << filename |
| 106 | << exit(FatalError); |
| 107 | } |
| 108 | |
| 109 | DynamicList<point> dynPoints; |
| 110 | DynamicList<edge> dynEdges; |
| 111 | DynamicList<label> dynUsedPoints; |
| 112 | |
| 113 | DynamicList<label> dynVertices; |
| 114 | |
| 115 | while (is.good()) |
| 116 | { |
| 117 | string line = this->getLineNoComment(is); |
| 118 | |
| 119 | // handle continuations |
| 120 | if (line[line.size()-1] == '\\') |
| 121 | { |
| 122 | line.substr(0, line.size()-1); |
| 123 | line += this->getLineNoComment(is); |
| 124 | } |
| 125 | |
| 126 | // Read first word |
| 127 | IStringStream lineStream(line); |
| 128 | word cmd; |
| 129 | lineStream >> cmd; |
| 130 | |
| 131 | if (cmd == "v") |
| 132 | { |
| 133 | scalar x, y, z; |
| 134 | lineStream >> x >> y >> z; |
| 135 | |
| 136 | dynPoints.append(point(x, y, z)); |
| 137 | dynUsedPoints.append(-1); |
| 138 | } |
| 139 | else if (cmd == "l") |
| 140 | { |
| 141 | // Assume 'l' is followed by space. |
| 142 | string::size_type endNum = 1; |
| 143 | |
| 144 | readVertices |
| 145 | ( |
| 146 | line, |
| 147 | endNum, |
| 148 | dynVertices |
| 149 | ); |
| 150 | |
| 151 | |
| 152 | for (label i = 1; i < dynVertices.size(); i++) |
| 153 | { |
| 154 | edge edgeRead(dynVertices[i-1], dynVertices[i]); |