meshgeometry.h 4.37 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
schultezub's avatar
schultezub committed
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>
schultezub's avatar
schultezub committed
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".
schultezub's avatar
schultezub committed
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
schultezub's avatar
schultezub committed
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.
schultezub's avatar
schultezub committed
22
23
24
25
26
27
// 
// ================================================================================================

#ifndef MESHGEOMETRY_H__
#define MESHGEOMETRY_H__

28
29
#include "cgt/bounds.h"
#include "cgt/vector.h"
schultezub's avatar
schultezub committed
30
31
32
33
34
#include "core/datastructures/geometrydata.h"
#include "core/datastructures/facegeometry.h"

#include <vector>

schultezub's avatar
schultezub committed
35
namespace campvis {
schultezub's avatar
schultezub committed
36
37
38
39
40
41
42

    /**
     * Class for mesh geometry.
     * Every MeshGeometry consists of a list of FaceGeometry objects.
     * 
     * The internal OpenGL buffers are lazy-instantiated.
     */
43
    class CAMPVIS_CORE_API MeshGeometry : public GeometryData {
schultezub's avatar
schultezub committed
44
45
46
47
    public:
        /**
         * Creates a new MeshGeometry built from the given faces.
         */
48
        explicit MeshGeometry(const std::vector<FaceGeometry>& faces);
schultezub's avatar
schultezub committed
49
50
51
52
53
54
55
56
57

        /**
         * Destructor, deletes VBOs/VAO if necessary. Hence, needs a valid OpenGL context
         */
        virtual ~MeshGeometry();

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

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

schultezub's avatar
schultezub committed
61
62
63
64
65
66
67
68
69
70
71
72
        /**
         * Returns the number of faces of this mesh.
         * \return _faces.size()
         */
        size_t size() const;

        /**
         * Gets the list of all faces of this mesh.
         * \return  _faces
         */
        const std::vector<FaceGeometry>& getFaces() const;

73
74
75
        /**
         * Clips this MeshGeometry against an aribtrary clip plane.
         * The clipped MeshGeometry is returned.
76
77
         * \note    When clipping against one of the faces of this mesh, the mesh closing 
         *          algorithm might fail and return an invalid mesh!
78
79
         * \param   p       Point on clip plane
         * \param   normal  Clip plane normal
80
81
         * \param   close   Flag, whether the returned mesh shall be closed. 
         *                  If true, the closing face will be the last one in the returned MeshGeometry.
82
83
84
         * \param   epsilon Clipping precision
         * \return  The clipped MeshGeometry
         */
85
        MeshGeometry clipAgainstPlane(float p, const tgt::vec3& normal, bool close = true, float epsilon = 1e-4f) const;
86

schultezub's avatar
schultezub committed
87
88
89
        /**
         * Renders this MeshGeometry.
         * Must be called from a valid OpenGL context.
90
         * \param   mode    OpenGL rendering mode for this mesh
schultezub's avatar
schultezub committed
91
         */
92
        virtual void render(GLenum mode) const;
schultezub's avatar
schultezub committed
93

94
95
        /// \see GeometryData::getWorldBounds
        virtual tgt::Bounds getWorldBounds() const;
96
97
        /// \see GeometryData::hasTextureCoordinates
        virtual bool hasTextureCoordinates() const;
98
99
        /// \see GeometryData::hasPickingInformation
        virtual bool hasPickingInformation() const;
100
101
        /// \see GeometryData::applyTransformationToVertices
        virtual void applyTransformationToVertices(const tgt::mat4& t);
102

schultezub's avatar
schultezub committed
103
    protected:
104
105
106
107
108
        /**
         * Creates the OpenGL VBOs and the VAO for this face's geometry.
         * Must be called from a valid OpenGL context.
         */
        void createGLBuffers() const;
schultezub's avatar
schultezub committed
109
110
111
112
113
114
115
116
117

        std::vector<FaceGeometry> _faces;           ///< List of all faces of this mesh

        static const std::string loggerCat_;
    };

}

#endif // MESHGEOMETRY_H__