3

如何从 C++ 程序或 javascript 中调用 meshlab 命令行版本我尝试了以下代码,但没有成功。我需要从输入的(.obj 文件)创建简化的多边形(.obj 文件)

#include <windows.h>
#include <cstdlib>

int main()
{
    std::system("path of meshlab.exe");

}
4

2 回答 2

0

这很奇怪,它应该有效。检查你的路径。

你也可以看看meshlabserver.exe。这是 meshlab 的命令行版本。

于 2015-01-16T09:47:59.097 回答
0

首先,这是我用来在我的程序中调用 meshlab(作为查看器)的 C++ 代码。它与您的非常相似,但是如果您在 Windows 中,您必须格外小心正确地转义空格和反斜杠,所以这可能是您的问题。

///////////////////////////////////////////////////////////////////////
//Save mesh to a file in .obj format
string outputFilename="output_meshColor.obj";

//Visualize the .obj file with an external viewer
#ifdef WIN32
    //Path to meshlab 2016.12    
    string viewcmd = "\"C:\\Program Files (x86)\\VCG\\MeshLab\\meshlab.exe\"";
    //Path to meshlab 1.32
    //string viewcmd = "C:/meshlab/meshlab_32.exe";
#else
    //Path to meshlab in linux
    string viewcmd = "/usr/bin/meshlab >/dev/null 2>&1 ";
#endif

string cmd = viewcmd+" "+outputFilename;
cout << "Executing external command: " << cmd << endl;
int result = std::system(cmd.c_str());

接下来,正如 lelabo_m 所指出的,您应该考虑使用它meshlabserver来自动创建缩减多边形网格。您需要使用的命令是

meshlabserver -i inputMesh.obj -o reducedMesh.obj -s quadric.mlx

其中 quadric.mlx 是这样的文件,但在第一个“三角形的目标数量”中替换了 1400

<!DOCTYPE FilterScript>
<FilterScript>
 <filter name="Simplification: Quadric Edge Collapse Decimation">
  <Param  value="1400" tooltip="The desired final number of faces." name="TargetFaceNum" type="RichInt" description="Target number of faces"/>
  <Param  value="0" tooltip="If non zero, this parameter specifies the desired final size of the mesh as a percentage of the initial size." name="TargetPerc" type="RichFloat" description="Percentage reduction (0..1)"/>
  <Param  value="0.3" tooltip="Quality threshold for penalizing bad shaped faces.&lt;br>The value is in the range [0..1]&#xa; 0 accept any kind of face (no penalties),&#xa; 0.5  penalize faces with quality &lt; 0.5, proportionally to their shape&#xa;" name="QualityThr" type="RichFloat" description="Quality threshold"/>
  <Param  value="false" tooltip="The simplification process tries to do not affect mesh boundaries during simplification" name="PreserveBoundary" type="RichBool" description="Preserve Boundary of the mesh"/>
  <Param  value="1" tooltip="The importance of the boundary during simplification. Default (1.0) means that the boundary has the same importance of the rest. Values greater than 1.0 raise boundary importance and has the effect of removing less vertices on the border. Admitted range of values (0,+inf). " name="BoundaryWeight" type="RichFloat" description="Boundary Preserving Weight"/>
  <Param  value="true" tooltip="Try to avoid face flipping effects and try to preserve the original orientation of the surface" name="PreserveNormal" type="RichBool" description="Preserve Normal"/>
  <Param  value="false" tooltip="Avoid all the collapses that should cause a topology change in the mesh (like closing holes, squeezing handles, etc). If checked the genus of the mesh should stay unchanged." name="PreserveTopology" type="RichBool" description="Preserve Topology"/>
  <Param  value="true" tooltip="Each collapsed vertex is placed in the position minimizing the quadric error.&#xa; It can fail (creating bad spikes) in case of very flat areas. &#xa;If disabled edges are collapsed onto one of the two original vertices and the final mesh is composed by a subset of the original vertices. " name="OptimalPlacement" type="RichBool" description="Optimal position of simplified vertices"/>
  <Param  value="false" tooltip="Add additional simplification constraints that improves the quality of the simplification of the planar portion of the mesh, as a side effect, more triangles will be preserved in flat areas (allowing better shaped triangles)." name="PlanarQuadric" type="RichBool" description="Planar Simplification"/>
  <Param  value="0.001" tooltip="How much we should try to preserve the triangles in the planar regions. If you lower this value planar areas will be simplified more." name="PlanarWeight" type="RichFloat" description="Planar Simp. Weight"/>
  <Param  value="false" tooltip="Use the Per-Vertex quality as a weighting factor for the simplification. The weight is used as a error amplification value, so a vertex with a high quality value will not be simplified and a portion of the mesh with low quality values will be aggressively simplified." name="QualityWeight" type="RichBool" description="Weighted Simplification"/>
  <Param  value="true" tooltip="After the simplification an additional set of steps is performed to clean the mesh (unreferenced vertices, bad faces, etc)" name="AutoClean" type="RichBool" description="Post-simplification cleaning"/>
  <Param  value="false" tooltip="The simplification is applied only to the selected set of faces.&#xa; Take care of the target number of faces!" name="Selected" type="RichBool" description="Simplify only selected faces"/>
 </filter>
</FilterScript>
于 2019-10-30T13:53:43.843 回答