qhull库 - C ++接口 [英] qhull Library - C++ Interface

查看:2783
本文介绍了qhull库 - C ++接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

qhull库(qhull.org)有几个例子可以在他的网站开始,但关于C ++的所有信息对我来说都不是很有用。

The qhull library ( qhull.org) has several examples to start in his website, but all the information regarding to the C++ is not very useful to me.

我试图做一个简单的凸点Hull的3D点,我从一个文件中读取,我不能使用的建议在网站中调用qhull.exe作为一个外部应用程序的技术,因为我需要制作几个凸包从我在数据点做的一些修改。

I am trying to make a simple convex Hull of 3D points that I read from a file, I can´t use the technique that is suggested in the website of calling the qhull.exe as an external application because I need to make several convex hull from some modifications that I made in the data points.

我找不到一个简单的例子,这样做,有人可以给我一些帮助这个任务吗?

I can´t find a simple example for doing this, can someone give me some help in this task? Any information would be useful.

感谢

推荐答案

一个很难用Qhull与c ++自己,没有找到任何有用的例子在网络上,anddddd终于成功地获得有效的结果,我在这里张贴我的代码,供将来使用。

Since I had a hard time using Qhull with c++ myself and couldn't find any useful examples on the web, anddddd have finally succeeded in getting valid results, I'm posting my code here for future use.


这个答案适用于windows,与visual studio 2012/3。我不知道如何或者如果它在其他平台上工作

This answer works for windows, with visual studio 2012/3. I don't know how or if it works on other platforms

因此,从一开始,从下载qhull源文件< a href =http://www.qhull.org/download/qhull-2012.1.zip>这里
并在VS中打开项目,您需要添加的唯一文件是以下2个目录:

So, to start with things, after downloading qhull source files from here and opening a project in VS, the only files you need to be add are the following 2 directories:

libqhull/...
libqhullcpp/...

将这些文件添加到项目后,添加以下代码(这是我的方式,显然你可以使用自己的方式):

After adding these files to your project, add the following code (this is my way, obviously you can use your own way):

Qhull.h

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

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);
}

最后这是如何使用代码:

Finally this is how to use the code:

//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
    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(pair<vec3, double>(normal, offset));
        }
    }
}

项目,并且已经修改它有点更多信息,但没有编译此示例。

I copied this code from my project and have modified it a bit to be more informative but haven't compiled this example.

这篇关于qhull库 - C ++接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