@@ -361,6 +361,140 @@ bool Scene::Export(const String& _fileName, const String& exportType, bool bView
361361 return bPoints || bMesh;
362362}
363363
364+ bool Scene::RunDensifyWorkflow (const DensifyWorkflowOptions& options) {
365+ if (!IsOpen ()) {
366+ DEBUG (" error: no scene loaded" );
367+ return false ;
368+ }
369+ if (scene.images .empty ()) {
370+ DEBUG (" error: scene has no images to densify" );
371+ return false ;
372+ }
373+
374+ MVS::OPTDENSE::init ();
375+ MVS::OPTDENSE::update ();
376+ MVS::OPTDENSE::nResolutionLevel = options.resolutionLevel ;
377+ MVS::OPTDENSE::nMaxResolution = options.maxResolution ;
378+ MVS::OPTDENSE::nMinResolution = options.minResolution ;
379+ MVS::OPTDENSE::nSubResolutionLevels = options.subResolutionLevels ;
380+ MVS::OPTDENSE::nNumViews = options.numViews ;
381+ MVS::OPTDENSE::nMinViews = MAXF (1u , options.minViews );
382+ MVS::OPTDENSE::nMinViewsTrustPoint = MAXF (1u , options.minViewsTrust );
383+ MVS::OPTDENSE::nMinViewsFuse = MAXF (1u , options.minViewsFuse );
384+ MVS::OPTDENSE::nEstimationIters = MAXF (1u , options.estimationIters );
385+ MVS::OPTDENSE::nEstimationGeometricIters = options.geometricIters ;
386+ MVS::OPTDENSE::nFuseFilter = CLAMP (options.fuseFilter , 0u , (unsigned )MVS::OPTDENSE::FUSE_DENSEFILTER);
387+ MVS::OPTDENSE::fDepthReprojectionErrorThreshold = options.fDepthReprojectionErrorThreshold ;
388+ MVS::OPTDENSE::nEstimateColors = options.estimateColors ? 2u : 0u ;
389+ MVS::OPTDENSE::nEstimateNormals = options.estimateNormals ? 2u : 0u ;
390+ MVS::OPTDENSE::bRemoveDmaps = options.removeDepthMaps ;
391+ MVS::OPTDENSE::nOptimize = options.postprocess ? (unsigned )MVS::OPTDENSE::OPTIMIZE : 0u ;
392+
393+ if (!scene.DenseReconstruction (options.fusionMode , options.cropToROI , options.borderROI , options.sampleMeshNeighbors )) {
394+ DEBUG (" error: dense reconstruction failed" );
395+ return false ;
396+ }
397+
398+ UpdateGeometryAfterModification ();
399+ return true ;
400+ }
401+
402+ bool Scene::RunReconstructMeshWorkflow (const ReconstructMeshWorkflowOptions& options) {
403+ if (!IsOpen ()) {
404+ DEBUG (" error: no scene loaded" );
405+ return false ;
406+ }
407+ if (!scene.pointcloud .IsValid ()) {
408+ DEBUG (" error: point-cloud is empty; run densify before reconstructing the mesh" );
409+ return false ;
410+ }
411+
412+ MVS::Scene& mvsScene = scene;
413+
414+ if (options.constantWeight )
415+ mvsScene.pointcloud .pointWeights .Release ();
416+
417+ if (!mvsScene.ReconstructMesh (options.minPointDistance , options.useFreeSpaceSupport , options.useOnlyROI ,
418+ 4 , options.thicknessFactor , options.qualityFactor )) {
419+ DEBUG (" error: mesh reconstruction failed" );
420+ return false ;
421+ }
422+
423+ if (options.cropToROI && mvsScene.IsBounded ()) {
424+ const size_t numVertices = mvsScene.mesh .vertices .size ();
425+ const size_t numFaces = mvsScene.mesh .faces .size ();
426+ mvsScene.mesh .RemoveFacesOutside (mvsScene.obb );
427+ VERBOSE (" Mesh trimmed to ROI: %u vertices and %u faces removed" ,
428+ (unsigned )(numVertices - mvsScene.mesh .vertices .size ()),
429+ (unsigned )(numFaces - mvsScene.mesh .faces .size ()));
430+ }
431+
432+ float decimate = options.decimateMesh ;
433+ if (options.targetFaceNum && !mvsScene.mesh .faces .empty ())
434+ decimate = static_cast <float >(options.targetFaceNum ) / mvsScene.mesh .faces .size ();
435+ decimate = CLAMP (decimate, 0 .f , 1 .f );
436+ if (decimate <= 0 .f )
437+ decimate = 1 .f ;
438+
439+ mvsScene.mesh .Clean (1 .f , options.removeSpurious , options.removeSpikes , options.closeHoles , options.smoothSteps , options.edgeLength , false );
440+ mvsScene.mesh .Clean (decimate, 0 .f , options.removeSpikes , options.closeHoles , 0u , 0 .f , false );
441+ mvsScene.mesh .Clean (1 .f , 0 .f , false , 0u , 0u , 0 .f , true );
442+
443+ UpdateGeometryAfterModification ();
444+ return true ;
445+ }
446+
447+ bool Scene::RunRefineMeshWorkflow (const RefineMeshWorkflowOptions& options) {
448+ if (!IsOpen ()) {
449+ DEBUG (" error: no scene loaded" );
450+ return false ;
451+ }
452+ if (scene.mesh .IsEmpty ()) {
453+ DEBUG (" error: mesh is empty; reconstruct a mesh before refining" );
454+ return false ;
455+ }
456+
457+ if (!scene.RefineMesh (options.resolutionLevel , options.minResolution , options.maxViews ,
458+ options.decimateMesh , options.closeHoles , options.ensureEdgeSize , options.maxFaceArea ,
459+ options.scales , options.scaleStep , options.alternatePair , options.regularityWeight ,
460+ options.rigidityElasticityRatio , options.gradientStep , options.planarVertexRatio ,
461+ options.reduceMemory )) {
462+ DEBUG (" error: mesh refinement failed" );
463+ return false ;
464+ }
465+
466+ UpdateGeometryAfterModification ();
467+ return true ;
468+ }
469+
470+ bool Scene::RunTextureMeshWorkflow (const TextureMeshWorkflowOptions& options) {
471+ if (!IsOpen ()) {
472+ DEBUG (" error: no scene loaded" );
473+ return false ;
474+ }
475+ if (scene.mesh .IsEmpty ()) {
476+ DEBUG (" error: mesh is empty; reconstruct or load a mesh before texturing" );
477+ return false ;
478+ }
479+
480+ float decimate = CLAMP (options.decimateMesh , 0 .f , 1 .f );
481+ if (decimate <= 0 .f )
482+ decimate = 1 .f ;
483+ scene.mesh .Clean (decimate, 0 .f , false , options.closeHoles , 0u , 0 .f , false );
484+ scene.mesh .Clean (1 .f , 0 .f , false , 0u , 0u , 0 .f , true );
485+
486+ if (!scene.TextureMesh (options.resolutionLevel , options.minResolution , options.minCommonCameras ,
487+ options.outlierThreshold , options.ratioDataSmoothness , options.globalSeamLeveling ,
488+ options.localSeamLeveling , options.textureSizeMultiple , options.rectPackingHeuristic ,
489+ Pixel8U (options.emptyColor ), options.sharpnessWeight , options.ignoreMaskLabel , options.maxTextureSize )) {
490+ DEBUG (" error: mesh texturing failed" );
491+ return false ;
492+ }
493+
494+ UpdateGeometryAfterModification ();
495+ return true ;
496+ }
497+
364498MVS::IIndex Scene::ImageIdxMVS2Viewer (MVS::IIndex idx) const {
365499 // Convert MVS image index to viewer index
366500 // The list of images in the viewer is a subset of the MVS images,
0 commit comments