如何从C ++程序或javascript中调用meshlab命令行版本 我尝试了以下代码,但没有奏效。我需要从输入的(.obj文件)
创建缩小的多边形(.obj文件)#include <windows.h>
#include <cstdlib>
int main()
{
std::system("path of meshlab.exe");
}
答案 0 :(得分:0)
这很奇怪,应该有用。检查你的路径。
您还可以查看meshlabserver.exe
。
它是meshlab的命令行版本。
答案 1 :(得分: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是这样的文件,但替换了第一个“
<!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.<br>The value is in the range [0..1]
 0 accept any kind of face (no penalties),
 0.5 penalize faces with quality < 0.5, proportionally to their shape
" 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.
 It can fail (creating bad spikes) in case of very flat areas. 
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.
 Take care of the target number of faces!" name="Selected" type="RichBool" description="Simplify only selected faces"/>
</filter>
</FilterScript>