Meshlab:调用Meshlab命令行版本

3
如何从C++程序或JavaScript中调用MeshLab命令行版本? 我尝试了以下代码,但没有成功。我需要从输入的.obj文件创建减少多边形(.obj文件)。
#include <windows.h>
#include <cstdlib>

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

}
2个回答

0

很奇怪,它本应该能够工作。检查一下你的路径。

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


0
首先,这是我在程序中使用的C++代码来调用meshlab(作为查看器)。它与你的代码非常相似,但如果你在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

where quadric.mlx is a file like this, but replacing the 1400 in the target number of triangles in the first "

<!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>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接