indexedmeshgeometry.h 5.84 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
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
13
14
15
16
// 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
17
// 
18
19
20
21
// 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.
22
23
24
// 
// ================================================================================================

25
26
#ifndef INDEXEDMESHGEOMETRY_H__
#define INDEXEDMESHGEOMETRY_H__
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#include "tgt/bounds.h"
#include "tgt/vector.h"
#include "core/datastructures/geometrydata.h"
#include "core/datastructures/facegeometry.h"

#include <vector>

namespace campvis {

    /**
     * Class for mesh geometry.
     * Every IndexedMeshGeometry consists of a stream of vertices and an index list defining the faces.
     * 
     * The internal OpenGL buffers are lazy-instantiated.
     * 
     * \note    Like all Geometry classes IndexedMeshGeometry has value-sematics: Once created, the 
     *          faces cannot be altered anymore.
     */
46
    class CAMPVIS_CORE_API IndexedMeshGeometry : public GeometryData {
47
48
49
50
51
52
53
54
55
    public:
        /**
         * Creates a new IndexedMeshGeometry built from the given faces.
         * \param   indices             Index list defining the faces.
         * \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.
         */
56
        explicit IndexedMeshGeometry(
57
58
59
60
61
62
            const std::vector<uint16_t>& indices,
            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>()
            );
63
64
65
66
67
68
        
        /**
         * Copy constructor
         * \param   rhs IndexedMeshGeometry to copy
         */
        IndexedMeshGeometry(const IndexedMeshGeometry& rhs);
69
70
71
72
73

        /**
         * Destructor, deletes VBOs/VAO if necessary. Hence, needs a valid OpenGL context
         */
        virtual ~IndexedMeshGeometry();
74
75
76
77
78
79
80
        
        /**
         * Assignment operator.
         * \param   rhs IndexedMeshGeometry to assign to this.
         * \return  *this after assignment
         */
        IndexedMeshGeometry& operator=(const IndexedMeshGeometry& rhs);
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95

        /**
         * 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);


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
        /// \see AbstractData::clone()
        virtual IndexedMeshGeometry* clone() const;

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

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

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

112
113
        /// \see GeometryData::getWorldBounds
        virtual tgt::Bounds getWorldBounds() const;
114
115
        /// \see GeometryData::hasTextureCoordinates
        virtual bool hasTextureCoordinates() const;
116
117
        /// \see GeometryData::hasPickingInformation
        virtual bool hasPickingInformation() const;
118
119
        /// \see GeometryData::applyTransformationToVertices
        virtual void applyTransformationToVertices(const tgt::mat4& t);
120
121

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

128
129
        /// Deletes the OpenGL BufferObject for the indices.
        void deleteIndicesBuffer() const;
130
131
132
133
134
135
136

        std::vector<uint16_t> _indices;                 ///< Index list defining the faces
        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.

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

139
140
141
142
143
144
145
        mutable tgt::BufferObject* _indicesBuffer;

        static const std::string loggerCat_;
    };

}

146
#endif // INDEXEDMESHGEOMETRY_H__