forked from evouga/developable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
materialmesh.cpp
97 lines (84 loc) · 2.15 KB
/
materialmesh.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "materialmesh.h"
#include <map>
using namespace std;
using namespace Eigen;
Vector2d MaterialBoundary::getPos()
{
return Eigen::Vector2d(xpos, onBottom ? 0.0 : m_->getH());
}
bool MaterialMesh::saveToStream(std::ostream &os)
{
if(!PeriodicMesh::saveToStream(os))
return false;
writeDouble(os, H_);
int nbdryverts = bdryverts_.size();
writeInt(os, nbdryverts);
for(int i=0; i<nbdryverts; i++)
{
writeInt(os, bdryverts_[i].vertid);
writeDouble(os, bdryverts_[i].xpos);
writeBool(os, bdryverts_[i].onBottom);
}
int nmapentries = embedge2matedge_.size();
writeInt(os, nmapentries);
for(map<int, int>::iterator it = embedge2matedge_.begin(); it != embedge2matedge_.end(); ++it)
{
writeInt(os, it->first);
writeInt(os, it->second);
}
return os;
}
bool MaterialMesh::loadFromStream(std::istream &is)
{
if(!PeriodicMesh::loadFromStream(is))
return false;
H_ = readDouble(is);
if(!is)
return false;
int nbdryverts = readInt(is);
if(!is)
return false;
bdryverts_.clear();
for(int i=0; i<nbdryverts; i++)
{
MaterialBoundary bdinfo(this);
bdinfo.vertid = readInt(is);
bdinfo.xpos = readDouble(is);
bdinfo.onBottom = readBool(is);
if(!is)
return false;
bdryverts_.push_back(bdinfo);
}
int nmapentries = readInt(is);
if(!is)
{
assert(false);
return false;
}
embedge2matedge_.clear();
for(int i=0; i<nmapentries; i++)
{
int idx1 = readInt(is);
int idx2 = readInt(is);
if(!is)
{
assert(false);
return false;
}
embedge2matedge_[idx1] = idx2;
}
return true;
}
void MaterialMesh::setMaterialEdge(int embeddedEdge, int materialEdge)
{
assert(embeddedEdge != -1);
assert(materialEdge != -1);
embedge2matedge_[embeddedEdge] = materialEdge;
}
int MaterialMesh::materialEdge(int embeddedEdge)
{
map<int, int>::iterator it = embedge2matedge_.find(embeddedEdge);
if(it != embedge2matedge_.end())
return it->second;
return -1;
}