Repository navigation
Expand file tree
/
Copy pathMeshAttributes.cpp
More file actions
71 lines (59 loc) · 2.26 KB
/
Copy pathMeshAttributes.cpp
File metadata and controls
71 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* This file is part of PyMesh. Copyright (c) 2015 by Qingnan Zhou */
#include "MeshAttributes.h"
#include <sstream>
#include <Core/EigenTypedef.h>
#include <Core/Exception.h>
#include "MeshAttribute.h"
#include "MeshAttributeFactory.h"
using namespace PyMesh;
bool PyMesh::MeshAttributes::has_attribute(const std::string& name) {
AttributeMap::iterator itr = m_attributes.find(name);
return (itr != m_attributes.end());
}
void PyMesh::MeshAttributes::add_empty_attribute(const std::string& name) {
MeshAttribute::Ptr attr = MeshAttributeFactory::create(name);
m_attributes.insert(AttributeMapEntry(name, attr));
}
void PyMesh::MeshAttributes::add_attribute(const std::string& name, Mesh& mesh) {
MeshAttribute::Ptr attr = MeshAttributeFactory::create(name);
attr->compute_from_mesh(mesh);
m_attributes.insert(AttributeMapEntry(name, attr));
}
void PyMesh::MeshAttributes::remove_attribute(const std::string& name) {
AttributeMap::iterator itr = m_attributes.find(name);
if (itr == m_attributes.end()) {
std::stringstream err_msg;
err_msg << "Attribute \"" << name << "\" does not exist.";
throw RuntimeError(err_msg.str());
}
m_attributes.erase(itr);
}
VectorF& PyMesh::MeshAttributes::get_attribute(const std::string& name) {
AttributeMap::iterator itr = m_attributes.find(name);
if (itr == m_attributes.end()) {
std::stringstream err_msg;
err_msg << "Attribute \"" << name << "\" does not exist.";
throw RuntimeError(err_msg.str());
}
return itr->second->get_values();
}
void PyMesh::MeshAttributes::set_attribute(const std::string& name, VectorF& value) {
MeshAttribute::Ptr attr;
AttributeMap::iterator itr = m_attributes.find(name);
if (itr == m_attributes.end()) {
std::stringstream err_msg;
err_msg << "Attribute \"" << name << "\" does not exist.";
throw RuntimeError(err_msg.str());
} else {
attr = itr->second;
}
attr->set_values(value);
}
MeshAttributes::AttributeNames PyMesh::MeshAttributes::get_attribute_names() const {
AttributeNames names;
for (AttributeMap::const_iterator itr = m_attributes.begin();
itr != m_attributes.end(); itr++) {
names.push_back(itr->first);
}
return names;
}