multiindexedgeometry.h 6.22 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

#ifndef MULTIINDEXEDGEOMETRY_H__
#define MULTIINDEXEDGEOMETRY_H__

28
29
#include "cgt/bounds.h"
#include "cgt/vector.h"
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "core/datastructures/geometrydata.h"
#include "core/datastructures/facegeometry.h"

#include <vector>

namespace campvis {

    /**
     * Class for indexed geometry consisting of multiple primitives.
     * Internally working with glMultiDrawElements(), every MultiIndexedGeometry consists of a 
     * stream of vertices, an index list defining the faces and a pair of arrays defining start
     * indices and number of indices for each primitive to render.
     * 
     * The internal OpenGL buffers are lazy-instantiated.
     */
45
    class CAMPVIS_CORE_API MultiIndexedGeometry : public GeometryData {
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    public:
        /**
         * Creates a new MultiIndexedGeometry using the given geometry. Indices are to be provided later.
         * \param   vertices            The list of the vertex positions of the face.
         * \param   textureCoordinates  The list of vertex texture coordinates, may be empty.
         * \param   colors              The list of vertex colors, may be empty.
         * \param   normals             The list of vertex normals, may be empty.
         */
        explicit MultiIndexedGeometry(
            const std::vector<tgt::vec3>& vertices,
            const std::vector<tgt::vec3>& textureCoordinates = std::vector<tgt::vec3>(),
            const std::vector<tgt::vec4>& colors = std::vector<tgt::vec4>(),
            const std::vector<tgt::vec3>& normals = std::vector<tgt::vec3>()
            );
        
        /**
         * Copy constructor
         * \param   rhs MultiIndexedGeometry to copy
         */
        MultiIndexedGeometry(const MultiIndexedGeometry& rhs);

        /**
         * Destructor, deletes VBOs/VAO if necessary. Hence, needs a valid OpenGL context
         */
        virtual ~MultiIndexedGeometry();
        
        /**
         * Assignment operator.
         * \param   rhs MultiIndexedGeometry to assign to this.
         * \return  *this after assignment
         */
        MultiIndexedGeometry& operator=(const MultiIndexedGeometry& rhs);

        /// \see AbstractData::clone()
        virtual MultiIndexedGeometry* clone() const;

        /// \see AbstractData::getLocalMemoryFootprint()
        virtual size_t getLocalMemoryFootprint() const;

        /// \see AbstractData::getVideoMemoryFootprint()
        virtual size_t getVideoMemoryFootprint() const;

        /**
         * Add a render primitive given by a list of indices.
         * \param   indices     Index list defining the faces.
         */
        void addPrimitive(const std::vector<uint16_t>& indices);
93
94
95
96
97
98
99
100
101
102
103
104
        
        /**
         * The list of picking information colors, may be empty.
         * \return  _pickingInformation
         */
        const std::vector<tgt::col4>& getPickingInformation() const;

        /**
         * Sets the picking information of this geometry to \a pickingInformation
         * \param   pickingInformation  The new list of picking information for this geometry
         */
        void setPickingInformation(const std::vector<tgt::col4>& pickingInformation);
105
106
107
108
109
110
111
112
113
114

        /**
         * Renders this MultiIndexedGeometry.
         * Must be called from a valid OpenGL context.
         * \param   mode    OpenGL rendering mode for this mesh
         */
        virtual void render(GLenum mode) const;

        /// \see GeometryData::getWorldBounds
        virtual tgt::Bounds getWorldBounds() const;
115
116
        /// \see GeometryData::hasTextureCoordinates
        virtual bool hasTextureCoordinates() const;
117
118
        /// \see GeometryData::hasPickingInformation
        virtual bool hasPickingInformation() const;
119
120
        /// \see GeometryData::applyTransformationToVertices
        virtual void applyTransformationToVertices(const tgt::mat4& t);
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

    protected:
        /**
         * Creates the OpenGL VBOs and the VAO for this face's geometry.
         * Must be called from a valid OpenGL context.
         */
        void createGLBuffers() const;

        /// Deletes the OpenGL BufferObject for the indices.
        void deleteIndicesBuffer() const;

        std::vector<uint16_t> _indices;                 ///< Index list defining the faces
        std::vector<void*> _offsets;                    ///< Byte offsets for each primitive to render
        std::vector<GLsizei> _counts;                   ///< Numer of vertices for each primitive to render

        std::vector<tgt::vec3> _vertices;               ///< The list of the vertex positions of the face.
        std::vector<tgt::vec3> _textureCoordinates;     ///< The list of vertex texture coordinates, may be empty.
        std::vector<tgt::vec4> _colors;                 ///< The list of vertex colors, may be empty.
        std::vector<tgt::vec3> _normals;                ///< The list of vertex normals, may be empty.

141
142
        std::vector<tgt::col4> _pickingInformation;     ///< The list of picking information colors, max be empty.

143
144
145
146
147
148
149
150
        mutable tgt::BufferObject* _indicesBuffer;

        static const std::string loggerCat_;
    };

}

#endif // MULTIINDEXEDGEOMETRY_H__