# Fast way to get polygon index per vertex [SOLVED]

• On 05/03/2015 at 12:22, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   14,15,16
Platform:   Windows  ;
Language(s) :     C++  ;

---------
Hi,

I am using this code to get the polygon index that every vertex belongs to, but it's very slow.
Is there a faster way to do it?

``````const CPolygon *pPolys = pobj->GetPolygonR();
for (int i = 0; i<pointCnt; i++)
{
for (int j=0; j<polyCnt; j++)
{
if (pPolys[j].a == i)
myIndexArray[i] = j;		//	myIndexArray is an integer BaseArray that is storing the polygon indices

}
}
``````

Since I am manually going over every vertex and from it check every polygon, the operation is very slow. I am hoping someone can give a faster alternative.

Thanks

• On 05/03/2015 at 12:45, xxxxxxxx wrote:

not sure, but a little better version:

``````
const CPolygon *pPolys = pobj->GetPolygonR();
for (int i = 0; i<pointCnt; i++)
{
for (int j=0; j<polyCnt; j++)
{
if (pPolys[j].a == i)
{
myIndexArray[i] = j;		//	myIndexArray is an integer BaseArray that is storing the polygon indices
break;
}
else if (pPolys[j].b == i)
{
myIndexArray[i] = j;		//	myIndexArray is an integer BaseArray that is storing the polygon indices
break;
}
else if (pPolys[j].c == i)
{
myIndexArray[i] = j;		//	myIndexArray is an integer BaseArray that is storing the polygon indices
break;
}
else if (pPolys[j].d == i)
{
myIndexArray[i] = j;		//	myIndexArray is an integer BaseArray that is storing the polygon indices
break;
}
}
}
``````

• On 05/03/2015 at 12:55, xxxxxxxx wrote:

and I think this version will be much better:

``````const CPolygon *pPolys = pobj->GetPolygonR();
//for(int i = 0; i<myIndexArray.size();++i)
//{
//	myIndexArray _= -1;_
_//}_
_
_
_for(int j = 0; j <polyCnt; ++j)_
_{_
_	 myIndexArray[pPolys[j].a] = j;_
_	 myIndexArray[pPolys[j].b] = j;_
_	 myIndexArray[pPolys[j].c] = j;_
_	 myIndexArray[pPolys[j].d] = j;_
_}_
_
``````

edit: the point can have many polygons, so depends on your needs you can modify it to get all polygons "not only last poly index"_
_
_
__

• On 05/03/2015 at 13:18, xxxxxxxx wrote:

Thanks a lot Mohamed. I ended up using your first suggestion. Using BREAK was the key to make the operation go faster.