-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathtestVisualization.cpp
535 lines (503 loc) · 26.3 KB
/
testVisualization.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/* -------------------------------------------------------------------------- *
* OpenSim: testVisualization.cpp *
* -------------------------------------------------------------------------- *
* The OpenSim API is a toolkit for musculoskeletal modeling and simulation. *
* See http://opensim.stanford.edu and the NOTICE file for more information. *
* OpenSim is developed at Stanford University and supported by the US *
* National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA *
* through the Warrior Web program. *
* *
* Copyright (c) 2005-2017 Stanford University and the Authors *
* Author(s): Ayman Habib *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain a *
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* -------------------------------------------------------------------------- */
#include <fstream>
#include <stdint.h>
#include <OpenSim/Simulation/Model/Model.h>
#include <OpenSim/Simulation/Model/PhysicalOffsetFrame.h>
#include <OpenSim/Simulation/Manager/Manager.h>
#include <OpenSim/Common/LoadOpenSimLibrary.h>
#include <OpenSim/Auxiliary/auxiliaryTestFunctions.h>
using namespace OpenSim;
using namespace std;
using namespace SimTK;
void testVisModel(Model& model, const std::string filename_for_standard);
Model createModel4AppearanceTest();
void populate_doublePendulumPrimitives(SimTK::Array_<DecorativeGeometry>&);
void populate_composedTransformPrimitives(SimTK::Array_<DecorativeGeometry>&);
void populate_contactModelPrimitives(SimTK::Array_<DecorativeGeometry>&);
void populate_wrapModelPrimitives(SimTK::Array_<DecorativeGeometry>&, bool includeFrames=true);
bool testVisModelAgainstStandard(Model& model, const SimTK::Array_<DecorativeGeometry>& stdPrimitives);
// Implementation of DecorativeGeometryImplementation that prints the representation to
// a StringStream for comparison
class DecorativeGeometryImplementationText : public SimTK::DecorativeGeometryImplementation
{
void implementPointGeometry(const DecorativePoint& dp) override{
printout << "DecorativePoint:" << dp.getPoint() << printCommonProps(dp) << std::endl;
};
void implementLineGeometry(const DecorativeLine& dl) override{
printout << "DecorativeLine:" << dl.getPoint1() << dl.getPoint2() << printCommonProps(dl) << std::endl;
};
void implementBrickGeometry(const DecorativeBrick& db) override{
printout << "DecorativeBrick:" << db.getHalfLengths() << printCommonProps(db) << std::endl;
};
void implementCylinderGeometry(const DecorativeCylinder& dc) override{
printout << "DecorativeCylinder:" << dc.getHalfHeight() << dc.getRadius() << printCommonProps(dc) << std::endl;
};
void implementCircleGeometry(const DecorativeCircle& dc) override{
printout << "DecorativeCircle:" << dc.getRadius() << printCommonProps(dc) << std::endl;
};
void implementSphereGeometry(const DecorativeSphere& dp) override{
printout << "DecorativeSphere:" << dp.getRadius() << printCommonProps(dp) << std::endl;
};
void implementEllipsoidGeometry(const DecorativeEllipsoid& dp) override{
printout << "DecorativeEllipsoid:" << dp.getRadii() << printCommonProps(dp) << std::endl;
};
void implementFrameGeometry(const DecorativeFrame& dp) override{
printout << "DecorativeFrame:" << dp.getAxisLength() << printCommonProps(dp) << std::endl;
};
void implementTextGeometry(const DecorativeText& dp) override{
printout << "DecorativeText:" << dp.getText() << printCommonProps(dp) << std::endl;
};
void implementMeshGeometry(const DecorativeMesh& dp) override{
printout << "DecorativeMesh:" << dp.getMesh().getNumFaces() << " " << dp.getMesh().getNumVertices() << printCommonProps(dp) << std::endl;
};
void implementMeshFileGeometry(const DecorativeMeshFile& dp) override{
std::string filename = dp.getMeshFile();
std::size_t found = filename.find_last_of("/\\");
if (found == string::npos)
printout << "DecorativeMeshFile:" << filename << " " << printCommonProps(dp) << std::endl;
else
printout << "DecorativeMeshFile:" << filename.substr(found+1) << " " << printCommonProps(dp) << std::endl;
};
void implementArrowGeometry(const DecorativeArrow& dp) override{
printout << "DecorativeArrow:" << dp.getStartPoint() << dp.getEndPoint() << dp.getTipLength() << printCommonProps(dp) << std::endl;
};
void implementTorusGeometry(const DecorativeTorus& dp) override{
printout << "DecorativeTorus:" << dp.getTorusRadius() << dp.getTubeRadius() << printCommonProps(dp) << std::endl;
};
void implementConeGeometry(const DecorativeCone& dp) override{
printout << "DecorativeTorus:" << dp.getBaseRadius() << dp.getDirection() << dp.getHeight() << printCommonProps(dp) << std::endl;
};
public:
std::string getAsString() {
return printout.str();
}
void setPrintTransforms(bool toPrint) { printTransform = toPrint;}
private:
std::stringstream printout;
bool printTransform = false; // Flag to indicate whether or not to output transform as String
std::string printCommonProps(const DecorativeGeometry& dg){
std::stringstream oneDGStream;
oneDGStream << " bodyId:" << dg.getBodyId() << " color:" << dg.getColor() << " indexOnBody:"
<< dg.getIndexOnBody() << " Opacity:" << dg.getOpacity() << " Rep:" << dg.getRepresentation() << " Scale:"
<< dg.getScaleFactors();
if (printTransform)
oneDGStream << " Transform:" << dg.getTransform();
return oneDGStream.str();
}
};
int main()
{
try {
LoadOpenSimLibrary("osimActuators");
Model testModel("BuiltinGeometry.osim");
testModel.enableVisualization(true);
testVisModel(testModel, "vis_BuiltinGeometry.txt");
std::cout << "BuiltinGeometry Passed" << std::endl;
Model testModel2 = createModel4AppearanceTest();
testModel2.enableVisualization(true);
testVisModel(testModel2, "vis_AppearanceTest.txt");
std::cout << "Appearance test Passed" << std::endl;
// Load Model in 3.3 format that had transforms attached to Geometry
Model testModel3("double_pendulum33.osim");
testModel3.enableVisualization(true);
SimTK::Array_<DecorativeGeometry> standard;
testModel3.updDisplayHints().set_show_frames(true);
populate_doublePendulumPrimitives(standard);
testVisModelAgainstStandard(testModel3, standard);
std::cout << "double_pendulum33 test Passed" << std::endl;
// Now a model from 3.3 where both GeometrySet and individual DisplayGeometry
// have a non-trivial transform.
Model composedTransformsModel("doubletransform33.osim");
composedTransformsModel.enableVisualization(true);
composedTransformsModel.updDisplayHints().set_show_frames(true);
populate_composedTransformPrimitives(standard);
testVisModelAgainstStandard(composedTransformsModel, standard);
// Model with contacts
Model modelWithContacts("visualize_contacts.osim");
modelWithContacts.enableVisualization(true);
modelWithContacts.updDisplayHints().set_show_frames(true);
populate_contactModelPrimitives(standard);
testVisModelAgainstStandard(modelWithContacts, standard);
// Model with WrapObjects
Model modelWithWrap("test_wrapAllVis.osim");
modelWithWrap.enableVisualization(true);
modelWithWrap.updDisplayHints().set_show_frames(true);
populate_wrapModelPrimitives(standard);
modelWithWrap.updDisplayHints().set_show_frames(false);
populate_wrapModelPrimitives(standard, false);
testVisModelAgainstStandard(modelWithWrap, standard);
}
catch (const std::exception& e) {
cout << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
void testVisModel(Model& model, const std::string standard_filename)
{
bool visualDebug = false; // Turn on only if you want to see API visualizer live
if (visualDebug)
model.setUseVisualizer(true);
SimTK::State& si = model.initSystem();
// Compute muscle dynamics to evaluate Muscle color
model.realizeDynamics(si);
if (visualDebug)
model.getVisualizer().show(si);
ModelDisplayHints mdh;
mdh.upd_show_frames() = true;
SimTK::Array_<SimTK::DecorativeGeometry> geometryToDisplay;
model.generateDecorations(true, mdh, si, geometryToDisplay);
cout << geometryToDisplay.size() << endl;
model.generateDecorations(false, mdh, si, geometryToDisplay);
cout << geometryToDisplay.size() << endl;
DecorativeGeometryImplementationText dgiText;
dgiText.setPrintTransforms(true); // In toy models Transforms can be printed and compared as strings
for (unsigned i = 0; i < geometryToDisplay.size(); i++)
geometryToDisplay[i].implementGeometry(dgiText);
std::ifstream t(standard_filename);
if (!t.good()) throw OpenSim::Exception("Could not open file. "+ standard_filename);
std::stringstream buffer;
buffer << t.rdbuf();
std::string fromFile = buffer.str();
std::string fromModel = dgiText.getAsString();
cout << "From Model " << endl << "=====" << endl;
cout << fromModel << endl;
cout << "From File " << endl << "=====" << endl;
cout << fromFile << endl;
cout << "Length:" << fromModel.length() << "vs." << fromFile.length() << std::endl;
int same = fromFile.compare(fromModel);
if (visualDebug) {
std::cout << "press Enter (or Return) to continue" << std::endl;
std::cin.get();
std::cout << "Continuing..." << std::endl;
}
ASSERT(same == 0, __FILE__, __LINE__,
"Visualization primitives from model do not match standard from file `"
+ standard_filename + "'.");
}
Model createModel4AppearanceTest()
{
Model modelWithGroundOnly;
Sphere* unitSphere = new Sphere(1.0);
const Ground& ground = modelWithGroundOnly.getGround();
//DecorativeGeometry default is Rep : 3 shaded in std file
modelWithGroundOnly.updGround().attachGeometry(unitSphere);
// Create offset frame and add to model
SimTK::Transform translate(Vec3(1.0, 0., 0.));
PhysicalOffsetFrame* oframe = new PhysicalOffsetFrame(ground, translate);
modelWithGroundOnly.addComponent(oframe);
// Change color and opacity
Sphere* offsetSphere = unitSphere->clone();
offsetSphere->upd_Appearance().set_color(SimTK::Cyan);
offsetSphere->upd_Appearance().set_opacity(0.5);
oframe->attachGeometry(offsetSphere);
PhysicalOffsetFrame* ooframe = new PhysicalOffsetFrame(ground, Vec3(2.0, 0., 0.));
modelWithGroundOnly.addComponent(ooframe);
// invisible Sphere
Sphere* ooffsetSphere = unitSphere->clone();
// Hidden
ooffsetSphere->upd_Appearance().set_visible(false);
ooframe->attachGeometry(ooffsetSphere);
PhysicalOffsetFrame* oooframe = new PhysicalOffsetFrame(ground, Vec3(3.0, 0., 0.));
modelWithGroundOnly.addComponent(oooframe);
// Wireframe Sphere
Sphere* oooffsetSphere = unitSphere->clone();
//DecorativeGeometry::DrawWireframe is Rep : 2 in std file
oooffsetSphere->upd_Appearance().set_representation(DecorativeGeometry::DrawWireframe);
oooframe->attachGeometry(oooffsetSphere);
return modelWithGroundOnly; // Return a copy
}
// Eventually all tests will go thru this function instead of comparing files then reference
// can be passed in.
bool testVisModelAgainstStandard(Model& model, const SimTK::Array_<DecorativeGeometry>& stdPrimitives) {
bool visualDebug = false; // Turn on only if you want to see API visualizer live
if (visualDebug)
model.setUseVisualizer(true);
SimTK::State& si = model.initSystem();
if (visualDebug)
model.getVisualizer().show(si);
const ModelDisplayHints& mdh = model.getDisplayHints();
SimTK::Array_<SimTK::DecorativeGeometry> geometryToDisplay;
model.generateDecorations(true, mdh, si, geometryToDisplay);
cout << "Number of fixed geometries: " << geometryToDisplay.size() << endl;
model.generateDecorations(false, mdh, si, geometryToDisplay);
cout << "Number of fixed and non-fixed geometries: "
<< geometryToDisplay.size() << endl;
/*
DecorativeGeometryImplementationText textFromModel;
textFromModel.setPrintTransforms(true); // Debugging
for (const SimTK::DecorativeGeometry* nextGeom = geometryToDisplay.begin();
nextGeom != geometryToDisplay.end();
++nextGeom) {
nextGeom->implementGeometry(textFromModel);
}
std::cout << textFromModel.getAsString() << std::endl;
*/
int i = 0;
for (const SimTK::DecorativeGeometry* nextGeom = stdPrimitives.begin();
nextGeom != stdPrimitives.end();
++nextGeom) {
DecorativeGeometryImplementationText dgiTextFromStandard;
nextGeom->implementGeometry(dgiTextFromStandard);
DecorativeGeometryImplementationText dgiTextFromModel;
geometryToDisplay[i].implementGeometry(dgiTextFromModel);
if (!(dgiTextFromStandard.getAsString() == dgiTextFromModel.getAsString()))
throw OpenSim::Exception("failed comparing " + dgiTextFromStandard.getAsString() + "vs." + dgiTextFromModel.getAsString());
// Compare transforms, this has to be more lenient than String comparison due to roundoff
SimTK::Mat44 diffTransform = nextGeom->getTransform().toMat44() - geometryToDisplay[i].getTransform().toMat44();
// std::cout << "Transform from standard: "
// << nextGeom->getTransform().toMat44() << std::endl;
// std::cout << "Transform from model: "
// << geometryToDisplay[i].getTransform().toMat44() << std::endl;
double norm = diffTransform.norm();
SimTK_TEST_EQ(norm, 0.)
++i;
}
if (visualDebug) {
std::cout << "press Enter (or Return) to continue" << std::endl;
std::cin.get();
std::cout << "Continuing..." << std::endl;
}
return true;
}
void populate_doublePendulumPrimitives(SimTK::Array_<DecorativeGeometry>& stdPrimitives) {
stdPrimitives.clear();
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(0).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Offset frame rod1
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White).setIndexOnBody(0).setScale(0.2)
.setOpacity(1).setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., .25, 0 })));
// Cylinder rod1
stdPrimitives.push_back(
DecorativeMeshFile("cylinder.vtp").setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScaleFactors(Vec3{ 0.02,0.5,0.02 }).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., .25, 0 })));
// Frame rod 1
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Block rod 1
stdPrimitives.push_back(
DecorativeMeshFile("block.vtp").setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(1).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Offset frame rod2
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(2).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., .25, 0 })));
// Cylinder rod2
stdPrimitives.push_back(
DecorativeMeshFile("cylinder.vtp").setBodyId(2).setColor(SimTK::White)
.setIndexOnBody(0).setScaleFactors(Vec3{ 0.02,0.5,0.02 }).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., .25, 0 })));
// Frame body 2
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(2).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Block rod 2
stdPrimitives.push_back(
DecorativeMeshFile("block.vtp").setBodyId(2).setColor(SimTK::White)
.setIndexOnBody(0).setScaleFactors(Vec3{ 1, 1.5, 2 }).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Two more offset frames and 2 for the Joint
stdPrimitives.push_back(
DecorativeFrame(1).setBodyId(0).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., 0, 0 })));
stdPrimitives.push_back(
DecorativeFrame(1).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., .5, 0 })));
stdPrimitives.push_back(
DecorativeFrame(1).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., 0, 0 })));
stdPrimitives.push_back(
DecorativeFrame(1).setBodyId(2).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., .5, 0 })));
}
void populate_composedTransformPrimitives(SimTK::Array_<DecorativeGeometry>& stdPrimitives) {
stdPrimitives.clear();
// In addition to Ground Frame, those frames for Joint
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(0).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// This the frame of the composed transform and attached geometry
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0.3, 0.3, 0.3 })));
stdPrimitives.push_back(
DecorativeMeshFile("block.vtp").setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScaleFactors(Vec3{ 1, 2, 3 }).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0.3, 0.3, 0.3 })));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(0).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., 0.05, 0. })));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(SimTK::Transform(Vec3{ 0., 0.5, 0. })));
}
void populate_contactModelPrimitives(SimTK::Array_<DecorativeGeometry>& stdPrimitives) {
stdPrimitives.clear();
// Frame for Ground
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(0).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Frame for Ball Body
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Frames for the Joint
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(0).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// 2 Contact Surfaces as Meshes (from sphere.vtp)
SimTK::PolygonalMesh mesh;
mesh.loadFile("sphere.vtp");
stdPrimitives.push_back(
DecorativeMesh(mesh).setBodyId(0).setColor(SimTK::Cyan)
.setIndexOnBody(-1).setOpacity(1).setScale(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawWireframe)
.setTransform(SimTK::Transform(Vec3{ 1, 2, 0. })));
stdPrimitives.push_back(
DecorativeMesh(mesh).setBodyId(1).setColor(SimTK::Cyan)
.setIndexOnBody(-1).setOpacity(1).setScale(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawWireframe)
.setTransform(SimTK::Transform(Vec3{ 1, 1, 0. })));
// ContactSphere
stdPrimitives.push_back(
DecorativeSphere(0.25).setBodyId(1).setColor(SimTK::Cyan)
.setIndexOnBody(-1).setOpacity(1).setScale(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawWireframe)
.setTransform(SimTK::Transform(Vec3{ 0, 1, 0. })));
// ContactHalfSpace as thin block
SimTK::Transform transform;
transform.updR().setRotationFromAngleAboutZ(.5);
stdPrimitives.push_back(
DecorativeBrick({ 0.0005,0.5,0.5 }).setBodyId(0).setColor(SimTK::Cyan)
.setIndexOnBody(-1).setOpacity(0.7).setScale(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(transform * Transform(Vec3(0.0005, 0, 0))));
}
void populate_wrapModelPrimitives(SimTK::Array_<DecorativeGeometry>& stdPrimitives, bool includeFrames) {
stdPrimitives.clear();
// Frame for Ground & Bodies
if (includeFrames) {
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(0).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(2).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(4).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(3).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface));
// Frames for the Joint
stdPrimitives.push_back(
DecorativeFrame(1.0).setBodyId(1).setColor(SimTK::White)
.setIndexOnBody(0).setScale(0.2).setOpacity(1)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(Vec3({ -.01, -.03, .03 })));
}
Transform cylTransform;
// This transform parallels the code in generateDecorations to reflect
// that DecorativeCylinder is Y aligned while WrapCylinder is Z aligned
cylTransform.updR().setRotationFromAngleAboutX(SimTK_PI / 2);
stdPrimitives.push_back(
DecorativeCylinder(.025, .05).setBodyId(0).setColor(Vec3(0, 0.2, 0.8))
.setIndexOnBody(-1).setScale(1).setOpacity(0.5)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(Transform(cylTransform.R(), Vec3({ .01, -.4, .01 }))));
stdPrimitives.push_back(
DecorativeCylinder(.03, .05).setBodyId(0).setColor(SimTK::Cyan)
.setIndexOnBody(-1).setScale(1).setOpacity(0.5)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(Transform(cylTransform.R(), Vec3({ .025, -.25, 0 }))));
stdPrimitives.push_back(
DecorativeCylinder(.03, .05).setBodyId(0).setColor(SimTK::Cyan)
.setIndexOnBody(-1).setScale(1).setOpacity(0.5)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(Transform(cylTransform.R(), Vec3({ .05, -.25, 0 }))));
stdPrimitives.push_back(
DecorativeSphere(.055).setBodyId(0).setColor(Vec3(0, 0.2, 0.8))
.setIndexOnBody(-1).setScale(1).setOpacity(0.5)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(Vec3({ .01, -.3, .01 })));
stdPrimitives.push_back(
DecorativeEllipsoid(Vec3(.1, .05, .15)).setBodyId(0).setColor(Vec3(0, 0.2, 0.8))
.setIndexOnBody(-1).setScale(1).setOpacity(0.5)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(Vec3({ -.01, -.5, .0 })));
stdPrimitives.push_back(
DecorativeTorus(.08, .035).setBodyId(1).setColor(Vec3(0, 0.2, 0.8))
.setIndexOnBody(-1).setScale(1).setOpacity(0.5)
.setRepresentation(SimTK::DecorativeGeometry::DrawSurface)
.setTransform(Vec3({ -.02, -.6, .01 })));
}