{
int i,j,n;
int nvert,nelmt;
int niso=iso.size();
int id1,id2;
Array<OneD, Array<OneD, int> > vidmap;
vidmap = Array<OneD, Array<OneD, int> > (niso);
for(i = 0; i < niso; ++i)
{
if(iso[i]->m_ntris)
{
m_ntris += iso[i]->m_ntris;
}
}
for(i = 0; i < niso; ++i)
{
if(iso[i]->m_ntris)
{
m_nvert += iso[i]->m_nvert;
}
}
vector< vector<int> > isocon;
isocon.resize(niso);
{
vector<Array<OneD, NekDouble> > sph(niso);
Array<OneD, NekDouble> rng(6);
for(i = 0; i < niso; ++i)
{
sph[i] = Array<OneD, NekDouble>(4);
rng[0] = rng[3] = iso[i]->m_x[0];
rng[1] = rng[4] = iso[i]->m_x[1];
rng[2] = rng[5] = iso[i]->m_x[2];
for(id1 = 1; id1 < iso[i]->m_nvert;++id1)
{
rng[0] = min(rng[0],iso[i]->
m_x[i]);
rng[1] = min(rng[1],iso[i]->
m_y[i]);
rng[2] = min(rng[2],iso[i]->
m_z[i]);
rng[3] = max(rng[3],iso[i]->
m_x[i]);
rng[4] = max(rng[4],iso[i]->
m_y[i]);
rng[5] = max(rng[5],iso[i]->
m_z[i]);
}
sph[i][0] = (rng[3]+rng[0])/2.0;
sph[i][1] = (rng[4]+rng[1])/2.0;
sph[i][2] = (rng[5]+rng[2])/2.0;
sph[i][3] = sqrt((rng[3]-rng[0])*(rng[3]-rng[0]) +
(rng[4]-rng[1])*(rng[4]-rng[1]) +
(rng[5]-rng[2])*(rng[5]-rng[2]));
}
for(i = 0; i < niso; ++i)
{
for(j = i+1; j < niso; ++j)
{
NekDouble diff=sqrt((sph[i][0]-sph[j][0])*(sph[i][0]-sph[j][0])+
(sph[i][1]-sph[j][1])*(sph[i][1]-sph[j][1])+
(sph[i][2]-sph[j][2])*(sph[i][2]-sph[j][2]));
if(diff < sph[i][3] + sph[j][3])
{
isocon[i].push_back(j);
}
}
}
}
for(i = 0; i < niso; ++i)
{
vidmap[i] = Array<OneD, int>(iso[i]->m_nvert,-1);
}
nvert = 0;
cout << "Matching Vertices [" <<flush;
int cnt = 0;
for(i = 0; i < niso; ++i)
{
for(n = 0; n < isocon[i].size(); ++n)
{
int con = isocon[i][n];
for(id1 = 0; id1 < iso[i]->m_nvert;++id1)
{
for(id2 = 0; id2 < iso[con]->m_nvert;++id2,++cnt)
{
if(cnt%1000000 == 0)
{
cout <<"." <<flush;
}
{
iso[i]->
m_z[id1], iso[con]->
m_x[id2],
iso[con]->
m_y[id2],iso[con]->
m_z[id2]))
{
if((vidmap[i][id1] == -1) &&
(vidmap[con][id2] != -1))
{
vidmap[i][id1] = vidmap[con][id2];
}
else if((vidmap[con][id2] == -1) &&
(vidmap[i][id1] != -1))
{
vidmap[con][id2] = vidmap[i][id1];
}
else if((vidmap[con][id2] == -1) &&
(vidmap[i][id1] == -1))
{
vidmap[i][id1] = vidmap[con][id2] = nvert++;
}
}
}
}
}
}
for(id1 = 0; id1 < iso[i]->m_nvert;++id1)
{
if(vidmap[i][id1] == -1)
{
vidmap[i][id1] = nvert++;
}
}
}
cout <<"]"<<endl;
m_nvert = nvert;
nelmt = 0;
for(n = 0; n < niso; ++n)
{
for(i = 0; i < iso[n]->m_ntris; ++i,nelmt++)
{
for(j=0; j < 3;++j)
{
m_vid[3*nelmt+j] = vidmap[n][iso[n]->m_vid[3*i+j]];
}
}
}
m_ntris = nelmt;
for(i = 0; i < iso[0]->m_fields.size(); ++i)
{
}
for(n = 0; n < niso; ++n)
{
for(i = 0; i < iso[n]->m_nvert; ++i)
{
m_x[vidmap[n][i]] = iso[n]->m_x[i];
m_y[vidmap[n][i]] = iso[n]->m_y[i];
m_z[vidmap[n][i]] = iso[n]->m_z[i];
{
m_fields[j][vidmap[n][i]] = iso[n]->m_fields[j][i];
}
}
}
}