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

can now also use scalar view for boundary layers

parent 7fd1c722
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#if defined(HAVE_POST) #if defined(HAVE_POST)
#include "PView.h" #include "PView.h"
#include "PViewData.h"
#include "OctreePost.h" #include "OctreePost.h"
#else #else
class OctreePost{ int dummy; }; class OctreePost{ int dummy; };
...@@ -22,40 +23,46 @@ class OctreePost{ int dummy; }; ...@@ -22,40 +23,46 @@ class OctreePost{ int dummy; };
template<class T> template<class T>
static void addExtrudeNormals(std::vector<T*> &elements, int invert, static void addExtrudeNormals(std::vector<T*> &elements, int invert,
OctreePost *octree, int index) OctreePost *octree, bool gouraud, int index)
{ {
// FIXME: generalize this
if(index < 0 || index > 1){ if(index < 0 || index > 1){
Msg::Error("Boundary layer index should be 0 or 1"); Msg::Error("Boundary layer index should be 0 or 1");
return; return;
} }
if(octree){ // get extrusion direction from post-processing view if(octree && !gouraud){ // get extrusion direction from post-processing view
std::set<MVertex*> verts; std::set<MVertex*> verts;
for(unsigned int i = 0; i < elements.size(); i++) for(unsigned int i = 0; i < elements.size(); i++)
for(int j = 0; j < elements[i]->getNumVertices(); j++) for(int j = 0; j < elements[i]->getNumVertices(); j++)
verts.insert(elements[i]->getVertex(j)); verts.insert(elements[i]->getVertex(j));
for(std::set<MVertex*>::iterator it = verts.begin(); it != verts.end(); it++){ for(std::set<MVertex*>::iterator it = verts.begin(); it != verts.end(); it++){
MVertex *v = *it; MVertex *v = *it;
double nn[3]; double nn[3] = {0., 0., 0.};
#if defined(HAVE_POST) #if defined(HAVE_POST)
octree->searchVector(v->x(), v->y(), v->z(), nn, 0); octree->searchVector(v->x(), v->y(), v->z(), nn, 0);
#endif #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);
} }
} }
else{ // get extrusion data from Gouraud-shaded element normals else{ // get extrusion direction from Gouraud-shaded element normals
for(unsigned int i = 0; i < elements.size(); i++){ for(unsigned int i = 0; i < elements.size(); i++){
MElement *ele = elements[i]; MElement *ele = elements[i];
SVector3 n(0, 0, 0); SVector3 n(0, 0, 0);
if(ele->getDim() == 2) if(ele->getDim() == 2)
n = ele->getFace(0).normal(); n = ele->getFace(0).normal();
else if(ele->getDim() == 1) // FIXME only valid in XY-plane else if(ele->getDim() == 1) // FIXME: generalize this!
n = crossprod(ele->getEdge(0).tangent(), SVector3(0, 0, 1)); n = crossprod(ele->getEdge(0).tangent(), SVector3(0., 0., 1.));
if(invert) n *= -1.; if(invert) n *= -1.;
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,20 +82,24 @@ static void addExtrudeNormals(std::set<T*> &entities, ...@@ -75,20 +82,24 @@ static void addExtrudeNormals(std::set<T*> &entities,
bool invert = it2->first; bool invert = it2->first;
int index = it2->second.first; int index = it2->second.first;
int view = it2->second.second; int view = it2->second.second;
bool gouraud = true;
OctreePost *octree = 0; OctreePost *octree = 0;
#if defined(HAVE_POST) #if defined(HAVE_POST)
if(view >= 0){ if(view >= 0){
if(view >= 0 && view < PView::list.size()) if(view >= 0 && view < PView::list.size()){
octree = new OctreePost(PView::list[view]); octree = new OctreePost(PView::list[view]);
if(PView::list[view]->getData()->getNumVectors())
gouraud = false;
}
else else
Msg::Error("Unknown View[%d]: using normals instead", view); Msg::Error("Unknown View[%d]: using normals instead", view);
} }
#endif #endif
if(ge->dim() == 1) if(ge->dim() == 1)
addExtrudeNormals(((GEdge*)ge)->lines, invert, octree, index); addExtrudeNormals(((GEdge*)ge)->lines, invert, octree, gouraud, index);
else if(ge->dim() == 2){ else if(ge->dim() == 2){
addExtrudeNormals(((GFace*)ge)->triangles, invert, octree, index); addExtrudeNormals(((GFace*)ge)->triangles, invert, octree, gouraud, index);
addExtrudeNormals(((GFace*)ge)->quadrangles, invert, octree, index); addExtrudeNormals(((GFace*)ge)->quadrangles, invert, octree, gouraud, index);
} }
} }
} }
...@@ -114,7 +125,8 @@ int Mesh2DWithBoundaryLayers(GModel *m) ...@@ -114,7 +125,8 @@ int Mesh2DWithBoundaryLayers(GModel *m)
return 0; return 0;
} }
if(ep->mesh.ViewIndex >= 0) normalize = false; if(ep->mesh.ViewIndex >= 0) normalize = false;
std::pair<bool, std::pair<int, int> > tags(ep->geo.Source < 0, std::pair<int, int> std::pair<bool, std::pair<int, int> > tags
(ep->geo.Source < 0, std::pair<int, int>
(ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex)); (ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex));
sourceEdgeInfo[from->tag()].insert(tags); sourceEdgeInfo[from->tag()].insert(tags);
sourceEdges.insert(from); sourceEdges.insert(from);
...@@ -135,7 +147,8 @@ int Mesh2DWithBoundaryLayers(GModel *m) ...@@ -135,7 +147,8 @@ int Mesh2DWithBoundaryLayers(GModel *m)
return 0; return 0;
} }
if(ep->mesh.ViewIndex >= 0) normalize = false; if(ep->mesh.ViewIndex >= 0) normalize = false;
std::pair<bool, std::pair<int, int> > tags(ep->geo.Source < 0, std::pair<int, int> std::pair<bool, std::pair<int, int> > tags
(ep->geo.Source < 0, std::pair<int, int>
(ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex)); (ep->mesh.BoundaryLayerIndex, ep->mesh.ViewIndex));
sourceFaceInfo[from->tag()].insert(tags); sourceFaceInfo[from->tag()].insert(tags);
sourceFaces.insert(from); sourceFaces.insert(from);
...@@ -183,7 +196,7 @@ int Mesh2DWithBoundaryLayers(GModel *m) ...@@ -183,7 +196,7 @@ int Mesh2DWithBoundaryLayers(GModel *m)
ExtrudeParams::normals[1]->add(p.x(), p.y(), p.z(), 3, n0); ExtrudeParams::normals[1]->add(p.x(), p.y(), p.z(), 3, n0);
} }
// normalize normals if not using post-processing views // normalize extrusion directions if not using post-processing views
if(normalize) if(normalize)
for(int i = 0; i < 2; i++) for(int i = 0; i < 2; i++)
ExtrudeParams::normals[i]->normalize(); ExtrudeParams::normals[i]->normalize();
......
Merge "sphere_boundary_layer_from_view.pos"; Merge "sphere_boundary_layer_from_view.pos";
Plugin(MathEval).Run;
lc = 0.2; lc = 0.2;
...@@ -40,9 +41,12 @@ Line Loop(27) = {-4,12,-6}; ...@@ -40,9 +41,12 @@ 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 View[0]; Using Index[0]; Surface{14:28:2}; Layers{5, 0.2}; Recombine; Using Index[0];
// can use scalar or vectpr view
//Using View[0];
Using View[1];
}; };
// test 2nd bnd layer // test 2nd bnd layer
Extrude { Surface{14:28:2}; Layers{5, -0.2}; Recombine; Using View[0]; Using Index[1]; } //Extrude { Surface{14:28:2}; Layers{5, -0.2}; Recombine; Using View[0]; Using Index[1]; }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment