diff --git a/src/meshlab.pro b/src/meshlab.pro index 7b7d7350c..67299e5a1 100644 --- a/src/meshlab.pro +++ b/src/meshlab.pro @@ -29,6 +29,7 @@ SUBDIRS = \ #sub projects names io_base \ # a few basic file formats (ply, obj, off), without this you cannot open anything decorate_base \ filter_measure_xml \ + filter_measure \ filter_meshing !meshlab_mini { @@ -123,6 +124,7 @@ meshlabserver.subdir = meshlabserver io_base.subdir = meshlabplugins/io_base decorate_base.subdir = meshlabplugins/decorate_base filter_measure_xml.subdir = meshlabplugins/filter_measure_xml +filter_measure.subdir = meshlabplugins/filter_measure filter_meshing.subdir = meshlabplugins/filter_meshing use_cpu_opengl.subdir = use_cpu_opengl # IO plugins @@ -200,6 +202,7 @@ meshlabserver.depends = common io_base.depends = common decorate_base.depends = common filter_measure_xml.depends = common +filter_measure.depends = common filter_meshing.depends = common # IO plugins io_3ds.depends = common diff --git a/src/meshlabplugins/filter_measure/CMakeLists.txt b/src/meshlabplugins/filter_measure/CMakeLists.txt new file mode 100644 index 000000000..b3bba9ed6 --- /dev/null +++ b/src/meshlabplugins/filter_measure/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright 2019-2020, Collabora, Ltd. +# SPDX-License-Identifier: BSL-1.0 + +### Generated file! Edit the templates in src/templates, +### specifically src/templates/CMakeLists.template.cmake (shared with all other directories), +### or create a derived template in src/templates/filter_sample.cmake, +### then re-run ./make-cmake.py + +set(SOURCES filter_sample.cpp) + +set(HEADERS filter_sample.h) + +add_library(filter_measure MODULE ${SOURCES} ${HEADERS}) + +target_include_directories(filter_measure PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(filter_measure PUBLIC common) + +set_property(TARGET filter_measure PROPERTY FOLDER Plugins) + +set_property(TARGET filter_measure PROPERTY RUNTIME_OUTPUT_DIRECTORY + ${MESHLAB_PLUGIN_OUTPUT_DIR}) + +set_property(TARGET filter_measure PROPERTY LIBRARY_OUTPUT_DIRECTORY + ${MESHLAB_PLUGIN_OUTPUT_DIR}) + +install( + TARGETS filter_measure + DESTINATION ${MESHLAB_PLUGIN_INSTALL_DIR} + COMPONENT Plugins) diff --git a/src/meshlabplugins/filter_measure/filter_measure.cpp b/src/meshlabplugins/filter_measure/filter_measure.cpp new file mode 100644 index 000000000..3dc2dc3c6 --- /dev/null +++ b/src/meshlabplugins/filter_measure/filter_measure.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +* MeshLab o o * +* A versatile mesh processing toolbox o o * +* _ O _ * +* Copyright(C) 2005 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ + +#include "filter_measure.h" +#include + +// Constructor usually performs only two simple tasks of filling the two lists +// - typeList: with all the possible id of the filtering actions +// - actionList with the corresponding actions. If you want to add icons to your filtering actions you can do here by construction the QActions accordingly + +ExtraSamplePlugin::ExtraSamplePlugin() +{ + typeList << FP_MOVE_VERTEX; + + foreach(FilterIDType tt , types()) + actionList << new QAction(filterName(tt), this); +} + +// ST() must return the very short string describing each filtering action +// (this string is used also to define the menu entry) +QString ExtraSamplePlugin::filterName(FilterIDType filterId) const +{ + switch(filterId) { + case FP_MOVE_VERTEX : return QString("Random Vertex Displacement"); + default : assert(0); + } + return QString(); +} + +// Info() must return the longer string describing each filtering action +// (this string is used in the About plugin dialog) + QString ExtraSamplePlugin::filterInfo(FilterIDType filterId) const +{ + switch(filterId) { + case FP_MOVE_VERTEX : return QString("Move the vertices of the mesh of a random quantity."); + default : assert(0); + } + return QString("Unknown Filter"); +} + +// The FilterClass describes in which generic class of filters it fits. +// This choice affect the submenu in which each filter will be placed +// More than a single class can be chosen. +ExtraSamplePlugin::FilterClass ExtraSamplePlugin::getClass(QAction *a) +{ + switch(ID(a)) + { + case FP_MOVE_VERTEX : return MeshFilterInterface::Smoothing; + default : assert(0); + } + return MeshFilterInterface::Generic; +} + +// This function define the needed parameters for each filter. Return true if the filter has some parameters +// it is called every time, so you can set the default value of parameters according to the mesh +// For each parameter you need to define, +// - the name of the parameter, +// - the string shown in the dialog +// - the default value +// - a possibly long string describing the meaning of that parameter (shown as a popup help in the dialog) +void ExtraSamplePlugin::initParameterSet(QAction *action,MeshModel &m, RichParameterSet & parlst) +{ + switch(ID(action)) { + case FP_MOVE_VERTEX : + parlst.addParam(new RichBool ("UpdateNormals", + true, + "Recompute normals", + "Toggle the recomputation of the normals after the random displacement.\n\n" + "If disabled the face normals will remains unchanged resulting in a visually pleasant effect.")); + parlst.addParam(new RichAbsPerc("Displacement", + m.cm.bbox.Diag()/100.0f,0.0f,m.cm.bbox.Diag(), + "Max displacement", + "The vertex are displaced of a vector whose norm is bounded by this value")); + break; + + default : assert(0); + } +} + +// The Real Core Function doing the actual mesh processing. +// Move Vertex of a random quantity +bool ExtraSamplePlugin::applyFilter(QAction * /*filter*/, MeshDocument &md, RichParameterSet & par, vcg::CallBackPos *cb) +{ + CMeshO &m = md.mm()->cm; + srand(time(NULL)); + const float max_displacement =par.getAbsPerc("Displacement"); + + for(unsigned int i = 0; i< m.vert.size(); i++){ + // Typical usage of the callback for showing a nice progress bar in the bottom. + // First parameter is a 0..100 number indicating percentage of completion, the second is an info string. + cb(100*i/m.vert.size(), "Randomly Displacing..."); + + Scalarm rndax = (Scalarm(2.0*rand())/RAND_MAX - 1.0 ) *max_displacement; + Scalarm rnday = (Scalarm(2.0*rand())/RAND_MAX - 1.0 ) *max_displacement; + Scalarm rndaz = (Scalarm(2.0*rand())/RAND_MAX - 1.0 ) *max_displacement; + m.vert[i].P() += Point3m(rndax,rnday,rndaz); + } + + // Log function dump textual info in the lower part of the MeshLab screen. + Log("Successfully displaced %i vertices",m.vn); + + // to access to the parameters of the filter dialog simply use the getXXXX function of the FilterParameter Class + if(par.getBool("UpdateNormals")) + vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(m); + + vcg::tri::UpdateBounding::Box(m); + + return true; +} + +MESHLAB_PLUGIN_NAME_EXPORTER(ExtraSamplePlugin) diff --git a/src/meshlabplugins/filter_measure/filter_measure.h b/src/meshlabplugins/filter_measure/filter_measure.h new file mode 100644 index 000000000..b75af9058 --- /dev/null +++ b/src/meshlabplugins/filter_measure/filter_measure.h @@ -0,0 +1,62 @@ +/**************************************************************************** +* MeshLab o o * +* A versatile mesh processing toolbox o o * +* _ O _ * +* Copyright(C) 2005 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History +$Log: sampleplugins.h,v $ +Revision 1.2 2006/11/29 00:59:21 cignoni +Cleaned plugins interface; changed useless help class into a plain string + +Revision 1.1 2006/09/25 09:24:39 e_cerisoli +add sampleplugins + +****************************************************************************/ + +#ifndef SAMPLEFILTERSPLUGIN_H +#define SAMPLEFILTERSPLUGIN_H + +#include + +class ExtraSamplePlugin : public QObject, public MeshFilterInterface +{ + Q_OBJECT + MESHLAB_PLUGIN_IID_EXPORTER(MESH_FILTER_INTERFACE_IID) + Q_INTERFACES(MeshFilterInterface) + +public: + enum { FP_MOVE_VERTEX } ; + + ExtraSamplePlugin(); + + virtual QString pluginName(void) const { return "ExtraSamplePlugin"; } + + QString filterName(FilterIDType filter) const; + QString filterInfo(FilterIDType filter) const; + void initParameterSet(QAction *,MeshModel &/*m*/, RichParameterSet & /*parent*/); + bool applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & /*parent*/, vcg::CallBackPos * cb) ; + int postCondition( QAction* ) const {return MeshModel::MM_VERTCOORD | MeshModel::MM_FACENORMAL | MeshModel::MM_VERTNORMAL;}; + FilterClass getClass(QAction *a); + FILTER_ARITY filterArity(QAction *) const {return SINGLE_MESH;} +}; + + +#endif diff --git a/src/meshlabplugins/filter_measure/filter_measure.pro b/src/meshlabplugins/filter_measure/filter_measure.pro new file mode 100644 index 000000000..9665416cd --- /dev/null +++ b/src/meshlabplugins/filter_measure/filter_measure.pro @@ -0,0 +1,9 @@ +include (../../shared.pri) + +HEADERS += \ + filter_measure.h + +SOURCES += \ + filter_measure.cpp + +TARGET = filter_measure