2013-10-23 14 views
12

qhull 라이브러리 (qhull.org)는 그의 웹 사이트에서 시작하는 몇 가지 예제가 있지만 C++ 관련 정보는별로 유용하지 않습니다.qhull 라이브러리 - C++ 인터페이스

파일에서 읽은 3D 점의 단순한 볼록 헐을 만들려고합니다. 웹 사이트에서 qhull.exe를 외부 응용 프로그램으로 호출하는 기술을 사용할 수 없습니다. 내가 데이터 포인트에서 만든 일부 수정에서 여러 볼록 선체를 만듭니다.

이 작업을 수행하는 간단한 예제를 찾을 수 없지만 누군가이 작업에 도움을 줄 수 있습니까? 모든 정보가 유용 할 것입니다.

덕분에 나는 C++로 자신을 Qhull를 사용하여 하드 시간이 있었고, 웹에 유용한 예제를 찾을 수 없습니다, anddddd 마지막으로 유효한 결과를 얻는 데 성공했기 때문에

+0

windows 또는 linux? – pippin1289

+0

나는 창문을 사용하고있다 –

답변

10

, 나는 미래를 위해 여기에 내 코드를 게시하도록하겠습니다 용도.

이 답변은 2012/3 Visual Studio와 함께 Windows에서 작동합니다. 그것은 다른 플랫폼

에 작동하는 경우에 나는 그래서, 당신이 추가 될 필요가있는 파일 만 here 에서 qhull 소스 파일을 다운로드 VS에서 프로젝트를 연 후, 일을 시작하는 방법을 알고하지 않거나 다음 2 디렉토리 :

Qhull.h

:

libqhull/... 
libqhullcpp/... 

프로젝트에이 파일을 추가 한 후는, (분명히 당신이 당신의 자신의 방법을 사용할 수 있습니다, 이건 내 방법) 다음 코드를 추가 17,451,515,

namespace orgQhull{ 
//... 
private: 
    PointCoordinates *m_externalPoints; 
//... 
public: 
    void runQhull3D(const std::vector<vec3> &points, const char* args); 
    void runQhull(const PointCoordinates &points, const char *qhullCommand2); 
//... 
} 

Qhull.cpp

void Qhull::runQhull3D(const std::vector<vec3> &points, const char* args) 
{ 
    m_externalPoints = new PointCoordinates(3); //3 = dimension 
    vector<double> allPoints; 
    for each (vec3 p in points) 
    { 
     allPoints.push_back(p.x()); 
     allPoints.push_back(p.y()); 
     allPoints.push_back(p.z()); 
    } 

    m_externalPoints->append(allPoints); //convert to vector<double> 
    runQhull(*m_externalPoints, args); 
} 

void Qhull::runQhull(const PointCoordinates &points, const char *qhullCommand2) 
{ 
    runQhull(points.comment().c_str(), points.dimension(), points.count(), &*points.coordinates(), qhullCommand2); 
} 

마지막으로이 코드를 사용하는 방법입니다 :

//not sure all these includes are needed 
#include "RboxPoints.h" 
#include "QhullError.h" 
#include "Qhull.h" 
#include "QhullQh.h" 
#include "QhullFacet.h" 
#include "QhullFacetList.h" 
#include "QhullLinkedList.h" 
#include "QhullVertex.h" 
#include "QhullSet.h" 
#include "QhullVertexSet.h" 
#include <vector> 

int main() 
{ 
    orgQhull::Qhull qhull; 
    std::vector<vec3> vertices; 
    qhull.runQhull3D(vertices, "Qt"); 

    QhullFacetList facets = qhull.facetList(); 
    for (QhullFacetList::iterator it = facets.begin(); it != facets.end(); ++it) 
    { 
     if (!(*it).isGood()) continue; 
     QhullFacet f = *it; 
     QhullVertexSet vSet = f.vertices(); 
     for (QhullVertexSet::iterator vIt = vSet.begin(); vIt != vSet.end(); ++vIt) 
     { 
      QhullVertex v = *vIt; 
      QhullPoint p = v.point(); 
      double * coords = p.coordinates(); 
      vec3 aPoint = vec3(coords[0], coords[1], coords[2]); 
      // ...Do what ever you want 
     } 
    } 

    // Another way to iterate (c++11), and the way the get the normals 
    std::vector<std::pair<vec3, double> > facetsNormals; 
    for each (QhullFacet facet in qhull.facetList().toStdVector()) 
    { 
     if (facet.hyperplane().isDefined()) 
     { 
      auto coord = facet.hyperplane().coordinates(); 
      vec3 normal(coord[0], coord[1], coord[2]); 
      double offset = facet.hyperplane().offset(); 
      facetsNormals.push_back(std::pair<vec3, double>(normal, offset)); 
     } 
    } 
} 

내 프로젝트에서이 코드를 복사하고 더 많은 정보를하지만 피난처로 그것을 약간 수정 한 이 예제를 컴파일하지 않았습니다.

+0

이것은 쓰레드에 안전하지 않다. – Raaj

+0

@Raaj는 다른 이들에게 그것을 지적 해 주셔서 감사한다. 스레드 안전 코드로 답을 자유롭게 편집하면 검토하고 수락합니다. – ZivS

+0

없습니다. 나는 전체 인터넷/github/codeproject 모든 것을 살펴 봤다. Convex/Concave 선체 알고리즘의 C/C++ 예제는 없습니다. – Raaj