Skip to content
Snippets Groups Projects
Commit f3109f61 authored by Jean-François Remacle's avatar Jean-François Remacle
Browse files

Changed the return type of GetOBB from SOrientedBoundingBox* to SOrientedBoundingBox
parent bbc7ddfd
No related branches found
No related tags found
No related merge requests found
...@@ -107,7 +107,7 @@ SBoundingBox3d GEdge::bounds() const ...@@ -107,7 +107,7 @@ SBoundingBox3d GEdge::bounds() const
return bbox; return bbox;
} }
SOrientedBoundingBox* GEdge::getOBB() { SOrientedBoundingBox GEdge::getOBB() {
if (!(this->_obb)) { if (!(this->_obb)) {
vector<SPoint3> vertices; vector<SPoint3> vertices;
if(this->getNumMeshVertices() > 0) { if(this->getNumMeshVertices() > 0) {
...@@ -137,7 +137,7 @@ SOrientedBoundingBox* GEdge::getOBB() { ...@@ -137,7 +137,7 @@ SOrientedBoundingBox* GEdge::getOBB() {
} }
this->_obb = SOrientedBoundingBox::buildOBB(vertices); this->_obb = SOrientedBoundingBox::buildOBB(vertices);
} }
return (this->_obb); return (SOrientedBoundingBox(this->_obb));
} }
void GEdge::setVisibility(char val, bool recursive) void GEdge::setVisibility(char val, bool recursive)
......
...@@ -62,7 +62,7 @@ class GEdge : public GEntity { ...@@ -62,7 +62,7 @@ class GEdge : public GEntity {
virtual SBoundingBox3d bounds() const; virtual SBoundingBox3d bounds() const;
// get the oriented bounding box // get the oriented bounding box
virtual SOrientedBoundingBox* getOBB(); virtual SOrientedBoundingBox getOBB();
// faces that this entity bounds // faces that this entity bounds
virtual std::list<GFace*> faces() const { return l_faces; } virtual std::list<GFace*> faces() const { return l_faces; }
......
...@@ -212,7 +212,7 @@ class GEntity { ...@@ -212,7 +212,7 @@ class GEntity {
virtual SBoundingBox3d bounds() const { return SBoundingBox3d(); } virtual SBoundingBox3d bounds() const { return SBoundingBox3d(); }
// get the oriented bounding box // get the oriented bounding box
virtual SOrientedBoundingBox* getOBB() {return new SOrientedBoundingBox(); } virtual SOrientedBoundingBox getOBB() {return SOrientedBoundingBox(); }
// get/set the visibility flag // get/set the visibility flag
virtual char getVisibility(); virtual char getVisibility();
......
...@@ -146,7 +146,7 @@ SBoundingBox3d GFace::bounds() const ...@@ -146,7 +146,7 @@ SBoundingBox3d GFace::bounds() const
return res; return res;
} }
SOrientedBoundingBox* GFace::getOBB() { SOrientedBoundingBox GFace::getOBB() {
if (!(this->_obb)) { if (!(this->_obb)) {
vector<SPoint3> vertices; vector<SPoint3> vertices;
if(this->getNumMeshVertices() > 0) { if(this->getNumMeshVertices() > 0) {
...@@ -193,7 +193,7 @@ SOrientedBoundingBox* GFace::getOBB() { ...@@ -193,7 +193,7 @@ SOrientedBoundingBox* GFace::getOBB() {
} }
this->_obb = SOrientedBoundingBox::buildOBB(vertices); this->_obb = SOrientedBoundingBox::buildOBB(vertices);
} }
return (this->_obb); return (SOrientedBoundingBox(this->_obb));
} }
......
...@@ -111,7 +111,7 @@ class GFace : public GEntity ...@@ -111,7 +111,7 @@ class GFace : public GEntity
virtual SBoundingBox3d bounds() const; virtual SBoundingBox3d bounds() const;
// get the oriented bounding box // get the oriented bounding box
virtual SOrientedBoundingBox* getOBB(); virtual SOrientedBoundingBox getOBB();
// retrieve surface params // retrieve surface params
virtual surface_params getSurfaceParams() const; virtual surface_params getSurfaceParams() const;
......
...@@ -111,7 +111,7 @@ SBoundingBox3d GRegion::bounds() const ...@@ -111,7 +111,7 @@ SBoundingBox3d GRegion::bounds() const
return res; return res;
} }
SOrientedBoundingBox* GRegion::getOBB() { SOrientedBoundingBox GRegion::getOBB() {
if (!(this->_obb)) { if (!(this->_obb)) {
vector<SPoint3> vertices; vector<SPoint3> vertices;
list<GFace*> b_faces = this->faces(); list<GFace*> b_faces = this->faces();
...@@ -159,7 +159,7 @@ SOrientedBoundingBox* GRegion::getOBB() { ...@@ -159,7 +159,7 @@ SOrientedBoundingBox* GRegion::getOBB() {
} }
this->_obb = SOrientedBoundingBox::buildOBB(vertices); this->_obb = SOrientedBoundingBox::buildOBB(vertices);
} }
return (this->_obb); return (SOrientedBoundingBox(this->_obb));
} }
void GRegion::setVisibility(char val, bool recursive) void GRegion::setVisibility(char val, bool recursive)
......
...@@ -50,7 +50,7 @@ class GRegion : public GEntity { ...@@ -50,7 +50,7 @@ class GRegion : public GEntity {
virtual SBoundingBox3d bounds() const; virtual SBoundingBox3d bounds() const;
// get the oriented bounding box // get the oriented bounding box
virtual SOrientedBoundingBox* getOBB(); virtual SOrientedBoundingBox getOBB();
// check if the region is connected to another region by an edge // check if the region is connected to another region by an edge
bool edgeConnected(GRegion *r) const; bool edgeConnected(GRegion *r) const;
......
...@@ -191,13 +191,13 @@ vector<Pair<GEdge*,GEdge*> >* GeomMeshMatcher::matchEdges(GModel* m1, GModel* m ...@@ -191,13 +191,13 @@ vector<Pair<GEdge*,GEdge*> >* GeomMeshMatcher::matchEdges(GModel* m1, GModel* m
Msg::Info("There are %i edges that could match.",common_edges.size()); Msg::Info("There are %i edges that could match.",common_edges.size());
// So, first step is to build an array of points taken on the geo entity // So, first step is to build an array of points taken on the geo entity
// Then, compute the minimal bounding box // Then, compute the minimal bounding box
SOrientedBoundingBox* geo_obb = ((GEdge*)(*entity1))->getOBB(); SOrientedBoundingBox geo_obb = ((GEdge*)(*entity1))->getOBB();
GEdge* choice = 0; GEdge* choice = 0;
double best_score = DBL_MAX; double best_score = DBL_MAX;
// Next, let's iterate over the mesh entities. // Next, let's iterate over the mesh entities.
for (vector<GEdge*>::iterator candidate = common_edges.begin(); candidate != common_edges.end(); candidate++) { for (vector<GEdge*>::iterator candidate = common_edges.begin(); candidate != common_edges.end(); candidate++) {
SOrientedBoundingBox* mesh_obb = (*candidate)->getOBB(); SOrientedBoundingBox mesh_obb = (*candidate)->getOBB();
Msg::Info("Comparing score : %f", SOrientedBoundingBox::compare(geo_obb,mesh_obb)); Msg::Info("Comparing score : %f", SOrientedBoundingBox::compare(geo_obb,mesh_obb));
//if (geo_obb->intersects(mesh_obb)) { //if (geo_obb->intersects(mesh_obb)) {
...@@ -273,26 +273,26 @@ vector<Pair<GFace*,GFace*> >* GeomMeshMatcher:: matchFaces(GModel* m1, GModel* m ...@@ -273,26 +273,26 @@ vector<Pair<GFace*,GFace*> >* GeomMeshMatcher:: matchFaces(GModel* m1, GModel* m
int N; int N;
// Then, compute the minimal bounding box // Then, compute the minimal bounding box
SOrientedBoundingBox* geo_obb = ((GFace*)(*entity1))->getOBB(); SOrientedBoundingBox geo_obb = ((GFace*)(*entity1))->getOBB();
GFace* choice = 0; GFace* choice = 0;
double best_score = DBL_MAX; double best_score = DBL_MAX;
// Next, let's iterate over the mesh entities. // Next, let's iterate over the mesh entities.
for (vector<GFace*>::iterator candidate = common_faces.begin(); candidate != common_faces.end(); candidate++) { for (vector<GFace*>::iterator candidate = common_faces.begin(); candidate != common_faces.end(); candidate++) {
SOrientedBoundingBox* mesh_obb = (*candidate)->getOBB(); SOrientedBoundingBox mesh_obb = (*candidate)->getOBB();
Msg::Info("Comparing score : %f", SOrientedBoundingBox::compare(geo_obb,mesh_obb)); Msg::Info("Comparing score : %f", SOrientedBoundingBox::compare(geo_obb,mesh_obb));
double cen_dist1 = geo_obb->getCenter()[0]-mesh_obb->getCenter()[0]; double cen_dist1 = geo_obb.getCenter()[0]-mesh_obb.getCenter()[0];
double cen_dist2 = geo_obb->getCenter()[1]-mesh_obb->getCenter()[1]; double cen_dist2 = geo_obb.getCenter()[1]-mesh_obb.getCenter()[1];
double cen_dist3 = geo_obb->getCenter()[2]-mesh_obb->getCenter()[2]; double cen_dist3 = geo_obb.getCenter()[2]-mesh_obb.getCenter()[2];
double score1 = sqrt( cen_dist1*cen_dist1 double score1 = sqrt( cen_dist1*cen_dist1
+ cen_dist2*cen_dist2 + cen_dist2*cen_dist2
+ cen_dist3*cen_dist3); + cen_dist3*cen_dist3);
double score2 = fabs(geo_obb->getSize()[0]-mesh_obb->getSize()[0]); double score2 = fabs(geo_obb.getSize()[0]-mesh_obb.getSize()[0]);
double score3 = fabs(geo_obb->getSize()[1]-mesh_obb->getSize()[1]); double score3 = fabs(geo_obb.getSize()[1]-mesh_obb.getSize()[1]);
double score4 = fabs(geo_obb->getSize()[2]-mesh_obb->getSize()[2]); double score4 = fabs(geo_obb.getSize()[2]-mesh_obb.getSize()[2]);
if (fmax(fmax(score1,score2),fmax(score3,score4)) < best_score) { if (fmax(fmax(score1,score2),fmax(score3,score4)) < best_score) {
...@@ -379,7 +379,7 @@ vector<Pair<GRegion*,GRegion*> >* GeomMeshMatcher:: matchRegions(GModel* m1, GMo ...@@ -379,7 +379,7 @@ vector<Pair<GRegion*,GRegion*> >* GeomMeshMatcher:: matchRegions(GModel* m1, GMo
double** vertices = new double*[N_total]; double** vertices = new double*[N_total];
// Then, compute the minimal bounding box // Then, compute the minimal bounding box
SOrientedBoundingBox* geo_obb = ((GRegion*) *entity1)->getOBB(); SOrientedBoundingBox geo_obb = ((GRegion*) *entity1)->getOBB();
GRegion* choice = 0; GRegion* choice = 0;
...@@ -387,20 +387,20 @@ vector<Pair<GRegion*,GRegion*> >* GeomMeshMatcher:: matchRegions(GModel* m1, GMo ...@@ -387,20 +387,20 @@ vector<Pair<GRegion*,GRegion*> >* GeomMeshMatcher:: matchRegions(GModel* m1, GMo
// Next, let's iterate over the mesh entities. // Next, let's iterate over the mesh entities.
for (vector<GRegion*>::iterator candidate = common_regions.begin(); candidate != common_regions.end(); candidate++) { for (vector<GRegion*>::iterator candidate = common_regions.begin(); candidate != common_regions.end(); candidate++) {
// Again, build an array with the vertices. // Again, build an array with the vertices.
SOrientedBoundingBox* mesh_obb = (*candidate)->getOBB(); SOrientedBoundingBox mesh_obb = (*candidate)->getOBB();
Msg::Info("Comparing score : %f", SOrientedBoundingBox::compare(geo_obb,mesh_obb)); Msg::Info("Comparing score : %f", SOrientedBoundingBox::compare(geo_obb,mesh_obb));
if (geo_obb->intersects(mesh_obb)) { if (geo_obb.intersects(mesh_obb)) {
double cen_dist1 = geo_obb->getCenter()[0]-mesh_obb->getCenter()[0]; double cen_dist1 = geo_obb.getCenter()[0]-mesh_obb.getCenter()[0];
double cen_dist2 = geo_obb->getCenter()[1]-mesh_obb->getCenter()[1]; double cen_dist2 = geo_obb.getCenter()[1]-mesh_obb.getCenter()[1];
double cen_dist3 = geo_obb->getCenter()[2]-mesh_obb->getCenter()[2]; double cen_dist3 = geo_obb.getCenter()[2]-mesh_obb.getCenter()[2];
double score1 = sqrt( cen_dist1*cen_dist1 double score1 = sqrt( cen_dist1*cen_dist1
+ cen_dist2*cen_dist2 + cen_dist2*cen_dist2
+ cen_dist3*cen_dist3); + cen_dist3*cen_dist3);
double score2 = fabs(geo_obb->getSize()[0]-mesh_obb->getSize()[0]); double score2 = fabs(geo_obb.getSize()[0]-mesh_obb.getSize()[0]);
double score3 = fabs(geo_obb->getSize()[1]-mesh_obb->getSize()[1]); double score3 = fabs(geo_obb.getSize()[1]-mesh_obb.getSize()[1]);
double score4 = fabs(geo_obb->getSize()[2]-mesh_obb->getSize()[2]); double score4 = fabs(geo_obb.getSize()[2]-mesh_obb.getSize()[2]);
if (fmax(fmax(score1,score2),fmax(score3,score4)) < best_score) { if (fmax(fmax(score1,score2),fmax(score3,score4)) < best_score) {
......
...@@ -102,8 +102,54 @@ SOrientedBoundingBox::SOrientedBoundingBox(SVector3& center, ...@@ -102,8 +102,54 @@ SOrientedBoundingBox::SOrientedBoundingBox(SVector3& center,
p8y = center[1] + (axisX[1]*dx) + (axisY[1]*dy) + (axisZ[1]*dz); p8y = center[1] + (axisX[1]*dx) + (axisY[1]*dy) + (axisZ[1]*dz);
p8z = center[2] + (axisX[2]*dx) + (axisY[2]*dy) + (axisZ[2]*dz); p8z = center[2] + (axisX[2]*dx) + (axisY[2]*dy) + (axisZ[2]*dz);
}
//-----------------------------------------------------------------------------
SOrientedBoundingBox::SOrientedBoundingBox(SOrientedBoundingBox* other) {
this->size = other->getSize();
this->axisX = other->getAxis(0);
this->axisY = other->getAxis(1);
this->axisZ = other->getAxis(2);
this->center = other->getCenter();
double dx = 0.5*size[0];
double dy = 0.5*size[1];
double dz = 0.5*size[2];
p1x = center[0] - (axisX[0]*dx) - (axisY[0]*dy) - (axisZ[0]*dz);
p1y = center[1] - (axisX[1]*dx) - (axisY[1]*dy) - (axisZ[1]*dz);
p1z = center[2] - (axisX[2]*dx) - (axisY[2]*dy) - (axisZ[2]*dz);
p2x = center[0] + (axisX[0]*dx) - (axisY[0]*dy) - (axisZ[0]*dz);
p2y = center[1] + (axisX[1]*dx) - (axisY[1]*dy) - (axisZ[1]*dz);
p2z = center[2] + (axisX[2]*dx) - (axisY[2]*dy) - (axisZ[2]*dz);
p3x = center[0] - (axisX[0]*dx) + (axisY[0]*dy) - (axisZ[0]*dz);
p3y = center[1] - (axisX[1]*dx) + (axisY[1]*dy) - (axisZ[1]*dz);
p3z = center[2] - (axisX[2]*dx) + (axisY[2]*dy) - (axisZ[2]*dz);
p4x = center[0] + (axisX[0]*dx) + (axisY[0]*dy) - (axisZ[0]*dz);
p4y = center[1] + (axisX[1]*dx) + (axisY[1]*dy) - (axisZ[1]*dz);
p4z = center[2] + (axisX[2]*dx) + (axisY[2]*dy) - (axisZ[2]*dz);
p5x = center[0] - (axisX[0]*dx) - (axisY[0]*dy) + (axisZ[0]*dz);
p5y = center[1] - (axisX[1]*dx) - (axisY[1]*dy) + (axisZ[1]*dz);
p5z = center[2] - (axisX[2]*dx) - (axisY[2]*dy) + (axisZ[2]*dz);
p6x = center[0] + (axisX[0]*dx) - (axisY[0]*dy) + (axisZ[0]*dz);
p6y = center[1] + (axisX[1]*dx) - (axisY[1]*dy) + (axisZ[1]*dz);
p6z = center[2] + (axisX[2]*dx) - (axisY[2]*dy) + (axisZ[2]*dz);
p7x = center[0] - (axisX[0]*dx) + (axisY[0]*dy) + (axisZ[0]*dz);
p7y = center[1] - (axisX[1]*dx) + (axisY[1]*dy) + (axisZ[1]*dz);
p7z = center[2] - (axisX[2]*dx) + (axisY[2]*dy) + (axisZ[2]*dz);
p8x = center[0] + (axisX[0]*dx) + (axisY[0]*dy) + (axisZ[0]*dz);
p8y = center[1] + (axisX[1]*dx) + (axisY[1]*dy) + (axisZ[1]*dz);
p8z = center[2] + (axisX[2]*dx) + (axisY[2]*dy) + (axisZ[2]*dz);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -134,24 +180,24 @@ SVector3 SOrientedBoundingBox::getAxis(int axis) { ...@@ -134,24 +180,24 @@ SVector3 SOrientedBoundingBox::getAxis(int axis) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool SOrientedBoundingBox::intersects(SOrientedBoundingBox* obb) { bool SOrientedBoundingBox::intersects(SOrientedBoundingBox& obb) {
SVector3 collide_axes[15]; SVector3 collide_axes[15];
for (int i = 0; i < 3; i ++) { for (int i = 0; i < 3; i ++) {
collide_axes[i] = this->getAxis(i); collide_axes[i] = this->getAxis(i);
collide_axes[i+3] = obb->getAxis(i); collide_axes[i+3] = obb.getAxis(i);
} }
SVector3 sizes[2]; SVector3 sizes[2];
sizes[0] = this->getSize(); sizes[0] = this->getSize();
sizes[1] = obb->getSize(); sizes[1] = obb.getSize();
for(unsigned int i=0 ; i<3 ; i++) { for(unsigned int i=0 ; i<3 ; i++) {
for(unsigned int j=3 ; j<6 ; j++) { for(unsigned int j=3 ; j<6 ; j++) {
collide_axes[3*i+j+3] = crossprod(collide_axes[i],collide_axes[j]); collide_axes[3*i+j+3] = crossprod(collide_axes[i],collide_axes[j]);
} }
} }
SVector3 T = obb->getCenter() - this->getCenter(); SVector3 T = obb.getCenter() - this->getCenter();
for(unsigned int i=0 ; i<15 ; i++) { for(unsigned int i=0 ; i<15 ; i++) {
double val = 0.0; double val = 0.0;
...@@ -516,23 +562,23 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(vector<SPoint3> vertices) { ...@@ -516,23 +562,23 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(vector<SPoint3> vertices) {
size[0], size[1], size[2], Axis1, Axis2, Axis3)); size[0], size[1], size[2], Axis1, Axis2, Axis3));
} }
double SOrientedBoundingBox::compare(SOrientedBoundingBox* obb1, SOrientedBoundingBox* obb2) { double SOrientedBoundingBox::compare(SOrientedBoundingBox& obb1, SOrientedBoundingBox& obb2) {
// "center term" // "center term"
double center_term = norm(obb1->getCenter() - obb2->getCenter()); double center_term = norm(obb1.getCenter() - obb2.getCenter());
// "size term" // "size term"
double size_term = 0.0; double size_term = 0.0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if ((obb1->getSize())(i) + (obb2->getSize())(i) != 0) { if ((obb1.getSize())(i) + (obb2.getSize())(i) != 0) {
size_term += fabs((obb1->getSize())(i) - (obb2->getSize())(i)) / ((obb1->getSize())(i) + (obb2->getSize())(i)); size_term += fabs((obb1.getSize())(i) - (obb2.getSize())(i)) / ((obb1.getSize())(i) + (obb2.getSize())(i));
} }
} }
// "orientation term" // "orientation term"
double orientation_term = 0.0; double orientation_term = 0.0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
orientation_term += 1 - fabs(dot(obb1->getAxis(i),obb2->getAxis(i))); orientation_term += 1 - fabs(dot(obb1.getAxis(i),obb2.getAxis(i)));
} }
return (center_term + size_term + orientation_term); return (center_term + size_term + orientation_term);
......
...@@ -59,6 +59,8 @@ class SOrientedBoundingBox { ...@@ -59,6 +59,8 @@ class SOrientedBoundingBox {
const SVector3& axisY, const SVector3& axisY,
const SVector3& axisZ); const SVector3& axisZ);
// Copy constructor
SOrientedBoundingBox(SOrientedBoundingBox* other);
~SOrientedBoundingBox(); ~SOrientedBoundingBox();
SVector3 getCenter() {return (this->center);}; SVector3 getCenter() {return (this->center);};
...@@ -75,9 +77,9 @@ class SOrientedBoundingBox { ...@@ -75,9 +77,9 @@ class SOrientedBoundingBox {
static SOrientedBoundingBox* buildOBB(vector<SPoint3> vertices); static SOrientedBoundingBox* buildOBB(vector<SPoint3> vertices);
bool intersects(SOrientedBoundingBox* obb); bool intersects(SOrientedBoundingBox& obb);
static double compare(SOrientedBoundingBox* obb1, SOrientedBoundingBox* obb2); static double compare(SOrientedBoundingBox& obb1, SOrientedBoundingBox& obb2);
private: private:
SVector3 center; SVector3 center;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment