20 LinkInfoSequence_var links = bodyInfo->links();
21 ShapeInfoSequence_var shapes = bodyInfo->shapes();
27 for(
int linkIndex = 0; linkIndex <
numLinks ; ++linkIndex){
29 LinkInfo& linkInfo = links[linkIndex];
31 int totalNumTriangles = 0;
32 int totalNumVertices = 0;
33 const TransformedShapeIndexSequence& shapeIndices = linkInfo.shapeIndices;
36 unsigned int nshape = shapeIndices.length();
37 for(
unsigned int i=0;
i < shapeIndices.length();
i++){
38 shapeIndex = shapeIndices[
i].shapeIndex;
39 const DblArray12 &tform = shapeIndices[
i].transformMatrix;
40 R[0] = tform[0]; R[1] = tform[1]; R[2] = tform[2]; p[0] = tform[3];
41 R[3] = tform[4]; R[4] = tform[5]; R[5] = tform[6]; p[1] = tform[7];
42 R[6] = tform[8]; R[7] = tform[9]; R[8] = tform[10]; p[2] = tform[11];
43 const ShapeInfo& shapeInfo = shapes[shapeIndex];
44 totalNumTriangles += shapeInfo.triangles.length() / 3;
45 totalNumVertices += shapeInfo.vertices.length() / 3;
48 const SensorInfoSequence& sensors = linkInfo.sensors;
49 for (
unsigned int i=0;
i<sensors.length();
i++){
50 const SensorInfo &sinfo = sensors[
i];
51 const TransformedShapeIndexSequence tsis = sinfo.shapeIndices;
52 nshape += tsis.length();
53 for (
unsigned int j=0;
j<tsis.length();
j++){
54 shapeIndex = tsis[
j].shapeIndex;
55 const DblArray12 &tform = tsis[
j].transformMatrix;
56 R[0] = tform[0]; R[1] = tform[1]; R[2] = tform[2]; p[0] = tform[3];
57 R[3] = tform[4]; R[4] = tform[5]; R[5] = tform[6]; p[1] = tform[7];
58 R[6] = tform[8]; R[7] = tform[9]; R[8] = tform[10]; p[2] = tform[11];
59 const ShapeInfo& shapeInfo = shapes[shapeIndex];
60 totalNumTriangles += shapeInfo.triangles.length() / 3;
61 totalNumVertices += shapeInfo.vertices.length() / 3 ;
68 coldetModel->setName(std::string(linkInfo.name));
70 if(totalNumTriangles > 0){
71 coldetModel->setNumVertices(totalNumVertices);
72 coldetModel->setNumTriangles(totalNumTriangles);
84 cout << linkInfo.name <<
" has "<< totalNumTriangles <<
" triangles." << endl;
89 const double *R,
const double *p,
90 const ShapeInfo& shapeInfo)
92 switch(shapeInfo.primitiveType){
94 coldetModel->setPrimitiveType(ColdetModel::SP_BOX);
97 coldetModel->setPrimitiveType(ColdetModel::SP_CYLINDER);
100 coldetModel->setPrimitiveType(ColdetModel::SP_CONE);
103 coldetModel->setPrimitiveType(ColdetModel::SP_SPHERE);
106 coldetModel->setPrimitiveType(ColdetModel::SP_PLANE);
111 coldetModel->setNumPrimitiveParams(shapeInfo.primitiveParameters.length());
112 for (
unsigned int i=0;
i<shapeInfo.primitiveParameters.length();
i++){
113 coldetModel->setPrimitiveParam(
i, shapeInfo.primitiveParameters[
i]);
115 coldetModel->setPrimitivePosition(R, p);
119 (
ColdetModelPtr& coldetModel,
const TransformedShapeIndex& tsi,
const Matrix44& Tparent, ShapeInfoSequence_var& shapes,
int& vertexIndex,
int& triangleIndex)
121 short shapeIndex = tsi.shapeIndex;
122 const DblArray12& M = tsi.transformMatrix;;
124 Tlocal << M[0], M[1], M[2], M[3],
125 M[4], M[5], M[6], M[7],
126 M[8], M[9], M[10], M[11],
128 T = Tparent * Tlocal;
130 const ShapeInfo& shapeInfo = shapes[shapeIndex];
131 int vertexIndexBase = vertexIndex;
132 const FloatSequence& vertices = shapeInfo.vertices;
133 const int numVertices = vertices.length() / 3;
134 for(
int j=0;
j < numVertices; ++
j){
135 Vector4 v(T *
Vector4(vertices[
j*3], vertices[j*3+1], vertices[j*3+2], 1.0));
136 coldetModel->setVertex(vertexIndex++, v[0], v[1], v[2]);
139 const LongSequence& triangles = shapeInfo.triangles;
140 const int numTriangles = triangles.length() / 3;
141 for(
int j=0;
j < numTriangles; ++
j){
142 int t0 = triangles[
j*3] + vertexIndexBase;
143 int t1 = triangles[
j*3+1] + vertexIndexBase;
144 int t2 = triangles[
j*3+2] + vertexIndexBase;
145 coldetModel->setTriangle( triangleIndex++, t0, t1, t2);
154 int triangleIndex = 0;
156 const TransformedShapeIndexSequence& shapeIndices = linkInfo.shapeIndices;
159 for(
unsigned int i=0;
i < shapeIndices.length();
i++){
161 vertexIndex, triangleIndex);
165 const SensorInfoSequence& sensors = linkInfo.sensors;
166 for (
unsigned int i=0;
i<sensors.length();
i++){
167 const SensorInfo& sensor = sensors[
i];
169 sensor.rotation[2]), sensor.rotation[3]);
170 T(0,3) = sensor.translation[0];
171 T(1,3) = sensor.translation[1];
172 T(2,3) = sensor.translation[2];
173 const TransformedShapeIndexSequence& shapeIndices = sensor.shapeIndices;
174 for (
unsigned int j=0;
j<shapeIndices.length();
j++){
177 vertexIndex, triangleIndex);
192 const int srcNumLinks = linkPositions.length();
194 for(
int i=0;
i < srcNumLinks &&
i < selfNumLinks; ++
i){
195 const LinkPosition& linkPosition = linkPositions[
i];
void setLinkPositions(const LinkPositionSequence &linkPositions)
vector< ColdetModelPtr > linkColdetModels
void addLinkVerticesAndTriangles(ColdetModelPtr &coldetModel, LinkInfo &linkInfo, ShapeInfoSequence_var &shapes)
ColdetBody(BodyInfo_ptr bodyInfo)
def j(str, encoding="cp932")
unsigned int numLinks() const
void addLinkPrimitiveInfo(ColdetModelPtr &coldetModel, const double *R, const double *p, const ShapeInfo &shapeInfo)
HRP_UTIL_EXPORT void calcRodrigues(Matrix33 &out_R, const Vector3 &axis, double q)
boost::intrusive_ptr< ColdetModel > ColdetModelPtr
map< string, ColdetModelPtr > linkNameToColdetModelMap