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

fix crash when displaying vectors

parent e8fd74f2
No related branches found
No related tags found
No related merge requests found
// $Id: VertexArray.cpp,v 1.27 2007-09-22 22:56:37 geuzaine Exp $ // $Id: VertexArray.cpp,v 1.28 2007-09-24 14:59:01 geuzaine Exp $
// //
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
// //
...@@ -35,22 +35,27 @@ VertexArray::VertexArray(int numVerticesPerElement, int numElements) ...@@ -35,22 +35,27 @@ VertexArray::VertexArray(int numVerticesPerElement, int numElements)
_colors.reserve(nb * 4); _colors.reserve(nb * 4);
} }
void VertexArray::add(float x, float y, float z, float n0, float n1, float n2, void VertexArray::addVertex(float x, float y, float z)
unsigned int col, MElement *ele)
{ {
_vertices.push_back(x); _vertices.push_back(x);
_vertices.push_back(y); _vertices.push_back(y);
_vertices.push_back(z); _vertices.push_back(z);
}
void VertexArray::addNormal(float nx, float ny, float nz)
{
// storing the normals as bytes hurts rendering performance, but it // storing the normals as bytes hurts rendering performance, but it
// significantly reduces the memory footprint // significantly reduces the memory footprint
char c0 = float2char(n0); char cx = float2char(nx);
char c1 = float2char(n1); char cy = float2char(ny);
char c2 = float2char(n2); char cz = float2char(nz);
_normals.push_back(c0); _normals.push_back(cx);
_normals.push_back(c1); _normals.push_back(cy);
_normals.push_back(c2); _normals.push_back(cz);
}
void VertexArray::addColor(unsigned int col)
{
unsigned char r = CTX.UNPACK_RED(col); unsigned char r = CTX.UNPACK_RED(col);
unsigned char g = CTX.UNPACK_GREEN(col); unsigned char g = CTX.UNPACK_GREEN(col);
unsigned char b = CTX.UNPACK_BLUE(col); unsigned char b = CTX.UNPACK_BLUE(col);
...@@ -59,7 +64,10 @@ void VertexArray::add(float x, float y, float z, float n0, float n1, float n2, ...@@ -59,7 +64,10 @@ void VertexArray::add(float x, float y, float z, float n0, float n1, float n2,
_colors.push_back(g); _colors.push_back(g);
_colors.push_back(b); _colors.push_back(b);
_colors.push_back(a); _colors.push_back(a);
}
void VertexArray::addElement(MElement *ele)
{
if(ele && CTX.pick_elements) _elements.push_back(ele); if(ele && CTX.pick_elements) _elements.push_back(ele);
} }
...@@ -87,18 +95,26 @@ void VertexArray::add(double *x, double *y, double *z, SVector3 *n, ...@@ -87,18 +95,26 @@ void VertexArray::add(double *x, double *y, double *z, SVector3 *n,
_barycenters.insert(pc); _barycenters.insert(pc);
} }
for(int i = 0; i < npe; i++) for(int i = 0; i < npe; i++){
add(x[i], y[i], z[i], n[i].x(), n[i].y(), n[i].z(), col[i], ele); addVertex(x[i], y[i], z[i]);
if(n) addNormal(n[i].x(), n[i].y(), n[i].z());
if(col) addColor(col[i]);
addElement(ele);
}
} }
void VertexArray::finalize() void VertexArray::finalize()
{ {
if(_data3.size()){ if(_data3.size()){
std::set<ElementData<3>, ElementDataLessThan<3> >::iterator it = _data3.begin(); std::set<ElementData<3>, ElementDataLessThan<3> >::iterator it = _data3.begin();
for(; it != _data3.end(); it++) for(; it != _data3.end(); it++){
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++){
add(it->x(i), it->y(i), it->z(i), it->nx(i), it->ny(i), it->nz(i), addVertex(it->x(i), it->y(i), it->z(i));
it->col(i), it->ele()); addNormal(it->nx(i), it->ny(i), it->nz(i));
addColor(it->col(i));
addElement(it->ele());
}
}
_data3.clear(); _data3.clear();
} }
_barycenters.clear(); _barycenters.clear();
......
...@@ -43,10 +43,17 @@ class ElementData { ...@@ -43,10 +43,17 @@ class ElementData {
_x[i] = x[i]; _x[i] = x[i];
_y[i] = y[i]; _y[i] = y[i];
_z[i] = z[i]; _z[i] = z[i];
_nx[i] = n[i].x(); if(n){
_ny[i] = n[i].y(); _nx[i] = n[i].x();
_nz[i] = n[i].z(); _ny[i] = n[i].y();
_col[i] = col[i]; _nz[i] = n[i].z();
}
else
_nx[i] = _ny[i] = _nz[i] = 0.;
if(col)
_col[i] = col[i];
else
_col[i] = 0;
} }
_ele = ele; _ele = ele;
} }
...@@ -141,10 +148,12 @@ class VertexArray{ ...@@ -141,10 +148,12 @@ class VertexArray{
unsigned char *getColorArray(int i=0){ return &_colors[i]; } unsigned char *getColorArray(int i=0){ return &_colors[i]; }
// returns a pointer to the raw element array // returns a pointer to the raw element array
MElement **getElementPointerArray(int i=0){ return &_elements[i]; } MElement **getElementPointerArray(int i=0){ return &_elements[i]; }
// adds a vertex in the arrays // adds stuff in the arrays
void add(float x, float y, float z, float n0, float n1, float n2, void addVertex(float x, float y, float z);
unsigned int col, MElement *ele=0); void addNormal(float nx, float ny, float nz);
// add an element in the arrays (if unique is set, only add the void addColor(unsigned int col);
void addElement(MElement *ele);
// add element data in the arrays (if unique is set, only add the
// element if another one with the same barycenter is not already // element if another one with the same barycenter is not already
// present) // present)
void add(double *x, double *y, double *z, SVector3 *n, unsigned int *col, void add(double *x, double *y, double *z, SVector3 *n, unsigned int *col,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment