Skip to content

Commit

Permalink
Merge pull request #21 from geoflow3d/add-attribute-mtc-types
Browse files Browse the repository at this point in the history
Add an AttributeMap and MultiTriangleCollection
  • Loading branch information
Ylannl authored Sep 23, 2020
2 parents d501d05 + c373f0f commit f433964
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
65 changes: 65 additions & 0 deletions src/geoflow/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,69 @@ const std::vector<int>& Mesh::get_labels() const {
// return attributes_;
// };

void MultiTriangleCollection::push_back(
TriangleCollection& trianglecollection)
{
trianglecollections_.push_back(trianglecollection);
}
void MultiTriangleCollection::push_back(
AttributeMap& attributemap)
{
attributes_.push_back(attributemap);
}

size_t MultiTriangleCollection::tri_size() const
{
return trianglecollections_.size();
}
size_t MultiTriangleCollection::attr_size() const
{
return attributes_.size();
}

bool MultiTriangleCollection::has_attributes()
{
return !attributes_.empty();
}
bool MultiTriangleCollection::has_attributes() const
{
return !attributes_.empty();
}

std::vector<TriangleCollection>& MultiTriangleCollection::get_tricollections()
{
return trianglecollections_;
}
const std::vector<TriangleCollection>& MultiTriangleCollection::get_tricollections() const
{
return trianglecollections_;
}

std::vector<AttributeMap>& MultiTriangleCollection::get_attributes()
{
return attributes_;
}
const std::vector<AttributeMap>& MultiTriangleCollection::get_attributes() const
{
return attributes_;
}

TriangleCollection& MultiTriangleCollection::tri_at(size_t i)
{
return trianglecollections_.at(i);
}
const TriangleCollection& MultiTriangleCollection::tri_at(size_t i) const
{
return trianglecollections_.at(i);
}

AttributeMap& MultiTriangleCollection::attr_at(size_t i)
{
return attributes_.at(i);
}
const AttributeMap& MultiTriangleCollection::attr_at(size_t i) const
{
return attributes_.at(i);
}

} // namespace geoflow
32 changes: 31 additions & 1 deletion src/geoflow/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <typeinfo>
#include <typeindex>
#include <string>
#include <variant>

namespace geoflow
{
Expand All @@ -38,7 +39,9 @@ typedef std::vector<float> vec1f;
typedef std::vector<size_t> vec1ui;
typedef std::vector<std::string> vec1s;

typedef std::unordered_map<std::string, std::vector<float>> AttributeMap;
// Attribute types
typedef std::variant<bool, int, std:: string, float> attribute_value;
typedef std::unordered_map<std::string, std::vector<attribute_value>> AttributeMap;

class Box
{
Expand Down Expand Up @@ -136,6 +139,33 @@ class TriangleCollection : public GeometryCollection<Triangle>
float *get_data_ptr();
};

// MultiTriangleCollection stores a collection of TriangleCollections along with
// attributes for each TriangleCollection. The vector of TriangleCollections
// `trianglecollections_` and the vector of AttributeMaps `attributes_`
// supposed to have the same length when attributes are present, however this is
// not enforced. The `attributes_` can be empty.
class MultiTriangleCollection
{
std::vector<TriangleCollection> trianglecollections_;
std::vector<AttributeMap> attributes_;

public:
void push_back(TriangleCollection & trianglecollection);
void push_back(AttributeMap & attributemap);
std::vector<TriangleCollection>& get_tricollections();
const std::vector<TriangleCollection>& get_tricollections() const;
std::vector<AttributeMap>& get_attributes();
const std::vector<AttributeMap>& get_attributes() const;
TriangleCollection& tri_at(size_t i);
const TriangleCollection& tri_at(size_t i) const;
AttributeMap& attr_at(size_t i);
const AttributeMap& attr_at(size_t i) const;
size_t tri_size() const;
size_t attr_size() const;
bool has_attributes();
bool has_attributes() const;
};

class SegmentCollection : public GeometryCollection<std::array<arr3f, 2>>
{
public:
Expand Down

0 comments on commit f433964

Please sign in to comment.