OpenCOVER
coSphere.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef CO_SPHERE_H
9#define CO_SPHERE_H
10
25#include <util/common.h>
26#include <osg/Drawable>
27#include <osg/Geometry>
28#include <OpenThreads/Mutex>
29#include <vector>
30#include <osg/Version>
31
32typedef struct _CGprogram *CGprogram;
33typedef struct _CGparameter *CGparameter;
34
35namespace opencover
36{
37class PLUGIN_UTILEXPORT coSphere : public osg::Drawable
38{
39 friend class SphereIntersector;
40public:
41 // keep in sync with Sphere module
43 {
44 RENDER_METHOD_CPU_BILLBOARDS = 0,
45 RENDER_METHOD_CG_SHADER = 1,
46 RENDER_METHOD_ARB_POINT_SPRITES = 2,
47 RENDER_METHOD_PARTICLE_CLOUD = 4,
48 RENDER_METHOD_DISC = 5,
49 RENDER_METHOD_TEXTURE = 6,
50 RENDER_METHOD_CG_SHADER_INVERTED = 7
51 };
52
54
56 void setNumberOfSpheres(int n);
57 void updateCoords(const float *x_c, const float *y_c, const float *z_c);
58 void updateCoords(const double *x_c, const double *y_c, const double *z_c);
59 void updateCoordsFromMatrices(float *const *matrices);
60 void updateCoords(int i, const osg::Vec3 &pos);
61 void setCoords(int no_of_points, const float *x, const float *y, const float *z, const float *r);
62 void setCoords(int no_of_points, const double *x, const double *y, const double *z, const double *r);
63 void setCoords(int no_of_points, const float *x, const float *y, const float *z, float r=1.f);
64 void setCoords(int no_of_points, const osg::Vec3Array* coords, const float *r);
65 void updateRadii(const float *r);
66 void updateRadii(const double *r);
67 void updateRadii(double r);
68 void updateNormals(const float *nx, const float *ny, const float *nz);
69 void setColorBinding(int colorbinding);
70 void setColor(int index, float r, float g, float b, float a);
71 void updateColors(const float *r, const float *g, const float *b, const float *a = NULL);
72 void updateColors(const int *pc);
73 static void setScale(float scale);
74 static void setTransparency(float alpha);
75 static void enableTransparencyOverride(bool);
76 void overrideBoundingBox(const osg::BoundingBox &bb);
77
78 virtual void drawImplementation(osg::RenderInfo &renderInfo) const;
79 void setMaxRadius(float m)
80 {
81 m_extMaxRadius = m;
82 };
83 void setVertexAttribArray(unsigned int index, const osg::Array *array, osg::Array::Binding binding = osg::Array::BIND_UNDEFINED);
84
85protected:
86#if OSG_VERSION_GREATER_OR_EQUAL(3, 3, 2)
87 virtual osg::BoundingBox computeBoundingBox() const;
88#else
89 virtual osg::BoundingBox computeBound() const;
90#endif
91 //virtual osg::BoundingBox getBoundingBox() const;
92
93private:
94 virtual ~coSphere();
95
96 virtual osg::Object *cloneType() const
97 {
98 return new coSphere();
99 }
100 virtual osg::Object *clone(const osg::CopyOp &copyop) const
101 {
102 return new coSphere(*this, copyop);
103 }
104
105 coSphere(const coSphere &, const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY);
106
107 struct BMPImage
108 {
109 int width;
110 int height;
111 unsigned char *data;
112 };
113 static void setTexture(const char *chTexFile);
114
115 static void getBitmapImageData(const char *pFileName, BMPImage *pImage);
116 static bool loadTexture(int context, const char *pFilename, int iTextureMode = 0, int colorR = 0, int colorG = 0, int colorB = 0);
117
118 float m_defaultColor[4];
119 int m_colorBinding;
120 static bool s_overrideTransparency;
121 float *m_coord;
122 float *m_color;
123 float *m_normals;
124 static float s_alpha;
125 static float s_scale;
126 int m_numSpheres;
127 bool m_useVertexArrays;
128 std::vector<int> *m_sortedRadiusIndices;
129 int m_maxPointSize;
130
131 float m_maxRadius;
132 float m_extMaxRadius;
133 float *m_radii;
134 mutable RenderMethod m_renderMethod;
135 bool m_overrideBounds;
136
137 static bool loadCgPrograms(int context);
138 bool unbindProgramAndParams(int context) const;
139 void bindMatrices(int context) const;
140 bool bindProgramAndParams(int context) const;
141 static void initTexture(int context);
142
143 static bool *s_CgChecked;
144 static bool s_pointSpritesChecked;
145 static bool s_configured; // prevent using coConfig before main
146 static bool s_useVertexArrays;
147
148 static CGprogram *s_VertexProgram;
149 static CGprogram *s_FragmentProgram;
150 static CGprogram *s_FragmentProgramParticleCloud;
151 static CGprogram *s_VertexProgramDisc;
152 static CGprogram *s_FragmentProgramDisc;
153 static CGprogram *s_FragmentProgramTexture;
154 static CGprogram *s_FragmentProgramInverted;
155
156 static CGparameter *s_CGVertexParam_modelViewProj;
157 static CGparameter *s_CGVertexParam_modelView;
158 static CGparameter *s_CGVertexParam_modelViewIT;
159 static CGparameter *s_CGVertexParam_lightPos;
160 static CGparameter *s_CGVertexParam_viewerPos;
161 static CGparameter *s_CGFragParam_glAmbient;
162 static CGparameter *s_CGFragParam_glDiffuse;
163 static CGparameter *s_CGFragParam_glSpecular;
164
165 static CGparameter *s_CGFragParamInverted_glAmbient;
166 static CGparameter *s_CGFragParamInverted_glDiffuse;
167 static CGparameter *s_CGFragParamInverted_glSpecular;
168
169 static CGparameter *s_CGVertexParamDisc_modelViewProj;
170 static CGparameter *s_CGVertexParamDisc_modelView;
171 static CGparameter *s_CGVertexParamDisc_modelViewIT;
172 static CGparameter *s_CGVertexParamDisc_lightPos;
173 static CGparameter *s_CGVertexParamDisc_viewerPos;
174 static CGparameter *s_CGFragParamDisc_glAmbient;
175 static CGparameter *s_CGFragParamDisc_glDiffuse;
176 static CGparameter *s_CGFragParamDisc_glSpecular;
177 static CGparameter *s_CGFragParamTexture_glAmbient;
178 static CGparameter *s_CGFragParamTexture_glDiffuse;
179 static CGparameter *s_CGFragParamTexture_glSpecular;
180 static GLuint *s_textureID;
181 static char *s_chTexFile;
182 static void(APIENTRY *s_glPointParameterfARB)(GLenum, GLfloat);
183 static void(APIENTRY *s_glPointParameterfvARB)(GLenum, const GLfloat *);
184
185 static OpenThreads::Mutex *mutex()
186 {
187 static OpenThreads::Mutex mutex;
188 return &mutex;
189 }
190
191 static int s_maxcontext;
192
193 void allocateColor();
194};
195}
196#endif
struct _CGprogram * CGprogram
Definition: coSphere.h:32
struct _CGparameter * CGparameter
Definition: coSphere.h:33
Definition: ARToolKit.h:33
Definition: coSphere.h:38
RenderMethod
Definition: coSphere.h:43
void updateCoordsFromMatrices(float *const *matrices)
static void setScale(float scale)
void updateRadii(double r)
static void setTransparency(float alpha)
void updateCoords(const float *x_c, const float *y_c, const float *z_c)
void setCoords(int no_of_points, const float *x, const float *y, const float *z, const float *r)
void setMaxRadius(float m)
Definition: coSphere.h:79
void updateCoords(const double *x_c, const double *y_c, const double *z_c)
void updateColors(const int *pc)
void updateNormals(const float *nx, const float *ny, const float *nz)
void setCoords(int no_of_points, const osg::Vec3Array *coords, const float *r)
void updateRadii(const float *r)
void overrideBoundingBox(const osg::BoundingBox &bb)
virtual osg::BoundingBox computeBound() const
void updateColors(const float *r, const float *g, const float *b, const float *a=NULL)
void setColor(int index, float r, float g, float b, float a)
static void enableTransparencyOverride(bool)
void setCoords(int no_of_points, const float *x, const float *y, const float *z, float r=1.f)
void setColorBinding(int colorbinding)
void updateRadii(const double *r)
void setVertexAttribArray(unsigned int index, const osg::Array *array, osg::Array::Binding binding=osg::Array::BIND_UNDEFINED)
void setRenderMethod(RenderMethod rm)
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
void updateCoords(int i, const osg::Vec3 &pos)
void setNumberOfSpheres(int n)
void setCoords(int no_of_points, const double *x, const double *y, const double *z, const double *r)