Commit d992ecd9 authored by Martin Heistermann's avatar Martin Heistermann
Browse files

check edge and face handles

parent 40e01383
...@@ -187,6 +187,7 @@ void BinaryFileReader::read_edges(Decoder &reader, const TopoChunkHeader &header ...@@ -187,6 +187,7 @@ void BinaryFileReader::read_edges(Decoder &reader, const TopoChunkHeader &header
uint64_t dst = read_one(reader) + header.span.first; uint64_t dst = read_one(reader) + header.span.first;
if (src >= n_verts_read_ || dst >= n_verts_read_) { if (src >= n_verts_read_ || dst >= n_verts_read_) {
state_ = ReadState::ErrorHandleRange; state_ = ReadState::ErrorHandleRange;
return;
} else { } else {
auto vh_src = VertexHandle::from_unsigned(src); auto vh_src = VertexHandle::from_unsigned(src);
auto vh_dst = VertexHandle::from_unsigned(dst); auto vh_dst = VertexHandle::from_unsigned(dst);
...@@ -218,6 +219,15 @@ void BinaryFileReader::read_faces(Decoder &reader, const TopoChunkHeader &header ...@@ -218,6 +219,15 @@ void BinaryFileReader::read_faces(Decoder &reader, const TopoChunkHeader &header
return; return;
} }
assert(header.valence != 0 || _valences.size() == header.span.count); assert(header.valence != 0 || _valences.size() == header.span.count);
auto read_heh = [&](uint32_t x)
{
auto idx = x + header.handle_offset;
if (idx >= 2 * n_edges_read_) {
throw parse_error("Invalid Halfedge handle");
}
return HEH::from_unsigned(idx);
};
for (uint64_t i = 0; i < header.span.count; ++i) for (uint64_t i = 0; i < header.span.count; ++i)
{ {
uint32_t valence = header.valence == 0 ? _valences[i] : header.valence; uint32_t valence = header.valence == 0 ? _valences[i] : header.valence;
...@@ -227,7 +237,7 @@ void BinaryFileReader::read_faces(Decoder &reader, const TopoChunkHeader &header ...@@ -227,7 +237,7 @@ void BinaryFileReader::read_faces(Decoder &reader, const TopoChunkHeader &header
header.handle_encoding, header.handle_encoding,
halfedges, halfedges,
valence, valence,
[&](uint32_t x){return HEH::from_unsigned(x + header.handle_offset);}); read_heh);
if (!success) break; if (!success) break;
mesh_->add_face(std::move(halfedges), options_.topology_check); mesh_->add_face(std::move(halfedges), options_.topology_check);
}; };
...@@ -254,6 +264,17 @@ void BinaryFileReader::read_cells(Decoder &reader, const TopoChunkHeader &header ...@@ -254,6 +264,17 @@ void BinaryFileReader::read_cells(Decoder &reader, const TopoChunkHeader &header
return; return;
} }
assert(header.valence != 0 || _valences.size() == header.span.count);
auto read_hfh = [&](uint32_t x)
{
auto idx = x + header.handle_offset;
if (idx >= 2 * n_faces_read_) {
throw parse_error("Invalid Halfface handle");
}
return HFH::from_unsigned(idx);
};
for (uint64_t i = 0; i < header.span.count; ++i) for (uint64_t i = 0; i < header.span.count; ++i)
{ {
uint32_t valence = header.valence == 0 ? _valences[i] : header.valence; uint32_t valence = header.valence == 0 ? _valences[i] : header.valence;
...@@ -263,7 +284,7 @@ void BinaryFileReader::read_cells(Decoder &reader, const TopoChunkHeader &header ...@@ -263,7 +284,7 @@ void BinaryFileReader::read_cells(Decoder &reader, const TopoChunkHeader &header
header.handle_encoding, header.handle_encoding,
halffaces, halffaces,
valence, valence,
[&](uint32_t x){return HFH::from_unsigned(x + header.handle_offset);}); read_hfh);
if (!success) break; if (!success) break;
mesh_->add_cell(std::move(halffaces), options_.topology_check); mesh_->add_cell(std::move(halffaces), options_.topology_check);
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment