Filter initialization policy changed

This commit is contained in:
Paolo Cignoni cignoni 2010-01-27 11:08:09 +00:00
parent a09aa6df8a
commit f45943a430
11 changed files with 91 additions and 4 deletions

View File

@ -1,5 +1,7 @@
#include "DynamicMeshSubFilter.h"
#include <vcg/complex/trimesh/append.h>
DynamicMeshSubFilter::DynamicMeshSubFilter() : m_steps(-1), m_seconds(-1) {
}
@ -20,10 +22,54 @@ bool DynamicMeshSubFilter::applyFilter(QAction* filter, MeshDocument &md, RichPa
bool DynamicMeshSubFilter::configurationHasChanged(MeshDocument& md, RichParameterSet& par){
bool changed = m_seconds != par.getInt("seconds");
// Does not work because meshlab fails at restoring the original translation matrix in the preview checkbox logic
/* Dim: the transformation matrices should not change
for(int i = 0; i < md.size(); i++){
for(int j = 0; j < 16; j++) std::cout << md.getMesh(i)->cm.Tr[j/4][j%4] <<" ";
std::cout<<std::endl;
}
*/
/*if(md.size() == m_state.size()){
for(int i = 0; i < m_state.size() && !changed; i++){
changed |= !compareMesh(md.getMesh(i), m_state[i]);
}
}else
changed = true;
saveMeshState(md);*/
// Old correctness testing
/*if(md.size() == m_files.size())
for(int i = 0; i < m_files.size(); i++)
changed |= m_files.at(i) != md.getMesh(i)->fileName;
else
changed = true;
m_files.clear();
for(int i = 0; i < md.size(); i++)
m_files.push_back(md.getMesh(i)->fileName);*/
m_seconds = par.getInt("seconds");
return changed;
}
bool DynamicMeshSubFilter::compareMesh(MeshModel* m1, MeshModel* m2){
return m1->fileName == m2->fileName && m1->cm.Tr == m2->cm.Tr;
}
void DynamicMeshSubFilter::saveMeshState(MeshDocument& md){
m_state.clear();
for(int i = 0; i < md.size(); i++){
MeshModel* meshCopy = new MeshModel();
vcg::tri::Append<CMeshO,CMeshO>::Mesh(meshCopy->cm, md.getMesh(i)->cm, false, true);
meshCopy->fileName = md.getMesh(i)->fileName;
meshCopy->cm.Tr = md.getMesh(i)->cm.Tr;
m_state.push_back(meshCopy);
}
}
void DynamicMeshSubFilter::initialize(MeshDocument&, RichParameterSet&, vcg::CallBackPos* cb){
m_steps = m_seconds / m_stepSize;
}

View File

@ -20,10 +20,16 @@ protected:
virtual void initialize(MeshDocument&, RichParameterSet&, vcg::CallBackPos* cb);
virtual bool configurationHasChanged(MeshDocument& md, RichParameterSet& par);
void saveMeshState(MeshDocument& md);
int m_steps;
int m_seconds;
LayersTransformations m_layersTrans;
std::vector<std::string> m_files;
std::vector<MeshModel*> m_state;
private:
bool compareMesh(MeshModel* m1, MeshModel* m2);
};
#endif // DYNAMICMESHSUBFILTER_H

View File

@ -1,6 +1,10 @@
#include "GravitySubFilter.h"
int GravitySubFilter::m_filterType = -1;
GravitySubFilter::GravitySubFilter() : m_scenery(0){
MeshSubFilter::m_currentFilterType += 1;
m_filterType = MeshSubFilter::m_currentFilterType;
}
void GravitySubFilter::initParameterSet(QAction* action,MeshDocument& md, RichParameterSet& par){
@ -24,8 +28,9 @@ bool GravitySubFilter::applyFilter(QAction* filter, MeshDocument &md, RichParame
}
bool GravitySubFilter::configurationHasChanged(MeshDocument& md, RichParameterSet& par){
bool changed = DynamicMeshSubFilter::configurationHasChanged(md, par) || m_scenery != par.getMesh("scenery");
bool changed = DynamicMeshSubFilter::configurationHasChanged(md, par) || m_scenery != par.getMesh("scenery") || m_currentFilterType != m_filterType;
m_scenery = par.getMesh("scenery");
m_currentFilterType = m_filterType;
return changed;
}

View File

@ -22,6 +22,8 @@ protected:
private:
MeshModel* m_scenery;
ODEFacade m_engine;
static int m_filterType;
};
#endif // GRAVITYSUBFILTER_H

View File

