Commit 1db0e658 authored by Philip Trettner's avatar Philip Trettner
Browse files

focused std dependencies in polymesh/std

parent 7e93efac
#pragma once
#include <iostream>
#include "primitives.hh"
#include "tmp.hh"
......@@ -194,34 +192,3 @@ struct halfedge_handle : primitive_handle<halfedge_tag>
halfedge_ring ring() const; ///< all half-edges along the same ring
};
}
// ======================== STD Extensions ========================
namespace std
{
template <class tag>
struct hash<polymesh::primitive_index<tag>>
{
size_t operator()(polymesh::primitive_index<tag> const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::face_index>
{
size_t operator()(polymesh::face_index const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::vertex_index>
{
size_t operator()(polymesh::vertex_index const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::edge_index>
{
size_t operator()(polymesh::edge_index const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::halfedge_index>
{
size_t operator()(polymesh::halfedge_index const& i) const { return std::hash<int>()(i.value); }
};
}
#include "debug.hh"
#include <fstream>
#include <iostream>
void polymesh::print_debug(const polymesh::Mesh& m)
{
using namespace std;
cout << "[Mesh: " << m.vertices().size() << " vertices, " << m.faces().size() << " faces, " << m.edges().size() << " edges]" << endl;
cout << " vertices:" << endl;
for (auto v : m.vertices())
cout << " [" << v.idx.value << "] -> half-edge #" << v.any_outgoing_halfedge().idx.value << endl;
cout << endl;
cout << " faces:" << endl;
for (auto f : m.faces())
cout << " [" << f.idx.value << "] -> half-edge #" << f.any_halfedge().idx.value << endl;
cout << endl;
cout << " half-edges:" << endl;
for (auto h : m.halfedges())
{
cout << " [" << h.idx.value << "] -> (";
cout << "opp #" << h.opposite().idx.value;
cout << ", next #" << h.next().idx.value;
cout << ", prev #" << h.prev().idx.value;
cout << ", f #" << h.face().idx.value;
cout << ", v-to #" << h.vertex_to().idx.value;
cout << ")" << endl;
}
cout << endl;
}
void polymesh::write_dot_graph(const polymesh::Mesh& m, std::ostream& out)
{
out << "strict digraph {\n";
for (auto v : m.vertices())
out << " v" << v.idx.value << ";\n";
for (auto h : m.halfedges())
{
auto v0 = h.vertex_from().idx.value;
auto v1 = h.vertex_to().idx.value;
out << " v" << v0 << " -> v" << v1 << " [label=\"h" << h.idx.value << "\"];\n";
}
out << "}\n";
}
void polymesh::write_dot_graph(const polymesh::Mesh& m, const std::string& filename)
{
std::ofstream file(filename);
write_dot_graph(m, file);
}
#pragma once
#include <fstream>
#include <iostream>
#include <iosfwd>
#include "Mesh.hh"
namespace polymesh
{
inline void print_debug(Mesh const& m)
{
using namespace std;
cout << "[Mesh: " << m.vertices().size() << " vertices, " << m.faces().size() << " faces, " << m.edges().size() << " edges]" << endl;
cout << " vertices:" << endl;
for (auto v : m.vertices())
cout << " [" << v.idx.value << "] -> half-edge #" << v.any_outgoing_halfedge().idx.value << endl;
cout << endl;
cout << " faces:" << endl;
for (auto f : m.faces())
cout << " [" << f.idx.value << "] -> half-edge #" << f.any_halfedge().idx.value << endl;
cout << endl;
cout << " half-edges:" << endl;
for (auto h : m.halfedges())
{
cout << " [" << h.idx.value << "] -> (";
cout << "opp #" << h.opposite().idx.value;
cout << ", next #" << h.next().idx.value;
cout << ", prev #" << h.prev().idx.value;
cout << ", f #" << h.face().idx.value;
cout << ", v-to #" << h.vertex_to().idx.value;
cout << ")" << endl;
}
cout << endl;
}
void print_debug(Mesh const& m);
inline void write_dot_graph(Mesh const& m, std::ostream& out)
{
out << "strict digraph {\n";
for (auto v : m.vertices())
out << " v" << v.idx.value << ";\n";
for (auto h : m.halfedges())
{
auto v0 = h.vertex_from().idx.value;
auto v1 = h.vertex_to().idx.value;
out << " v" << v0 << " -> v" << v1 << " [label=\"h" << h.idx.value << "\"];\n";
}
out << "}\n";
}
void write_dot_graph(Mesh const& m, std::ostream& out);
inline void write_dot_graph(Mesh const& m, std::string const& filename)
{
std::ofstream file(filename);
write_dot_graph(m, file);
}
void write_dot_graph(Mesh const& m, std::string const& filename);
}
#pragma once
#include <iostream>
#include <iosfwd>
#include <typeindex>
#include "../Mesh.hh"
......
#include <iostream>
#include "formats.hh"
#include <algorithm>
......
#include "obj.hh"
#include <iostream>
#include <fstream>
#include <sstream>
......
#pragma once
#include <iostream>
#include <iosfwd>
#include <string>
#include "../Mesh.hh"
......
#include "off.hh"
#include <iostream>
#include <fstream>
#include <sstream>
......
#pragma once
#include <array>
#include <iostream>
#include <iosfwd>
#include <string>
#include "../Mesh.hh"
......
#pragma once
#include <iostream>
#include <iosfwd>
#include <string>
#include "../Mesh.hh"
......
......@@ -271,4 +271,15 @@ static bool registered_default_types = []() {
return true;
}();
void detail::ostream_write(std::ostream& out, const char* data, size_t size)
{
out.write(data, size);
}
void detail::ostream_read(std::istream& in, char* data, size_t size)
{
in.read(data, size);
}
} // namespace polymesh
#pragma once
#include <iostream>
#include <iosfwd>
#include <string>
#include "../Mesh.hh"
......@@ -19,14 +19,17 @@ bool read_pm(std::istream& input, Mesh& mesh, attribute_collection& attributes);
namespace detail
{
void ostream_write(std::ostream& out, char const* data, size_t size);
void ostream_read(std::istream& in, char* data, size_t size);
template <typename T>
struct bytewise_serdes
{
void serialize(std::ostream& out, T const* data, size_t num_items) const
{
out.write(reinterpret_cast<char const*>(data), num_items * sizeof(T));
ostream_write(out, reinterpret_cast<char const*>(data), num_items * sizeof(T));
}
void deserialize(std::istream& in, T* data, size_t num_items) const { in.read(reinterpret_cast<char*>(data), num_items * sizeof(T)); }
void deserialize(std::istream& in, T* data, size_t num_items) const { ostream_read(in, reinterpret_cast<char*>(data), num_items * sizeof(T)); }
};
struct string_serdes
......@@ -34,7 +37,7 @@ struct string_serdes
void serialize(std::ostream& out, std::string const* strings, size_t num_items) const
{
for (size_t i = 0; i < num_items; i++)
out.write(strings[i].c_str(), strings[i].size() + 1);
ostream_write(out, strings[i].c_str(), strings[i].size() + 1);
}
void deserialize(std::istream& in, std::string* strings, size_t num_items) const
{
......
#include "stl.hh"
#include <cstddef>
#include <fstream>
#include <iostream>
#include <sstream>
/*
......
#pragma once
#include <array>
#include <iostream>
#include <iosfwd>
#include <string>
#include "../Mesh.hh"
......
......@@ -133,20 +133,4 @@ inline vertex_face_ring vertex_handle::faces() const { return {*this}; }
inline vertex_vertex_ring vertex_handle::adjacent_vertices() const { return {*this}; }
inline halfedge_ring halfedge_handle::ring() const { return {*this}; }
template <class tag>
std::ostream& operator<<(std::ostream& out, primitive_index<tag> const& v)
{
out << primitive<tag>::name << " " << v.value;
if (v.is_invalid())
out << " (invalid)";
return out;
}
template <class tag>
std::ostream& operator<<(std::ostream& out, primitive_handle<tag> const& v)
{
out << v.idx;
return out;
}
} // namespace polymesh
#pragma once
#include <memory>
#include <polymesh/pm.hh>
#include "pm.hh"
// Several standard library adaptors that should not be transitively included
namespace polymesh
{
// TODO: conversion from pm::unique_ptr to std::unique/shared_ptr
}
#include <polymesh/std/hash.hh>
#include <polymesh/std/io.hh>
#include <polymesh/std/memory.hh>
#pragma once
#include <utility>
#include <polymesh/Mesh.hh>
namespace std
{
template <class tag>
struct hash<polymesh::primitive_index<tag>>
{
size_t operator()(polymesh::primitive_index<tag> const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::face_index>
{
size_t operator()(polymesh::face_index const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::vertex_index>
{
size_t operator()(polymesh::vertex_index const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::edge_index>
{
size_t operator()(polymesh::edge_index const& i) const { return std::hash<int>()(i.value); }
};
template <>
struct hash<polymesh::halfedge_index>
{
size_t operator()(polymesh::halfedge_index const& i) const { return std::hash<int>()(i.value); }
};
template <class tag>
struct hash<polymesh::primitive_handle<tag>>
{
size_t operator()(polymesh::primitive_handle<tag> const& i) const { return std::hash<int>()(i.idx.value); }
};
template <>
struct hash<polymesh::face_handle>
{
size_t operator()(polymesh::face_handle const& i) const { return std::hash<int>()(i.idx.value); }
};
template <>
struct hash<polymesh::vertex_handle>
{
size_t operator()(polymesh::vertex_handle const& i) const { return std::hash<int>()(i.idx.value); }
};
template <>
struct hash<polymesh::edge_handle>
{
size_t operator()(polymesh::edge_handle const& i) const { return std::hash<int>()(i.idx.value); }
};
template <>
struct hash<polymesh::halfedge_handle>
{
size_t operator()(polymesh::halfedge_handle const& i) const { return std::hash<int>()(i.idx.value); }
};
}
#pragma once
#include <iostream>
#include <polymesh/Mesh.hh>
namespace polymesh
{
template <class tag>
std::ostream& operator<<(std::ostream& out, primitive_index<tag> const& v)
{
out << primitive<tag>::name << " " << v.value;
if (v.is_invalid())
out << " (invalid)";
return out;
}
template <class tag>
std::ostream& operator<<(std::ostream& out, primitive_handle<tag> const& v)
{
out << v.idx;
return out;
}
}
#pragma once
#include <memory>
#include <polymesh/detail/unique_array.hh>
#include <polymesh/detail/unique_ptr.hh>
namespace polymesh
{
// TODO: conversion from pm::unique_ptr to std::unique/shared_ptr
}
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