1 |
< |
#include "visitors/RigidBodyVisitor.hpp" |
2 |
< |
#include "primitives/RigidBody.hpp" |
3 |
< |
#include "math/MatVec3.h" |
4 |
< |
|
5 |
< |
namespace oopse { |
6 |
< |
|
7 |
< |
void LipidHeadVisitor::visit(RigidBody* rb){ |
8 |
< |
Vector3d pos; |
9 |
< |
Vector3d u(0, 0, 1); |
10 |
< |
Vector3d newVec; |
11 |
< |
GenericData* data; |
12 |
< |
AtomData* atomData; |
13 |
< |
AtomInfo* atomInfo; |
14 |
< |
bool haveAtomData; |
15 |
< |
RotMat3x3d rotMatrix; |
16 |
< |
|
17 |
< |
if(!canVisit(rb->getType())) |
18 |
< |
return; |
19 |
< |
|
20 |
< |
pos = rb->getPos(); |
21 |
< |
rotMatrix = rb->getA(); |
22 |
< |
//matVecMul3(rotMatrix, u, newVec); |
23 |
< |
newVec = rotMatrix * u; |
24 |
< |
|
25 |
< |
data = rb->getPropertyByName("ATOMDATA"); |
26 |
< |
if(data != NULL){ |
27 |
< |
|
28 |
< |
atomData = dynamic_cast<AtomData*>(data); |
29 |
< |
if(atomData == NULL){ |
30 |
< |
cerr << "can not get Atom Data from " << rb->getType() << endl; |
31 |
< |
atomData = new AtomData; |
32 |
< |
haveAtomData = false; |
33 |
< |
} |
34 |
< |
else |
35 |
< |
haveAtomData = true; |
36 |
< |
} |
37 |
< |
else{ |
38 |
< |
atomData = new AtomData; |
39 |
< |
haveAtomData = false; |
40 |
< |
} |
41 |
< |
|
42 |
< |
atomInfo = new AtomInfo; |
43 |
< |
atomInfo->AtomType = "X"; |
44 |
< |
atomInfo->pos[0] = pos[0]; |
45 |
< |
atomInfo->pos[1] = pos[1]; |
46 |
< |
atomInfo->pos[2] = pos[2]; |
47 |
< |
atomInfo->dipole[0] = newVec[0]; |
48 |
< |
atomInfo->dipole[1] = newVec[1]; |
49 |
< |
atomInfo->dipole[2] = newVec[2]; |
50 |
< |
|
51 |
< |
atomData->addAtomInfo(atomInfo); |
52 |
< |
|
53 |
< |
if(!haveAtomData){ |
54 |
< |
atomData->setID("ATOMDATA"); |
55 |
< |
rb->addProperty(atomData); |
56 |
< |
} |
57 |
< |
|
58 |
< |
} |
59 |
< |
|
60 |
< |
void LipidHeadVisitor::addLipidHeadName(const string& name){ |
61 |
< |
lipidHeadName.insert(name); |
62 |
< |
|
63 |
< |
} |
64 |
< |
|
65 |
< |
bool LipidHeadVisitor::canVisit(const string& name){ |
66 |
< |
return lipidHeadName.find(name) != lipidHeadName.end() ? true : false; |
67 |
< |
|
68 |
< |
} |
69 |
< |
|
70 |
< |
const string LipidHeadVisitor::toString(){ |
71 |
< |
char buffer[65535]; |
72 |
< |
string result; |
73 |
< |
set<string>::iterator i; |
74 |
< |
|
75 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
76 |
< |
result += buffer; |
77 |
< |
|
78 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
79 |
< |
result += buffer; |
80 |
< |
|
81 |
< |
//print the ignore type list |
82 |
< |
sprintf(buffer , "lipidHeadName list contains below types:\n"); |
83 |
< |
result += buffer; |
84 |
< |
|
85 |
< |
for(i = lipidHeadName.begin(); i != lipidHeadName.end(); ++i){ |
86 |
< |
sprintf(buffer ,"%s\t", i->c_str()); |
87 |
< |
result += buffer; |
88 |
< |
} |
89 |
< |
|
90 |
< |
sprintf(buffer ,"\n"); |
91 |
< |
result += buffer; |
92 |
< |
|
93 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
94 |
< |
result += buffer; |
95 |
< |
|
96 |
< |
return result; |
97 |
< |
|
98 |
< |
} |
99 |
< |
|
100 |
< |
void RBCOMVisitor::visit(RigidBody* rb){ |
101 |
< |
AtomData* atomData; |
102 |
< |
AtomInfo* atomInfo; |
103 |
< |
Vector3d pos; |
104 |
< |
|
105 |
< |
pos = rb->getPos(); |
106 |
< |
atomInfo = new AtomInfo; |
107 |
< |
atomInfo->AtomType = "X"; |
108 |
< |
atomInfo->pos[0] = pos[0]; |
109 |
< |
atomInfo->pos[1] = pos[1]; |
110 |
< |
atomInfo->pos[2] = pos[2]; |
111 |
< |
atomInfo->dipole[0] = 0; |
112 |
< |
atomInfo->dipole[1] = 0; |
113 |
< |
atomInfo->dipole[2] = 0; |
114 |
< |
|
115 |
< |
atomData = new AtomData; |
116 |
< |
atomData->setID("ATOMDATA"); |
117 |
< |
atomData->addAtomInfo(atomInfo); |
118 |
< |
|
119 |
< |
rb->addProperty(atomData); |
120 |
< |
} |
121 |
< |
|
122 |
< |
const string RBCOMVisitor::toString(){ |
123 |
< |
char buffer[65535]; |
124 |
< |
string result; |
125 |
< |
|
126 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
127 |
< |
result += buffer; |
128 |
< |
|
129 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
130 |
< |
result += buffer; |
131 |
< |
|
132 |
< |
//print the ignore type list |
133 |
< |
sprintf(buffer , "Visitor Description: add a pseudo atom at the center of the mass of the rigidbody\n"); |
134 |
< |
result += buffer; |
135 |
< |
|
136 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
137 |
< |
result += buffer; |
138 |
< |
|
139 |
< |
return result; |
140 |
< |
|
141 |
< |
} |
142 |
< |
|
143 |
< |
|
144 |
< |
}//namespace oopse |
1 |
> |
#include "visitors/RigidBodyVisitor.hpp" |
2 |
> |
|
3 |
> |
#include "primitives/RigidBody.hpp" |
4 |
> |
|
5 |
> |
#include "math/MatVec3.h" |
6 |
> |
|
7 |
> |
|
8 |
> |
|
9 |
> |
namespace oopse { |
10 |
> |
|
11 |
> |
|
12 |
> |
|
13 |
> |
void LipidHeadVisitor::visit(RigidBody* rb){ |
14 |
> |
|
15 |
> |
Vector3d pos; |
16 |
> |
|
17 |
> |
Vector3d u(0, 0, 1); |
18 |
> |
|
19 |
> |
Vector3d newVec; |
20 |
> |
|
21 |
> |
GenericData* data; |
22 |
> |
|
23 |
> |
AtomData* atomData; |
24 |
> |
|
25 |
> |
AtomInfo* atomInfo; |
26 |
> |
|
27 |
> |
bool haveAtomData; |
28 |
> |
|
29 |
> |
RotMat3x3d rotMatrix; |
30 |
> |
|
31 |
> |
|
32 |
> |
|
33 |
> |
if(!canVisit(rb->getType())) |
34 |
> |
|
35 |
> |
return; |
36 |
> |
|
37 |
> |
|
38 |
> |
|
39 |
> |
pos = rb->getPos(); |
40 |
> |
|
41 |
> |
rotMatrix = rb->getA(); |
42 |
> |
|
43 |
> |
//matVecMul3(rotMatrix, u, newVec); |
44 |
> |
|
45 |
> |
newVec = rotMatrix * u; |
46 |
> |
|
47 |
> |
|
48 |
> |
|
49 |
> |
data = rb->getPropertyByName("ATOMDATA"); |
50 |
> |
|
51 |
> |
if(data != NULL){ |
52 |
> |
|
53 |
> |
|
54 |
> |
|
55 |
> |
atomData = dynamic_cast<AtomData*>(data); |
56 |
> |
|
57 |
> |
if(atomData == NULL){ |
58 |
> |
|
59 |
> |
cerr << "can not get Atom Data from " << rb->getType() << endl; |
60 |
> |
|
61 |
> |
atomData = new AtomData; |
62 |
> |
|
63 |
> |
haveAtomData = false; |
64 |
> |
|
65 |
> |
} |
66 |
> |
|
67 |
> |
else |
68 |
> |
|
69 |
> |
haveAtomData = true; |
70 |
> |
|
71 |
> |
} |
72 |
> |
|
73 |
> |
else{ |
74 |
> |
|
75 |
> |
atomData = new AtomData; |
76 |
> |
|
77 |
> |
haveAtomData = false; |
78 |
> |
|
79 |
> |
} |
80 |
> |
|
81 |
> |
|
82 |
> |
|
83 |
> |
atomInfo = new AtomInfo; |
84 |
> |
|
85 |
> |
atomInfo->AtomType = "X"; |
86 |
> |
|
87 |
> |
atomInfo->pos[0] = pos[0]; |
88 |
> |
|
89 |
> |
atomInfo->pos[1] = pos[1]; |
90 |
> |
|
91 |
> |
atomInfo->pos[2] = pos[2]; |
92 |
> |
|
93 |
> |
atomInfo->dipole[0] = newVec[0]; |
94 |
> |
|
95 |
> |
atomInfo->dipole[1] = newVec[1]; |
96 |
> |
|
97 |
> |
atomInfo->dipole[2] = newVec[2]; |
98 |
> |
|
99 |
> |
|
100 |
> |
|
101 |
> |
atomData->addAtomInfo(atomInfo); |
102 |
> |
|
103 |
> |
|
104 |
> |
|
105 |
> |
if(!haveAtomData){ |
106 |
> |
|
107 |
> |
atomData->setID("ATOMDATA"); |
108 |
> |
|
109 |
> |
rb->addProperty(atomData); |
110 |
> |
|
111 |
> |
} |
112 |
> |
|
113 |
> |
|
114 |
> |
|
115 |
> |
} |
116 |
> |
|
117 |
> |
|
118 |
> |
|
119 |
> |
void LipidHeadVisitor::addLipidHeadName(const string& name){ |
120 |
> |
|
121 |
> |
lipidHeadName.insert(name); |
122 |
> |
|
123 |
> |
|
124 |
> |
|
125 |
> |
} |
126 |
> |
|
127 |
> |
|
128 |
> |
|
129 |
> |
bool LipidHeadVisitor::canVisit(const string& name){ |
130 |
> |
|
131 |
> |
return lipidHeadName.find(name) != lipidHeadName.end() ? true : false; |
132 |
> |
|
133 |
> |
|
134 |
> |
|
135 |
> |
} |
136 |
> |
|
137 |
> |
|
138 |
> |
|
139 |
> |
const std::stringLipidHeadVisitor::toString(){ |
140 |
> |
|
141 |
> |
char buffer[65535]; |
142 |
> |
|
143 |
> |
std::stringresult; |
144 |
> |
|
145 |
> |
set<string>::iterator i; |
146 |
> |
|
147 |
> |
|
148 |
> |
|
149 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
150 |
> |
|
151 |
> |
result += buffer; |
152 |
> |
|
153 |
> |
|
154 |
> |
|
155 |
> |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
156 |
> |
|
157 |
> |
result += buffer; |
158 |
> |
|
159 |
> |
|
160 |
> |
|
161 |
> |
//print the ignore type list |
162 |
> |
|
163 |
> |
sprintf(buffer , "lipidHeadName list contains below types:\n"); |
164 |
> |
|
165 |
> |
result += buffer; |
166 |
> |
|
167 |
> |
|
168 |
> |
|
169 |
> |
for(i = lipidHeadName.begin(); i != lipidHeadName.end(); ++i){ |
170 |
> |
|
171 |
> |
sprintf(buffer ,"%s\t", i->c_str()); |
172 |
> |
|
173 |
> |
result += buffer; |
174 |
> |
|
175 |
> |
} |
176 |
> |
|
177 |
> |
|
178 |
> |
|
179 |
> |
sprintf(buffer ,"\n"); |
180 |
> |
|
181 |
> |
result += buffer; |
182 |
> |
|
183 |
> |
|
184 |
> |
|
185 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
186 |
> |
|
187 |
> |
result += buffer; |
188 |
> |
|
189 |
> |
|
190 |
> |
|
191 |
> |
return result; |
192 |
> |
|
193 |
> |
|
194 |
> |
|
195 |
> |
} |
196 |
> |
|
197 |
> |
|
198 |
> |
|
199 |
> |
void RBCOMVisitor::visit(RigidBody* rb){ |
200 |
> |
|
201 |
> |
AtomData* atomData; |
202 |
> |
|
203 |
> |
AtomInfo* atomInfo; |
204 |
> |
|
205 |
> |
Vector3d pos; |
206 |
> |
|
207 |
> |
|
208 |
> |
|
209 |
> |
pos = rb->getPos(); |
210 |
> |
|
211 |
> |
atomInfo = new AtomInfo; |
212 |
> |
|
213 |
> |
atomInfo->AtomType = "X"; |
214 |
> |
|
215 |
> |
atomInfo->pos[0] = pos[0]; |
216 |
> |
|
217 |
> |
atomInfo->pos[1] = pos[1]; |
218 |
> |
|
219 |
> |
atomInfo->pos[2] = pos[2]; |
220 |
> |
|
221 |
> |
atomInfo->dipole[0] = 0; |
222 |
> |
|
223 |
> |
atomInfo->dipole[1] = 0; |
224 |
> |
|
225 |
> |
atomInfo->dipole[2] = 0; |
226 |
> |
|
227 |
> |
|
228 |
> |
|
229 |
> |
atomData = new AtomData; |
230 |
> |
|
231 |
> |
atomData->setID("ATOMDATA"); |
232 |
> |
|
233 |
> |
atomData->addAtomInfo(atomInfo); |
234 |
> |
|
235 |
> |
|
236 |
> |
|
237 |
> |
rb->addProperty(atomData); |
238 |
> |
|
239 |
> |
} |
240 |
> |
|
241 |
> |
|
242 |
> |
|
243 |
> |
const std::stringRBCOMVisitor::toString(){ |
244 |
> |
|
245 |
> |
char buffer[65535]; |
246 |
> |
|
247 |
> |
std::stringresult; |
248 |
> |
|
249 |
> |
|
250 |
> |
|
251 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
252 |
> |
|
253 |
> |
result += buffer; |
254 |
> |
|
255 |
> |
|
256 |
> |
|
257 |
> |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
258 |
> |
|
259 |
> |
result += buffer; |
260 |
> |
|
261 |
> |
|
262 |
> |
|
263 |
> |
//print the ignore type list |
264 |
> |
|
265 |
> |
sprintf(buffer , "Visitor Description: add a pseudo atom at the center of the mass of the rigidbody\n"); |
266 |
> |
|
267 |
> |
result += buffer; |
268 |
> |
|
269 |
> |
|
270 |
> |
|
271 |
> |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
272 |
> |
|
273 |
> |
result += buffer; |
274 |
> |
|
275 |
> |
|
276 |
> |
|
277 |
> |
return result; |
278 |
> |
|
279 |
> |
|
280 |
> |
|
281 |
> |
} |
282 |
> |
|
283 |
> |
|
284 |
> |
|
285 |
> |
|
286 |
> |
|
287 |
> |
}//namespace oopse |
288 |
> |
|