mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-15 00:54:38 +00:00
FilterSampleDyn uses new applyFilter call
This commit is contained in:
parent
be908963be
commit
d4e98ebe3e
@ -129,7 +129,7 @@ else()
|
||||
|
||||
# Filter plugins
|
||||
meshlabplugins/filter_sample
|
||||
# meshlabplugins/filter_sample_dyn
|
||||
meshlabplugins/filter_sample_dyn
|
||||
# meshlabplugins/filter_createiso
|
||||
# meshlabplugins/filter_geodesic
|
||||
# meshlabplugins/filter_sample_gpu
|
||||
|
||||
@ -36,34 +36,34 @@ using namespace vcg;
|
||||
ExtraSampleDynPlugin::ExtraSampleDynPlugin()
|
||||
{
|
||||
typeList << FP_VERTEX_COLOR_NOISE;
|
||||
|
||||
foreach(ActionIDType tt , types())
|
||||
actionList << new QAction(filterName(tt), this);
|
||||
|
||||
foreach(ActionIDType tt , types())
|
||||
actionList << new QAction(filterName(tt), this);
|
||||
}
|
||||
|
||||
QString ExtraSampleDynPlugin::pluginName() const
|
||||
{
|
||||
return "FilterSampleDyn";
|
||||
return "FilterSampleDyn";
|
||||
}
|
||||
|
||||
// ST() must return the very short string describing each filtering action
|
||||
// (this string is used also to define the menu entry)
|
||||
QString ExtraSampleDynPlugin::filterName(ActionIDType filterId) const
|
||||
{
|
||||
switch(filterId) {
|
||||
case FP_VERTEX_COLOR_NOISE : return QString("Vertex Color Noise");
|
||||
default : assert(0);
|
||||
switch(filterId) {
|
||||
case FP_VERTEX_COLOR_NOISE : return QString("Vertex Color Noise");
|
||||
default : assert(0);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Info() must return the longer string describing each filtering action
|
||||
// (this string is used in the About plugin dialog)
|
||||
QString ExtraSampleDynPlugin::filterInfo(ActionIDType filterId) const
|
||||
QString ExtraSampleDynPlugin::filterInfo(ActionIDType filterId) const
|
||||
{
|
||||
switch(filterId) {
|
||||
case FP_VERTEX_COLOR_NOISE : return QString("Randomly add a small amount of a random base color to the mesh");
|
||||
default : assert(0);
|
||||
switch(filterId) {
|
||||
case FP_VERTEX_COLOR_NOISE : return QString("Randomly add a small amount of a random base color to the mesh");
|
||||
default : assert(0);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@ -71,7 +71,7 @@ QString ExtraSampleDynPlugin::filterName(ActionIDType filterId) const
|
||||
// The FilterClass describes in which generic class of filters it fits.
|
||||
// This choice affect the submenu in which each filter will be placed
|
||||
// In this case this sample belong to the class of filters that change the vertex colors
|
||||
FilterPlugin::FilterClass ExtraSampleDynPlugin::getClass(const QAction *) const { return FilterPlugin::VertexColoring; }
|
||||
FilterPlugin::FilterClass ExtraSampleDynPlugin::getClass(const QAction *) const { return FilterPlugin::VertexColoring; }
|
||||
|
||||
// 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
|
||||
@ -94,52 +94,57 @@ QString ExtraSampleDynPlugin::filterName(ActionIDType filterId) const
|
||||
|
||||
void ExtraSampleDynPlugin::initParameterList(const QAction *action,MeshModel &/*m*/, RichParameterList & parlst)
|
||||
{
|
||||
switch(ID(action)) {
|
||||
case FP_VERTEX_COLOR_NOISE :
|
||||
parlst.addParam(RichColor ("baseColor",
|
||||
Color4b::Black,
|
||||
"BaseColor",
|
||||
"The base color that is added to the mesh."));
|
||||
|
||||
parlst.addParam(RichDynamicFloat("percentage",
|
||||
0.5, 0, 1,
|
||||
"Alpha",
|
||||
"The random color is blended with the current one with the specified alpha"));
|
||||
|
||||
parlst.addParam(RichDynamicFloat("frequency",
|
||||
20, 1, 200,
|
||||
"Noisy Frequency",
|
||||
"The frequency of the Noise on the mesh. Higher numbers means smaller spots."));
|
||||
break;
|
||||
|
||||
default: break; // do not add any parameter for the other filters
|
||||
}
|
||||
switch(ID(action)) {
|
||||
case FP_VERTEX_COLOR_NOISE :
|
||||
parlst.addParam(RichColor ("baseColor",
|
||||
Color4b::Black,
|
||||
"BaseColor",
|
||||
"The base color that is added to the mesh."));
|
||||
|
||||
parlst.addParam(RichDynamicFloat("percentage",
|
||||
0.5, 0, 1,
|
||||
"Alpha",
|
||||
"The random color is blended with the current one with the specified alpha"));
|
||||
|
||||
parlst.addParam(RichDynamicFloat("frequency",
|
||||
20, 1, 200,
|
||||
"Noisy Frequency",
|
||||
"The frequency of the Noise on the mesh. Higher numbers means smaller spots."));
|
||||
break;
|
||||
|
||||
default: break; // do not add any parameter for the other filters
|
||||
}
|
||||
}
|
||||
|
||||
// The Real Core Function doing the actual mesh processing.
|
||||
// It changes the color of the mesh according to a perlin noise function
|
||||
bool ExtraSampleDynPlugin::applyFilter(const QAction *, MeshDocument &md, std::map<std::string, QVariant>&, unsigned int& /*postConditionMask*/, const RichParameterList & par, vcg::CallBackPos *)
|
||||
std::map<std::string, QVariant> ExtraSampleDynPlugin::applyFilter(const QAction *action, const RichParameterList & par, MeshDocument &md, unsigned int& /*postConditionMask*/, vcg::CallBackPos *)
|
||||
{
|
||||
MeshModel &m=*(md.mm());
|
||||
const Color4b baseColor = par.getColor4b("baseColor");
|
||||
const Scalarm percentage = par.getDynamicFloat("percentage");
|
||||
const Scalarm freq = par.getDynamicFloat("frequency");
|
||||
const Scalarm frequency = math::Clamp<Scalarm>(freq, 1.0, 1000.0);
|
||||
if (ID(action) == FP_VERTEX_COLOR_NOISE) {
|
||||
MeshModel &m=*(md.mm());
|
||||
const Color4b baseColor = par.getColor4b("baseColor");
|
||||
const Scalarm percentage = par.getDynamicFloat("percentage");
|
||||
const Scalarm freq = par.getDynamicFloat("frequency");
|
||||
const Scalarm frequency = math::Clamp<Scalarm>(freq, 1.0, 1000.0);
|
||||
|
||||
CMeshO::VertexIterator vi;
|
||||
|
||||
float scale = frequency/m.cm.bbox.Diag() ;
|
||||
|
||||
//qDebug("Dynamic Apply percentage %f frequency %f",percentage,frequency);
|
||||
for(vi=m.cm.vert.begin();vi!=m.cm.vert.end();++vi)
|
||||
if(!(*vi).IsD())
|
||||
{
|
||||
float alpha = percentage * (0.5f+math::Perlin::Noise((*vi).P()[0]*scale,(*vi).P()[1]*scale,(*vi).P()[2]*scale));
|
||||
alpha=math::Clamp(alpha,0.0f,1.0f);
|
||||
(*vi).C().lerp ( (*vi).C(), baseColor, alpha);
|
||||
CMeshO::VertexIterator vi;
|
||||
|
||||
float scale = frequency/m.cm.bbox.Diag() ;
|
||||
|
||||
//qDebug("Dynamic Apply percentage %f frequency %f",percentage,frequency);
|
||||
for(vi=m.cm.vert.begin();vi!=m.cm.vert.end();++vi) {
|
||||
if(!(*vi).IsD())
|
||||
{
|
||||
float alpha = percentage * (0.5f+math::Perlin::Noise((*vi).P()[0]*scale,(*vi).P()[1]*scale,(*vi).P()[2]*scale));
|
||||
alpha=math::Clamp(alpha,0.0f,1.0f);
|
||||
(*vi).C().lerp ( (*vi).C(), baseColor, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
wrongActionCalled(action);
|
||||
}
|
||||
return std::map<std::string, QVariant>();
|
||||
}
|
||||
|
||||
MESHLAB_PLUGIN_NAME_EXPORTER(ExtraSampleDynPlugin)
|
||||
|
||||
@ -34,19 +34,19 @@ class ExtraSampleDynPlugin : public QObject, public FilterPlugin
|
||||
MESHLAB_PLUGIN_IID_EXPORTER(FILTER_PLUGIN_IID)
|
||||
Q_INTERFACES(FilterPlugin)
|
||||
|
||||
public:
|
||||
enum { FP_VERTEX_COLOR_NOISE } ;
|
||||
public:
|
||||
enum { FP_VERTEX_COLOR_NOISE } ;
|
||||
|
||||
ExtraSampleDynPlugin();
|
||||
ExtraSampleDynPlugin();
|
||||
|
||||
QString pluginName() const;
|
||||
virtual QString filterName(ActionIDType filter) const;
|
||||
virtual QString filterInfo(ActionIDType filter) const;
|
||||
virtual void initParameterList(const QAction*, MeshModel &/*m*/, RichParameterList & /*parent*/);
|
||||
virtual int postCondition(const QAction* ) const {return MeshModel::MM_VERTCOLOR;};
|
||||
virtual bool applyFilter(const QAction *filter, MeshDocument &md, std::map<std::string, QVariant>& outputValues, unsigned int& postConditionMask, const RichParameterList & /*parent*/, vcg::CallBackPos * cb) ;
|
||||
virtual FilterClass getClass(const QAction*) const;
|
||||
FILTER_ARITY filterArity(const QAction *) const {return SINGLE_MESH;}
|
||||
QString pluginName() const;
|
||||
virtual QString filterName(ActionIDType filter) const;
|
||||
virtual QString filterInfo(ActionIDType filter) const;
|
||||
virtual void initParameterList(const QAction*, MeshModel &/*m*/, RichParameterList & /*parent*/);
|
||||
virtual int postCondition(const QAction* ) const {return MeshModel::MM_VERTCOLOR;};
|
||||
std::map<std::string, QVariant> applyFilter(const QAction* action, const RichParameterList & /*parent*/, MeshDocument &md, unsigned int& postConditionMask, vcg::CallBackPos * cb);
|
||||
virtual FilterClass getClass(const QAction*) const;
|
||||
FILTER_ARITY filterArity(const QAction *) const {return SINGLE_MESH;}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user