TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
The purpose of these forums is to discuss TurboCAD.  Please keep the discussion of other products to compatibility issues or how the other software’s can be used with TurboCAD.


Create surface faster
Read 2403 times
* February 03, 2010, 04:52:04 PM
Below is how I create a surface faset or triangle.
I need to call it 100000 time and it take an hour.
Is there a better faster way to do it?




HRESULT CreateQuad( Facets* pFacetsCol, Nodes* pNodesCol, SPoint& p0, SPoint& p1, SPoint& p2, SPoint& p3, long* id )
{
   if (pFacetsCol==NULL) return E_POINTER;
   if (pNodesCol==NULL) return E_POINTER;

#if !defined(_DEBUG)
      static HRESULT hRes;
#else
      HRESULT hRes;
#endif

      hRes = S_OK;

   try
   {
      static const long int numOfNodes = 4;
#if !defined(_DEBUG)
      static long int k;
      static long int pIndex[4];
      static long int StartIndex=-1L;
      static INode *pINode = NULL;
      static IFacet *pIFacet = NULL;
      static long index;
      static long L;
#else
      long int k;
      long int pIndex[4];
      long int StartIndex=-1L;
      INode *pINode = NULL;
      IFacet *pIFacet = NULL;
      long index;
      long L;
#endif
      pINode = NULL;
      pIFacet = NULL;
      hRes = pNodesCol->get_Count(&StartIndex);
      if (SUCCEEDED(hRes))
      {
         TRACE("Facet %d\n",StartIndex);
         hRes = pNodesCol->Add(&_variant_t(p0.x), &_variant_t(p0.y), &_variant_t(p0.z),
            &varOptional, &varOptional, &varOptional, &varOptional, &varOptional, &pINode);
         if (SUCCEEDED(hRes))
         {
            pINode->Release();
            hRes = pNodesCol->Add(&_variant_t(p1.x), &_variant_t(p1.y), &_variant_t(p1.z),
               &varOptional, &varOptional, &varOptional, &varOptional, &varOptional, &pINode);
            if (SUCCEEDED(hRes))
            {
               pINode->Release();
               hRes = pNodesCol->Add(&_variant_t(p2.x), &_variant_t(p2.y), &_variant_t(p2.z),
                  &varOptional, &varOptional, &varOptional, &varOptional, &varOptional, &pINode);
               if (SUCCEEDED(hRes))
               {
                  pINode->Release();
                  hRes = pNodesCol->Add(&_variant_t(p3.x), &_variant_t(p3.y), &_variant_t(p3.z),
                     &varOptional, &varOptional, &varOptional, &varOptional, &varOptional, &pINode);
                  if (SUCCEEDED(hRes))
                  {
                     pINode->Release();
                     for(k = 0; k < numOfNodes; k++ ) pIndex[k] = StartIndex + k;
                     if (FacetInd.vt==VT_EMPTY) FacetInd.CreateOneDim(VT_I4, numOfNodes, (void*)&pIndex[0]);
//                     if (FacetInd.vt==VT_EMPTY) FacetInd.CreateOneDim(VT_I4, numOfNodes);
                     for(k = 0; k < numOfNodes; k++ )
                     {
                        index = k;
                        L = StartIndex + k;
                        FacetInd.PutElement(&index,(void*)&L);
                     }
                     hRes = pFacetsCol->Add(FacetInd, &varOptional, &varOptional, &varOptional, &varOptional, &pIFacet);
                     if (SUCCEEDED(hRes))
                     {
//                        pIFacet->get_ID(id);
                        pIFacet->Release();
//                        TRACE("Facet %d\n",StartIndex);
                     }
                     else
                     {
                        TRACE("could not add faset to facet collection\n");
                     }
//                     FacetInd.Clear();
                  }
                  else
                  {
                     TRACE("could not add fourth note to node collection\n");
                  }
               }
               else
               {
                  TRACE("could not add third note to node collection\n");
               }
            }
            else
            {
               TRACE("could not add second note to node collection\n");
            }
         }
         else
         {
            TRACE("could not add first note to node collection\n");
         }
      }
      else
      {
         TRACE("could not get start index from node collection\n");
      }
   }
   catch(COleException e)
   {
      TRACE("CreateQuad through an OLE exception\n");
      return E_FAIL;
   }
   catch(CException e)
   {
      TRACE("CreateQuad through an C exception\n");
      return E_FAIL;
   }
   catch(...)
   {
      TRACE("CreateQuad through an unknown exception\n");
      return E_FAIL;
   }
   return hRes;
}

Logged