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

fix extrude with scalar view

parent 5cbb73df
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,9 @@ class smooth_data{ ...@@ -48,6 +48,9 @@ class smooth_data{
private: private:
std::set<xyzv, lessthanxyzv> c; std::set<xyzv, lessthanxyzv> c;
public: public:
typedef std::set<xyzv, lessthanxyzv>::iterator iter;
iter begin(){ return c.begin(); }
iter end(){ return c.end(); }
smooth_data() {} smooth_data() {}
void add(double x, double y, double z, int n, double *vals); void add(double x, double y, double z, int n, double *vals);
bool get(double x, double y, double z, int n, double *vals); bool get(double x, double y, double z, int n, double *vals);
......
...@@ -56,13 +56,6 @@ static void addExtrudeNormals(std::vector<T*> &elements, int invert, ...@@ -56,13 +56,6 @@ static void addExtrudeNormals(std::vector<T*> &elements, int invert,
double nn[3] = {n[0], n[1], n[2]}; double nn[3] = {n[0], n[1], n[2]};
for(int k = 0; k < ele->getNumVertices(); k++){ for(int k = 0; k < ele->getNumVertices(); k++){
MVertex *v = ele->getVertex(k); MVertex *v = ele->getVertex(k);
if(octree){
#if defined(HAVE_POST)
double d;
octree->searchScalarWithTol(v->x(), v->y(), v->z(), &d, 0);
for(int i = 0; i < 3; i++) nn[i] *= d;
#endif
}
ExtrudeParams::normals[index]->add(v->x(), v->y(), v->z(), 3, nn); ExtrudeParams::normals[index]->add(v->x(), v->y(), v->z(), 3, nn);
} }
} }
...@@ -75,6 +68,9 @@ template<class T> ...@@ -75,6 +68,9 @@ template<class T>
static void addExtrudeNormals(std::set<T*> &entities, static void addExtrudeNormals(std::set<T*> &entities,
std::map<int, infoset> &infos) std::map<int, infoset> &infos)
{ {
bool normalize = true;
std::vector<OctreePost*> octrees;
for(typename std::set<T*>::iterator it = entities.begin(); it != entities.end(); it++){ for(typename std::set<T*>::iterator it = entities.begin(); it != entities.end(); it++){
T *ge = *it; T *ge = *it;
infoset info = infos[ge->tag()]; infoset info = infos[ge->tag()];
...@@ -90,6 +86,7 @@ static void addExtrudeNormals(std::set<T*> &entities, ...@@ -90,6 +86,7 @@ static void addExtrudeNormals(std::set<T*> &entities,
octree = new OctreePost(PView::list[view]); octree = new OctreePost(PView::list[view]);
if(PView::list[view]->getData()->getNumVectors()) if(PView::list[view]->getData()->getNumVectors())
gouraud = false; gouraud = false;
octrees.push_back(octree);
} }
else else
Msg::Error("Unknown View[%d]: using normals instead", view); Msg::Error("Unknown View[%d]: using normals instead", view);
...@@ -101,8 +98,44 @@ static void addExtrudeNormals(std::set<T*> &entities, ...@@ -101,8 +98,44 @@ static void addExtrudeNormals(std::set<T*> &entities,
addExtrudeNormals(((GFace*)ge)->triangles, invert, octree, gouraud, index); addExtrudeNormals(((GFace*)ge)->triangles, invert, octree, gouraud, index);
addExtrudeNormals(((GFace*)ge)->quadrangles, invert, octree, gouraud, index); addExtrudeNormals(((GFace*)ge)->quadrangles, invert, octree, gouraud, index);
} }
if(!gouraud) normalize = false;
} }
} }
// enforce coherent normals at some points if necessary
for(int i = 0; i < ExtrudeParams::normalsCoherence.size(); i++){
SPoint3 &p(ExtrudeParams::normalsCoherence[i]);
double n0[3], n1[3];
ExtrudeParams::normals[0]->get(p.x(), p.y(), p.z(), 3, n0);
ExtrudeParams::normals[1]->get(p.x(), p.y(), p.z(), 3, n1);
ExtrudeParams::normals[0]->add(p.x(), p.y(), p.z(), 3, n1);
ExtrudeParams::normals[1]->add(p.x(), p.y(), p.z(), 3, n0);
}
// normalize extrusion directions if not using explicit vector
// post-processing views
if(normalize){
for(int i = 0; i < 2; i++){
ExtrudeParams::normals[i]->normalize();
#if defined(HAVE_POST)
if(octrees.size()){ // scale normals by scalar views
for(smooth_data::iter it = ExtrudeParams::normals[i]->begin();
it != ExtrudeParams::normals[i]->end(); it++){
for(unsigned int j = 0; j < octrees.size(); j++){
double d;
if(octrees[j]->searchScalarWithTol(it->x, it->y, it->z, &d, 0)){
for(int k = 0; k < 3; k++) it->vals[k] *= d;
break;
}
}
}
}
#endif
}
}
for(unsigned int i = 0; i < octrees.size(); i++)
delete octrees[i];
} }
int Mesh2DWithBoundaryLayers(GModel *m) int Mesh2DWithBoundaryLayers(GModel *m)
...@@ -110,7 +143,6 @@ int Mesh2DWithBoundaryLayers(GModel *m) ...@@ -110,7 +143,6 @@ int Mesh2DWithBoundaryLayers(GModel *m)
std::set<GFace*> sourceFaces, otherFaces; std::set<GFace*> sourceFaces, otherFaces;
std::set<GEdge*> sourceEdges, otherEdges; std::set<GEdge*> sourceEdges, otherEdges;
std::map<int, infoset> sourceFaceInfo, sourceEdgeInfo; std::map<int, infoset> sourceFaceInfo, sourceEdgeInfo;
bool normalize = true;
// 2D boundary layers // 2D boundary layers
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){ for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
...@@ -124,7 +156,6 @@ int Mesh2DWithBoundaryLayers(GModel *m) ...@@ -124,7 +156,6 @@ int Mesh2DWithBoundaryLayers(GModel *m)
Msg::Error("Unknown source curve %d for boundary layer", ep->geo.Source); Msg::Error("Unknown source curve %d for boundary layer", ep->geo.Source);
return 0; return 0;
} }
if(ep->mesh.ViewIndex >= 0) normalize = false;
std::pair<bool, std::pair<int, int> > tags std::pair<bool, std::pair<int, int> > tags
(ep->geo.Source < 0, std::pair<int, int> (ep->geo.Source < 0, std::pair<int, int>
(ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex)); (ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex));
...@@ -146,7 +177,6 @@ int Mesh2DWithBoundaryLayers(GModel *m) ...@@ -146,7 +177,6 @@ int Mesh2DWithBoundaryLayers(GModel *m)
Msg::Error("Unknown source face %d for boundary layer", ep->geo.Source); Msg::Error("Unknown source face %d for boundary layer", ep->geo.Source);
return 0; return 0;
} }
if(ep->mesh.ViewIndex >= 0) normalize = false;
std::pair<bool, std::pair<int, int> > tags std::pair<bool, std::pair<int, int> > tags
(ep->geo.Source < 0, std::pair<int, int> (ep->geo.Source < 0, std::pair<int, int>
(ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex)); (ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex));
...@@ -186,21 +216,6 @@ int Mesh2DWithBoundaryLayers(GModel *m) ...@@ -186,21 +216,6 @@ int Mesh2DWithBoundaryLayers(GModel *m)
else else
addExtrudeNormals(sourceFaces, sourceFaceInfo); addExtrudeNormals(sourceFaces, sourceFaceInfo);
// enforce coherent normals at some points if necessary
for(int i = 0; i < ExtrudeParams::normalsCoherence.size(); i++){
SPoint3 &p(ExtrudeParams::normalsCoherence[i]);
double n0[3], n1[3];
ExtrudeParams::normals[0]->get(p.x(), p.y(), p.z(), 3, n0);
ExtrudeParams::normals[1]->get(p.x(), p.y(), p.z(), 3, n1);
ExtrudeParams::normals[0]->add(p.x(), p.y(), p.z(), 3, n1);
ExtrudeParams::normals[1]->add(p.x(), p.y(), p.z(), 3, n0);
}
// normalize extrusion directions if not using post-processing views
if(normalize)
for(int i = 0; i < 2; i++)
ExtrudeParams::normals[i]->normalize();
// set the position of boundary layer points using the smooth normal // set the position of boundary layer points using the smooth normal
// field // field
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){ for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
......
lc = 0.1; lc = 0.1;
Point(1) = {0,0,0,lc}; Point(1) = {0,0,0,lc};
Point(2) = {1,0,0,lc}; Point(2) = {1,0,0,lc};
// Fabien - enleve ceci:
PolarSphere (1) = {1,2}; PolarSphere (1) = {1,2};
Point(3) = {0.335046,-1.96526,0,lc}; Point(3) = {0.335046,-1.96526,0,lc};
Point(4) = {0.319083,-1.86011,0,lc}; Point(4) = {0.319083,-1.86011,0,lc};
Point(5) = {0.298206,-1.76125,0,lc}; Point(5) = {0.298206,-1.76125,0,lc};
......
// merge vector view (View[0])
Merge "sphere_boundary_layer_from_view.pos"; Merge "sphere_boundary_layer_from_view.pos";
// create scalar view View[1] for testing
Plugin(MathEval).Run; Plugin(MathEval).Run;
lc = 0.2; lc = 0.2;
...@@ -41,10 +44,9 @@ Line Loop(27) = {-4,12,-6}; ...@@ -41,10 +44,9 @@ Line Loop(27) = {-4,12,-6};
Ruled Surface(28) = {27}; Ruled Surface(28) = {27};
tmp[] = Extrude { tmp[] = Extrude {
Surface{14:28:2}; Layers{5, 0.2}; Recombine; Using Index[0]; Surface{14:28:2}; Layers{5, 0.2}; Recombine;
// can use scalar or vectpr view //Using View[0]; // provide extrude directions using vector field
//Using View[0]; Using View[1]; // use mesh normals, but scaled by scalar field
Using View[1];
}; };
// test 2nd bnd layer // test 2nd bnd layer
......
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