mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-16 17:44:36 +00:00
code cleaning e and commenting
This commit is contained in:
parent
ba95fb7740
commit
f22639f4d6
@ -23,9 +23,9 @@
|
||||
#ifndef DIRT_UTILS_H
|
||||
#define DIRT_UTILS_H
|
||||
|
||||
#define PI 3.14159265
|
||||
//Include Files
|
||||
#define PI 3.14159265 //To delete?
|
||||
|
||||
//Include Files
|
||||
#include <math.h>
|
||||
#include <common/meshmodel.h>
|
||||
#include <common/interfaces.h>
|
||||
@ -42,7 +42,14 @@
|
||||
using namespace vcg;
|
||||
using namespace tri;
|
||||
|
||||
/**
|
||||
@def This funcion calculate the cartesian coordinates of a point given from its barycentric coordinates
|
||||
|
||||
@param Point3f bc - barycentric coordinates of the point
|
||||
@param FacePointer f - pointer to the face
|
||||
|
||||
@return cartesian coordinates of the point
|
||||
*/
|
||||
CMeshO::CoordType fromBarCoords(Point3f bc,CMeshO::FacePointer f){
|
||||
|
||||
CMeshO::CoordType p;
|
||||
@ -55,8 +62,10 @@ CMeshO::CoordType fromBarCoords(Point3f bc,CMeshO::FacePointer f){
|
||||
return p;
|
||||
};
|
||||
|
||||
|
||||
CMeshO::CoordType CoordinateCorrection(CMeshO::CoordType p,CMeshO::FacePointer f){
|
||||
/**
|
||||
@def
|
||||
*/
|
||||
CMeshO::CoordType fixEdgePointCoordinates(CMeshO::CoordType p,CMeshO::FacePointer f){
|
||||
Point3f bc;
|
||||
CMeshO::CoordType c_p; //Correct Position
|
||||
InterpolationParameters(*f,p,bc);
|
||||
@ -81,15 +90,6 @@ CMeshO::CoordType CoordinateCorrection(CMeshO::CoordType p,CMeshO::FacePointer f
|
||||
return c_p;
|
||||
};
|
||||
|
||||
bool SameSide(Point3f p1,Point3f p2,Point3f a,Point3f b){
|
||||
Point3f cp1;
|
||||
Point3f cp2;
|
||||
cp1 = (b-a)^(p1-a);
|
||||
cp2 = (b-a)^(p2-a);
|
||||
if (cp1.dot(cp2) >= 0) return true;
|
||||
else return false;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@def Verify if a point lies on a face
|
||||
@ -100,190 +100,7 @@ bool SameSide(Point3f p1,Point3f p2,Point3f a,Point3f b){
|
||||
@return true if point p is on face f, false elsewhere.
|
||||
*/
|
||||
bool IsOnFace(Point3f p, CMeshO::FacePointer f){
|
||||
//Verify if the point is on the same plane of the face
|
||||
|
||||
|
||||
CMeshO::CoordType n=f->N();
|
||||
|
||||
Point3f a=f->P(0);
|
||||
if(math::Abs((p-a).dot(n))>0.0005) return false;
|
||||
|
||||
|
||||
|
||||
//Point3f bc;
|
||||
//isOnFace=InterpolationParameters(*f,vcg::Normal(*f),p,bc);
|
||||
|
||||
//if(isOnFace && bc[0]>=0 && bc[1]>=0 && (bc[0]+bc[1]<=1)) return true;
|
||||
|
||||
|
||||
//Point3f a=f->P(0);
|
||||
//float tmp2=n.dot(p);
|
||||
//float tmp=n.dot(a);
|
||||
//if(math::Abs(tmp2-tmp)>0.01) return false;
|
||||
//Point3f v0 = (f->V(0))->P();
|
||||
//Point3f v1 = (f->V(1))->P();
|
||||
//Point3f v2 = (f->V(2))->P();
|
||||
|
||||
|
||||
// if(SameSide(p,v0,v1,v2) && SameSide(p,v1,v0,v2) && SameSide(p,v2,v0,v1)) return true;
|
||||
// return false;
|
||||
/*
|
||||
//Compute Barycentric coordinates
|
||||
Point3f bc;
|
||||
bool isOnFace=false;
|
||||
isOnFace=InterpolationParameters(*f,vcg::Normal(*f),p,bc);
|
||||
if(!isOnFace) return false;
|
||||
isOnFace=(bc[0]>=0 && bc[1]>=0) && (bc[0]+bc[1] < 1);
|
||||
return isOnFace;
|
||||
*/
|
||||
/*
|
||||
|
||||
CMeshO::CoordType n=f->N();
|
||||
Point3f a=f->P(0);
|
||||
float tmp2=n.dot(p);
|
||||
float tmp=n.dot(a);
|
||||
if(math::Abs(tmp2-tmp)>0.001) return false;
|
||||
*/
|
||||
|
||||
/*
|
||||
int max_c;
|
||||
|
||||
if(math::Abs(n[0])>math::Abs(n[1])){
|
||||
if(math::Abs(n[0])>math::Abs(n[2])) max_c=0;
|
||||
else max_c=2;
|
||||
}else{
|
||||
if(math::Abs(n[1])>math::Abs(n[2])) max_c=1;
|
||||
else max_c=2;
|
||||
}
|
||||
|
||||
|
||||
CMeshO::CoordType fv0 = (f->V(0))->P();
|
||||
CMeshO::CoordType fv1 = (f->V(1))->P();
|
||||
CMeshO::CoordType fv2 = (f->V(2))->P();
|
||||
Point2<float> A;
|
||||
Point2<float> B;
|
||||
Point2<float> C;
|
||||
Point2<float> P;
|
||||
switch(max_c){
|
||||
|
||||
case 0:{
|
||||
A=Point2f(fv0[1],fv0[2]);
|
||||
B=Point2f(fv1[1],fv1[2]);
|
||||
C=Point2f(fv2[1],fv2[2]);
|
||||
P=Point2f(p[1],p[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:{
|
||||
A=Point2f(fv0[0],fv0[2]);
|
||||
B=Point2f(fv1[0],fv1[2]);
|
||||
C=Point2f(fv2[0],fv2[2]);
|
||||
P=Point2f(p[0],p[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:{
|
||||
A=Point2f(fv0[0],fv0[1]);
|
||||
B=Point2f(fv1[0],fv1[1]);
|
||||
C=Point2f(fv2[0],fv2[1]);
|
||||
P=Point2f(p[0],p[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Point3f A=f->V(0)->P();
|
||||
Point3f B=f->V(1)->P();
|
||||
Point3f C=f->V(2)->P();
|
||||
|
||||
Point3fv0 = C - A;
|
||||
Point3fv1 = B - A;
|
||||
Point3fv2 = p - A;
|
||||
|
||||
// Compute dot products
|
||||
double dot00 = v0.dot(v0);
|
||||
double dot01 = v0.dot(v1);
|
||||
double dot02 = v0.dot(v2);
|
||||
double dot11 = v1.dot(v1);
|
||||
double dot12 = v1.dot(v2);
|
||||
|
||||
// Compute barycentric coordinates
|
||||
double invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
|
||||
double u = (dot11 * dot02 - dot01 * dot12) * invDenom;
|
||||
double v = (dot00 * dot12 - dot01 * dot02) * invDenom;
|
||||
|
||||
// Check if point is in triangle
|
||||
//Compute Barycentric coordinates
|
||||
Point3f bc;
|
||||
|
||||
InterpolationParameters(*f,vcg::Normal(*f),p,bc);
|
||||
|
||||
bool isOnFace=(u >= 0) && (v >= 0) && (u + v <= 1.00001);
|
||||
return isOnFace;
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int max_c;
|
||||
|
||||
float n0=math::Abs(n[0]);
|
||||
float n1=math::Abs(n[1]);
|
||||
float n2=math::Abs(n[2]);
|
||||
|
||||
if(n0>n1){
|
||||
if(n0>n2) max_c=0;
|
||||
else max_c=2;
|
||||
}else{
|
||||
if(n1>n2) max_c=1;
|
||||
else max_c=2;
|
||||
}
|
||||
|
||||
|
||||
Point2f p_2d;
|
||||
Point2f p0_2d;
|
||||
Point2f p1_2d;
|
||||
Point2f p2_2d;
|
||||
|
||||
CMeshO::CoordType p0 = f->P(0);
|
||||
CMeshO::CoordType p1 = f->P(1);
|
||||
CMeshO::CoordType p2 = f->P(2);
|
||||
switch(max_c){
|
||||
case 0:{
|
||||
p0_2d=Point2f(p0[1],p0[2]);
|
||||
p1_2d=Point2f(p1[1],p1[2]);
|
||||
p2_2d=Point2f(p2[1],p2[2]);
|
||||
p_2d =Point2f(p[1],p[2]);
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
p0_2d=Point2f(p0[0],p0[2]);
|
||||
p1_2d=Point2f(p1[0],p1[2]);
|
||||
p2_2d=Point2f(p2[0],p2[2]);
|
||||
p_2d =Point2f(p[0],p[2]);
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
p0_2d=Point2f(p0[0],p0[1]);
|
||||
p1_2d=Point2f(p1[0],p1[1]);
|
||||
p2_2d=Point2f(p2[0],p2[1]);
|
||||
p_2d =Point2f(p[0],p[1]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Triangle2<float> f_2d=Triangle2<float>(p0_2d,p1_2d,p2_2d);
|
||||
|
||||
|
||||
|
||||
return IsInsideTrianglePoint(f_2d,p_2d);
|
||||
|
||||
};
|
||||
@ -330,10 +147,7 @@ float getElapsedTime(CMeshO::CoordType vi,CMeshO::CoordType vf,CMeshO::FacePoint
|
||||
return t;
|
||||
};
|
||||
|
||||
/**
|
||||
@def
|
||||
|
||||
*/
|
||||
bool IsOnEdge(CMeshO::CoordType p,CMeshO::FacePointer f){
|
||||
if(f==0) return false;
|
||||
float bc[3];
|
||||
@ -343,6 +157,60 @@ bool IsOnEdge(CMeshO::CoordType p,CMeshO::FacePointer f){
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
CMeshO::CoordType ComputeVelocity(CMeshO::CoordType vi,CMeshO::CoordType ac,float t){
|
||||
|
||||
CMeshO::CoordType n_vel;
|
||||
|
||||
n_vel[0]=vi[0]+ac[0]*t;
|
||||
n_vel[1]=vi[1]+ac[1]*t;
|
||||
n_vel[2]=vi[2]+ac[2]*t;
|
||||
|
||||
return n_vel;
|
||||
};
|
||||
CMeshO::CoordType UpdateVelocity(CMeshO::CoordType pf,CMeshO::CoordType pi,CMeshO::CoordType v,float m,CMeshO::FacePointer &face,CMeshO::CoordType force){
|
||||
|
||||
CMeshO::CoordType new_vel;
|
||||
Point3f n= face->cN();
|
||||
float a=n[0]*force[0]+n[1]*force[1]+n[2]*force[2];
|
||||
//float b=n[0]*vel[0]+n[1]*vel[1]+n[2]*vel[2];
|
||||
|
||||
Point3f f;
|
||||
//Point3f v;
|
||||
|
||||
f[0]=force[0]-a*n[0];
|
||||
f[1]=force[1]-a*n[1];
|
||||
f[2]=force[2]-a*n[2];
|
||||
|
||||
|
||||
//v[0]=vel[0]-b*n[0];
|
||||
//v[1]=vel[1]-b*n[1];
|
||||
//v[2]=vel[2]-b*n[2];
|
||||
|
||||
new_vel[0]=sqrt(pow(v[0],2)+2*(f[0]/m)*(pf[0]-pi[0]) );
|
||||
new_vel[1]=sqrt(pow(v[1],2)+2*(f[1]/m)*(pf[1]-pi[1]) );
|
||||
new_vel[2]=sqrt(pow(v[2],2)+2*(f[2]/m)*(pf[2]-pi[2]) );
|
||||
|
||||
|
||||
return new_vel;
|
||||
};
|
||||
CMeshO::CoordType ComputeAcceleration(float m,CMeshO::FacePointer face,CMeshO::CoordType dir){
|
||||
CMeshO::CoordType acc;
|
||||
|
||||
Point3f n= face->N();
|
||||
float a=n[0]*dir[0]+n[1]*dir[1]+n[2]*dir[2];
|
||||
|
||||
acc[0]=dir[0]-a*n[0];
|
||||
acc[1]=dir[1]-a*n[1];
|
||||
acc[2]=dir[2]-a*n[2];
|
||||
|
||||
return acc;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@def
|
||||
*/
|
||||
CMeshO::CoordType GetVelocityComponents(float v,float l,CMeshO::FacePointer face){
|
||||
|
||||
Point3f dir = Point3f(0,-1,0);
|
||||
@ -382,58 +250,9 @@ CMeshO::CoordType GetVelocityComponents(float v,float l,CMeshO::FacePointer face
|
||||
|
||||
};
|
||||
|
||||
CMeshO::CoordType ComputeVelocity(CMeshO::CoordType vi,CMeshO::CoordType ac,float t){
|
||||
|
||||
CMeshO::CoordType n_vel;
|
||||
|
||||
n_vel[0]=vi[0]+ac[0]*t;
|
||||
n_vel[1]=vi[1]+ac[1]*t;
|
||||
n_vel[2]=vi[2]+ac[2]*t;
|
||||
|
||||
return n_vel;
|
||||
};
|
||||
CMeshO::CoordType UpdateVelocity(CMeshO::CoordType pf,CMeshO::CoordType pi,CMeshO::CoordType v,float m,CMeshO::FacePointer &face,CMeshO::CoordType force){
|
||||
|
||||
CMeshO::CoordType new_vel;
|
||||
Point3f n= face->cN();
|
||||
float a=n[0]*force[0]+n[1]*force[1]+n[2]*force[2];
|
||||
//float b=n[0]*vel[0]+n[1]*vel[1]+n[2]*vel[2];
|
||||
|
||||
Point3f f;
|
||||
//Point3f v;
|
||||
|
||||
f[0]=force[0]-a*n[0];
|
||||
f[1]=force[1]-a*n[1];
|
||||
f[2]=force[2]-a*n[2];
|
||||
|
||||
|
||||
//v[0]=vel[0]-b*n[0];
|
||||
//v[1]=vel[1]-b*n[1];
|
||||
//v[2]=vel[2]-b*n[2];
|
||||
|
||||
new_vel[0]=sqrt(pow(v[0],2)+2*(f[0]/m)*(pf[0]-pi[0]) );
|
||||
new_vel[1]=sqrt(pow(v[1],2)+2*(f[1]/m)*(pf[1]-pi[1]) );
|
||||
new_vel[2]=sqrt(pow(v[2],2)+2*(f[2]/m)*(pf[2]-pi[2]) );
|
||||
|
||||
|
||||
return new_vel;
|
||||
};
|
||||
|
||||
CMeshO::CoordType ComputeAcceleration(float m,CMeshO::FacePointer face,CMeshO::CoordType dir){
|
||||
CMeshO::CoordType acc;
|
||||
|
||||
Point3f n= face->N();
|
||||
float a=n[0]*dir[0]+n[1]*dir[1]+n[2]*dir[2];
|
||||
|
||||
acc[0]=dir[0]-a*n[0];
|
||||
acc[1]=dir[1]-a*n[1];
|
||||
acc[2]=dir[2]-a*n[2];
|
||||
|
||||
return acc;
|
||||
};
|
||||
|
||||
/**
|
||||
@description Simulate the movement of a point, affected by a force "dir" on a face.
|
||||
@def Simulate the movement of a point, affected by a force "dir" on a face.
|
||||
|
||||
@param CoordType p - coordinates of the point
|
||||
@param CoordType v - velocity of the particle
|
||||
@ -444,36 +263,23 @@ CMeshO::CoordType ComputeAcceleration(float m,CMeshO::FacePointer face,CMeshO::C
|
||||
|
||||
@return new coordinates of the point
|
||||
*/
|
||||
CMeshO::CoordType StepForward(CMeshO::CoordType p,
|
||||
float v,
|
||||
float m,
|
||||
CMeshO::FacePointer &face,
|
||||
CMeshO::CoordType dir,float l,
|
||||
float t=1){
|
||||
|
||||
/* if(v<0.005 && IsOnEdge(p,face))
|
||||
return p;
|
||||
*/
|
||||
|
||||
|
||||
CMeshO::CoordType StepForward(CMeshO::CoordType p,float v,float m,CMeshO::FacePointer &face,CMeshO::CoordType dir,float l,float t=1){
|
||||
|
||||
dir=dir*l;
|
||||
Point3f new_pos;
|
||||
Point3f n= face->N();
|
||||
float a=n[0]*dir[0]+n[1]*dir[1]+n[2]*dir[2];
|
||||
|
||||
// float b=n[0]*vel[0]+n[1]*vel[1]+n[2]*vel[2];
|
||||
|
||||
|
||||
|
||||
Point3f f;
|
||||
Point3f vel=GetVelocityComponents(v,l,face);
|
||||
//Calcolo le componenti della forza lungo la faccia
|
||||
|
||||
//Compute force component along the face
|
||||
f[0]=dir[0]-a*n[0];
|
||||
f[1]=dir[1]-a*n[1];
|
||||
f[2]=dir[2]-a*n[2];
|
||||
|
||||
|
||||
new_pos[0]=p[0]+vel[0]*t+0.5*(f[0]/m)*pow(t,2);
|
||||
new_pos[1]=p[1]+vel[1]*t+0.5*(f[1]/m)*pow(t,2);
|
||||
new_pos[2]=p[2]+vel[2]*t+0.5*(f[2]/m)*pow(t,2);
|
||||
@ -503,7 +309,8 @@ void DrawDirt(MeshModel *m/*,std::vector<Point3f> &dp*/){
|
||||
@param CoordType int_point - intersection point this is a return parameter for the function.
|
||||
@param FacePointer face - pointer to the new face
|
||||
|
||||
@return true if there is an intersection
|
||||
@return true if there is an intersection, false elsewhere
|
||||
|
||||
*/
|
||||
bool ComputeIntersection(CMeshO::CoordType p1,CMeshO::CoordType p2,CMeshO::FacePointer &f,CMeshO::FacePointer &new_f,CMeshO::CoordType &int_point)
|
||||
{
|
||||
@ -569,8 +376,9 @@ bool ComputeIntersection(CMeshO::CoordType p1,CMeshO::CoordType p2,CMeshO::FaceP
|
||||
|
||||
Point2f tmp_int;
|
||||
bool int_found=false;
|
||||
int edge;
|
||||
int edge=-1;
|
||||
float dist=0;
|
||||
|
||||
if(LineSegmentIntersection(seg,line0,tmp_int)){
|
||||
dist=Distance(p2_2d,tmp_int);
|
||||
edge=0;
|
||||
@ -616,76 +424,6 @@ bool ComputeIntersection(CMeshO::CoordType p1,CMeshO::CoordType p2,CMeshO::FaceP
|
||||
|
||||
|
||||
|
||||
|
||||
if(!int_found){
|
||||
Point3f bc;
|
||||
InterpolationParameters(*f,f->N(),p1,bc);
|
||||
int p=1;
|
||||
}
|
||||
|
||||
/*
|
||||
if(SegmentSegmentIntersection(line0,seg,tmp)){
|
||||
if(tmp!=p1_2d){
|
||||
int_p=tmp;
|
||||
edge=0;
|
||||
int_found=true;
|
||||
}
|
||||
}
|
||||
if(SegmentSegmentIntersection(line1,seg,tmp)){
|
||||
if(tmp!=p1_2d){
|
||||
int_p =tmp;
|
||||
edge=1;
|
||||
int_found=true;
|
||||
}
|
||||
}
|
||||
if(SegmentSegmentIntersection(line2,seg,tmp)){
|
||||
if(tmp!=p1_2d){
|
||||
int_p =tmp;
|
||||
edge=2;
|
||||
int_found=true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
bool int_found=false;
|
||||
int edge=-1;
|
||||
Point2f tmp;
|
||||
if(SegmentSegmentIntersection(line0,seg,tmp)){
|
||||
int_found=true;
|
||||
int_p=tmp;
|
||||
edge=0;
|
||||
}
|
||||
if(SegmentSegmentIntersection(line1,seg,tmp)){
|
||||
if(int_found){
|
||||
|
||||
if(Segment2f(tmp,p2_2d).Length()<Segment2f(int_p,p2_2d).Length()){
|
||||
int_found=true;
|
||||
int_p=tmp;
|
||||
edge=1;
|
||||
}
|
||||
}else{
|
||||
int_found=true;
|
||||
int_p=tmp;
|
||||
edge=1;
|
||||
}
|
||||
}
|
||||
if(SegmentSegmentIntersection(line2,seg,tmp)){
|
||||
if(int_found){
|
||||
if(Segment2f(tmp,p2_2d).Length()<Segment2f(int_p,p2_2d).Length()){
|
||||
int_found=true;
|
||||
int_p=tmp;
|
||||
edge=2;
|
||||
}
|
||||
}else{
|
||||
int_found=true;
|
||||
int_p=tmp;
|
||||
edge=2;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
if(int_found){
|
||||
new_f=f->FFp(edge);
|
||||
switch(max_c){
|
||||
@ -708,69 +446,21 @@ bool ComputeIntersection(CMeshO::CoordType p1,CMeshO::CoordType p2,CMeshO::FaceP
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if(int_found){
|
||||
Point3f bc;
|
||||
InterpolationParameters(*new_f,new_f->N(),int_point,bc);
|
||||
int min_c;
|
||||
|
||||
if(bc[0]<bc[1]){
|
||||
if(bc[0]<bc[2]){
|
||||
min_c=0;
|
||||
}else{
|
||||
min_c=2;
|
||||
}
|
||||
}else{
|
||||
if(bc[1]<bc[2]){
|
||||
min_c=1;
|
||||
}else{
|
||||
min_c=2;
|
||||
}
|
||||
}
|
||||
|
||||
switch(edge){
|
||||
|
||||
case 0:{
|
||||
bc[0]=0;
|
||||
bc[1]=bc[1];
|
||||
bc[2]=1-bc[1]-0.0001;
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
bc[0]=bc[0];
|
||||
bc[1]=0;
|
||||
bc[2]=1-bc[0]-0.0001;
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
bc[0]=bc[0];
|
||||
bc[1]=1-bc[0]-0.0001;
|
||||
bc[2]=0;
|
||||
break;
|
||||
}
|
||||
if(!IsOnFace(int_point,new_face)){
|
||||
int_point=fixEdgePointCoordinates(int_point,new_f);
|
||||
}
|
||||
|
||||
|
||||
Point3f nf0=new_f->P(0);
|
||||
Point3f nf1=new_f->P(1);
|
||||
Point3f nf2=new_f->P(2);
|
||||
int_point[0]=nf0[0]*bc[0]+nf1[0]*bc[1]+nf2[0]*bc[2];
|
||||
int_point[1]=nf0[1]*bc[0]+nf1[1]*bc[1]+nf2[1]*bc[2];
|
||||
int_point[2]=nf0[2]*bc[0]+nf1[2]*bc[1]+nf2[2]*bc[2];
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
return int_found;
|
||||
};
|
||||
|
||||
/**
|
||||
@description generate random baricentric coordinates
|
||||
@def Generate random barycentric coordinates
|
||||
@return a triple of barycentri coordinates
|
||||
*/
|
||||
CMeshO::CoordType RandomBaricentric(){
|
||||
CMeshO::CoordType interp;
|
||||
|
||||
static math::MarsenneTwisterRNG rnd;
|
||||
interp[1] = rnd.generate01();
|
||||
interp[2] = rnd.generate01();
|
||||
@ -792,13 +482,10 @@ CMeshO::CoordType RandomBaricentric(){
|
||||
@param u CoordType dust direction
|
||||
@param k float
|
||||
@param s float
|
||||
|
||||
@return nothing
|
||||
*/
|
||||
bool ComputeNormalDustAmount(MeshModel* m,CMeshO::CoordType u,float k,float s){
|
||||
|
||||
//Verify if FaceQualty is enabled
|
||||
|
||||
|
||||
|
||||
void ComputeNormalDustAmount(MeshModel* m,CMeshO::CoordType u,float k,float s){
|
||||
|
||||
CMeshO::FaceIterator fi;
|
||||
float d;
|
||||
@ -811,12 +498,13 @@ bool ComputeNormalDustAmount(MeshModel* m,CMeshO::CoordType u,float k,float s){
|
||||
};
|
||||
|
||||
/**
|
||||
@description This function compute the Surface Exposure per face of a Mesh m
|
||||
@def This function compute the Surface Exposure per face of a Mesh m
|
||||
|
||||
@param MeshModel* m - Pointer to the new mesh
|
||||
@param int r - scaling factor
|
||||
@param int n_ray - number of rays emitted
|
||||
|
||||
@return nothing
|
||||
*/
|
||||
void ComputeSurfaceExposure(MeshModel* m,int r,int n_ray){
|
||||
CMeshO::FaceIterator fi;
|
||||
@ -877,6 +565,8 @@ void ComputeSurfaceExposure(MeshModel* m,int r,int n_ray){
|
||||
|
||||
};
|
||||
|
||||
|
||||
//To delete?
|
||||
void CreateDustTexture(MeshModel* m){
|
||||
QString textName="dust_texture";
|
||||
QString fileName(m->fullName());
|
||||
@ -891,7 +581,7 @@ void CreateDustTexture(MeshModel* m){
|
||||
}
|
||||
|
||||
/**
|
||||
@def
|
||||
@def This funcion
|
||||
|
||||
@param
|
||||
@param
|
||||
@ -950,11 +640,9 @@ return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
void associateParticles(MeshModel* b_m,MeshModel* c_m,float m,float v){
|
||||
CMeshO::PerVertexAttributeHandle<Particle<CMeshO> > ph= tri::Allocator<CMeshO>::AddPerVertexAttribute<Particle<CMeshO> > (c_m->cm,std::string("ParticleInfo"));
|
||||
CMeshO::FaceIterator fi;
|
||||
@ -974,7 +662,13 @@ void associateParticles(MeshModel* b_m,MeshModel* c_m,float m,float v){
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@def This function initialize the mesh m in order to respect some prerequisites of the filter
|
||||
|
||||
@param MeshModel* m - Pointer to the Mesh
|
||||
|
||||
@return nothing
|
||||
*/
|
||||
void prepareMesh(MeshModel* m){
|
||||
//clean flags
|
||||
|
||||
@ -1004,63 +698,52 @@ void prepareMesh(MeshModel* m){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@def This function simulate the movement of the cloud mesh, it requires that every point is associated with a Particle data structure
|
||||
|
||||
bool MoveCloudMeshForward(MeshModel *cloud,Point3f force,float l,float time){
|
||||
@param MeshModel cloud - Mesh of points
|
||||
@param Point3f force - Direction of the force
|
||||
@param float l - Lenght of the step
|
||||
@param float time - Time Step
|
||||
|
||||
@return nothing
|
||||
*/
|
||||
void MoveCloudMeshForward(MeshModel *cloud,Point3f force,float l,float time){
|
||||
CMeshO::PerVertexAttributeHandle<Particle<CMeshO> > ph = Allocator<CMeshO>::GetPerVertexAttribute<Particle<CMeshO> >(cloud->cm,"ParticleInfo");
|
||||
CMeshO::VertexIterator vi;
|
||||
CMeshO::FacePointer current_face;
|
||||
CMeshO::FacePointer new_face;
|
||||
float velocity;
|
||||
float mass;
|
||||
CMeshO::CoordType new_pos;
|
||||
CMeshO::CoordType current_pos;
|
||||
CMeshO::CoordType int_pos;
|
||||
|
||||
for(vi=cloud->cm.vert.begin();vi!=cloud->cm.vert.end();++vi){
|
||||
float t=time;
|
||||
|
||||
current_face=ph[vi].face;
|
||||
new_face=current_face ;
|
||||
current_pos=vi->P();
|
||||
|
||||
velocity=ph[vi].vel;
|
||||
mass=ph[vi].mass;
|
||||
|
||||
new_pos=StepForward(vi->P(),velocity,mass,current_face,force,l,t);
|
||||
|
||||
while(!IsOnFace(new_pos,current_face)){
|
||||
bool tmp=ComputeIntersection(current_pos,new_pos,current_face,new_face,int_pos);
|
||||
new_face->C()=Color4b::Yellow;
|
||||
if(!tmp){
|
||||
break;
|
||||
}
|
||||
CMeshO::FacePointer new_face;
|
||||
ComputeIntersection(current_pos,new_pos,current_face,new_face,int_pos);
|
||||
new_pos=int_pos;
|
||||
|
||||
//Debug
|
||||
current_face->C()=Color4b::Black;
|
||||
current_face=new_face;
|
||||
|
||||
t=t/2;
|
||||
if(t>0.5){
|
||||
new_pos=StepForward(vi->P(),velocity,mass,current_face,force,l,t);
|
||||
}else{
|
||||
current_face->C()=Color4b::Green;
|
||||
if(!IsOnFace(new_pos,current_face)){
|
||||
CoordinateCorrection(new_pos,current_face);
|
||||
Point3f bc;
|
||||
InterpolationParameters(*new_face,new_pos,bc);
|
||||
current_face->C()=Color4b::Red;
|
||||
|
||||
}
|
||||
|
||||
InterpolationParameters(*current_face,new_pos,bc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vi->P()=new_pos;
|
||||
ph[vi].face=current_face;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@ -206,6 +206,7 @@ bool FilterDirt::applyFilter(QAction *filter, MeshDocument &md, RichParameterSet
|
||||
|
||||
float default_time=1;
|
||||
|
||||
//Get Parameters
|
||||
Point3f dir=par.getPoint3f("force_dir");;
|
||||
float l =par.getAbsPerc("s_length");
|
||||
float v=par.getFloat("velocity");
|
||||
@ -217,6 +218,7 @@ bool FilterDirt::applyFilter(QAction *filter, MeshDocument &md, RichParameterSet
|
||||
associateParticles(base_mesh,cloud_mesh,m,v);
|
||||
}
|
||||
|
||||
//Move Cloud Mesh
|
||||
MoveCloudMeshForward(cloud_mesh,dir,l,1);
|
||||
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user