~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/drawables.h

  • Committer: Bazaar Package Importer
  • Author(s): D Haley
  • Date: 2010-09-22 20:09:24 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100922200924-bkyorwswrntnst4d
Tags: 0.0.2-1
* New upstream version
* Enable parallel build

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
//Note, this define is repeated in drawables.cpp
24
24
//to avoid exposing glew.h in this header,
25
25
//which complains bitterly about header orders.
26
 
//#define HPMC_GPU_ISOSURFACE 0
 
26
//#define HPMC_GPU_ISOSURFACE
27
27
 
28
28
#include "APTClasses.h"
29
29
#include "cameras.h"
30
30
#include "textures.h"
31
 
 
 
31
#include "voxels.h"
 
32
#include "IsoSurface.h"
32
33
 
33
34
//STL includes
34
35
#include <vector>
75
76
};
76
77
 
77
78
 
78
 
//TODO: Make sure all solids support this (how to tell glu??)
79
79
//!Primitve drawing mode. (wireframe/solid)
80
80
enum
81
81
{
82
82
        DRAW_WIREFRAME,
 
83
        DRAW_FLAT,
 
84
        DRAW_SMOOTH,
83
85
};
84
86
 
85
87
#include "basics.h"
102
104
                DrawableObj();
103
105
                
104
106
                //!Clone object
105
 
                virtual DrawableObj* clone() const = 0;
 
107
//              virtual DrawableObj* clone() const = 0;
106
108
 
107
109
                //!Set the active state of the object
108
110
                void setActive(bool active);
239
241
        protected:
240
242
                //!The vertices of the triangle
241
243
                Point3D vertices[3];
 
244
                Point3D vertNorm[3];
242
245
                //!Colour data - red, green, blue, alpha
243
246
                float r,g,b,a;
244
247
        public:
251
254
 
252
255
                //!Set one of three vertices (0-2) locations
253
256
                void setVertex(unsigned int, const Point3D &);
 
257
                //!Set the vertex normals
 
258
                void setVertexNorm(unsigned int, const Point3D &);
254
259
                //!Set the colour of the triangle
255
260
                void setColour(float r, float g, float b, float a);
256
261
                //!Draw the triangle
675
680
};
676
681
 
677
682
 
 
683
struct RGBThis
 
684
{
 
685
        unsigned char v[3];
 
686
};
 
687
//!This class allows for the visualisation of 3D scalar fields
 
688
class DrawField3D : public DrawableObj
 
689
{
 
690
        private:
 
691
                mutable std::vector<std::pair<Point3D,RGBThis> > ptsCache;
 
692
                mutable bool ptsCacheOK;
 
693
        protected:
 
694
                //CurCam
 
695
                static const Camera *curCam;
 
696
                //!Alpha transparancy of objects in field
 
697
                float alphaVal;
 
698
 
 
699
                //!Size of points in the field -
 
700
                //only meaningful if the render mode is set to alpha blended points
 
701
                float pointSize;
 
702
 
 
703
                //!True if the scalar field's bounding box is to be drawn
 
704
                bool drawBoundBox;
 
705
 
 
706
                //!Colours for the bounding boxes
 
707
                Colour boxColour;
 
708
                
 
709
                //!True if volume grid is enabled
 
710
                bool volumeGrid;
 
711
 
 
712
                //!Colour map lower and upper bounds
 
713
                float colourMapBound[2];
 
714
 
 
715
                //!Which colourmap to use
 
716
                unsigned int colourMapID;
 
717
 
 
718
                //!Sets the render mode for the 3D volume 
 
719
                /* Possible modes
 
720
                 * 0: Alpha blended points
 
721
                 */
 
722
                unsigned int volumeRenderMode;
 
723
                //!The scalar field - used to store data values
 
724
                const Voxels<float> *field;
 
725
        public:
 
726
                //!Default Constructor
 
727
                DrawField3D();
 
728
                //!Destructor
 
729
                virtual ~DrawField3D();
 
730
 
 
731
                //!Clone
 
732
                DrawableObj *clone() const;
 
733
 
 
734
                //!Get the bounding box for this object
 
735
                void getBoundingBox(BoundCube &b) const;
 
736
                
 
737
                //!Set the render mode (see volumeRenderMode variable for details)
 
738
                void setRenderMode(unsigned int);
 
739
                
 
740
                //!Set the field pointer 
 
741
                void setField(const Voxels<float> *field); 
 
742
 
 
743
                //!Set the alpha value for elemnts
 
744
                void setAlpha(float alpha);
 
745
 
 
746
                //!Set the colour bar minima and maxima from current field values
 
747
                void setColourMinMax();
 
748
 
 
749
                //!Set the colourMap ID
 
750
                void setColourMapID(unsigned int i){ colourMapID=i;};
 
751
 
 
752
                //!Render the field
 
753
                void draw() const;
 
754
 
 
755
                //!Set the size of points
 
756
                void setPointSize(float size);
 
757
                
 
758
                //!Set the colours that ar ebeing used in the tempMap
 
759
                void setMapColours(unsigned int map);
 
760
 
 
761
                //!Set the coour of the bounding box
 
762
                void setBoxColours(float r, float g, float b, float a);
 
763
                //!Set the current camera
 
764
                static void setCurCamera(const Camera *c){curCam=c;};
 
765
 
 
766
};
 
767
 
 
768
class DrawIsoSurface: public DrawableObj
 
769
{
 
770
private:
 
771
        mutable bool cacheOK;
 
772
 
 
773
        //!should we draw the thing 
 
774
        //      - in wireframe
 
775
        //      -Flat
 
776
        //      -Smooth
 
777
        //
 
778
        unsigned int drawMode;
 
779
 
 
780
        //!Isosurface scalar threshold
 
781
        float threshold;
 
782
 
 
783
        Voxels<float> *voxels;  
 
784
 
 
785
        mutable vector<TriangleWithVertexNorm> mesh;
 
786
 
 
787
        //!Warning. Although I declare this as const, I do some naughty mutating to the cache.
 
788
        void updateMesh() const;        
 
789
        
 
790
        //!Point colour (r,g,b,a) range: [0.0f,1.0f]
 
791
        float r,g,b,a;
 
792
public:
 
793
 
 
794
        DrawIsoSurface();
 
795
        ~DrawIsoSurface();
 
796
 
 
797
        //!Clone object
 
798
        DrawableObj* clone() const;
 
799
 
 
800
        //!Transfer ownership of data pointer to class
 
801
        void swapVoxels(Voxels<float> *v);
 
802
 
 
803
        //!Set the drawing method
 
804
 
 
805
        //Draw
 
806
        void draw() const;
 
807
 
 
808
        //!Set the isosurface value
 
809
        void setScalarThresh(float thresh) { threshold=thresh;cacheOK=false;mesh.clear();};
 
810
 
 
811
        //!Get the bouding box (of the entire scalar field)     
 
812
        void getBoundingBox(BoundCube &b) const ;
 
813
                
 
814
        //!Sets the color of the point to be drawn
 
815
        void setColour(float rP, float gP, float bP, float alpha) { r=rP;g=gP;b=bP;a=alpha;} ;
 
816
};
678
817
 
679
818
#ifdef HPMC_GPU_ISOSURFACE
680
819
//!A class to use GPU shaders to draw isosurfaces
711
850
        bool shadersOK;
712
851
        //should we draw the thing in wireframe?
713
852
        bool wireframe;
 
853
        //Pointer to data
 
854
        char *dataset;
714
855
 
715
856
 
716
857
        struct HPMCConstants* hpmc_c;
739
880
        GLuint flat_v;
740
881
        GLuint flat_p;
741
882
 
742
 
        //Isosurface scalar threshold
 
883
        //Isosurface scalar threshold (true value)
743
884
        float threshold;
 
885
 
 
886
        //true data maximum
 
887
        float trueMax;
 
888
 
 
889
        //Voxel data Bounding box
 
890
        BoundCube bounds;
744
891
        
745
892
        //Compile shader for video card 
746
893
        void compileShader( GLuint shader, const std::string& what );
752
899
        ~DrawIsoSurfaceWithShader();
753
900
 
754
901
        //initialise dataset and shaders
755
 
        bool init(unsigned int dataX,
756
 
                unsigned int dataY, unsigned int dataZ, const char *dataset);
 
902
        bool init(const Voxels<float> &v);
757
903
        //Draw
758
904
        void draw() const;
759
905
 
760
 
        void setScalarThresh(float thresh) { threshold=thresh;};
 
906
        //Can the shader run?
 
907
        bool canRun() const{return shadersOK;};
 
908
 
 
909
        void setScalarThresh(float thresh) ;
 
910
 
 
911
        void getBoundingBox(BoundCube &b) const;
761
912
};
762
913
#endif
763
914