StelVertexArray.hpp   StelVertexArray.hpp
skipping to change at line 52 skipping to change at line 52
StelVertexArray(StelPrimitiveType pType=StelVertexArray::Triangles) : primitiveType(pType) {;} StelVertexArray(StelPrimitiveType pType=StelVertexArray::Triangles) : primitiveType(pType) {;}
StelVertexArray(const QVector<Vec3d>& v, StelPrimitiveType pType=Ste lVertexArray::Triangles,const QVector<Vec2f>& t=QVector<Vec2f>(), const QVe ctor<unsigned short> i=QVector<unsigned short>()) : StelVertexArray(const QVector<Vec3d>& v, StelPrimitiveType pType=Ste lVertexArray::Triangles,const QVector<Vec2f>& t=QVector<Vec2f>(), const QVe ctor<unsigned short> i=QVector<unsigned short>()) :
vertex(v), texCoords(t), indices(i), primitiveType(pType) {; } vertex(v), texCoords(t), indices(i), primitiveType(pType) {; }
//! OpenGL compatible array of 3D vertex to be displayed using verte x arrays. //! OpenGL compatible array of 3D vertex to be displayed using verte x arrays.
//! TODO, move to float? Most of the vectors are normalized, thus th e precision is around 1E-45 using float //! TODO, move to float? Most of the vectors are normalized, thus th e precision is around 1E-45 using float
//! which is enough (=2E-37 milli arcsec). //! which is enough (=2E-37 milli arcsec).
QVector<Vec3d> vertex; QVector<Vec3d> vertex;
//! OpenGL compatible array of edge flags to be displayed using vert ex arrays. //! OpenGL compatible array of edge flags to be displayed using vert ex arrays.
QVector<Vec2f> texCoords; QVector<Vec2f> texCoords;
//! OpenGL compatible array of vertex colors to be displayed using a
rrays. (GZ/NEW)
//! The color (if exists) shall be multiplied with texture to modula
te e.g. for extinction of Milky Way or other large items.
QVector<Vec3f> colors;
//! OpenGL compatible array of indices for the vertex and the textur es //! OpenGL compatible array of indices for the vertex and the textur es
QVector<unsigned short> indices; QVector<unsigned short> indices;
StelPrimitiveType primitiveType; StelPrimitiveType primitiveType;
bool isIndexed() const {return !indices.isEmpty();} bool isIndexed() const {return !indices.isEmpty();}
bool isTextured() const {return !texCoords.isEmpty();} bool isTextured() const {return !texCoords.isEmpty();}
bool isColored() const {return !colors.isEmpty();}
//! call a function for each triangle of the array. //! call a function for each triangle of the array.
//! func should define the following method : //! func should define the following method : // GZ NEW: colors
//! void operator() (const Vec3d* vertex[3], const Vec2f* tex[3] //! void operator() (const Vec3d* vertex[3], const Vec2f* tex[3]
, unsigned int indices[3]) , const Vec3f* colors[3], unsigned int indices[3])
//! The method takes arrays of *pointers* as arguments because we ca n't assume the values are contiguous //! The method takes arrays of *pointers* as arguments because we ca n't assume the values are contiguous
template<class Func> template<class Func>
inline Func foreachTriangle(Func func) const; inline Func foreachTriangle(Func func) const;
//! Create a copy of the array with all the triangles intersecting t he projector discontinuty removed. //! Create a copy of the array with all the triangles intersecting t he projector discontinuity removed.
StelVertexArray removeDiscontinuousTriangles(const class StelProject or* prj) const; StelVertexArray removeDiscontinuousTriangles(const class StelProject or* prj) const;
private: private:
// Below we define a few methods that are templated to be optimized according to different types of VertexArray : // Below we define a few methods that are templated to be optimized according to different types of VertexArray :
// The template parameter <bool T> defines whether the array has a t exture. // The template parameter <bool T> defines whether the array has a t exture.
// The template parameter <bool I> defines whether the array is inde xed. // The template parameter <bool I> defines whether the array is inde xed.
// The template parameter <bool C> defines whether the array is colo red. // NEW GZ
template <bool I> template <bool I>
const Vec3d* specVertexAt(int i) const { const Vec3d* specVertexAt(int i) const {
return &vertex.at(specIndiceAt<I>(i)); return &vertex.at(specIndiceAt<I>(i));
} }
template <bool T, bool I> template <bool T, bool I>
const Vec2f* specTexCoordAt(int i) const { const Vec2f* specTexCoordAt(int i) const {
return T ? &texCoords.at(specIndiceAt<I>(i)) : NULL; return T ? &texCoords.at(specIndiceAt<I>(i)) : NULL;
} }
// NEW GZ
template <bool C, bool I>
const Vec3f* specColorAt(int i) const {
return C ? &colors.at(specIndiceAt<I>(i)) : NULL;
}
template<bool I> template<bool I>
unsigned int specIndiceAt(unsigned int i) const { unsigned int specIndiceAt(unsigned int i) const {
return I ? indices.at(i) : i; return I ? indices.at(i) : i;
} }
template<bool T, bool I, template<bool T, bool I, bool C, class Func> // GZ added bool C
inline Func specForeachTriangle(Func func) const; inline Func specForeachTriangle(Func func) const;
}; };
// Serialization routines // Serialization routines
QDataStream& operator<<(QDataStream& out, const StelVertexArray&); QDataStream& operator<<(QDataStream& out, const StelVertexArray&);
QDataStream& operator>>(QDataStream& in, StelVertexArray&); QDataStream& operator>>(QDataStream& in, StelVertexArray&);
template<class Func> template<class Func>
Func StelVertexArray::foreachTriangle(Func func) const Func StelVertexArray::foreachTriangle(Func func) const
{ {
// Here we just dispa cases // Here we just dispatch the method into one of the 8 possible cases // GZ NEW: 8, not 4, cases
bool textured = isTextured(); bool textured = isTextured();
bool colored = isColored();
bool useIndice = isIndexed(); bool useIndice = isIndexed();
if (textured) if (textured)
{
if (useIndice) if (useIndice)
return specForeachTriangle<true, true, Func>(func); {
else if (colored)
return specForeachTriangle<true, false, Func>(func); return specForeachTriangle<true, true, true,
else Func>(func);
else
return specForeachTriangle<true, true, false
, Func>(func);
}
else // not indiced
{
if (colored)
return specForeachTriangle<true, false, true
, Func>(func);
else
return specForeachTriangle<true, false, fals
e, Func>(func);
}
}
else // not textured
{
if (useIndice) if (useIndice)
return specForeachTriangle<false, true, Func>(func); {
else if (colored)
return specForeachTriangle<false, false, return specForeachTriangle<false, true, true
, Func>(func);
else
return specForeachTriangle<false, true, fals
e, Func>(func);
}
else // not indiced
{
if (colored)
return specForeachTriangle<false, false, tru
e, Func>(func);
else
return specForeachTriangle<false, false, fal
se, Func>(func);
}
}
Q_ASSERT(0); // GZ. Just make sure...
} }
template<bool T, bool I, class Func> template<bool T, bool I, bool C, class Func>
Func StelVertexArray::specForeachTriangle(Func func) const Func StelVertexArray::specForeachTriangle(Func func) const
{ {
switch (primitiveType) switch (primitiveType)
{ {
case StelVertexArray::Triangles: case StelVertexArray::Triangles:
Q_ASSERT(vertex.size() % 3 == 0); Q_ASSERT(vertex.size() % 3 == 0);
for (int i = 0; i < vertex.size(); i += 3) for (int i = 0; i < vertex.size(); i += 3)
{ {
func(specVertexAt<I>(i), specVertexAt<I>(i+1 ), specVertexAt<I>(i+2), func(specVertexAt<I>(i), specVertexAt<I>(i+1 ), specVertexAt<I>(i+2),
specTexCoordAt<T, I>(i), specTexCoo rdAt<T, I>(i+1), specTexCoordAt<T, I>(i+2), specTexCoordAt<T, I>(i), specTexCoo rdAt<T, I>(i+1), specTexCoordAt<T, I>(i+2),
specColorAt<C, I>(i), specColorAt<C , I>(i+1), specColorAt<C, I>(i+2),
specIndiceAt<I>(i), specIndiceAt<I> (i+1), specIndiceAt<I>(i+2)); specIndiceAt<I>(i), specIndiceAt<I> (i+1), specIndiceAt<I>(i+2));
} }
break; break;
case StelVertexArray::TriangleFan: case StelVertexArray::TriangleFan:
{ {
const Vec3d* v0 = specVertexAt<I>(0); const Vec3d* v0 = specVertexAt<I>(0);
const Vec2f* t0 = specTexCoordAt<T, I>(0); const Vec2f* t0 = specTexCoordAt<T, I>(0);
const Vec3f* c0 = specColorAt<C, I>(0);
unsigned int i0 = specIndiceAt<I>(0); unsigned int i0 = specIndiceAt<I>(0);
for (int i = 1; i < vertex.size() - 1; ++i) for (int i = 1; i < vertex.size() - 1; ++i)
{ {
func(v0, specVertexAt<I>(i), specVertexAt<I> (i+1), func(v0, specVertexAt<I>(i), specVertexAt<I> (i+1),
t0, specTexCoordAt<T, I>(i), specTe xCoordAt<T, I>(i+1), t0, specTexCoordAt<T, I>(i), specTe xCoordAt<T, I>(i+1),
i0, specIndiceAt<I>(i), c0, specColorAt<C, I>(i), specCo
lorAt<C, I>(i+1),
i0, specIndiceAt<I>(i), specIn
diceAt<I>(i+1));
} }
break; break;
} }
case StelVertexArray::TriangleStrip: case StelVertexArray::TriangleStrip:
{ {
for (int i = 2; i < vertex.size(); ++i) for (int i = 2; i < vertex.size(); ++i)
{ {
if (i % 2 == 0) if (i % 2 == 0)
func(specVertexAt<I>(i-2), specVerte xAt<I>(i-1), specVertexAt<I>(i), func(specVertexAt<I>(i-2), specVerte xAt<I>(i-1), specVertexAt<I>(i),
specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i),
specColorAt<C, I>(i-2), spe cColorAt<C, I>(i-1), specColorAt<C, I>(i),
specIndiceAt<I>(i-2), specI ndiceAt<I>(i-1), specIndiceAt<I>(i)); specIndiceAt<I>(i-2), specI ndiceAt<I>(i-1), specIndiceAt<I>(i));
else else
func(specVertexAt<I>(i-1), specVerte xAt<I>(i-2), specVertexAt<I>(i), func(specVertexAt<I>(i-1), specVerte xAt<I>(i-2), specVertexAt<I>(i),
specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i),
specColorAt<C, I>(i-1), spe cColorAt<C, I>(i-2), specColorAt<C, I>(i),
specIndiceAt<I>(i-1), specI ndiceAt<I>(i-2), specIndiceAt<I>(i)); specIndiceAt<I>(i-1), specI ndiceAt<I>(i-2), specIndiceAt<I>(i));
} }
break; break;
} }
default: default:
Q_ASSERT_X(0, Q_FUNC_INFO, "unsupe"); Q_ASSERT_X(0, Q_FUNC_INFO, "unsupported primitive ty pe");
} }
return func; return func;
} }
#endif // __STELVERTEXARRAY_HPP__ #endif // __STELVERTEXARRAY_HPP__
End of changes. 19 change blocks.
18 lines changed or deleted 71 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/