Skip to content

Commit

Permalink
Allow skipping elements entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
bchretien committed Jan 27, 2017
1 parent 5595393 commit 4bd2d49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
17 changes: 15 additions & 2 deletions source/tinyply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,17 @@ void PlyFile::read_internal(std::istream & is)
read = [&](PlyProperty::Type t, void * dest, size_t & destOffset, std::istream & is) { read_property_ascii(t, dest, destOffset, is); };
skip = [&](const PlyProperty & property, std::istream & is) { skip_property_ascii(property, is); };
}


auto skip_element = [&](const PlyElement & element, std::istream & is) {
for (size_t count = 0; count < element.size; ++count)
{
for (auto& property : element.properties)
{
skip(property, is);
}
}
};

std::set<std::shared_ptr<DataCursor>> processed_cursors;
for (auto & element : get_elements())
{
Expand Down Expand Up @@ -437,7 +447,10 @@ void PlyFile::read_internal(std::istream & is)
}
}
}
else continue;
else
{
skip_element(element, is);
}
}

// Reset offsets
Expand Down
20 changes: 14 additions & 6 deletions tests/read.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void print_faces<std::vector<uint32_t>>(const std::vector<uint32_t>& faces, int
}

template <typename FaceType, int NVertices>
int read_file(const std::string& path)
int read_file(const std::string& path, bool read_vertices = true, bool read_faces = true)
{
using namespace tinyply;
try
Expand All @@ -74,8 +74,10 @@ int read_file(const std::string& path)
std::vector<float> vertices;
std::vector<FaceType> faces;

uint32_t vertexCount = file.request_properties_from_element("vertex", { "x", "y", "z" }, vertices, 1);
uint32_t faceCount = file.request_properties_from_element("face", { "vertex_indices" }, faces, NVertices);
if (read_vertices)
file.request_properties_from_element("vertex", { "x", "y", "z" }, vertices, 1);
if (read_faces)
file.request_properties_from_element("face", { "vertex_indices" }, faces, NVertices);

// Use different ifstream with proper openmode and position
std::ios::openmode mode = file.is_binary()? std::ios::in | std::ios::binary
Expand Down Expand Up @@ -103,8 +105,14 @@ int read_file(const std::string& path)
int main(int argc, char *argv[])
{
int res = 0;
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/cube_ascii.ply");
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/icosahedron.ply");
res += read_file<uint32_t, 4>(ASSETS_DIR "/cube_quad_ascii.ply");
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/cube_ascii.ply", true, true);
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/cube_ascii.ply", true, false);
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/cube_ascii.ply", false, true);
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/icosahedron.ply", true, true);
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/icosahedron.ply", true, false);
res += read_file<std::vector<uint32_t>, 0>(ASSETS_DIR "/icosahedron.ply", false, true);
res += read_file<uint32_t, 4>(ASSETS_DIR "/cube_quad_ascii.ply", true, true);
res += read_file<uint32_t, 4>(ASSETS_DIR "/cube_quad_ascii.ply", true, false);
res += read_file<uint32_t, 4>(ASSETS_DIR "/cube_quad_ascii.ply", false, true);
return res;
}

0 comments on commit 4bd2d49

Please sign in to comment.