Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Fast way to get polygon index per vertex [SOLVED]

    SDK Help
    0
    4
    382
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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;
        		}
        	}
        }
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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"_
          _
          _
          __

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post