~ubuntu-branches/ubuntu/trusty/3depict/trusty

« back to all changes in this revision

Viewing changes to src/drawables.h

  • Committer: Package Import Robot
  • Author(s): D Haley
  • Date: 2011-12-18 19:33:32 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20111218193332-1motgr3vg9xeh41b
Tags: 0.0.9-1
* Update to upstream 0.0.9 
* Close powerpc bug fixed by 0.0.8-1 (Closes: #655682) 
* Close mgl font parsing bug fixed by mathgl upstream (Closes: #623431)
* Fix unclean source package (Closes: #643039)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *      drawables.h - Opengl drawable objects header
3
 
 *      Copyright (C) 2010, D Haley 
 
3
 *      Copyright (C) 2011, D Haley 
4
4
 
5
5
 *      This program is free software: you can redistribute it and/or modify
6
6
 *      it under the terms of the GNU General Public License as published by
19
19
#ifndef DRAWABLES_H
20
20
#define DRAWABLES_H
21
21
 
22
 
//Do we have the HPMC Real-time on-gpu isosurface library?
23
 
//Note, this define is repeated in drawables.cpp
24
 
//to avoid exposing glew.h in this header,
25
 
//which complains bitterly about header orders.
26
 
//#define HPMC_GPU_ISOSURFACE
27
 
 
28
22
#include "textures.h"
29
23
#include "cameras.h"
30
24
#include "voxels.h"
91
85
        AXIS_IN_SPACE
92
86
};
93
87
 
 
88
//!Drawable types
 
89
enum
 
90
{
 
91
        DRAW_TYPE_POINT,
 
92
        DRAW_TYPE_MANYPOINT,
 
93
        DRAW_TYPE_VECTOR,
 
94
        DRAW_TYPE_TRIANGLE,
 
95
        DRAW_TYPE_QUAD,
 
96
        DRAW_TYPE_SPHERE,
 
97
        DRAW_TYPE_CYLINDER,
 
98
        DRAW_TYPE_DISPLAYLIST,
 
99
        DRAW_TYPE_GLTEXT,
 
100
        DRAW_TYPE_RECTPRISM,
 
101
        DRAW_TYPE_COLOURBAR,
 
102
        DRAW_TYPE_TEXTUREDOVERLAY,
 
103
        DRAW_TYPE_FIELD3D,
 
104
        DRAW_TYPE_ISOSURFACE,
 
105
        DRAW_TYPE_AXIS,
 
106
};
 
107
 
94
108
 
95
109
//!Binding enums. Needed to bind drawable selection
96
110
//to internal modification actions inside the drawable
99
113
        DRAW_SPHERE_BIND_ORIGIN,
100
114
        DRAW_SPHERE_BIND_RADIUS,
101
115
        DRAW_VECTOR_BIND_ORIENTATION,
 
116
        DRAW_VECTOR_BIND_ORIGIN_ONLY,
102
117
        DRAW_VECTOR_BIND_ORIGIN,
 
118
        DRAW_VECTOR_BIND_TARGET,
103
119
        DRAW_CYLINDER_BIND_ORIGIN,
104
120
        DRAW_CYLINDER_BIND_DIRECTION,
105
121
        DRAW_CYLINDER_BIND_RADIUS,
106
122
        DRAW_RECT_BIND_TRANSLATE,
107
123
        DRAW_RECT_BIND_CORNER_MOVE,
 
124
        DRAW_TEXT_BIND_ORIGIN,
 
125
        //DRAW_TEXT_BIND_TEXTDIR, //FIXME: Implement me for annotation todo.
 
126
        //DRAW_TEXT_BIND_UPDIR,
108
127
        DRAW_BIND_ENUM_END
109
128
};
110
129
 
121
140
                bool haveChanged;
122
141
                //!Pointer to current scene camera
123
142
                static const Camera *curCamera; 
124
 
                
 
143
        
125
144
        public: 
126
145
                //!Can be selected from openGL viewport interactively?
127
146
                bool canSelect;
135
154
                //!Constructor
136
155
                DrawableObj();
137
156
 
 
157
                virtual unsigned int getType() const =0;        
 
158
                
138
159
                //!Do we need to do element based depth sorting?
139
160
                virtual bool needsDepthSorting() const { return false; } ;
140
161
 
185
206
                DrawPoint(float,float,float);
186
207
                //!Destructor
187
208
                virtual ~DrawPoint();
188
 
        
 
209
 
189
210
                //!Sets the color of the point to be drawn
190
211
                void setColour(float r, float g, float b, float alpha);
191
212
                //!Draws the points
216
237
                DrawManyPoints();
217
238
                //!Destructor
218
239
                virtual ~DrawManyPoints();
 
240
                
 
241
                virtual unsigned int getType() const {return DRAW_TYPE_MANYPOINT;};     
219
242
                //!Swap out the internal vector with an extenal one
220
243
                void swap(std::vector<Point3D> &);
221
244
                //!Remove all points
268
291
                //!Destructor
269
292
                virtual ~DrawVector();
270
293
        
 
294
                virtual unsigned int getType() const {return DRAW_TYPE_VECTOR;};        
271
295
                
272
296
                //!Sets the color of the point to be drawn
273
297
                void setColour(float r, float g, float b, float alpha);
277
301
                void setOrigin(const Point3D &);
278
302
                //!Sets the location of the poitns
279
303
                void setVector(const Point3D &);
280
 
                //!Gets the cylinder axis direction
 
304
                //!Gets the arrow axis direction
281
305
                Point3D getVector(){ return vector;};
282
306
 
 
307
                //!Gets the arrow axis direction
 
308
                Point3D getOrigin(){ return origin;};
 
309
 
 
310
                //!Set the arrowhead size
 
311
                void setArrowSize(float size) { arrowSize=size;}
 
312
 
283
313
                void getBoundingBox(BoundCube &b) const; 
 
314
 
 
315
 
284
316
                //!Recompute the internal parameters using the input vector information
285
317
                void recomputeParams(const std::vector<Point3D> &vecs, 
286
318
                                        const std::vector<float> &scalars, unsigned int mode);
302
334
                //!Destructor
303
335
                virtual ~DrawTriangle();
304
336
 
 
337
                virtual unsigned int getType() const {return DRAW_TYPE_TRIANGLE;};      
 
338
                
305
339
                //!Set one of three vertices (0-2) locations
306
340
                void setVertex(unsigned int, const Point3D &);
307
341
                //!Set the vertex normals
336
370
                DrawQuad();
337
371
                //!Destructor
338
372
                virtual ~DrawQuad();
 
373
                
 
374
                virtual unsigned int getType() const {return DRAW_TYPE_QUAD;};  
339
375
                //!sets the vertices to defautl colours (r g b and white ) for each vertex respectively
340
376
                void colourVerticies();
341
377
                //!Set vertex's location
373
409
                //! Destructor
374
410
                virtual ~DrawSphere();
375
411
 
 
412
                virtual unsigned int getType() const {return DRAW_TYPE_SPHERE;};        
376
413
                //!Sets the location of the sphere's origin
377
414
                void setOrigin(const Point3D &p);
378
415
                //!Gets the location of the sphere's origin
393
430
                void getBoundingBox(BoundCube &b) const ;
394
431
 
395
432
                //!Recompute the internal parameters using the input vector information
396
 
                void recomputeParams(const vector<Point3D> &vecs, const vector<float> &scalars, unsigned int mode);
 
433
                // i.e. this is used for (eg) mouse interaction
 
434
                void recomputeParams(const vector<Point3D> &vecs, 
 
435
                                const vector<float> &scalars, unsigned int mode);
397
436
 
398
437
};
399
438
 
