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

add min, max, time and bbox to serialization

parent 4c0f4765
Branches
Tags
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "GmshSocket.h" #include "GmshSocket.h"
#include "PView.h" #include "PView.h"
#include "PViewOptions.h" #include "PViewOptions.h"
#include "PViewData.h"
#include "VertexArray.h" #include "VertexArray.h"
int GmshDaemon(std::string socket) int GmshDaemon(std::string socket)
...@@ -52,8 +53,12 @@ int GmshDaemon(std::string socket) ...@@ -52,8 +53,12 @@ int GmshDaemon(std::string socket)
PView *view = PView::list[0]; PView *view = PView::list[0];
view->getOptions()->intervalsType = PViewOptions::Iso; view->getOptions()->intervalsType = PViewOptions::Iso;
view->fillVertexArrays(); view->fillVertexArrays();
PViewData *data = view->getData();
int len; 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); client.SendMessage(GmshSocket::GMSH_VERTEX_ARRAY, len, ss);
delete [] ss; delete [] ss;
} }
......
...@@ -217,46 +217,67 @@ int VertexArray::getMemoryUsage() ...@@ -217,46 +217,67 @@ int VertexArray::getMemoryUsage()
return bytes / 1024 / 1024; 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 vn = _vertices.size(), nn = _normals.size(), cn = _colors.size();
int vs = vn * sizeof(float), ns = nn * sizeof(char), cs = cn * sizeof(unsigned char); 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; len = 5 * is + 9 * ds + vs + ns + cs;
char *data = new char[len]; char *bytes = new char[len];
int index = 0; int index = 0;
memcpy(&data[index], &num, is); index += is; memcpy(&bytes[index], &num, is); index += is;
memcpy(&data[index], &type, is); index += is; memcpy(&bytes[index], &type, is); index += is;
memcpy(&data[index], &vn, is); index += is; memcpy(&bytes[index], &min, ds); index += ds;
memcpy(&data[index], &_vertices[0], vs); index += vs; memcpy(&bytes[index], &max, ds); index += ds;
memcpy(&data[index], &nn, is); index += is; memcpy(&bytes[index], &time, ds); index += ds;
memcpy(&data[index], &_normals[0], ns); index += ns; memcpy(&bytes[index], &xmin, ds); index += ds;
memcpy(&data[index], &cn, is); index += is; memcpy(&bytes[index], &ymin, ds); index += ds;
memcpy(&data[index], &_colors[0], cs); index += cs; memcpy(&bytes[index], &zmin, ds); index += ds;
return data; 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){ int is = sizeof(int), ds = sizeof(double), index = 0;
Msg::Error("Byte swapping not implemented in VertexArray::fromChar");
return; int num; memcpy(&num, &bytes[index], is); index += is;
}
int is = sizeof(int), index = 0; 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, &bytes[index], is); index += is;
int type; memcpy(&type, &data[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); _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); _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); _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;
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include "SVector3.h" #include "SVector3.h"
#include "SBoundingBox3d.h"
class MElement; class MElement;
...@@ -163,8 +164,9 @@ class VertexArray{ ...@@ -163,8 +164,9 @@ class VertexArray{
int getMemoryUsage(); int getMemoryUsage();
// serialize the vertex array into a string (for sending over the // serialize the vertex array into a string (for sending over the
// network) // network)
char *toChar(int num, int type, int &len); char *toChar(int num, int type, double min, double max, double time,
void fromChar(const char *data, bool swap=false); SBoundingBox3d bbox, int &len);
void fromChar(const char *bytes);
}; };
#endif #endif
...@@ -22,6 +22,9 @@ class SBoundingBox3d { ...@@ -22,6 +22,9 @@ class SBoundingBox3d {
: MinPt(DBL_MAX,DBL_MAX,DBL_MAX), MaxPt(-DBL_MAX,-DBL_MAX,-DBL_MAX) {} : MinPt(DBL_MAX,DBL_MAX,DBL_MAX), MaxPt(-DBL_MAX,-DBL_MAX,-DBL_MAX) {}
SBoundingBox3d(const SPoint3 &pt) SBoundingBox3d(const SPoint3 &pt)
: MinPt(pt), MaxPt(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() bool empty()
{ {
if(MinPt.x() == DBL_MAX || MinPt.y() == DBL_MAX || MinPt.z() == DBL_MAX || if(MinPt.x() == DBL_MAX || MinPt.y() == DBL_MAX || MinPt.z() == DBL_MAX ||
......
...@@ -21,10 +21,10 @@ class PViewDataRemote : public PViewData { ...@@ -21,10 +21,10 @@ class PViewDataRemote : public PViewData {
SBoundingBox3d _bbox; SBoundingBox3d _bbox;
std::vector<double> _time; std::vector<double> _time;
public: 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); _time.push_back(time);
_bbox += SPoint3(1, 1, 1);
} }
~PViewDataRemote(){} ~PViewDataRemote(){}
bool finalize(){} bool finalize(){}
...@@ -32,6 +32,25 @@ class PViewDataRemote : public PViewData { ...@@ -32,6 +32,25 @@ class PViewDataRemote : public PViewData {
double getMin(int step=-1){ return _min; } double getMin(int step=-1){ return _min; }
double getMax(int step=-1){ return _max; } double getMax(int step=-1){ return _max; }
SBoundingBox3d getBoundingBox(int step=-1){ return _bbox; } 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 #endif
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "VertexArray.h" #include "VertexArray.h"
#include "SmoothData.h" #include "SmoothData.h"
#include "Context.h" #include "Context.h"
#include "OpenFile.h"
#include "mathEvaluator.h" #include "mathEvaluator.h"
static void saturate(int nb, double val[PVIEW_NMAX][9], double vmin, double vmax, static void saturate(int nb, double val[PVIEW_NMAX][9], double vmin, double vmax,
...@@ -1116,20 +1117,25 @@ void PView::fillVertexArrays() ...@@ -1116,20 +1117,25 @@ void PView::fillVertexArrays()
void PView::fillVertexArray(int length, const char *bytes) void PView::fillVertexArray(int length, const char *bytes)
{ {
int is = sizeof(int); int is = sizeof(int), ds = sizeof(double);
if(length < 2 * is){ if(length < 2 * is){
Msg::Error("Too few bytes to create vertex array: %d", length); Msg::Error("Too few bytes to create vertex array: %d", length);
return; return;
} }
int num; memcpy(&num, &bytes[0], is); int index = 0;
int type; memcpy(&type, &bytes[is], is); int num; memcpy(&num, &bytes[index], is); index += is;
int type; memcpy(&type, &bytes[index], is); index += is;
// we should also serialize the following info double min; memcpy(&min, &bytes[index], ds); index += ds;
// min, max double max; memcpy(&max, &bytes[index], ds); index += ds;
// time value double time; memcpy(&time, &bytes[index], ds); index += ds;
// bounding box 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); 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) ...@@ -1139,7 +1145,10 @@ void PView::fillVertexArray(int length, const char *bytes)
} }
else{ else{
Msg::Info("View num %d does not exist: creating new view"); 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){ switch(type){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment