# Faster way to 'weld' geometry?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 10/08/2004 at 11:45, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   8.503
Platform:   Windows  ;
Language(s) :     C++  ;

---------
Here is the method that I'm using to 'weld' two PolygonSelections together (no change of vertices - just reassigning indices of duplicate points) :

``````
// Weld Geometry (remove seams)
void PoserCharacter::WeldGeometry(void)
{
ParentChild *w;
PoserBase *c, *p;
LONG seg,i,a,b,seg2,j,a2,b2;
LONG *fi, *fj, *fid, *fjd;
Polygon* polys;
Vector* verts;
BaseSelect *bs, *bs2;
SelectionTag *group, *group2;

polys = (static_cast<PolygonObject*>baseObject)->GetPolygon();
verts = (static_cast<PolygonObject*>baseObject)->GetPoint();
for (w = weld; w != NULL; w = (ParentChild* )w->GetNext())
{
if ((c = w->GetChild()) == NULL) continue;
if ((group = c->GetGroup()) == NULL) continue;
if ((p = w->GetParent()) == NULL) continue;
if ((group2 = p->GetGroup()) == NULL) continue;

bs = group->GetBaseSelect();
bs2 = group2->GetBaseSelect();
seg=0;
while (bs->GetRange(seg++,&a;,&b;))
{
for (i=a; i<=b; ++i)
{
seg2=0;
while (bs2->GetRange(seg2++, &a2;, &b2;))
{
for (j = a2; j<=b2; ++j)
{
for (fi = &(polys _.a), fid = fi+5; fi != fid; fi++)
{
for (fj = &(polys[j].a), fjd = fj+5; fj != fjd; fj++)
{
if ((*fi != *fj) && (verts[*fi] == verts[*fj])) *fj = *fi;
}
}
}
}
}
}
}
}
``````

Is there a better way to do this? Thanks,
Robert

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 10/08/2004 at 12:19, xxxxxxxx wrote:

Ahhhh, shucks. Nevermind again. Found a faster solution, just required some pressure waiting for a response to get it.

So, instead of going through every BaseSelect for every BaseSelect, I'm creating a substitution array for the vertices, then when one is encountered in a BaseSelect, the substitution replaces the value:

``````
void PoserCharacter::WeldGeometry(void)
{
LONG seg, i, a, b;
LONG *fi, *fid, *subs;
Polygon* polys;
Vector* verts;
BaseSelect *bs;
SelectionTag *group;
ParentChild *w;
PoserBase *c;

polys = ((PolygonObject* )baseObject)->GetPolygon();
verts = ((PolygonObject* )baseObject)->GetPoint();
seg = ((PolygonObject* )baseObject)->GetPointCount();
// Assign substitutions if vertices are same
if ((subs = (LONG* )GeAlloc(sizeof(LONG)*seg)) == NULL) throw ErrorException(ERROR_MEMORY, NULL);
for (i = 0; i < seg; i++) subs _= -1;
for (i = 0; i < seg; i++)
{
for (a = i+1; a < seg; a++)
{
if ((subs[a] < 0) && (verts[a] == verts _)) subs[a] = i;
}
}
for (w = weld; w != NULL; w = (ParentChild* )w->GetNext())
{
if ((c = w->GetChild()) == NULL) continue;
if ((group = c->GetGroup()) == NULL) continue;

bs = group->GetBaseSelect();
seg=0;
while (bs->GetRange(seg++,&a;,&b;))
{
for (i=a; i<=b; ++i)
{
for (fi = &(polys _.a), fid = fi+5; fi != fid; fi++)
{
if (subs[*fi] != -1) *fi = subs[*fi];
}
}
}
}
GeFree(subs);
}
``````

Robert