425
464
                //!Destructor
426
465
                virtual ~DrawCylinder();
427
466
 
 
467
                virtual unsigned int getType() const {return DRAW_TYPE_CYLINDER;};      
428
468
                //!Set the location of the base of the cylinder
429
469
                void setOrigin(const Point3D &pt);
430
470
                //!Number of cuts perpendicular to axis - ie disks
481
521
                mutable Point3D lastCamLoc;
482
522
        public:
483
523
                DrawDepthSorted() { haveLastDist=false;};
 
524
                virtual unsigned int getType() const {return -1; ASSERT(false);};       
484
525
                void addObjectsAsNeeded(const DrawableObj *);
485
526
                void draw() const; 
486
527
                void getBoundingBox(BoundCube &b) const { ASSERT(false);};
512
553
                DrawDispList();
513
554
                //!Destructor
514
555
                virtual ~DrawDispList();
 
556
                
 
557
                virtual unsigned int getType() const {return DRAW_TYPE_DISPLAYLIST;}
515
558
 
516
559
                //!Execute the display list
517
560
                void draw() const;              
605
648
                //!Destructor
606
649
                virtual ~DrawGLText();
607
650
 
 
651
                virtual unsigned int getType() const {return DRAW_TYPE_GLTEXT;}
608
652
                //!Set the size of the text (in points (which may be GL units,
609
653
                //unsure))
610
654
                inline void setSize(unsigned int size)
617
661
                        {return isOK;};
618
662
 
619
663
                //!Set the text string to be displayed
620
 
                inline void setString(std::string str)
 
664
                inline void setString(const std::string &str)
621
665
                        {strText=str;};
622
666
 
623
667
                //!Render the text string
662
706
 
663
707
                //!Set the text alignment (default is left)
664
708
                void setAlignment(unsigned int mode);
 
709
                
 
710
                //Binding parameter recomputation
 
711
                void recomputeParams(const vector<Point3D> &vecs, 
 
712
                                const vector<float> &scalars, unsigned int mode);
665
713
};
666
714
 
667
715
 
685
733
                DrawRectPrism();
686
734
                ~DrawRectPrism();
687
735
 
 
736
                virtual unsigned int getType() const {return DRAW_TYPE_RECTPRISM;}
 
737
                
688
738
                //!Draw object
689
739
                void draw() const;
690
740
 
730
780
        
731
781
                DrawColourBarOverlay();
732
782
                ~DrawColourBarOverlay(){delete font;};
 
783
                
 
784
                virtual unsigned int getType() const {return DRAW_TYPE_COLOURBAR;}
 
785
        
733
786
                void getBoundingBox(BoundCube &b) const ;
734
787
 
735
788
                //!This is an overlay
761
814
        public:
762
815
                DrawTexturedQuadOverlay();
763
816
                ~DrawTexturedQuadOverlay();
 
817
                
 
818
                virtual unsigned int getType() const {return DRAW_TYPE_TEXTUREDOVERLAY;}
764
819
 
765
820
                //!This is an overlay
766
821
                bool isOverlay() const {return true;};
832
887
                //!Destructor
833
888
                virtual ~DrawField3D();
834
889
 
 
890
                virtual unsigned int getType() const {return DRAW_TYPE_FIELD3D;}
835
891
 
836
892
                //!Get the bounding box for this object
837
893
                void getBoundingBox(BoundCube &b) const;
895
951
        DrawIsoSurface();
896
952
        ~DrawIsoSurface();
897
953
 
 
954
        virtual unsigned int getType() const {return DRAW_TYPE_ISOSURFACE;}
898
955
        //!Transfer ownership of data pointer to class
899
956
        void swapVoxels(Voxels<float> *v);
900
957
 
916
973
        bool needsDepthSorting() const;
917
974
};
918
975
 
919
 
#ifdef HPMC_GPU_ISOSURFACE
920
 
//!A class to use GPU shaders to draw isosurfaces
921
 
// **********************************************************************
922
 
// Adapted from 
923
 
// http://www.sintef.no/Projectweb/Heterogeneous-Computing/
924
 
