【问题标题】:provide qconvex's input in C++ Code在 C++ 代码中提供 qconvex 的输入
【发布时间】:2015-05-23 06:23:57
【问题描述】:

对于我的代码,我需要计算一系列点的 Convexhull,出于某些原因,我需要使用 qhull 库。在这个库中有一个方法qconvex 可以满足我的需要。我可以在终端中运行这个命令并得到我想要的。例如,假设我有一个像points.txt 这样的输入:

2   #dimension
5   #number of points
0 0
1 0
0.5 0.5
1 1
0 1

我可以在终端一中运行这些命令以获得结果:qconvex Fx < points.txtcat points.txt | qconvex -Fx,输出为:

4 
0
1
3
4

现在我的问题是如何在我的 C++ 代码中通过我的输入迭代地调用此命令:在我的代码中,我有 2 个 for 相互调用一个特定函数,每次将生成 10 个点(存储在 @ 987654329@) 我需要每次计算这 10 个点的 qconvex。如何在我的代码中运行qconvex 并将rs_tmp 作为其输入?宁愿避免将rs_tmp 写入某个临时文件并从中读取,因为我需要我的代码非常快。

float **rs_tmp;
for (int i = 0; i < NUMBER; i++)
{
    for (int j = 0; j < NUMBER; j++)
    {
        rs_tmp = generate_points(label, dect[i], dect[j], fun);
        // HERE I NEED TO CALL QCONVEX SOME HOW
        // THE POINTS ARE STORED IN rs_tmp as 2-Dimensional floating points array
    }
     int size = fun.size();
     for(int i = 0; i < size; ++i)     
     {
         delete[] rs_tmp[i]; 
     }   
     delete[] rs_tmp;         
}

【问题讨论】:

    标签: c++ command qhull


    【解决方案1】:

    我遇到同样的问题已经有一段时间了,只是设法解决了它。 Qhull 提供了一个非常简洁的示例,内容丰富。如果您从 git 克隆,您可以在目录 qhull/src/user_eg3/user_eg3.cpp 中看到示例。我花了一点时间来理解他们在做什么,但是一旦你掌握了它的窍门,它实际上很容易。除了您要查找的选项之外,我已删除所有额外选项。

    /*--------------------------------------------
    -user_eg3-  main procedure of user_eg3 application
    */
    int main(int argc, char **argv) {
        try{
            return user_eg3(argc, argv);
        }catch(QhullError &e){
            cerr << e.what() << std::endl;
            return e.errorCode();
        }
    }//main
    
    int user_eg3(int argc, char **argv)
    {
      RboxPoints rbox;
      Qhull qhull;
      line = "";
      std::istringstream is("2 4 1 0 1 1 0 0 0 1"); // To be passed to rbox: produces a unit square where 2 is the dimension 4 is the count and the points follow. This will also accept any valid rbox flags. 
      std::stringstream output;
    
      rbox.appendPoints(is); // appendPoints accepts either a const char* or an istream object. See libqhullcpp/RboxPoints.h and libqhullcpp/PointCoordinates.h 
    
      cerr << "@@@@@@@@@@\n" << rbox << "@@@@@@@@@@\n";
      qhull.runQhull(rbox, ""); //you can set any flag you would set for qhull in the terminal inside the ""
      qhull.setOutputStream(&output); //this will take any output stream 
      qhull.outputQhull("m"); //this will take any qhull output option
      cerr << "My Output : " << output.str() << "%%\n";
      qhull.setOutputStream(&cout);
      qhull.outputQhull("n");
      return 0;
    }//user_eg3
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      • 2016-08-12
      • 1970-01-01
      • 2017-03-15
      相关资源
      最近更新 更多