void getFacetFromSurfaceBodies( const vector& inSurfaceBody)
{
HRESULT hr = S_OK;
vector arrVertex;
vector arrIndex;
int currIndex=0;
for(int i=0;i<inSurfaceBody.size();i++)
{
SurfaceBodyPtr surfaceBody = inSurfaceBody[i];
//Determine the highest tolerance of the existing facet sets.
long toleranceCount;
SAFEARRAY* existingTol =NULL ;
double* pTols;
surfaceBody->GetExistingFacetTolerances(&toleranceCount,&existingTol);
long index = 0;
double bestTol=0.1;
hr = SafeArrayGetElement(existingTol,&index,&bestTol);
for (long i = 1; i < toleranceCount; i++)
{
double tol;
hr = SafeArrayGetElement(existingTol,&i,&tol);
if (tol < bestTol)
bestTol = tol;
}
//Get a set of existing facets.
long vertexCount;
long facetCount;
//Calculate Facets on each Surface Body
SAFEARRAY* vertexCoords = NULL;
SAFEARRAY* normalVectors = NULL;
SAFEARRAY* vertexIndices = NULL;
hr=surfaceBody->CalculateFacets(bestTol,&vertexCount,&facetCount,
&vertexCoords,&normalVectors,&vertexIndices);
int length;
long lBound;
long uBound;
unsigned int dim = SafeArrayGetDim(vertexCoords);
hr = SafeArrayGetLBound(vertexCoords,dim,&lBound);
hr = SafeArrayGetUBound(vertexCoords,dim,&uBound);
length = (uBound - lBound)+1;
size_t lastVSize = arrVertex.size();
arrVertex.resize(lastVSize+length);
//Get x,y,z coordinate of each vertex
float x,y,z;
for(long i=0;i<length;i+=3)
{
SafeArrayGetElement(vertexCoords,&i,&x);
arrVertex[lastVSize+i] = x;
i++;
SafeArrayGetElement(vertexCoords,&i,&y);
arrVertex[lastVSize+i] = y;
i++;
SafeArrayGetElement(vertexCoords,&i,&z);
arrVertex[lastVSize+i] = z;
}
//Get indices from index array to create facet
lastVSize = arrIndex.size();
arrIndex.resize(lastVSize+ (facetCount*3));
for(long i=0;i<facetCount*3;i++)
{
int val;
SafeArrayGetElement(vertexIndices,&i,&val);
arrIndex[lastVSize+i] = currIndex + val-1;
}
currIndex = arrVertex.size()/3;
}
return S_OK;
}