Skip to content

Commit

Permalink
mesh2ply : option to clean input mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
valette committed Jul 11, 2024
1 parent ffd6437 commit 7245b03
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
5 changes: 5 additions & 0 deletions ACVD.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@
"name": "inputMesh",
"type": "file",
"required": true
},
{
"name": "clean",
"type": "flag",
"prefix" : "1"
}
],
"executable": "bin/mesh2ply"
Expand Down
29 changes: 20 additions & 9 deletions Common/Examples/mesh2ply.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Author: Sebastien Valette
// .SECTION Description

#include "vtkSurface.h"
#include <vtkCleanPolyData.h>
#include <vtkPLYWriter.h>

/// a simple mesh consersion tool
Expand All @@ -43,22 +44,32 @@ Author: Sebastien Valette

int main( int argc, char *argv[] )
{
vtkSurface *Mesh;

if (argc<2)
{
cout<<"Usage : mesh2ply inputmesh"<<endl;
cout<<"Usage : mesh2ply inputmesh clean"<<endl;
exit(1);
}

// Load the mesh and create the vtkSurface data structure
Mesh=vtkSurface::New();
vtkSurface *mesh = vtkSurface::New();
cout <<"load : "<<argv[1]<<endl;
Mesh->CreateFromFile(argv[1]);
vtkPLYWriter *Writer=vtkPLYWriter::New();
Writer->SetInputData(Mesh);
Writer->SetFileName("mesh.ply");
Writer->Write();
mesh->CreateFromFile(argv[1]);
mesh->DisplayMeshProperties();
vtkPolyData *m = mesh;

if ( argc > 2 ) {
if ( atoi( argv[ 2 ] ) == 1 ) {
vtkCleanPolyData *cleaner = vtkCleanPolyData::New();
cleaner->SetInputData( mesh );
cleaner->Update();
m = cleaner->GetOutput();
}
}

vtkNew<vtkPLYWriter> writer;
writer->SetInputData( m );
writer->SetFileName("mesh.ply");
writer->Write();
cout<<"conversion to mesh.ply finished!"<<endl;
return (0);
}
33 changes: 31 additions & 2 deletions js/ACVD.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

{
const { async, desk } = window;
const { require, async, desk } = window;

const ACVD = {};

Expand Down Expand Up @@ -38,5 +38,34 @@

} ;

ACVD.cleanMeshes = async function ( inputDir, outputDir ) {

const path = require( "path" );
await desk.FileSystem.traverseAsync( inputDir, async function ( inputMesh, cb ) {

const clean = await desk.Actions.executeAsync( {
action : "mesh2ply",
inputMesh,
clean : true
} );

const relative = path.relative( inputDir, inputMesh );
const destination = path.join( outputDir, relative );
const destDir = path.dirname( destination );
await desk.FileSystem.mkdirpAsync( destDir );

await desk.Actions.executeAsync( {
action : "copy",
source : path.join( clean.outputDirectory, "mesh.ply" ),
destination
} );

cb();

}, true );

};

window.ACVD = ACVD;
}
}
console.clear();

0 comments on commit 7245b03

Please sign in to comment.