OECalculateTriangleAreas

bool OECalculateTriangleAreas(const OESurface &surf, float *areas)

Will calculate the area of every triangle of surf and store the result in the array areas of that should be large enough to hold GetNumTriangles() floats. The array is indexed by the triangle indices.

Listing 1 demonstrates how to calculate the surface area contribution from each atom. It is assumed surf is an OESurface created from the molecule mol.

Listing 1: Calculates the surface area contribution from each atom

float *areas = new float[surf.GetNumTriangles()];
OECalculateTriangleAreas(surf, areas);

float *atomareas = new float[mol.GetMaxAtomIdx()];
memset(atomareas, 0, mol.GetMaxAtomIdx()*sizeof(float));

unsigned int tri[3];
unsigned int a1, a2, a3;
for (unsigned int i=0; i < surf.GetNumTriangles(); i++)
{
  surf.GetTriangle(i, tri);
  
  a1 = surf.GetAtomsElement(tri[0]);
  a2 = surf.GetAtomsElement(tri[1]);
  a3 = surf.GetAtomsElement(tri[2]);
  
  atomareas[a1] += areas[i]/3.0f;
  atomareas[a2] += areas[i]/3.0f;
  atomareas[a3] += areas[i]/3.0f;
}

for (OEIter<OEAtomBase> atom = mol.GetAtoms(); atom; ++atom)
  std::cout<<"atom "<<atom->GetIdx()<<" area = "<<atomareas[atom->GetIdx()]<<std::endl;

delete[] areas;
delete[] atomareas;