Author Topic: Anyone use CGAL?  (Read 3708 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Anyone use CGAL?
« on: August 24, 2010, 12:01:02 AM »
CGAL @ www.cgal.org

It's kind of a pain to get installed/compiled, but it has some really cool stuff in it.
I tried one of the many triangle algorithms and here are the results

only calculating the triangles
3.21761 seconds - 213,093 points
162.707 seconds - 3,265,110 points

calculating triangles and drawing 3d faces
4.342942 seconds - 213,093 points
254.525742 seconds - 3,265,110 points

Code: [Select]
  static void ArxPointCloud_tpc(void)
  {
    CalDelaunay dt;
    ads_name name = {0L,0L};
    ads_point point = {0.0,0.0,0.0};
    if(acedEntSel(_T("Select Point Cloud"),name,point) != RTNORM)
      return;

    LARGE_INTEGER freq,start,end;   
    QueryPerformanceFrequency(&freq);
    QueryPerformanceCounter(&start);

    // My Point cloud object
    AcDbObjectPointer<ExtPointCloud> pCloud( (AcDbObjectId)(AcDbStub*)name[0],AcDb::kForRead);
    if(pCloud.openStatus() != Acad::eOk)
      return;

    // inserting does the Delaunay!?!
    const AcGePoint3dArray &points = pCloud->PointArray();
    for (long i = 0; i < points.length(); i++)
      dt.insert(CalPoint(points[i].x,points[i].y,points[i].z));

    AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase();
    AcDbBlockTableRecordPointer pBlockTableRecord(pDB->currentSpaceId(),AcDb::kForWrite);
    if(pBlockTableRecord.openStatus() != Acad::eOk)
      return;

    AcGePoint3d A,B,C;

    for (CalDelaunay::Finite_faces_iterator it = dt.finite_faces_begin();
                                             it!=dt.finite_faces_end();++it)
    {
      const CalPoint& pt0 =  (*it).vertex(0)->point();
      const CalPoint& pt1 =  (*it).vertex(1)->point();
      const CalPoint& pt2 =  (*it).vertex(2)->point();

      AcDbFace *pFace = new AcDbFace();
      if(pFace)
      {
        A.x = pt0.x(); A.y = pt0.y(); A.z = pt0.z();
        B.x = pt1.x(); B.y = pt1.y(); B.z = pt1.z();
        C.x = pt2.x(); C.y = pt2.y(); C.z = pt2.z();

        pFace->setVertexAt(0, A);
        pFace->setVertexAt(1, B);
        pFace->setVertexAt(2, C);
        pFace->setVertexAt(3, A);

        if(pBlockTableRecord->appendAcDbEntity(pFace) != Acad::eOk)
          delete pFace;
        else
          pFace->close();
      }
    }

    QueryPerformanceCounter(&end);
    acutPrintf(_T("\n%g seconds - %ld points"),
      (double)(end.QuadPart-start.QuadPart)/freq.QuadPart,points.length() );
  }

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: Anyone use CGAL?
« Reply #1 on: August 24, 2010, 01:16:06 AM »
so fantastic!
I have been wondering to use CGAL for a long time.

about Delaunay,I made a routine for autocad 2004-2006 too.

this one is my work.
type "DDD" ,select the point cloud , then you can get  the delaunay triangles.

I am a bilingualist,Chinese and Chinglish.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: Anyone use CGAL?
« Reply #2 on: August 24, 2010, 01:56:59 AM »
Seems I was doing something wrong ,  this code is much faster

calcs only
0.306322 seconds - 213,093 points
4.976534 seconds - 3,265,110 points

calcs and drawing
1.433781 seconds - 213093 points
97.373313 seconds - 3265110 points

Code: [Select]
static void ArxPointCloud_tpc(void)
  {
    CalDelaunay dt;
    ads_name name = {0L,0L};
    ads_point point = {0.0,0.0,0.0};
    if(acedEntSel(_T("Select Point Cloud"),name,point) != RTNORM)
      return;

    LARGE_INTEGER freq,start,end;   
    QueryPerformanceFrequency(&freq);
    QueryPerformanceCounter(&start);

    // My Point cloud object
    AcDbObjectPointer<ExtPointCloud> pCloud( (AcDbObjectId)(AcDbStub*)name[0],AcDb::kForRead);
    if(pCloud.openStatus() != Acad::eOk)
      return;

   
    const AcGePoint3dArray &points = pCloud->PointArray();
    std::vector<CalPoint> calPoints;
    calPoints.reserve(points.length());

    for (long i = 0; i < points.length(); i++)
      calPoints.push_back(CalPoint(points[i].x,points[i].y,points[i].z));

    // inserting does the Delaunay!?!
    dt.insert(calPoints.begin(),calPoints.end());

    AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase();
    if(!pDB) return;

    AcDbBlockTableRecordPointer pBlockTableRecord(pDB->currentSpaceId(),AcDb::kForWrite);
    if(pBlockTableRecord.openStatus() != Acad::eOk)
      return;

    AcGePoint3d A,B,C;

    for (CalDelaunay::Finite_faces_iterator it = dt.finite_faces_begin();
                                             it!=dt.finite_faces_end();++it)
    {
      const CalPoint& pt0 =  (*it).vertex(0)->point();
      const CalPoint& pt1 =  (*it).vertex(1)->point();
      const CalPoint& pt2 =  (*it).vertex(2)->point();

      AcDbFace *pFace = new AcDbFace();
      if(pFace)
      {
        A.x = pt0.x(); A.y = pt0.y(); A.z = pt0.z();
        B.x = pt1.x(); B.y = pt1.y(); B.z = pt1.z();
        C.x = pt2.x(); C.y = pt2.y(); C.z = pt2.z();

        pFace->setVertexAt(0, A);
        pFace->setVertexAt(1, B);
        pFace->setVertexAt(2, C);
        pFace->setVertexAt(3, A);

        if(pBlockTableRecord->appendAcDbEntity(pFace) != Acad::eOk)
          delete pFace;
        else
          pFace->close();
      }
    }

    QueryPerformanceCounter(&end);
    acutPrintf(_T("\n%g seconds - %ld points"),
      (double)(end.QuadPart-start.QuadPart)/freq.QuadPart,points.length() );
  }

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: Anyone use CGAL?
« Reply #3 on: August 24, 2010, 01:58:01 AM »
so fantastic!
I have been wondering to use CGAL for a long time.

about Delaunay,I made a routine for autocad 2004-2006 too.

this one is my work.
type "DDD" ,select the point cloud , then you can get  the delaunay triangles.



Man yours is smoking fast!

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: Anyone use CGAL?
« Reply #4 on: August 24, 2010, 02:04:01 AM »
here are your times highflybird... nice work  8-)

The time for Collecting points is :0.227737 Seconds.
There are 212996 points.
The time for Delaunay is :0.357808 Seconds.
The time for Drawing Delaunay is :1.934219 Seconds

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: Anyone use CGAL?
« Reply #5 on: August 24, 2010, 02:42:17 AM »
Anway, I was thinking of adding something like this for my point cloud stuff
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Surface_reconstruction_points_3/Chapter_main.html

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: Anyone use CGAL?
« Reply #6 on: August 24, 2010, 06:00:15 AM »
some day I will try it.
It will save a lot of time.
Hi,Daniel,could you introduce how to use it?Thank you very much.
I am a bilingualist,Chinese and Chinglish.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7033
  • AKA Daniel
Re: Anyone use CGAL?
« Reply #7 on: August 24, 2010, 09:09:23 AM »
Just install boost (make sure to include the threading library) , which is a really cool to have anyway.
download cgal, and the latest vision of cmake (creates the VS solution for you). It took me a couple of hours of fiddling to get cmake to build the solution, but this was more of an issue of it finding my compiler on a x64 bit machine...

I posted my solution in the show my stuff area
http://www.theswamp.org/index.php?topic=34607.0