Skip to content
Snippets Groups Projects
Commit 14db45e5 authored by Tristan Carrier Baudouin's avatar Tristan Carrier Baudouin
Browse files

reverting to the isotropic version of the RTree algorithm

parent 6fd564fb
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
#include "rtree.h" #include "rtree.h"
#endif #endif
#define baseline 0.7 #define k1 0.7 //k1*h is the minimal distance between two nodes
#define k2 0.5 //k2*h is the minimal distance to the boundary
#define sqrt3 1.73205081
/*********definitions*********/ /*********definitions*********/
...@@ -49,46 +51,43 @@ class Metric{ ...@@ -49,46 +51,43 @@ class Metric{
class Node{ class Node{
private: private:
double h1; double h;
double h2;
double h3;
Metric m; Metric m;
SPoint3 point; SPoint3 point;
public: public:
double min[3];
double max[3];
Node(); Node();
Node(SPoint3); Node(SPoint3);
~Node(); ~Node();
void set_h1(double); void set_size(double);
void set_h2(double);
void set_h3(double);
void set_metric(Metric); void set_metric(Metric);
void set_point(SPoint3); void set_point(SPoint3);
double get_h1(); double get_size();
double get_h2();
double get_h3();
Metric get_metric(); Metric get_metric();
SPoint3 get_point(); SPoint3 get_point();
double min[3];
double max[3];
}; };
class Wrapper{ class Wrapper{
private: private:
bool too_close; bool too_close;
Node* spawn; Node* spawn;
Node* parent;
public: public:
Wrapper(); Wrapper();
Wrapper(Node*); Wrapper(Node*,Node*);
~Wrapper(); ~Wrapper();
void set_too_close(bool); void set_too_close(bool);
void set_spawn(Node*); void set_spawn(Node*);
void set_parent(Node*);
bool get_too_close(); bool get_too_close();
Node* get_spawn(); Node* get_spawn();
Node* get_parent();
}; };
/*********functions*********/ /*********functions*********/
double infinity_distance(SPoint3 p1,SPoint3 p2,Metric m,double h1,double h2,double h3){ double infinity_distance(SPoint3 p1,SPoint3 p2,Metric m){
double distance; double distance;
double x1,y1,z1; double x1,y1,z1;
double x2,y2,z2; double x2,y2,z2;
...@@ -103,39 +102,38 @@ double infinity_distance(SPoint3 p1,SPoint3 p2,Metric m,double h1,double h2,doub ...@@ -103,39 +102,38 @@ double infinity_distance(SPoint3 p1,SPoint3 p2,Metric m,double h1,double h2,doub
g = m.get_m13(); g = m.get_m13();
h = m.get_m23(); h = m.get_m23();
i = m.get_m33(); i = m.get_m33();
x1 = a*p1.x() + b*p1.y() + c*p1.z();
y1 = d*p1.x() + e*p1.y() + f*p1.z();
z1 = g*p1.x() + h*p1.y() + i*p1.z();
x1 = (1.0/h1)*(a*p1.x() + b*p1.y() + c*p1.z()); x2 = a*p2.x() + b*p2.y() + c*p2.z();
y1 = (1.0/h2)*(d*p1.x() + e*p1.y() + f*p1.z()); y2 = d*p2.x() + e*p2.y() + f*p2.z();
z1 = (1.0/h3)*(g*p1.x() + h*p1.y() + i*p1.z()); z2 = g*p2.x() + h*p2.y() + i*p2.z();
x2 = (1.0/h1)*(a*p2.x() + b*p2.y() + c*p2.z());
y2 = (1.0/h2)*(d*p2.x() + e*p2.y() + f*p2.z());
z2 = (1.0/h3)*(g*p2.x() + h*p2.y() + i*p2.z());
distance = std::max(std::max(fabs(x2-x1),fabs(y2-y1)),fabs(z2-z1)); distance = std::max(std::max(fabs(x2-x1),fabs(y2-y1)),fabs(z2-z1));
return distance; return distance;
} }
bool rtree_callback(Node* neighbour,void* w){ bool rtree_callback(Node* neighbour,void* w){
double h1; double h;
double h2;
double h3;
double distance; double distance;
Metric m; Metric m;
Node *spawn; Node *spawn,*parent;
Wrapper* wrapper; Wrapper* wrapper;
wrapper = static_cast<Wrapper*>(w); wrapper = static_cast<Wrapper*>(w);
spawn = wrapper->get_spawn(); spawn = wrapper->get_spawn();
h1 = spawn->get_h1(); parent = wrapper->get_parent();
h2 = spawn->get_h2(); h = spawn->get_size();
h3 = spawn->get_h3();
m = spawn->get_metric(); m = spawn->get_metric();
distance = infinity_distance(spawn->get_point(),neighbour->get_point(),m,h1,h2,h3); if(neighbour!=parent){
if(distance<baseline){ distance = infinity_distance(spawn->get_point(),neighbour->get_point(),m);
wrapper->set_too_close(1); if(distance<k1*h){
return false; wrapper->set_too_close(1);
return false;
}
} }
return true; return true;
...@@ -239,16 +237,8 @@ Node::Node(SPoint3 new_point){ ...@@ -239,16 +237,8 @@ Node::Node(SPoint3 new_point){
Node::~Node(){} Node::~Node(){}
void Node::set_h1(double new_h1){ void Node::set_size(double new_h){
h1 = new_h1; h = new_h;
}
void Node::set_h2(double new_h2){
h2 = new_h2;
}
void Node::set_h3(double new_h3){
h3 = new_h3;
} }
void Node::set_metric(Metric new_m){ void Node::set_metric(Metric new_m){
...@@ -259,16 +249,8 @@ void Node::set_point(SPoint3 new_point){ ...@@ -259,16 +249,8 @@ void Node::set_point(SPoint3 new_point){
point = new_point; point = new_point;
} }
double Node::get_h1(){ double Node::get_size(){
return h1; return h;
}
double Node::get_h2(){
return h2;
}
double Node::get_h3(){
return h3;
} }
Metric Node::get_metric(){ Metric Node::get_metric(){
...@@ -285,9 +267,10 @@ Wrapper::Wrapper(){ ...@@ -285,9 +267,10 @@ Wrapper::Wrapper(){
too_close = 0; too_close = 0;
} }
Wrapper::Wrapper(Node* new_spawn){ Wrapper::Wrapper(Node* new_spawn,Node* new_parent){
too_close = 0; too_close = 0;
spawn = new_spawn; spawn = new_spawn;
parent = new_parent;
} }
Wrapper::~Wrapper(){} Wrapper::~Wrapper(){}
...@@ -300,6 +283,10 @@ void Wrapper::set_spawn(Node* new_spawn){ ...@@ -300,6 +283,10 @@ void Wrapper::set_spawn(Node* new_spawn){
spawn = new_spawn; spawn = new_spawn;
} }
void Wrapper::set_parent(Node* new_parent){
parent = new_parent;
}
bool Wrapper::get_too_close(){ bool Wrapper::get_too_close(){
return too_close; return too_close;
} }
...@@ -308,6 +295,10 @@ Node* Wrapper::get_spawn(){ ...@@ -308,6 +295,10 @@ Node* Wrapper::get_spawn(){
return spawn; return spawn;
} }
Node* Wrapper::get_parent(){
return parent;
}
/*********class Filler*********/ /*********class Filler*********/
Filler::Filler(){} Filler::Filler(){}
...@@ -335,8 +326,7 @@ void Filler::treat_region(GRegion* gr){ ...@@ -335,8 +326,7 @@ void Filler::treat_region(GRegion* gr){
bool ok; bool ok;
double x,y,z; double x,y,z;
SPoint3 point; SPoint3 point;
Node *node,*spawn,*parent; Node *node,*spawn,*parent,*n1,*n2,*n3,*n4,*n5,*n6;
Node *n1,*n2,*n3,*n4,*n5,*n6;
MVertex* vertex; MVertex* vertex;
MElement* element; MElement* element;
MElementOctree* octree; MElementOctree* octree;
...@@ -391,7 +381,7 @@ void Filler::treat_region(GRegion* gr){ ...@@ -391,7 +381,7 @@ void Filler::treat_region(GRegion* gr){
n4 = new Node(); n4 = new Node();
n5 = new Node(); n5 = new Node();
n6 = new Node(); n6 = new Node();
offsprings(parent,n1,n2,n3,n4,n5,n6); offsprings(gr,octree,parent,n1,n2,n3,n4,n5,n6);
data.clear(); data.clear();
data.push_back(n1); data.push_back(n1);
data.push_back(n2); data.push_back(n2);
...@@ -408,16 +398,19 @@ void Filler::treat_region(GRegion* gr){ ...@@ -408,16 +398,19 @@ void Filler::treat_region(GRegion* gr){
z = point.z(); z = point.z();
if(inside_domain(octree,x,y,z)){ if(inside_domain(octree,x,y,z)){
compute_parameters(spawn,gr); compute_parameters(spawn,gr);
wrapper.set_too_close(0); if(far_from_boundary(octree,spawn)){
wrapper.set_spawn(spawn); wrapper.set_too_close(0);
rtree.Search(spawn->min,spawn->max,rtree_callback,&wrapper); wrapper.set_spawn(spawn);
if(!wrapper.get_too_close()){ wrapper.set_parent(parent);
fifo.push(spawn); rtree.Search(spawn->min,spawn->max,rtree_callback,&wrapper);
rtree.Insert(spawn->min,spawn->max,spawn); if(!wrapper.get_too_close()){
vertex = new MVertex(x,y,z,gr,0); fifo.push(spawn);
new_vertices.push_back(vertex); rtree.Insert(spawn->min,spawn->max,spawn);
ok = 1; vertex = new MVertex(x,y,z,gr,0);
} new_vertices.push_back(vertex);
ok = 1;
}
}
} }
if(!ok) delete spawn; if(!ok) delete spawn;
} }
...@@ -461,15 +454,7 @@ Metric Filler::get_metric(double x,double y,double z){ ...@@ -461,15 +454,7 @@ Metric Filler::get_metric(double x,double y,double z){
return m; return m;
} }
double Filler::get_h1(double x,double y,double z){ double Filler::get_size(double x,double y,double z){
return 0.25;
}
double Filler::get_h2(double x,double y,double z){
return 0.25;
}
double Filler::get_h3(double x,double y,double z){
return 0.25; return 0.25;
} }
...@@ -503,7 +488,7 @@ Metric Filler::get_clf_metric(double x,double y,double z,GEntity* ge){ ...@@ -503,7 +488,7 @@ Metric Filler::get_clf_metric(double x,double y,double z,GEntity* ge){
return m; return m;
} }
double Filler::get_clf_h(double x,double y,double z,GEntity* ge){ double Filler::get_clf_size(double x,double y,double z,GEntity* ge){
double h; double h;
Field* field; Field* field;
FieldManager* manager; FieldManager* manager;
...@@ -527,11 +512,32 @@ bool Filler::inside_domain(MElementOctree* octree,double x,double y,double z){ ...@@ -527,11 +512,32 @@ bool Filler::inside_domain(MElementOctree* octree,double x,double y,double z){
else return 0; else return 0;
} }
bool Filler::far_from_boundary(MElementOctree* octree,Node* node){
double x,y,z;
double h;
SPoint3 point;
MElement *e1,*e2,*e3,*e4,*e5,*e6;
point = node->get_point();
x = point.x();
y = point.y();
z = point.z();
h = node->get_size();
e1 = (MElement*)octree->find(x+k2*h,y,z,3,true);
e2 = (MElement*)octree->find(x-k2*h,y,z,3,true);
e3 = (MElement*)octree->find(x,y+k2*h,z,3,true);
e4 = (MElement*)octree->find(x,y-k2*h,z,3,true);
e5 = (MElement*)octree->find(x,y,z+k2*h,3,true);
e6 = (MElement*)octree->find(x,y,z-k2*h,3,true);
if(e1!=NULL && e2!=NULL && e3!=NULL && e4!=NULL && e5!=NULL && e6!=NULL) return 1;
else return 0;
}
void Filler::compute_parameters(Node* node,GEntity* ge){ void Filler::compute_parameters(Node* node,GEntity* ge){
double x,y,z; double x,y,z;
double h1; double h;
double h2;
double h3;
Metric m; Metric m;
SPoint3 point; SPoint3 point;
...@@ -540,23 +546,19 @@ void Filler::compute_parameters(Node* node,GEntity* ge){ ...@@ -540,23 +546,19 @@ void Filler::compute_parameters(Node* node,GEntity* ge){
y = point.y(); y = point.y();
z = point.z(); z = point.z();
m = get_metric(x,y,z); m = get_metric(x,y,z);
h1 = get_h1(x,y,z); h = get_size(x,y,z);
h2 = get_h2(x,y,z);
h3 = get_h3(x,y,z);
node->set_size(h);
node->set_metric(m); node->set_metric(m);
node->set_h1(h1); node->min[0] = x - sqrt3*h;
node->set_h2(h2); node->min[1] = y - sqrt3*h;
node->set_h3(h3); node->min[2] = z - sqrt3*h;
node->min[0] = x - sqrt(h1*h1 + h2*h2 + h3*h3); node->max[0] = x + sqrt3*h;
node->min[1] = y - sqrt(h1*h1 + h2*h2 + h3*h3); node->max[1] = y + sqrt3*h;
node->min[2] = z - sqrt(h1*h1 + h2*h2 + h3*h3); node->max[2] = z + sqrt3*h;
node->max[0] = x + sqrt(h1*h1 + h2*h2 + h3*h3); }
node->max[1] = y + sqrt(h1*h1 + h2*h2 + h3*h3);
node->max[2] = z + sqrt(h1*h1 + h2*h2 + h3*h3); void Filler::offsprings(GEntity* ge,MElementOctree* octree,Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5,Node* n6){
}
void Filler::offsprings(Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5,Node* n6){
double x,y,z; double x,y,z;
double x1,y1,z1; double x1,y1,z1;
double x2,y2,z2; double x2,y2,z2;
...@@ -564,9 +566,8 @@ void Filler::offsprings(Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5, ...@@ -564,9 +566,8 @@ void Filler::offsprings(Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5,
double x4,y4,z4; double x4,y4,z4;
double x5,y5,z5; double x5,y5,z5;
double x6,y6,z6; double x6,y6,z6;
double h1; double h;
double h2; double h1,h2,h3,h4,h5,h6;
double h3;
Metric m; Metric m;
SPoint3 point; SPoint3 point;
...@@ -574,34 +575,38 @@ void Filler::offsprings(Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5, ...@@ -574,34 +575,38 @@ void Filler::offsprings(Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5,
x = point.x(); x = point.x();
y = point.y(); y = point.y();
z = point.z(); z = point.z();
h1 = node->get_h1(); h = node->get_size();
h2 = node->get_h2();
h3 = node->get_h3();
m = node->get_metric(); m = node->get_metric();
h1 = improvement(ge,octree,point,h,SVector3(m.get_m11(),m.get_m21(),m.get_m31()));
x1 = x + h1*m.get_m11(); x1 = x + h1*m.get_m11();
y1 = y + h1*m.get_m21(); y1 = y + h1*m.get_m21();
z1 = z + h1*m.get_m31(); z1 = z + h1*m.get_m31();
x2 = x - h1*m.get_m11(); h2 = improvement(ge,octree,point,h,SVector3(-m.get_m11(),-m.get_m21(),-m.get_m31()));
y2 = y - h1*m.get_m21(); x2 = x - h2*m.get_m11();
z2 = z - h1*m.get_m31(); y2 = y - h2*m.get_m21();
z2 = z - h2*m.get_m31();
x3 = x + h2*m.get_m12(); h3 = improvement(ge,octree,point,h,SVector3(m.get_m12(),m.get_m22(),m.get_m32()));
y3 = y + h2*m.get_m22(); x3 = x + h3*m.get_m12();
z3 = z + h2*m.get_m32(); y3 = y + h3*m.get_m22();
z3 = z + h3*m.get_m32();
x4 = x - h2*m.get_m12(); h4 = improvement(ge,octree,point,h,SVector3(-m.get_m12(),-m.get_m22(),-m.get_m32()));
y4 = y - h2*m.get_m22(); x4 = x - h4*m.get_m12();
z4 = z - h2*m.get_m32(); y4 = y - h4*m.get_m22();
z4 = z - h4*m.get_m32();
x5 = x + h3*m.get_m13(); h5 = improvement(ge,octree,point,h,SVector3(m.get_m13(),m.get_m23(),m.get_m33()));
y5 = y + h3*m.get_m23(); x5 = x + h5*m.get_m13();
z5 = z + h3*m.get_m33(); y5 = y + h5*m.get_m23();
z5 = z + h5*m.get_m33();
x6 = x - h3*m.get_m13(); h6 = improvement(ge,octree,point,h,SVector3(-m.get_m13(),-m.get_m23(),-m.get_m33()));
y6 = y - h3*m.get_m23(); x6 = x - h6*m.get_m13();
z6 = z - h3*m.get_m33(); y6 = y - h6*m.get_m23();
z6 = z - h6*m.get_m33();
*n1 = Node(SPoint3(x1,y1,z1)); *n1 = Node(SPoint3(x1,y1,z1));
*n2 = Node(SPoint3(x2,y2,z2)); *n2 = Node(SPoint3(x2,y2,z2));
...@@ -611,6 +616,31 @@ void Filler::offsprings(Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5, ...@@ -611,6 +616,31 @@ void Filler::offsprings(Node* node,Node* n1,Node* n2,Node* n3,Node* n4,Node* n5,
*n6 = Node(SPoint3(x6,y6,z6)); *n6 = Node(SPoint3(x6,y6,z6));
} }
double Filler::improvement(GEntity* ge,MElementOctree* octree,SPoint3 point,double h_nearer,SVector3 direction){
double x,y,z;
double average;
double h_farther;
double coeffA,coeffB;
x = point.x() + h_nearer*direction.x();
y = point.y() + h_nearer*direction.y();
z = point.z() + h_nearer*direction.z();
if(inside_domain(octree,x,y,z)){
h_farther = get_size(x,y,z);
}
else h_farther = h_nearer;
coeffA = 1.0;
coeffB = 0.2;
if(h_farther>h_nearer){
average = coeffA*h_nearer + (1.0-coeffA)*h_farther;
}
else{
average = coeffB*h_nearer + (1.0-coeffB)*h_farther;
}
return average;
}
int Filler::get_nbr_new_vertices(){ int Filler::get_nbr_new_vertices(){
return new_vertices.size(); return new_vertices.size();
} }
...@@ -634,9 +664,7 @@ void Filler::print_node(Node* node,std::ofstream& file){ ...@@ -634,9 +664,7 @@ void Filler::print_node(Node* node,std::ofstream& file){
double x4,y4,z4; double x4,y4,z4;
double x5,y5,z5; double x5,y5,z5;
double x6,y6,z6; double x6,y6,z6;
double h1; double h;
double h2;
double h3;
Metric m; Metric m;
SPoint3 point; SPoint3 point;
...@@ -644,34 +672,32 @@ void Filler::print_node(Node* node,std::ofstream& file){ ...@@ -644,34 +672,32 @@ void Filler::print_node(Node* node,std::ofstream& file){
x = point.x(); x = point.x();
y = point.y(); y = point.y();
z = point.z(); z = point.z();
h1 = node->get_h1(); h = node->get_size();
h2 = node->get_h2();
h3 = node->get_h3();
m = node->get_metric(); m = node->get_metric();
x1 = x + h1*m.get_m11(); x1 = x + h*m.get_m11();
y1 = y + h1*m.get_m21(); y1 = y + h*m.get_m21();
z1 = z + h1*m.get_m31(); z1 = z + h*m.get_m31();
x2 = x - h1*m.get_m11(); x2 = x - h*m.get_m11();
y2 = y - h1*m.get_m21(); y2 = y - h*m.get_m21();
z2 = z - h1*m.get_m31(); z2 = z - h*m.get_m31();
x3 = x + h2*m.get_m12(); x3 = x + h*m.get_m12();
y3 = y + h2*m.get_m22(); y3 = y + h*m.get_m22();
z3 = z + h2*m.get_m32(); z3 = z + h*m.get_m32();
x4 = x - h2*m.get_m12(); x4 = x - h*m.get_m12();
y4 = y - h2*m.get_m22(); y4 = y - h*m.get_m22();
z4 = z - h2*m.get_m32(); z4 = z - h*m.get_m32();
x5 = x + h3*m.get_m13(); x5 = x + h*m.get_m13();
y5 = y + h3*m.get_m23(); y5 = y + h*m.get_m23();
z5 = z + h3*m.get_m33(); z5 = z + h*m.get_m33();
x6 = x - h3*m.get_m13(); x6 = x - h*m.get_m13();
y6 = y - h3*m.get_m23(); y6 = y - h*m.get_m23();
z6 = z - h3*m.get_m33(); z6 = z - h*m.get_m33();
print_segment(SPoint3(x,y,z),SPoint3(x1,y1,z1),file); print_segment(SPoint3(x,y,z),SPoint3(x1,y1,z1),file);
print_segment(SPoint3(x,y,z),SPoint3(x2,y2,z2),file); print_segment(SPoint3(x,y,z),SPoint3(x2,y2,z2),file);
......
...@@ -15,14 +15,14 @@ class Filler{ ...@@ -15,14 +15,14 @@ class Filler{
private: private:
static std::vector<MVertex*> new_vertices; static std::vector<MVertex*> new_vertices;
Metric get_metric(double,double,double); Metric get_metric(double,double,double);
double get_h1(double,double,double); double get_size(double,double,double);
double get_h2(double,double,double);
double get_h3(double,double,double);
Metric get_clf_metric(double,double,double,GEntity*); Metric get_clf_metric(double,double,double,GEntity*);
double get_clf_h(double,double,double,GEntity*); double get_clf_size(double,double,double,GEntity*);
bool inside_domain(MElementOctree*,double,double,double); bool inside_domain(MElementOctree*,double,double,double);
bool far_from_boundary(MElementOctree*,Node*);
void compute_parameters(Node*,GEntity*); void compute_parameters(Node*,GEntity*);
void offsprings(Node*,Node*,Node*,Node*,Node*,Node*,Node*); void offsprings(GEntity*,MElementOctree*,Node*,Node*,Node*,Node*,Node*,Node*,Node*);
double improvement(GEntity*,MElementOctree*,SPoint3,double,SVector3);
void print_segment(SPoint3,SPoint3,std::ofstream&); void print_segment(SPoint3,SPoint3,std::ofstream&);
void print_node(Node*,std::ofstream&); void print_node(Node*,std::ofstream&);
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment