00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FX_DISABLEGL
00022
00023 #if FX_GRAPHINGMODULE
00024
00025 #ifndef TNFXGRAPH_H
00026 #define TNFXGRAPH_H
00027
00028 #include "FXApp.h"
00029 #include "FXGLObject.h"
00030 #include "FXVec4f.h"
00031 #include "qmemarray.h"
00032
00033 namespace FX {
00034
00063 class FXGLVertices;
00064 class FXVec3d;
00065 template<class type> class QPtrVector;
00066
00067
00081 struct TnFXGraphItem;
00082 class FXGRAPHINGMODULEAPI TnFXGraph : public FXGLGroup
00083 {
00084 FXDECLARE_ABSTRACT(TnFXGraph)
00085 TnFXGraph(const TnFXGraph &);
00086 TnFXGraph &operator=(const TnFXGraph &);
00087 inline FXDLLLOCAL TnFXGraphItem *int_item(FXuint item);
00088 protected:
00089 QPtrVector<TnFXGraphItem> *items;
00090 virtual void int_prepareItems(FXGLViewer *viewer)=0;
00091 TnFXGraph();
00092 public:
00093 ~TnFXGraph();
00094
00096 typedef void (*ExpandFunc)(QMemArray<FXVec3f> &out, const QMemArray<FXVec2f> &in);
00098 typedef void (*ReduceFunc)(QMemArray<FXVec3f> &out, const QMemArray<FXVec3f> &in);
00099
00101 FXGLVertices *setItemDetails(FXuint item, const FXString &title, const FXGLColor &colour, FXfloat pointsize=4.0f, FXfloat linesize=2.0f);
00103 FXGLVertices *setItemData(FXuint item, const FXVec2f *data, FXuint elements, ExpandFunc expand=Expand);
00105 FXGLVertices *setItemData(FXuint item, const QMemArray<FXVec2f> *data, ExpandFunc expand=Expand);
00107 FXGLVertices *setItemData(FXuint item, const FXVec3f *data, FXuint elements, ReduceFunc reduce=ReduceZ);
00109 FXGLVertices *setItemData(FXuint item, const QMemArray<FXVec3f> *data, ReduceFunc reduce=ReduceZ);
00111 FXGLVertices *itemChanged(FXuint item);
00112
00113 virtual void bounds(FXRangef& box);
00114 virtual void draw(FXGLViewer *viewer);
00115 virtual void hit(FXGLViewer *viewer);
00116 public:
00118 template<FXint zval> static void Expand(QMemArray<FXVec3f> &out, const QMemArray<FXVec2f> &in)
00119 {
00120 out.resize(in.count());
00121 for(FXuint n=0; n<in.count(); n++)
00122 {
00123 out[n].x=in[n].x;
00124 out[n].y=in[n].y;
00125 out[n].z=zval;
00126 }
00127 }
00129 static void Expand(QMemArray<FXVec3f> &out, const QMemArray<FXVec2f> &in)
00130 {
00131 out.resize(in.count());
00132 for(FXuint n=0; n<in.count(); n++)
00133 {
00134 out[n].x=in[n].x;
00135 out[n].y=in[n].y;
00136 out[n].z=0.0f;
00137 }
00138 }
00140 template<int offset, int stepe, int stepm> static void ReduceE(QMemArray<FXVec3f> &out, const QMemArray<FXVec3f> &in)
00141 {
00142 out.resize(in.count()*3/(stepe+stepm));
00143 FXfloat *FXRESTRICT o=(FXfloat *) out.data();
00144 const FXfloat *FXRESTRICT i=(const FXfloat *) in.data();
00145 for(FXuint n=offset; n<in.count()*3; n+=stepe)
00146 {
00147 *o++=i[n];
00148 *o++=i[n+stepm];
00149 *o++=0;
00150 }
00151 }
00153 template<int yinc, int offset, int step> static void ReduceE2x(QMemArray<FXVec3f> &out, const QMemArray<FXVec3f> &in)
00154 {
00155 out.resize(in.count()*3/step);
00156 FXfloat y=0;
00157 FXfloat *FXRESTRICT o=(FXfloat *) out.data();
00158 const FXfloat *FXRESTRICT i=(const FXfloat *) in.data();
00159 for(FXuint n=offset; n<in.count()*3; n+=step)
00160 {
00161 *o++=i[n];
00162 *o++=y;
00163 *o++=0;
00164 y+=yinc;
00165 }
00166 }
00168 template<int xinc, int offset, int step> static void ReduceE2y(QMemArray<FXVec3f> &out, const QMemArray<FXVec3f> &in)
00169 {
00170 out.resize(in.count()*3/step);
00171 FXfloat x=0;
00172 FXfloat *FXRESTRICT o=(FXfloat *) out.data();
00173 const FXfloat *FXRESTRICT i=(const FXfloat *) in.data();
00174 for(FXuint n=offset; n<in.count()*3; n+=step)
00175 {
00176 *o++=x;
00177 x+=xinc;
00178 *o++=i[n];
00179 *o++=0;
00180 }
00181 }
00183 static void ReduceZ(QMemArray<FXVec3f> &out, const QMemArray<FXVec3f> &in)
00184 {
00185 out.resize(in.count());
00186 for(FXuint n=0; n<in.count(); n++)
00187 {
00188 out[n].x=in[n].x/in[n].z;
00189 out[n].y=in[n].y/in[n].z;
00190 out[n].z=0;
00191 }
00192 }
00193 };
00194
00195
00203 struct TnFX2DGraphPrivate;
00204 class FXGRAPHINGMODULEAPI TnFX2DGraph : public TnFXGraph
00205 {
00206 FXDECLARE(TnFX2DGraph)
00207 TnFX2DGraphPrivate *p;
00208 TnFX2DGraph(const TnFX2DGraph &);
00209 TnFX2DGraph &operator=(const TnFX2DGraph &);
00210 void init();
00211 virtual void int_prepareItems(FXGLViewer *viewer);
00212 void int_drawLabels(FXGLViewer *viewer);
00213 public:
00215 TnFX2DGraph();
00216 TnFX2DGraph(const QMemArray<FXVec2f> *data, ExpandFunc expand=Expand);
00217 TnFX2DGraph(const QMemArray<FXVec3f> *data, ReduceFunc reduce=ReduceZ);
00218 ~TnFX2DGraph();
00219
00221 FXGLVertices *setAxes(const FXVec4f &range=FXVec4f(Generic::BiggestValue<float>::value, Generic::BiggestValue<float>::value, Generic::BiggestValue<float>::value, Generic::BiggestValue<float>::value), FXfloat lineSize=4.0f);
00223 FXGLVertices *setAxesMajor(FXfloat granx=0, FXfloat grany=0, FXfloat lineSize=2.0f, const FXFont *font=FXApp::instance()->getNormalFont());
00224
00225 virtual void bounds(FXRangef& box);
00226 virtual void draw(FXGLViewer *viewer);
00227 virtual void hit(FXGLViewer *viewer);
00228 };
00229
00230
00246 struct TnFX3DGraphPrivate;
00247 class FXGRAPHINGMODULEAPI TnFX3DGraph : public TnFXGraph
00248 {
00249 FXDECLARE(TnFX3DGraph)
00250 TnFX3DGraphPrivate *p;
00251 TnFX3DGraph(const TnFX3DGraph &);
00252 TnFX3DGraph &operator=(const TnFX3DGraph &);
00253 void init();
00254 virtual void int_prepareItems(FXGLViewer *viewer);
00255 public:
00257 TnFX3DGraph();
00258 TnFX3DGraph(const QMemArray<FXVec2f> *data, ExpandFunc expand=Expand);
00259 TnFX3DGraph(const QMemArray<FXVec3f> *data, ReduceFunc reduce=ReduceZ);
00260 ~TnFX3DGraph();
00261 };
00262
00263 }
00264
00265 #endif
00266 #endif
00267 #endif