Skip to content
Snippets Groups Projects
Commit 922c66aa authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

DivideAndConquer now throws an exception, so that we don't crash if it fails

parent 541a1342
No related branches found
No related tags found
No related merge requests found
...@@ -319,8 +319,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -319,8 +319,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
Axis1, Axis2, Axis3)); Axis1, Axis2, Axis3));
} }
// We take the smallest component, then project the data on the plane defined
// We take the smallest component, then project the data on the plane defined by the other twos // by the other twos
int smallest_comp = 0; int smallest_comp = 0;
if (sizes[0] <= sizes[1] && sizes[0] <= sizes[2]) if (sizes[0] <= sizes[1] && sizes[0] <= sizes[2])
...@@ -334,9 +334,11 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -334,9 +334,11 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
// We just ignore the coordinate corresponding to smallest_comp. // We just ignore the coordinate corresponding to smallest_comp.
std::vector<SPoint2*> points; std::vector<SPoint2*> points;
for (int i = 0; i < num_vertices; i++) { for (int i = 0; i < num_vertices; i++) {
SPoint2* p = new SPoint2(projected(smallest_comp==0?1:0,i), projected(smallest_comp==2?1:2,i)); SPoint2* p = new SPoint2(projected(smallest_comp==0?1:0,i),
projected(smallest_comp==2?1:2,i));
bool keep = true; bool keep = true;
for (std::vector<SPoint2*>::iterator point = points.begin();point != points.end();point++) { for (std::vector<SPoint2*>::iterator point = points.begin();
point != points.end();point++) {
if ( fabs((*p)[0] -(**point)[0]) < 10e-10 && fabs((*p)[1] -(**point)[1]) < 10e-10 ) { if ( fabs((*p)[0] -(**point)[0]) < 10e-10 && fabs((*p)[1] -(**point)[1]) < 10e-10 ) {
keep = false; keep = false;
break; break;
...@@ -354,12 +356,19 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -354,12 +356,19 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
record.numPoints = points.size(); record.numPoints = points.size();
srand((unsigned)time(0)); srand((unsigned)time(0));
for (unsigned int i = 0; i < points.size(); i++) { for (unsigned int i = 0; i < points.size(); i++) {
record.points[i].where.h = points[i]->x()+(10e-6)*sizes[smallest_comp==0?1:0]*(-0.5+((double)rand())/RAND_MAX); record.points[i].where.h = points[i]->x()+
record.points[i].where.v = points[i]->y()+(10e-6)*sizes[smallest_comp==2?1:0]*(-0.5+((double)rand())/RAND_MAX); (10e-6)*sizes[smallest_comp==0?1:0]*(-0.5+((double)rand())/RAND_MAX);
record.points[i].where.v = points[i]->y()+
(10e-6)*sizes[smallest_comp==2?1:0]*(-0.5+((double)rand())/RAND_MAX);
record.points[i].adjacent = NULL; record.points[i].adjacent = NULL;
} }
try{
record.MakeMeshWithPoints(); record.MakeMeshWithPoints();
}
catch(const char *err){
Msg::Error("%s", err);
}
std::vector<Segment> convex_hull; std::vector<Segment> convex_hull;
for (int i = 0; i < record.numTriangles; i++) { for (int i = 0; i < record.numTriangles; i++) {
...@@ -373,8 +382,10 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -373,8 +382,10 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
for (int j = 0; j < 3; j++) { for (int j = 0; j < 3; j++) {
bool okay = true; bool okay = true;
for (std::vector<Segment>::iterator seg = convex_hull.begin(); seg != convex_hull.end(); seg++) { for (std::vector<Segment>::iterator seg = convex_hull.begin();
if ( ((*seg).from == segs[j].from && (*seg).from == segs[j].to) || ((*seg).from == segs[j].to && (*seg).from == segs[j].from)) { seg != convex_hull.end(); seg++) {
if ( ((*seg).from == segs[j].from && (*seg).from == segs[j].to) ||
((*seg).from == segs[j].to && (*seg).from == segs[j].from)) {
convex_hull.erase(seg); convex_hull.erase(seg);
okay = false; okay = false;
break; break;
...@@ -401,7 +412,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -401,7 +412,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
least_rectangle.size->at(0) = -1; least_rectangle.size->at(0) = -1;
least_rectangle.size->at(1) = 1; least_rectangle.size->at(1) = 1;
for (std::vector<Segment>::iterator seg = convex_hull.begin(); seg != convex_hull.end(); seg++) { for (std::vector<Segment>::iterator seg = convex_hull.begin();
seg != convex_hull.end(); seg++) {
fullVector<double> segment(2); fullVector<double> segment(2);
//segment(0) = record.points[(*seg).from].where.h - record.points[(*seg).to].where.h; //segment(0) = record.points[(*seg).from].where.h - record.points[(*seg).to].where.h;
...@@ -457,7 +469,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -457,7 +469,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
rotation_inv.mult(axis2,axis_rot2); rotation_inv.mult(axis2,axis_rot2);
//*/ //*/
if ((least_rectangle.area() == -1) || (max_x-min_x)*(max_y-min_y) < least_rectangle.area()) { if ((least_rectangle.area() == -1) ||
(max_x-min_x)*(max_y-min_y) < least_rectangle.area()) {
least_rectangle.size->at(0) = max_x-min_x; least_rectangle.size->at(0) = max_x-min_x;
least_rectangle.size->at(1) = max_y-min_y; least_rectangle.size->at(1) = max_y-min_y;
...@@ -558,7 +571,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -558,7 +571,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
aux2(i) = left_eigv(i,smallest_comp==0?1:0); aux2(i) = left_eigv(i,smallest_comp==0?1:0);
aux3(i) = left_eigv(i,smallest_comp==2?1:2); aux3(i) = left_eigv(i,smallest_comp==2?1:2);
} }
center = aux1*center_pca + aux2*least_rectangle.center->at(0) + aux3*least_rectangle.center->at(1); center = aux1*center_pca + aux2*least_rectangle.center->at(0) +
aux3*least_rectangle.center->at(1);
//center[1] = -center[1]; //center[1] = -center[1];
/* /*
...@@ -578,7 +592,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic ...@@ -578,7 +592,8 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3> vertic
#endif #endif
} }
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());
...@@ -587,7 +602,8 @@ double SOrientedBoundingBox::compare(SOrientedBoundingBox& obb1, SOrientedBoundi ...@@ -587,7 +602,8 @@ double SOrientedBoundingBox::compare(SOrientedBoundingBox& obb1, SOrientedBoundi
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));
} }
} }
...@@ -598,5 +614,4 @@ double SOrientedBoundingBox::compare(SOrientedBoundingBox& obb1, SOrientedBoundi ...@@ -598,5 +614,4 @@ double SOrientedBoundingBox::compare(SOrientedBoundingBox& obb1, SOrientedBoundi
} }
return (center_term + size_term + orientation_term); return (center_term + size_term + orientation_term);
} }
...@@ -162,8 +162,8 @@ Segment DocRecord::UpperCommonTangent(DT vl, DT vr) ...@@ -162,8 +162,8 @@ Segment DocRecord::UpperCommonTangent(DT vl, DT vr)
int DocRecord::Qtest(PointNumero h, PointNumero i, PointNumero j, PointNumero k) int DocRecord::Qtest(PointNumero h, PointNumero i, PointNumero j, PointNumero k)
{ {
if((h == i) && (h == j) && (h == k)) { if((h == i) && (h == j) && (h == k)) {
Msg::Error("Identical points in triangulation: increase element size " throw "Identical points in triangulation: increase element size "
"or Mesh.RandomFactor"); "or Mesh.RandomFactor";
return 0; return 0;
} }
...@@ -959,7 +959,13 @@ void DocRecord::concave(double x,double y,GFace* gf) ...@@ -959,7 +959,13 @@ void DocRecord::concave(double x,double y,GFace* gf)
points[i].vicinity.clear(); points[i].vicinity.clear();
} }
try{
MakeMeshWithPoints(); MakeMeshWithPoints();
}
catch(const char *err){
Msg::Error("%s", err);
}
set = tagInterior(x,y); set = tagInterior(x,y);
for(it2 = set.begin(); it2 != set.end(); it2++){ for(it2 = set.begin(); it2 != set.end(); it2++){
index1 = triangles[*it2].a; index1 = triangles[*it2].a;
......
...@@ -1090,7 +1090,12 @@ bool meshGenerator(GFace *gf, int RECUR_ITER, ...@@ -1090,7 +1090,12 @@ bool meshGenerator(GFace *gf, int RECUR_ITER,
// -) It contains triangles outside the domain (the first edge // -) It contains triangles outside the domain (the first edge
// loop is the outer one) // loop is the outer one)
Msg::Debug("Meshing of the convex hull (%d points)", points.size()); Msg::Debug("Meshing of the convex hull (%d points)", points.size());
try{
doc.MakeMeshWithPoints(); doc.MakeMeshWithPoints();
}
catch(const char *err){
Msg::Error("%s", err);
}
Msg::Debug("Meshing of the convex hull (%d points) done", points.size()); Msg::Debug("Meshing of the convex hull (%d points) done", points.size());
for(int i = 0; i < doc.numTriangles; i++) { for(int i = 0; i < doc.numTriangles; i++) {
...@@ -1900,7 +1905,13 @@ static bool meshGeneratorPeriodic(GFace *gf, bool debug = true) ...@@ -1900,7 +1905,13 @@ static bool meshGeneratorPeriodic(GFace *gf, bool debug = true)
// -) It contains triangles outside the domain (the first edge // -) It contains triangles outside the domain (the first edge
// loop is the outer one) // loop is the outer one)
Msg::Debug("Meshing of the convex hull (%d points)", nbPointsTotal); Msg::Debug("Meshing of the convex hull (%d points)", nbPointsTotal);
try{
doc.MakeMeshWithPoints(); doc.MakeMeshWithPoints();
}
catch(const char *err){
Msg::Error("%s", err);
}
for(int i = 0; i < doc.numTriangles; i++){ for(int i = 0; i < doc.numTriangles; i++){
int a = doc.triangles[i].a; int a = doc.triangles[i].a;
......
...@@ -138,7 +138,12 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) ...@@ -138,7 +138,12 @@ PView *GMSH_TriangulatePlugin::execute(PView *v)
} }
// triangulate // triangulate
try{
doc.MakeMeshWithPoints(); doc.MakeMeshWithPoints();
}
catch(const char *err){
Msg::Error("%s", err);
}
// create output (using unperturbed data) // create output (using unperturbed data)
PView *v2 = new PView(); PView *v2 = new PView();
......
Merge "aorta2.stl"; Merge "aorta2.stl";
CreateTopology; CreateTopology;
//Merge "aortaRADIUS2.bgm"; Merge "aortaRADIUS2.bgm";
// create a boundary layer, whose tickness is given in View[0] // create a boundary layer, whose tickness is given in View[0]
out1[] = Extrude{Surface{-1}; Layers{4, 0.5}; Using Index[0]; Using View[0]; }; out1[] = Extrude{Surface{-1}; Layers{4, 0.5}; Using Index[0]; Using View[0]; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment