From da5ff60b886984462b1e6350be69f70518e001ec Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 31 Mar 2008 16:04:42 +0000
Subject: [PATCH] test gauss point views

---
 Graphics/Post.cpp          | 20 ++++++++++++++++--
 Post/PViewData.h           |  1 +
 Post/PViewDataGModel.cpp   | 42 ++++++++++++++++++++++++--------------
 Post/PViewDataGModel.h     |  1 +
 Post/PViewDataGModelIO.cpp |  8 ++++----
 5 files changed, 51 insertions(+), 21 deletions(-)

diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp
index a7da542087..e168246e9f 100644
--- a/Graphics/Post.cpp
+++ b/Graphics/Post.cpp
@@ -1,4 +1,4 @@
-// $Id: Post.cpp,v 1.160 2008-03-29 11:51:37 geuzaine Exp $
+// $Id: Post.cpp,v 1.161 2008-03-31 16:04:41 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -914,7 +914,23 @@ void addElementsInArrays(PView *p, bool preprocessNormalsOnly)
         addOutlineElement(p, numEdges, xyz, preprocessNormalsOnly);
       
       if(opt->IntervalsType != PViewOptions::Numeric){
-        if(numComp == 1 && opt->DrawScalars)
+	if(data->useGaussPoints()){
+	  for(int j = 0; j < numNodes; j++){
+	    double xyz2[NMAX][3], val2[NMAX][9];
+	    xyz2[0][0] = xyz[j][0];
+	    xyz2[0][1] = xyz[j][1];
+	    xyz2[0][2] = xyz[j][2];
+	    for(int k = 0; k < numComp; k++)
+	      val2[0][k] = val[j][k];
+	    if(numComp == 1 && opt->DrawScalars)
+	      addScalarElement(p, 0, xyz2, val2, preprocessNormalsOnly);
+	    else if(numComp == 3 && opt->DrawVectors)
+	      addVectorElement(p, ent, i, 1, 0, xyz2, val2, preprocessNormalsOnly);
+	    else if(numComp == 9 && opt->DrawTensors)
+	      addTensorElement(p, 1, 0, xyz2, val2, preprocessNormalsOnly);
+	  }
+	}
+        else if(numComp == 1 && opt->DrawScalars)
           addScalarElement(p, numEdges, xyz, val, preprocessNormalsOnly);
         else if(numComp == 3 && opt->DrawVectors)
           addVectorElement(p, ent, i, numNodes, numEdges, xyz, val, preprocessNormalsOnly);
diff --git a/Post/PViewData.h b/Post/PViewData.h
index e62f92e3b9..15f9448135 100644
--- a/Post/PViewData.h
+++ b/Post/PViewData.h
@@ -112,6 +112,7 @@ class PViewData {
   virtual bool hasTimeStep(int step){ return step < getNumTimeSteps(); }
   virtual bool hasPartition(int part){ return false; }
   virtual bool hasMultipleMeshes(){ return false; }
+  virtual bool useGaussPoints(){ return false; }
 
   // I/O routines
   virtual bool writeSTL(std::string fileName);
diff --git a/Post/PViewDataGModel.cpp b/Post/PViewDataGModel.cpp
index ad76d0a151..f7961ba4c7 100644
--- a/Post/PViewDataGModel.cpp
+++ b/Post/PViewDataGModel.cpp
@@ -1,4 +1,4 @@
-// $Id: PViewDataGModel.cpp,v 1.42 2008-03-30 22:59:26 geuzaine Exp $
+// $Id: PViewDataGModel.cpp,v 1.43 2008-03-31 16:04:42 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -140,12 +140,22 @@ int PViewDataGModel::getDimension(int step, int ent, int ele)
 int PViewDataGModel::getNumNodes(int step, int ent, int ele)
 {
   // no sanity checks (assumed to be guarded by skipElement)
+  if(_type == GaussPointData) return 1; // FIXME!
+
   return _steps[step]->getEntity(ent)->getMeshElement(ele)->getNumVertices();
+  //return _steps[step]->getEntity(ent)->getMeshElement(ele)->getNumPrimaryVertices();
 }
 
 void PViewDataGModel::getNode(int step, int ent, int ele, int nod, 
                               double &x, double &y, double &z)
 {
+  if(_type == GaussPointData){ // FIXME!
+    MElement *e = _steps[step]->getEntity(ent)->getMeshElement(ele);
+    SPoint3 bc = e->barycenter();
+    x = bc.x(); y = bc.y(); z = bc.z();
+    return;
+  }
+
   // no sanity checks (assumed to be guarded by skipElement)
   MVertex *v = _steps[step]->getEntity(ent)->getMeshElement(ele)->getVertex(nod);
   x = v->x();
@@ -163,22 +173,24 @@ void PViewDataGModel::getValue(int step, int ent, int ele, int nod, int comp, do
 {
   // no sanity checks (assumed to be guarded by skipElement)
   stepData<double> *sd = _steps[step];
-  if(_type == NodeData){
-    MVertex *v = sd->getEntity(ent)->getMeshElement(ele)->getVertex(nod);
-    val = sd->getData(v->getNum())[comp];
-  }
-  else{
-    MElement *e = sd->getEntity(ent)->getMeshElement(ele);
-    switch(_type){
-    case ElementNodeData:
-      val = sd->getData(e->getNum())[sd->getNumComponents() * nod + comp];
+  switch(_type){
+  case NodeData: 
+    {
+      MVertex *v = sd->getEntity(ent)->getMeshElement(ele)->getVertex(nod);
+      val = sd->getData(v->getNum())[comp];
       break;
-    case GaussPointData:
-      Msg(WARNING, "GaussPoint data not ready yet!");
-      val = sd->getData(e->getNum())[comp];
+    }
+  case ElementNodeData:
+  case GaussPointData: 
+    {
+      MElement *e = sd->getEntity(ent)->getMeshElement(ele);
+      val = sd->getData(e->getNum())[sd->getNumComponents() * nod + comp];
       break;
-    case ElementData: 
-    default:
+    }
+  case ElementData: 
+  default: 
+    {
+      MElement *e = sd->getEntity(ent)->getMeshElement(ele);
       val = sd->getData(e->getNum())[comp];
       break;
     }
diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h
index ec02ae11b5..2187ae3fcb 100644
--- a/Post/PViewDataGModel.h
+++ b/Post/PViewDataGModel.h
@@ -160,6 +160,7 @@ class PViewDataGModel : public PViewData {
   bool hasTimeStep(int step);
   bool hasPartition(int part);
   bool hasMultipleMeshes();
+  bool useGaussPoints(){ return _type == GaussPointData; }
 
   // get/set the data type
   DataType getType(){ return _type; }
diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp
index 0dc751fe9f..631f0a46a9 100644
--- a/Post/PViewDataGModelIO.cpp
+++ b/Post/PViewDataGModelIO.cpp
@@ -1,4 +1,4 @@
-// $Id: PViewDataGModelIO.cpp,v 1.28 2008-03-30 22:59:26 geuzaine Exp $
+// $Id: PViewDataGModelIO.cpp,v 1.29 2008-03-31 16:04:42 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -332,10 +332,10 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
 	  int j2 = (ent == MED_NOEUD_ELEMENT) ? med2msh(ele, j) : j;
 	  for(int k = 0; k < numComp; k++)
 	    d[numComp * j + k] = val[numComp * mult * i + numComp * j2 + k];
+	  double s = ComputeScalarRep(_steps[step]->getNumComponents(), &d[numComp * j]);
+	  _steps[step]->setMin(std::min(_steps[step]->getMin(), s));
+	  _steps[step]->setMax(std::max(_steps[step]->getMax(), s));
 	}
-	double s = ComputeScalarRep(_steps[step]->getNumComponents(), d);
-	_steps[step]->setMin(std::min(_steps[step]->getMin(), s));
-	_steps[step]->setMax(std::max(_steps[step]->getMax(), s));
       }
     }
   }
-- 
GitLab