facegeometry.h 6.85 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
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
27
// 
// ================================================================================================

#ifndef FACEGEOMETRY_H__
#define FACEGEOMETRY_H__

28
#include "tgt/bounds.h"
29
#include "tgt/vector.h"
30
#include "core/datastructures/geometrydata.h"
31
32
33

#include <vector>

schultezub's avatar
schultezub committed
34
namespace campvis {
35
36
37
38
39
40
41
42
43
44
45
46

    /**
     * Class for face geometry.
     * Every FaceGeometry has a list of vertices which also defines the number of elements (size). 
     * Colors, normals and texture coordinates are optional. Their lists are either empty or as
     * large as the vertex list. Furthermore, each FaceGeometry has a face normal.
     * 
     * The internal OpenGL buffers are lazy-instantiated.
     * 
     * \note    This class expects all vertices lying within one plane. Everything other that that
     *          leads to undefined behavior.
     */
47
    class CAMPVIS_CORE_API FaceGeometry : public GeometryData {
48
49
    public:
        /**
50
51
52
53
54
55
         * Creates a new empty FaceGeometry.
         */
        explicit FaceGeometry();

        /**
         * Creates a new FaceGeometry initialized from the given data.
56
57
58
59
60
         * \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.
         */
61
        explicit FaceGeometry(
62
63
64
65
66
67
68
            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>()
            );

        /**
69
         * Destructor, deletes VBOs/VAO if necessary.
70
71
72
73
74
75
         */
        virtual ~FaceGeometry();

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

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

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
        /**
         * Returns the number of vertices of this face.
         * \return _vertices.size()
         */
        size_t size() const;

        /**
         * The list of the vertex positions of the face.
         * \return _vertices
         */
        const std::vector<tgt::vec3>& getVertices() const;

        /**
         * The list of vertex colors, may be empty.
         * \return _colors
         */
        const std::vector<tgt::vec4>& getColors() const;

        /**
         * The list of vertex normals, may be empty.
         * \return _normals
         */
        const std::vector<tgt::vec3>& getNormals() const;

        /**
         * The list of vertex texture coordinates, may be empty.
         * \return _textureCoordinates
         */
        const std::vector<tgt::vec3>& getTextureCoordinates() const;
108
109
110
111
112
113
114
115
116
117
118
119
        
        /**
         * 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);
120
121
122
123
124
125
126

        /**
         * The normal vector of this face.
         * \return _faceNormal
         */
        const tgt::vec3& getFaceNormal() const;

127
128
129
        /**
         * Clips this FaceGeometry against an aribtrary clip plane.
         * The clipped FaceGeometry is returned.
130
         * \note    Because of using only float internally, the precision is somewhat poor.
131
132
133
134
135
136
137
         * \param   p       Point on clip plane
         * \param   normal  Clip plane normal
         * \param   epsilon Clipping precision
         * \return  The clipped FaceGeometry
         */
        FaceGeometry clipAgainstPlane(float p, const tgt::vec3& normal, float epsilon = 1e-4f) const;

138
139
140
        /**
         * Renders this FaceGeometry.
         * Must be called from a valid OpenGL context.
141
         * \param   mode    OpenGL rendering mode for this face
142
         */
143
        virtual void render(GLenum mode) const;
144
145
146
                
        /// \see GeometryData::getWorldBounds
        virtual tgt::Bounds getWorldBounds() const;
147
148
        /// \see GeometryData::hasTextureCoordinates
        virtual bool hasTextureCoordinates() const;
149
150
        /// \see GeometryData::hasPickingInformation
        virtual bool hasPickingInformation() const;
151
152
        /// \see GeometryData::applyTransformationToVertices
        virtual void applyTransformationToVertices(const tgt::mat4& t);
153

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

161
162
163
164
165
        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.

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

168
169
170
171
172
        tgt::vec3 _faceNormal;                          ///< The normal vector of this face.

        static const std::string loggerCat_;
    };

173

174
175
176
}

#endif // FACEGEOMETRY_H__