, 나는 미래를 위해 여기에 내 코드를 게시하도록하겠습니다 용도.
이 답변은 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));
}
}
}
내 프로젝트에서이 코드를 복사하고 더 많은 정보를하지만 피난처로 그것을 약간 수정 한 이 예제를 컴파일하지 않았습니다.
windows 또는 linux? – pippin1289
나는 창문을 사용하고있다 –