From 8db8e30cb07ed8ceea2f1ccbcaa961399f5d7183 Mon Sep 17 00:00:00 2001 From: Marco Callieri mcallieri Date: Mon, 16 Jan 2012 18:06:27 +0000 Subject: [PATCH] added alpha masking for image weighting (still to be tested), commented out some problematic QWarning --- .../filter_img_patch_param/TexturePainter.cpp | 2 +- .../VisibilityCheck.cpp | 2 +- .../filter_img_patch_param/VisibleSet.cpp | 29 +++++++++++++++++++ .../filter_img_patch_param/VisibleSet.h | 1 + .../filter_img_patch_param.cpp | 6 ++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/meshlabplugins/filter_img_patch_param/TexturePainter.cpp b/src/meshlabplugins/filter_img_patch_param/TexturePainter.cpp index 699261f50..25148ff87 100644 --- a/src/meshlabplugins/filter_img_patch_param/TexturePainter.cpp +++ b/src/meshlabplugins/filter_img_patch_param/TexturePainter.cpp @@ -64,7 +64,7 @@ bool TexturePainter::init( int texSize ) .AttachAndLink( fpg, &logs ) ) { - qWarning( (std::string(__func__)+": "+logs).c_str() ); + // qWarning( (std::string(__func__)+": "+logs).c_str() ); return false; } diff --git a/src/meshlabplugins/filter_img_patch_param/VisibilityCheck.cpp b/src/meshlabplugins/filter_img_patch_param/VisibilityCheck.cpp index 45128cac5..e1f2ec30b 100644 --- a/src/meshlabplugins/filter_img_patch_param/VisibilityCheck.cpp +++ b/src/meshlabplugins/filter_img_patch_param/VisibilityCheck.cpp @@ -370,7 +370,7 @@ bool VisibilityCheck_ShadowMap::initShaders() !fpg.CompileSrcFile( basename+"visibility_detection.frag", &logs ) || !m_VisDetectionShader.Attach( vpg ).AttachAndLink( fpg, &logs ) ) { - qWarning( ( std::string(__func__)+ ": "+logs).c_str() ); + // qWarning( ( std::string(__func__)+ ": "+logs).c_str() ); return false; } diff --git a/src/meshlabplugins/filter_img_patch_param/VisibleSet.cpp b/src/meshlabplugins/filter_img_patch_param/VisibleSet.cpp index 192219467..7c30a7108 100644 --- a/src/meshlabplugins/filter_img_patch_param/VisibleSet.cpp +++ b/src/meshlabplugins/filter_img_patch_param/VisibleSet.cpp @@ -99,5 +99,34 @@ float VisibleSet::getWeight( const RasterModel *rm, CFaceO &f ) std::abs(2.0f*cam.Y()/rm->shot.Intrinsics.ViewportPx.Y()-1.0f) ); } + if( (m_WeightMask & W_IMG_ALPHA) && weight>0.0f ) + { + vcg::Point2f ppoint0 = rm->shot.Project( f.V(0)->P() ); + vcg::Point2f ppoint1 = rm->shot.Project( f.V(0)->P() ); + vcg::Point2f ppoint2 = rm->shot.Project( f.V(0)->P() ); + + float aweight = 1.0; + float wt; + QRgb pcolor; + + // vertex 0 + pcolor = rm->currentPlane->image.pixel(ppoint0[0],rm->shot.Intrinsics.ViewportPx[1] - ppoint0[1]); + wt = (qAlpha(pcolor) / 255.0); + if(aweight > wt) + aweight = wt; + // vertex 0 + pcolor = rm->currentPlane->image.pixel(ppoint1[0],rm->shot.Intrinsics.ViewportPx[1] - ppoint1[1]); + wt = (qAlpha(pcolor) / 255.0); + if(aweight > wt) + aweight = wt; + // vertex 0 + pcolor = rm->currentPlane->image.pixel(ppoint2[0],rm->shot.Intrinsics.ViewportPx[1] - ppoint2[1]); + wt = (qAlpha(pcolor) / 255.0); + if(aweight > wt) + aweight = wt; + + weight *= aweight; + } + return weight; } diff --git a/src/meshlabplugins/filter_img_patch_param/VisibleSet.h b/src/meshlabplugins/filter_img_patch_param/VisibleSet.h index 7b8fdba67..0c22920e4 100644 --- a/src/meshlabplugins/filter_img_patch_param/VisibleSet.h +++ b/src/meshlabplugins/filter_img_patch_param/VisibleSet.h @@ -38,6 +38,7 @@ public: W_ORIENTATION = 0x01, W_DISTANCE = 0x02, W_IMG_BORDER = 0x04, + W_IMG_ALPHA = 0x08, }; diff --git a/src/meshlabplugins/filter_img_patch_param/filter_img_patch_param.cpp b/src/meshlabplugins/filter_img_patch_param/filter_img_patch_param.cpp index f1c94146b..8113603c8 100644 --- a/src/meshlabplugins/filter_img_patch_param/filter_img_patch_param.cpp +++ b/src/meshlabplugins/filter_img_patch_param/filter_img_patch_param.cpp @@ -147,6 +147,10 @@ void FilterImgPatchParamPlugin::initParameterSet( QAction *act, true, "Use image border weight", "Includes a weight accounting for the distance to the image border during the computation of reference images") ); + par.addParam(new RichBool ( "useAlphaWeight", + false, + "use image alpha weight", + "If true, alpha channel of the image is used as additional weight. In this way it is possible to mask-out parts of the images that should not be projected on the mesh. Please note this is not a transparency effect, but just influences the weigthing between different images")); par.addParam( new RichBool( "cleanIsolatedTriangles", true, "Clean isolated triangles", @@ -832,6 +836,8 @@ void FilterImgPatchParamPlugin::patchBasedTextureParameterization( RasterPatchMa weightMask |= VisibleSet::W_DISTANCE; if( par.getBool("useImgBorderWeight") ) weightMask |= VisibleSet::W_IMG_BORDER; + if( par.getBool("useAlphaWeight") ) + weightMask |= VisibleSet::W_IMG_ALPHA; VisibleSet *faceVis = new VisibleSet( mesh, rasterList, weightMask ); Log( "VISIBILITY CHECK: %.3f sec.", 0.001f*t.elapsed() );