From ebcf48ba5544acb0e37f3feb724307e58bd9dce2 Mon Sep 17 00:00:00 2001 From: Fabio Ganovelli ganovelli Date: Wed, 1 Sep 2010 16:07:37 +0000 Subject: [PATCH] added option to generate shots (todo: some renaming) --- .../filter_vsa/region_growing.h | 10 ++- src/meshlabplugins/filter_vsa/vsa.cpp | 67 +++++++++++++------ src/meshlabplugins/filter_vsa/vsa.h | 1 + 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/meshlabplugins/filter_vsa/region_growing.h b/src/meshlabplugins/filter_vsa/region_growing.h index 9a86e221f..c2325646c 100755 --- a/src/meshlabplugins/filter_vsa/region_growing.h +++ b/src/meshlabplugins/filter_vsa/region_growing.h @@ -24,6 +24,7 @@ public: typedef typename FaceType::ScalarType ScalarType; typedef typename std::list ::iterator TriRegIterator; typedef typename std::list::iterator AdjIterator; + typedef typename PlanarRegion::Pov Pov; std::list regions; std::vector workingset; @@ -382,10 +383,13 @@ void GrowStepOnce(){ } } - void ComputeShots(){ - int vpsize[2] = {800,800}; + void ComputeShots(int * vpsize, int pps){ for(TriRegIterator tri = regions.begin(); tri != regions.end(); ++tri) - (*tri).ComputeShot(vpsize,10000.f / m->bbox.Diag()); + (*tri).ComputeShot(vpsize,pps); + } + void GetAllShots( std::vector & povs){ + for(TriRegIterator tri = regions.begin(); tri != regions.end(); ++tri) + povs.insert(povs.end(),(*tri).povs.begin(),(*tri).povs.end()); } }; diff --git a/src/meshlabplugins/filter_vsa/vsa.cpp b/src/meshlabplugins/filter_vsa/vsa.cpp index eb4e71002..8ffde0763 100755 --- a/src/meshlabplugins/filter_vsa/vsa.cpp +++ b/src/meshlabplugins/filter_vsa/vsa.cpp @@ -56,6 +56,20 @@ VsaPlugin::VsaPlugin() actionList << new QAction(filterName(tt), this); } +VsaPlugin::~VsaPlugin(){ +// typedef RegionGrower::Pov Pov; +// CMeshO::PerMeshAttributeHandle * > rg_handle; +// rg_handle = vcg::tri::Allocator::GetPerMeshAttribute *> (md.mm()->cm,"regiongrower"); +// if (vcg::tri::Allocator::IsValidHandle(md.mm()->cm,rg_handle) && ( rg_handle() != NULL)) +// delete rg_handle(); +// +// CMeshO::PerMeshAttributeHandle * > povs_handle; +// povs_handle = vcg::tri::Allocator::GetPerMeshAttribute *> (md.mm()->cm,"pointofviews"); +// if (vcg::tri::Allocator::IsValidHandle(md.mm()->cm,povs_handle) && ( povs_handle() != NULL)) +// delete povs_handle(); + +} + // ST() must return the very short string describing each filtering action // (this string is used also to define the menu entry) QString VsaPlugin::filterName(FilterIDType filterId) const @@ -88,6 +102,10 @@ void VsaPlugin::initParameterSet(QAction *action,MeshDocument & m , RichParamet switch(ID(action)) { case FP_VSA : parlst.addParam(new RichInt ("MaxPatches", 10,"maximum number of patches to use")); + parlst.addParam(new RichBool ("ComputeSamplingViews", false,"Also compute the view for sampling","")); + parlst.addParam(new RichInt ("Width", 1024,"width of the viewport")); + parlst.addParam(new RichInt ("Heigth", 512,"height of the viewport")); + parlst.addParam(new RichInt ("Resolution", 10000,"Linear resolution: number of samples along the diagonal of the bbox")); break; default: break; // do not add any parameter for the other filters @@ -100,39 +118,50 @@ int VsaPlugin::getRequirements(QAction *){ // The Real Core Function doing the actual mesh processing. bool VsaPlugin::applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & par, vcg::CallBackPos *cb) { - + typedef RegionGrower::Pov Pov; + switch(ID(filter)) { case FP_VSA : { // to access to the parameters of the filter dialog simply use the getXXXX function of the FilterParameter Class int maxpatches = par.getInt("MaxPatches"); - CMeshO::PerMeshAttributeHandle * > rg_handle; + CMeshO::PerMeshAttributeHandle > rg_handle; + rg_handle = vcg::tri::Allocator::GetPerMeshAttribute > (md.mm()->cm,"regiongrower"); + if (!vcg::tri::Allocator::IsValidHandle(md.mm()->cm,rg_handle) ) + rg_handle = vcg::tri::Allocator::AddPerMeshAttribute > (md.mm()->cm,"regiongrower"); - rg_handle = vcg::tri::Allocator::GetPerMeshAttribute *> (md.mm()->cm,"regiongrower"); - if (vcg::tri::Allocator::IsValidHandle(md.mm()->cm,rg_handle) && ( rg_handle() != NULL)) - delete rg_handle(); - else - rg_handle = vcg::tri::Allocator::AddPerMeshAttribute *> (md.mm()->cm,"regiongrower"); - - - rg_handle() = new RegionGrower(); - - - rg_handle()->Init(md.mm()->cm,maxpatches); - rg_handle()->Refill(); + rg_handle().Init(md.mm()->cm,maxpatches); + rg_handle().Refill(); for(int ns = 0; ns < 20; ++ns) - rg_handle()->GrowStep(); + rg_handle().GrowStep(); - for( RegionGrower::TriRegIterator ti = rg_handle()->regions.begin(); ti != rg_handle()->regions.end(); ++ti) + for( RegionGrower::TriRegIterator ti = rg_handle().regions.begin(); ti != rg_handle().regions.end(); ++ti) for( RegionGrower::RegionType::FaceIterator fi = (*ti).face.begin(); fi != (*ti).face.end(); ++fi) (*fi)->C() = (*ti).color; - // Log function dump textual info in the lower part of the MeshLab screen. -// Log("Merged all the layers to single mesh of %i vertices",md.mm()->cm.vn); + + Log("Mesh Partitioned in Almost Planar regions"); + bool alsoviews = par.getBool("ComputeSamplingViews"); + + if(alsoviews){ + int vpsize[2]; int pps; + vpsize[0] = par.getInt("Width"); + vpsize[1] = par.getInt("Height"); + pps = par.getInt("Resolution"); + Log("Computing Views"); + rg_handle().ComputeShots(vpsize,pps); + + CMeshO::PerMeshAttributeHandle > povs_handle; + povs_handle = vcg::tri::Allocator::GetPerMeshAttribute > (md.mm()->cm,"pointofviews"); + if (!vcg::tri::Allocator::IsValidHandle(md.mm()->cm,povs_handle) ) + povs_handle = vcg::tri::Allocator::AddPerMeshAttribute > (md.mm()->cm,"pointofviews"); + + rg_handle().GetAllShots(povs_handle()); + } - } break; + } break; default: assert (0); } return true; diff --git a/src/meshlabplugins/filter_vsa/vsa.h b/src/meshlabplugins/filter_vsa/vsa.h index 97e691d32..e06b4f887 100755 --- a/src/meshlabplugins/filter_vsa/vsa.h +++ b/src/meshlabplugins/filter_vsa/vsa.h @@ -47,6 +47,7 @@ public: enum { FP_VSA } ; VsaPlugin(); + virtual ~VsaPlugin(); virtual QString filterName(FilterIDType filter) const; virtual QString filterInfo(FilterIDType filter) const;