void GvPath::GetCumulativeTransform(Transform3 *T) { T->Identity(); int i; for (i=0; i<mAncestryLength; ++i) { Geom *g = mAncestry[i]; if (g->IsInstanceOf(TYPE_INFO(GeomWrapped))) { Transform3 *M = ((GeomWrapped*)g)->GetTransform(); // Explanation of the order of multiplication: Our // transform libarary treats data points as row vectors; // transforms act on them by right multiplication, i.e. // [point] * [matrix] = [new point]. Transforms lower in // the heirarchy are closer to the data points (the one // just above the leaf node Geom being the one that acts // on it first), so the order in which the product of // transformations act on a point is: // [point] * [transf n] * ... * [transf 1] * [transf 0] // = [new point] // At this point, we've accumulated the product // [transf i-1] ... [transf 0] // in T, and we're about to multiply it by [transf i] // (which is in M), so the order should be M * T. T->Concat(M, T); } } }
Transform3 *GvPath::GetLocalTransform() { if (mAncestryLength <= 1) { return &Transform3::IDENTITY; } Geom *parent = mAncestry[mAncestryLength-2]; if (!parent->IsInstanceOf(TYPE_INFO(GeomWrapped))) { return NULL; } return ((GeomWrapped*)parent)->GetTransform(); }
int GvPath::FindStack(UtLStack<Geom *> *stack, Geom *geom) { Geom *g = *(stack->Top()); if ( g == geom ) { return 1; } if (g->IsInstanceOf(TYPE_INFO(GeomParent))) { GeomParent *p = (GeomParent*)g; int nchildren = p->GetChildCount(); for (int i=0; i<nchildren; ++i) { (*(stack->Push())) = p->GetChild(i); if (FindStack(stack, geom)) { return 1; } stack->Pop(); } } return 0; }