// Research-Topics/Marching-Cubes-using-Histogram-Pyramids/
925
 
//
926
 
// Reference:
927
 
//  High-speed Marching Cubes using Histogram Pyramids
928
 
//  Christopher Dyken, Gernot Ziegler, Christian Theobalt and Hans-Peter Seidel
929
 
//
930
 
//
931
 
// Original File: texture3d.cpp
932
 
//
933
 
// Authors: Christopher Dyken <christopher.dyken@sintef.no>
934
 
//
935
 
//Licence:
936
 
// Copyright (C) 2009 by SINTEF.  All rights reserved.
937
 
//   
938
 
// This library is free software; you can redistribute it and/or
939
 
// modify it under the terms of the GNU General Public License
940
 
// ("GPL") version 2 as published by the Free Software Foundation.
941
 
// See the file LICENSE.GPL at the root directory of this source
942
 
// distribution for additional information about the GNU GPL.
943
 
// 
944
 
// SINTEF, Pb 124 Blindern, N-0314 Oslo, Norway
945
 
// http://www.sintef.no
946
 
// ********************************************************************/
947
 
class DrawIsoSurfaceWithShader: public DrawableObj
948
 
{
949
 
private:
950
 
        //can we use shaders?
951
 
        bool shadersOK;
952
 
        //should we draw the thing in wireframe?
953
 
        bool wireframe;
954
 
        //Pointer to data
955
 
        char *dataset;
956
 
 
957
 
 
958
 
        struct HPMCConstants* hpmc_c;
959
 
        struct HPMCHistoPyramid* hpmc_h;
960
 
        struct HPMCTraversalHandle* hpmc_th_shaded;
961
 
 
962
 
        //Shader handles
963
 
        GLuint shaded_v;
964
 
        GLuint shaded_f;
965
 
        GLuint shaded_p;
966
 
        //Texture handles
967
 
        GLuint volume_tex;
968
 
 
969
 
        //On-card volume size
970
 
        int volume_size_x;
971
 
        int volume_size_y;
972
 
        int volume_size_z;
973
 
 
974
 
        struct HPMCTraversalHandle* hpmc_th_flat;
975
 
 
976
 
        //Shader functions, for dynamic compilation
977
 
        std::string shaded_vertex_shader;
978
 
        std::string shaded_fragment_shader;
979
 
        std::string flat_vertex_shader;
980
 
 
981
 
        GLuint flat_v;
982
 
        GLuint flat_p;
983
 
 
984
 
        //Isosurface scalar threshold (true value)
985
 
        float threshold;
986
 
 
987
 
        //true data maximum
988
 
        float trueMax;
989
 
 
990
 
        //Voxel data Bounding box
991
 
        BoundCube bounds;
992
 
        
993
 
        //Compile shader for video card 
994
 
        void compileShader( GLuint shader, const std::string& what );
995
 
        //Link shader
996
 
        void linkProgram( GLuint program, const std::string& what );
997
 
public:
998
 
 
999
 
        DrawIsoSurfaceWithShader();
1000
 
        ~DrawIsoSurfaceWithShader();
1001
 
 
1002
 
        //initialise dataset and shaders
1003
 
        bool init(const Voxels<float> &v);
1004
 
        //Draw
1005
 
        void draw() const;
1006
 
 
1007
 
        //Can the shader run?
1008
 
        bool canRun() const{return shadersOK;};
1009
 
 
1010
 
        void setScalarThresh(float thresh) ;
1011
 
 
1012
 
        void getBoundingBox(BoundCube &b) const;
1013
 
};
1014
 
#endif
1015
976
 
1016
977
class DrawAxis : public DrawableObj
1017
978
{
1024
985
        public:
1025
986
                DrawAxis();
1026
987
                ~DrawAxis();
 
988
        
 
989
                virtual unsigned int getType() const {return DRAW_TYPE_AXIS;}
1027
990
 
1028
991
                //!Draw object
1029
992
                void draw() const;