@ -2,3 +2,5 @@
const float MeshSubFilter::m_stepSize = 0.02;
const unsigned int MeshSubFilter::m_stepsPerSecond = 1.0f/m_stepSize;
//MeshSubFilter::FilterType MeshSubFilter::m_currentFilterType = FILTERTYPE_UNDEFINED;
int MeshSubFilter::m_currentFilterType = 0;

View File

@ -14,10 +14,11 @@ public:
virtual bool applyFilter(QAction* filter, MeshDocument &md, RichParameterSet& par, vcg::CallBackPos* cb) = 0;
protected:
enum SubType{ GRAVITY, RANDOMDROP, RANDOMFILL };
enum FilterType{ FILTERTYPE_UNDEFINED, FILTERTYPE_GRAVITY, FILTERTYPE_RANDOMDROP, FILTERTYPE_RANDOMFILL };
static const float m_stepSize;
static const unsigned int m_stepsPerSecond;
static int m_currentFilterType;
};
#endif // MESHSUBFILTER_H

View File

@ -103,7 +103,8 @@ void ODEFacade::setAsRigidBody(MeshModel& mesh, bool isRigidBody){
dMassSetParameters(&m_registeredMeshes[index()].second->mass, inertia.Mass() > 0.f ? inertia.Mass() : 1.f,
inertia.CenterOfMass()[0], inertia.CenterOfMass()[1], inertia.CenterOfMass()[2],
IT[0][0], IT[1][1], IT[2][2], IT[0][1], IT[0][2], IT[1][2]);
dBodySetMass(m_registeredMeshes[index()].second->body, &m_registeredMeshes[index()].second->mass);
//For now it is best to let ODE do the job automatically
//dBodySetMass(m_registeredMeshes[index()].second->body, &m_registeredMeshes[index()].second->mass);
}

View File

@ -8,7 +8,11 @@
using namespace std;
int RandomDropFilter::m_filterType = -1;
RandomDropFilter::RandomDropFilter() : m_randomMesh(0), m_dropRate(-1), m_distance(-1){
MeshSubFilter::m_currentFilterType += 1;
m_filterType = MeshSubFilter::m_currentFilterType;
}
void RandomDropFilter::initParameterSet(QAction* action,MeshDocument& md, RichParameterSet & par){
@ -93,6 +97,11 @@ void RandomDropFilter::initialize(MeshDocument& md, RichParameterSet& par, vcg::
m_engine.integrate(m_stepSize);
}
/* Was need for old correctness testing
m_files.clear();
for(int i = 0; i < md.size(); i++)
m_files.push_back(md.getMesh(i)->fileName);*/
if(cb != 0) (*cb)(99, "Physics pre-renderization of the scene completed...");
}
@ -116,11 +125,13 @@ bool RandomDropFilter::configurationHasChanged(MeshDocument& md, RichParameterSe
bool changed = DynamicMeshSubFilter::configurationHasChanged(md, par) ||
m_randomMesh != par.getMesh("randomMesh") ||
m_distance != par.getFloat("distance") ||
m_dropRate != par.getInt("dropRate");
m_dropRate != par.getInt("dropRate") ||
m_currentFilterType != m_filterType;
m_randomMesh = par.getMesh("randomMesh");
m_distance = par.getFloat("distance");
m_dropRate = par.getInt("dropRate");
m_currentFilterType = m_filterType;
return changed;
}

View File

@ -25,6 +25,8 @@ private:
int m_dropRate;
float m_distance;
ODEFacade m_engine;
static int m_filterType;
};
#endif // RANDOMDROPFILTER_H

View File

@ -8,6 +8,13 @@
using namespace std;
using namespace vcg;
int RandomFillFilter::m_filterType = -1;
RandomFillFilter::RandomFillFilter(){
MeshSubFilter::m_currentFilterType += 1;
m_filterType = MeshSubFilter::m_currentFilterType;
}
void RandomFillFilter::initParameterSet(QAction* action,MeshDocument& md, RichParameterSet & par){
par.addParam(new RichMesh("container", 0, &md, "Container mesh", "This mesh will act as a container for the filling mesh"));
par.addParam(new RichMesh("filler", 0, &md, "Filler mesh", "The container mesh will be filled with this mesh"));

View File

@ -8,6 +8,8 @@
class RandomFillFilter : public MeshSubFilter{
public:
RandomFillFilter();
virtual void initParameterSet(QAction* action,MeshDocument& md, RichParameterSet & par);
virtual bool applyFilter(QAction* filter, MeshDocument &md, RichParameterSet& par, vcg::CallBackPos* cb);
@ -17,6 +19,8 @@ protected:
private:
int m_dropRate;
ODEFacade m_engine;
static int m_filterType;
};
#endif // RANDOMFILLFILTER_H