MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vrml.h File Reference

Go to the source code of this file.

Functions

void CylinderTransformer (Vec3D pointA, Vec3D pointB, Mdouble *length, Mdouble *angle, Vec3D *translation, Vec3D *axis)
 
void Export_to_VRML_format2 (std::string fname)
 

Function Documentation

void CylinderTransformer ( Vec3D  pointA,
Vec3D  pointB,
Mdouble length,
Mdouble angle,
Vec3D translation,
Vec3D axis 
)

Definition at line 28 of file vrml.h.

References Vec3D::GetLength(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by Export_to_VRML_format2().

29 {
30 
31  *length = GetDistance(pointA, pointB);
32 
33  // the translation (center of the cylinder) needed is
34  *translation = (pointA + pointB) / 2.0f;
35 
36  //the initial orientation of the bond is in the y axis
37  Vec3D init = Vec3D(0.0f, 1.0f, 0.0f);
38 
39  //the vector needed is the same as that from a to b
40  Vec3D needed = Vec3D(pointB.X - pointA.X, pointB.Y - pointA.Y, pointB.Z - pointA.Z);
41 
42 
43  Vec3D needed_n, init_n; // normilized
44 
45  needed_n = needed / needed.GetLength();
46  init_n = init / init.GetLength();
47 
48  //so the angle to rotate the bond by is:
49  *angle = acos(Dot(needed_n, init_n));
50 
51 
52  //and the axis to rotate by is the cross product of the initial and
53  //needed vectors - ie the vector orthogonal to them both
54  Mdouble vx = init.Y * needed.Z - init.Z * needed.Y;
55  Mdouble vy = init.Z * needed.X - init.X * needed.Z;
56  Mdouble vz = init.X * needed.Y - init.Y * needed.X;
57 
58  *axis = Vec3D(vx, vy, vz);
59 
60 }
Mdouble X
Definition: Vector.h:44
double Mdouble
Definition: ExtendedMath.h:33
Mdouble Y
Definition: Vector.h:44
Mdouble GetLength() const
Definition: Vector.h:248
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
Mdouble Z
Definition: Vector.h:44
void Export_to_VRML_format2 ( std::string  fname)

Definition at line 63 of file vrml.h.

References CylinderTransformer(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

64 {
65  ofstream grout(fname.c_str());
66 
67  grout << "\
68 #VRML V2.0 utf8 \n\n\
69 Group {\n\
70  children [\n\
71  WorldInfo {\n\
72  title \"Granular Media\"\n\
73  info [\n\
74  \"Packing configuration.\"\n\
75  \"Author: Vitaliy Ogarko; vogarko@gmail.com\"\n\
76  ]\n\
77  }\n\
78  NavigationInfo {\n\
79  type [ \"EXAMINE\", \"ANY\" ]\n\
80  }\n\
81  Background {\n\
82  skyColor [ 1 1 1 ]\n\
83  }\n\
84  ]\n\
85 }\n\n";
86 
87 /*
88  grout << "\
89 Shape {\n\
90  appearance Appearance {\n\
91  material Material {\n\
92  emissiveColor 0 0 0\n\
93  }\n\
94  }\n\
95  geometry IndexedLineSet {\n\
96  coord Coordinate {\n\
97  point [\n\
98  # Coordinates around the top of the cube\n\
99  0 1.0 1.0,\n\
100  1.0 1.0 1.0,\n\
101  1.0 1.0 0,\n\
102  0 1.0 0,\n\
103  # Coordinates around the bottom of the cube\n\
104  0 0 1.0,\n\
105  1.0 0 1.0,\n\
106  1.0 0 0,\n\
107  0 0 0\n\
108  ]\n\
109  }\n\
110  coordIndex [\n\
111  # top\n\
112  0, 1, 2, 3, 0, -1,\n\
113  # bottom\n\
114  4, 5, 6, 7, 4, -1,\n\
115  # vertical edges\n\
116  0, 4, -1,\n\
117  1, 5, -1,\n\
118  2, 6, -1,\n\
119  3, 7\n\
120  ]\n\
121  }\n\
122 }\n\n";
123 */
124 
125 
127 
128  Vec3D translation, axis;
129  Mdouble length, angle;
130 
131  Vec3D pointsA[12];
132  Vec3D pointsB[12];
133 
134  pointsA[0] = Vec3D(0,0,0); pointsB[0] = Vec3D(1,0,0);
135  pointsA[1] = Vec3D(0,0,0); pointsB[1] = Vec3D(0,1,0);
136  pointsA[2] = Vec3D(0,0,0); pointsB[2] = Vec3D(0,0,1);
137 
138  pointsA[3] = Vec3D(1,0,0); pointsB[3] = Vec3D(1,0,1);
139  pointsA[4] = Vec3D(1,0,0); pointsB[4] = Vec3D(1,1,0);
140 
141  pointsA[5] = Vec3D(0,1,0); pointsB[5] = Vec3D(0,1,1);
142  pointsA[6] = Vec3D(0,1,0); pointsB[6] = Vec3D(1,1,0);
143 
144  pointsA[7] = Vec3D(0,0,1); pointsB[7] = Vec3D(0,1,1);
145  pointsA[8] = Vec3D(0,0,1); pointsB[8] = Vec3D(1,0,1);
146 
147  pointsA[9] = Vec3D(1,1,1); pointsB[9] = Vec3D(0,1,1);
148  pointsA[10] = Vec3D(1,1,1); pointsB[10] = Vec3D(1,1,0);
149  pointsA[11] = Vec3D(1,1,1); pointsB[11] = Vec3D(1,0,1);
150 
151 
152  for(int i=0; i<12; i++)
153  {
154 
155  CylinderTransformer(pointsA[i], pointsB[i], &length, &angle, &translation, &axis);
156 
157  if (i == 11) { angle = 0.; } // without this a stick becomes black colored
158 
159  grout << "\
160 Transform{\n\
161  translation " << translation.X << " " << translation.Y << " " << translation.Z << "\n\
162  rotation " << axis.X << " " << axis.Y << " " << axis.Z << " " << angle << "\n\
163  children Shape {\n\
164  appearance Appearance {\n\
165  material Material { diffuseColor 0.8 0.8 0.8 }\n\
166  }\n\
167  geometry Cylinder {\n\
168  radius 0.005\n\
169  height " << length << "\n\
170  }}}\n\n";
171 
172 
173  } // for
174 
175 
176  grout << "\
177 Transform {\n\
178  translation 0 0 0\n\
179  children Shape {\n\
180  geometry Sphere {\n\
181  radius 0.005\n\
182  }\n\
183  appearance Appearance {\n\
184  material Material { diffuseColor 0.8 0.8 0.8\n\
185 }}}}\n\n";
186 
187  grout << "\
188 Transform {\n\
189  translation 1 0 0\n\
190  children Shape {\n\
191  geometry Sphere {\n\
192  radius 0.005\n\
193  }\n\
194  appearance Appearance {\n\
195  material Material { diffuseColor 0.8 0.8 0.8\n\
196 }}}}\n\n";
197 
198  grout << "\
199 Transform {\n\
200  translation 0 1 0\n\
201  children Shape {\n\
202  geometry Sphere {\n\
203  radius 0.005\n\
204  }\n\
205  appearance Appearance {\n\
206  material Material { diffuseColor 0.8 0.8 0.8\n\
207 }}}}\n\n";
208 
209  grout << "\
210 Transform {\n\
211  translation 0 0 1\n\
212  children Shape {\n\
213  geometry Sphere {\n\
214  radius 0.005\n\
215  }\n\
216  appearance Appearance {\n\
217  material Material { diffuseColor 0.8 0.8 0.8\n\
218 }}}}\n\n";
219 
220  grout << "\
221 Transform {\n\
222  translation 1 1 0\n\
223  children Shape {\n\
224  geometry Sphere {\n\
225  radius 0.005\n\
226  }\n\
227  appearance Appearance {\n\
228  material Material { diffuseColor 0.8 0.8 0.8\n\
229 }}}}\n\n";
230 
231  grout << "\
232 Transform {\n\
233  translation 1 0 1\n\
234  children Shape {\n\
235  geometry Sphere {\n\
236  radius 0.005\n\
237  }\n\
238  appearance Appearance {\n\
239  material Material { diffuseColor 0.8 0.8 0.8\n\
240 }}}}\n\n";
241 
242  grout << "\
243 Transform {\n\
244  translation 0 1 1\n\
245  children Shape {\n\
246  geometry Sphere {\n\
247  radius 0.005\n\
248  }\n\
249  appearance Appearance {\n\
250  material Material { diffuseColor 0.8 0.8 0.8\n\
251 }}}}\n\n";
252 
253  grout << "\
254 Transform {\n\
255  translation 1 1 1\n\
256  children Shape {\n\
257  geometry Sphere {\n\
258  radius 0.005\n\
259  }\n\
260  appearance Appearance {\n\
261  material Material { diffuseColor 0.8 0.8 0.8\n\
262 }}}}\n\n";
263 
265 
266 
267 
268 // http://vrmlworks.crispen.org/orient.html >> calculate oriantation for a viewpoint
269 
270  grout << "\
271 Viewpoint {\n\
272  position -0.9 1.6 3\n\
273  orientation -0.572612659264449 -0.806095467134217 -0.14941499361097152 0.6261167634082665\n\
274  fieldOfView 0.785398\n\
275  description \"Viewpoint 1\"\n\
276 }\n\n";
277 
278 
279  Mdouble r, c1, c2, c3;
280 
281  for(int i=0; i<Nmax; i++)
282  {
283 
284  grout << "Transform {" << "\n";
285  grout << "translation ";
286 
287  //grout << Particles[i]->Position << "\n";
288  grout << Px[i] << ' ' << Py[i] << ' ' << Pz[i] << "\n";
289 
290  grout << "children Shape {" << "\n";
291  grout << "geometry Sphere {" << "\n";
292  grout << "radius ";
293 
294  //grout << Particles[i]->Radius << "\n";
295  grout << Pr[i] << "\n";
296 
297  grout << "} \n";
298 
299 
300  grout << "appearance Appearance {" << "\n";
301 
302  //grout << "material Material { diffuseColor 0.915064 0 0.0849365 }" << "\n";
303  grout << "material Material { diffuseColor ";
304 
305 
306  //Mdouble r = (Particles[i]->Radius - MinRadius) / (MaxRadius - MinRadius);
307 
308  Mdouble transparency = 0.2;
309 
310  if (PolyType == 1)
311  {
312  c1 = 0.5;
313  c2 = 0.9;
314  c3 = 0.9;
315  } else
316  if (PolyType == 2)
317  {
318  // small particle
319  if (Pr[i] == MinRadius)
320  {
321  c1 = 0.5;
322  c2 = 0.9;
323  c3 = 0.9;
324  } else
325  {
326  c1 = 0.9;
327  c2 = 0.1;
328  c3 = 0.9;
329  }
330  } else
331  {
332 
333  r = (Pr[i] - MinRadius) / (MaxRadius - MinRadius);
334 
335  c3 = r;
336  c2 = 4*r*(1-r);
337  c1 = 1-r;
338 
339 
340  // !!! (Big - blue, small - yellow)
341  c3 = r;
342  c1 = 1-r;
343  c2 = 1-r;
344 
345  transparency = 0;
346 
347  }
348 
349 
350  /*
351  Mdouble r = pow(GetDistance(Particles[i]->Position, Vec3D(0.5, 0.5, 0.5)), 2./3.) / sqrt(0.75);
352 
353  Mdouble c3 = r;
354  Mdouble c2 = 4*r*(1-r);
355  Mdouble c1 = 1-r;
356  */
357 
358  //grout << c1 << " " << c2 << " " << c3 << " }\n";
359  grout << c1 << " " << c2 << " " << c3 << "\n";
360 
361  grout << " transparency " << transparency << "\n}\n";
362 
363  grout << "} \n";
364  grout << "} \n";
365  grout << "} \n";
366  grout << "\n";
367 
368  }
369 
370 
371  grout.close();
372 
373 }
Mdouble X
Definition: Vector.h:44
void CylinderTransformer(Vec3D pointA, Vec3D pointB, Mdouble *length, Mdouble *angle, Vec3D *translation, Vec3D *axis)
Definition: vrml.h:28
double Mdouble
Definition: ExtendedMath.h:33
Mdouble Y
Definition: Vector.h:44
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
Mdouble Z
Definition: Vector.h:44