From abafc640e9ede8faba76bd131a5c62f4833d131e Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 14 Sep 2009 06:17:47 +0000
Subject: [PATCH] also transfer vector arrays

(we should design a small container atop the va to store the additional
info we need to transfer: min/max, bbox, timeval)
---
 Common/GmshDaemon.cpp      |  2 +-
 Common/VertexArray.cpp     | 11 +++--------
 Common/VertexArray.h       |  2 +-
 Post/PViewVertexArrays.cpp | 10 ++++++++++
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/Common/GmshDaemon.cpp b/Common/GmshDaemon.cpp
index f96ac335a0..1d8886773e 100644
--- a/Common/GmshDaemon.cpp
+++ b/Common/GmshDaemon.cpp
@@ -53,7 +53,7 @@ int GmshDaemon(std::string socket)
                 view->getOptions()->intervalsType = PViewOptions::Iso;
                 view->fillVertexArrays();
                 int len;
-                char *ss = view->va_triangles->toChar(view->getNum(), len);
+                char *ss = view->va_triangles->toChar(view->getNum(), 3, len);
                 client.SendMessage(GmshSocket::GMSH_VERTEX_ARRAY, len, ss);
                 delete [] ss;
               }
diff --git a/Common/VertexArray.cpp b/Common/VertexArray.cpp
index 7faf3a52d7..282bd149ef 100644
--- a/Common/VertexArray.cpp
+++ b/Common/VertexArray.cpp
@@ -217,7 +217,7 @@ int VertexArray::getMemoryUsage()
   return bytes / 1024 / 1024;
 }
 
-char *VertexArray::toChar(int num, int &len)
+char *VertexArray::toChar(int num, int type, int &len)
 {
   int vn = _vertices.size(), nn = _normals.size(), cn = _colors.size();
   int vs = vn * sizeof(float), ns = nn * sizeof(char), cs = cn * sizeof(unsigned char);
@@ -227,7 +227,7 @@ char *VertexArray::toChar(int num, int &len)
   char *data = new char[len];
   int index = 0;
   memcpy(&data[index], &num, is); index += is;
-  memcpy(&data[index], &_numVerticesPerElement, is); index += is;
+  memcpy(&data[index], &type, is); index += is;
   memcpy(&data[index], &vn, is); index += is;
   memcpy(&data[index], &_vertices[0], vs); index += vs;
   memcpy(&data[index], &nn, is); index += is;
@@ -246,12 +246,7 @@ void VertexArray::fromChar(const char *data, bool swap)
   int is = sizeof(int), index = 0;
 
   int num; memcpy(&num, &data[index], is); index += is;
-  int tmp; memcpy(&tmp, &data[index], is); index += is;
-  if(tmp != _numVerticesPerElement){
-    Msg::Error("Incompatible raw data for vertex array (%d != %d)",
-               tmp, _numVerticesPerElement);
-    return;
-  }
+  int type; memcpy(&type, &data[index], is); index += is;
 
   int vn; memcpy(&vn, &data[index], is); index += is;
   _vertices.resize(vn); int vs = vn * sizeof(float);
diff --git a/Common/VertexArray.h b/Common/VertexArray.h
index 6c8fc165ae..5821b8565a 100644
--- a/Common/VertexArray.h
+++ b/Common/VertexArray.h
@@ -163,7 +163,7 @@ class VertexArray{
   int getMemoryUsage();
   // serialize the vertex array into a string (for sending over the
   // network)
-  char *toChar(int num, int &len);
+  char *toChar(int num, int type, int &len);
   void fromChar(const char *data, bool swap=false);
 };
 
diff --git a/Post/PViewVertexArrays.cpp b/Post/PViewVertexArrays.cpp
index 3e97f74377..7614886599 100644
--- a/Post/PViewVertexArrays.cpp
+++ b/Post/PViewVertexArrays.cpp
@@ -1126,6 +1126,11 @@ void PView::fillVertexArray(int length, const char *bytes)
   int num; memcpy(&num, &bytes[0], is);
   int type; memcpy(&type, &bytes[is], is);
 
+  // we should also serialize the following info
+  //   min, max
+  //   time value
+  //   bounding box
+  
   Msg::Info("Filling vertex array (type %d) in view num %d", type, num);
 
   PView *view;
@@ -1153,6 +1158,11 @@ void PView::fillVertexArray(int length, const char *bytes)
     view->va_triangles = new VertexArray(3, 100);
     view->va_triangles->fromChar(bytes);
     break;
+  case 4:
+    if(view->va_vectors) delete view->va_vectors;
+    view->va_vectors = new VertexArray(2, 100);
+    view->va_vectors->fromChar(bytes);
+    break;
   default: 
     Msg::Error("Cannot fill vertex array of type %d", type);
     return;
-- 
GitLab