diff --git a/Common/GmshDaemon.cpp b/Common/GmshDaemon.cpp index 1d8886773ee0a050f12f1673dbfed7e836cc263f..b5b63d8bf419e2be5a76d2955fe65665960eb8ae 100644 --- a/Common/GmshDaemon.cpp +++ b/Common/GmshDaemon.cpp @@ -9,6 +9,7 @@ #include "GmshSocket.h" #include "PView.h" #include "PViewOptions.h" +#include "PViewData.h" #include "VertexArray.h" int GmshDaemon(std::string socket) @@ -52,8 +53,12 @@ int GmshDaemon(std::string socket) PView *view = PView::list[0]; view->getOptions()->intervalsType = PViewOptions::Iso; view->fillVertexArrays(); + PViewData *data = view->getData(); + int len; - char *ss = view->va_triangles->toChar(view->getNum(), 3, len); + char *ss = view->va_triangles->toChar + (view->getNum(), 3, data->getMin(), data->getMax(), + data->getTime(0), data->getBoundingBox(), len); client.SendMessage(GmshSocket::GMSH_VERTEX_ARRAY, len, ss); delete [] ss; } diff --git a/Common/VertexArray.cpp b/Common/VertexArray.cpp index 282bd149ef4186932909d2b05207b9b5c57b7eec..8a747147d2210dd5ffe755b9801f0c560b391cc6 100644 --- a/Common/VertexArray.cpp +++ b/Common/VertexArray.cpp @@ -217,46 +217,67 @@ int VertexArray::getMemoryUsage() return bytes / 1024 / 1024; } -char *VertexArray::toChar(int num, int type, int &len) +char *VertexArray::toChar(int num, int type, double min, double max, double time, + SBoundingBox3d bbox, 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); - int is = sizeof(int); + int is = sizeof(int), ds = sizeof(double); + double xmin = bbox.min().x(), ymin = bbox.min().y(), zmin = bbox.min().z(); + double xmax = bbox.max().x(), ymax = bbox.max().y(), zmax = bbox.max().z(); - len = 5 * is + vs + ns + cs; - char *data = new char[len]; + len = 5 * is + 9 * ds + vs + ns + cs; + char *bytes = new char[len]; int index = 0; - memcpy(&data[index], &num, 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; - memcpy(&data[index], &_normals[0], ns); index += ns; - memcpy(&data[index], &cn, is); index += is; - memcpy(&data[index], &_colors[0], cs); index += cs; - return data; + memcpy(&bytes[index], &num, is); index += is; + memcpy(&bytes[index], &type, is); index += is; + memcpy(&bytes[index], &min, ds); index += ds; + memcpy(&bytes[index], &max, ds); index += ds; + memcpy(&bytes[index], &time, ds); index += ds; + memcpy(&bytes[index], &xmin, ds); index += ds; + memcpy(&bytes[index], &ymin, ds); index += ds; + memcpy(&bytes[index], &zmin, ds); index += ds; + memcpy(&bytes[index], &xmax, ds); index += ds; + memcpy(&bytes[index], &ymax, ds); index += ds; + memcpy(&bytes[index], &zmax, ds); index += ds; + memcpy(&bytes[index], &vn, is); index += is; + memcpy(&bytes[index], &_vertices[0], vs); index += vs; + memcpy(&bytes[index], &nn, is); index += is; + memcpy(&bytes[index], &_normals[0], ns); index += ns; + memcpy(&bytes[index], &cn, is); index += is; + memcpy(&bytes[index], &_colors[0], cs); index += cs; + return bytes; } -void VertexArray::fromChar(const char *data, bool swap) +void VertexArray::fromChar(const char *bytes) { - if(swap){ - Msg::Error("Byte swapping not implemented in VertexArray::fromChar"); - return; - } - int is = sizeof(int), index = 0; + int is = sizeof(int), ds = sizeof(double), index = 0; + + int num; memcpy(&num, &bytes[index], is); index += is; + + if(num > 65535) + Msg::Error("Should swap data in vertex array stream"); - int num; memcpy(&num, &data[index], is); index += is; - int type; memcpy(&type, &data[index], is); index += is; + int type; memcpy(&type, &bytes[index], is); index += is; + double min; memcpy(&min, &bytes[index], ds); index += ds; + double max; memcpy(&max, &bytes[index], ds); index += ds; + double time; memcpy(&time, &bytes[index], ds); index += ds; + double xmin; memcpy(&xmin, &bytes[index], ds); index += ds; + double ymin; memcpy(&ymin, &bytes[index], ds); index += ds; + double zmin; memcpy(&zmin, &bytes[index], ds); index += ds; + double xmax; memcpy(&xmax, &bytes[index], ds); index += ds; + double ymax; memcpy(&ymax, &bytes[index], ds); index += ds; + double zmax; memcpy(&zmax, &bytes[index], ds); index += ds; - int vn; memcpy(&vn, &data[index], is); index += is; + int vn; memcpy(&vn, &bytes[index], is); index += is; _vertices.resize(vn); int vs = vn * sizeof(float); - memcpy(&_vertices[0], &data[index], vs); index += vs; + memcpy(&_vertices[0], &bytes[index], vs); index += vs; - int nn; memcpy(&nn, &data[index], is); index += is; + int nn; memcpy(&nn, &bytes[index], is); index += is; _normals.resize(nn); int ns = nn * sizeof(char); - memcpy(&_normals[0], &data[index], ns); index += ns; + memcpy(&_normals[0], &bytes[index], ns); index += ns; - int cn; memcpy(&cn, &data[index], is); index += is; + int cn; memcpy(&cn, &bytes[index], is); index += is; _colors.resize(cn); int cs = cn * sizeof(unsigned char); - memcpy(&_colors[0], &data[index], cs); index += cs; + memcpy(&_colors[0], &bytes[index], cs); index += cs; } diff --git a/Common/VertexArray.h b/Common/VertexArray.h index 5821b8565a822e6f45c65986bc982f2fa56912cb..4e7bdc3b75f89228cce366a9ebe1eea34760f91d 100644 --- a/Common/VertexArray.h +++ b/Common/VertexArray.h @@ -9,6 +9,7 @@ #include <vector> #include <set> #include "SVector3.h" +#include "SBoundingBox3d.h" class MElement; @@ -163,8 +164,9 @@ class VertexArray{ int getMemoryUsage(); // serialize the vertex array into a string (for sending over the // network) - char *toChar(int num, int type, int &len); - void fromChar(const char *data, bool swap=false); + char *toChar(int num, int type, double min, double max, double time, + SBoundingBox3d bbox, int &len); + void fromChar(const char *bytes); }; #endif diff --git a/Geo/SBoundingBox3d.h b/Geo/SBoundingBox3d.h index 6992af9e986d754a3655ccc7fbb3ce3f6808f34c..c4010a7ef2acd7f54171401aacfe6b53237078a9 100644 --- a/Geo/SBoundingBox3d.h +++ b/Geo/SBoundingBox3d.h @@ -22,6 +22,9 @@ class SBoundingBox3d { : MinPt(DBL_MAX,DBL_MAX,DBL_MAX), MaxPt(-DBL_MAX,-DBL_MAX,-DBL_MAX) {} SBoundingBox3d(const SPoint3 &pt) : MinPt(pt), MaxPt(pt) {} + SBoundingBox3d(double xmin, double ymin, double zmin, + double xmax, double ymax, double zmax) + : MinPt(xmin, ymin, zmin), MaxPt(xmax, ymax, zmax) {} bool empty() { if(MinPt.x() == DBL_MAX || MinPt.y() == DBL_MAX || MinPt.z() == DBL_MAX || diff --git a/Post/PViewDataRemote.h b/Post/PViewDataRemote.h index 57308a8bc4fbc658b6112ce05ae9c5c118fdd737..7adade2db69e67a7c9663c0acf0d14fac9beb990 100644 --- a/Post/PViewDataRemote.h +++ b/Post/PViewDataRemote.h @@ -21,10 +21,10 @@ class PViewDataRemote : public PViewData { SBoundingBox3d _bbox; std::vector<double> _time; public: - PViewDataRemote() : _numTimeSteps(1), _min(0.), _max(2.2) + PViewDataRemote(double min, double max, double time, SBoundingBox3d bbox) + : _numTimeSteps(1), _min(min), _max(max), _bbox(bbox) { - _bbox += SPoint3(-1, -1, -1); - _bbox += SPoint3(1, 1, 1); + _time.push_back(time); } ~PViewDataRemote(){} bool finalize(){} @@ -32,6 +32,25 @@ class PViewDataRemote : public PViewData { double getMin(int step=-1){ return _min; } double getMax(int step=-1){ return _max; } SBoundingBox3d getBoundingBox(int step=-1){ return _bbox; } + double getTime(int step) + { + if(step >= 0 && step < _time.size()) return _time[step]; + return 0.; + } + int getNumElements(int step=-1, int ent=-1) + { + // hack so that it does not retrn 0 + return -1; + } + + void setMin(double min){ _min = min; } + void setMax(double max){ _min = max; } + void setBoundingBox(SBoundingBox3d bbox){ _bbox = bbox; } + void setTime(int step, double time) + { + if(step >= _time.size()) _time.resize(step + 1); + _time[step] = time; + } }; #endif diff --git a/Post/PViewVertexArrays.cpp b/Post/PViewVertexArrays.cpp index 7614886599ce52523e26c85f2631772df8a1be88..773b8d7e4ccc9df32d136a4f6e8bd8833cbc7749 100644 --- a/Post/PViewVertexArrays.cpp +++ b/Post/PViewVertexArrays.cpp @@ -15,6 +15,7 @@ #include "VertexArray.h" #include "SmoothData.h" #include "Context.h" +#include "OpenFile.h" #include "mathEvaluator.h" static void saturate(int nb, double val[PVIEW_NMAX][9], double vmin, double vmax, @@ -1116,20 +1117,25 @@ void PView::fillVertexArrays() void PView::fillVertexArray(int length, const char *bytes) { - int is = sizeof(int); + int is = sizeof(int), ds = sizeof(double); if(length < 2 * is){ Msg::Error("Too few bytes to create vertex array: %d", length); return; } - 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 + int index = 0; + int num; memcpy(&num, &bytes[index], is); index += is; + int type; memcpy(&type, &bytes[index], is); index += is; + double min; memcpy(&min, &bytes[index], ds); index += ds; + double max; memcpy(&max, &bytes[index], ds); index += ds; + double time; memcpy(&time, &bytes[index], ds); index += ds; + double xmin; memcpy(&xmin, &bytes[index], ds); index += ds; + double ymin; memcpy(&ymin, &bytes[index], ds); index += ds; + double zmin; memcpy(&zmin, &bytes[index], ds); index += ds; + double xmax; memcpy(&xmax, &bytes[index], ds); index += ds; + double ymax; memcpy(&ymax, &bytes[index], ds); index += ds; + double zmax; memcpy(&zmax, &bytes[index], ds); index += ds; Msg::Info("Filling vertex array (type %d) in view num %d", type, num); @@ -1139,7 +1145,10 @@ void PView::fillVertexArray(int length, const char *bytes) } else{ Msg::Info("View num %d does not exist: creating new view"); - view = new PView(new PViewDataRemote); + view = new PView + (new PViewDataRemote(min, max, time, SBoundingBox3d(xmin, ymin, zmin, + xmax, ymax, zmax))); + SetBoundingBox(); } switch(type){