meshgeometry.h 5.09 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, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
schultezub's avatar
schultezub committed
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
schultezub's avatar
schultezub committed
11
12
13
14
15
16
17
18
19
20
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
schultezub's avatar
schultezub committed
21
22
23
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
schultezub's avatar
schultezub committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

#ifndef MESHGEOMETRY_H__
#define MESHGEOMETRY_H__

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

#include <vector>

schultezub's avatar
schultezub committed
40
namespace campvis {
schultezub's avatar
schultezub committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

    /**
     * Class for mesh geometry.
     * Every MeshGeometry consists of a list of FaceGeometry objects.
     * 
     * The internal OpenGL buffers are lazy-instantiated.
     * 
     * \note    Like all Geometry classes MeshGeometry has value-sematics: Once created, the 
     *          faces cannot be altered anymore.
     */
    class MeshGeometry : public GeometryData {
    public:
        /**
         * Creates a new MeshGeometry built from the given faces.
         */
        MeshGeometry(const std::vector<FaceGeometry>& faces);

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

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

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

schultezub's avatar
schultezub committed
69
70
71
72
73
74
75
76
77
78
79
80
        /**
         * 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;

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

schultezub's avatar
schultezub committed
95
96
97
98
        /**
         * Renders this MeshGeometry.
         * Must be called from a valid OpenGL context.
         */
99
        virtual void render() const;
schultezub's avatar
schultezub committed
100
101
102
103
104

        /**
         * Creates the OpenGL VBOs and the VAO for this face's geometry.
         * Must be called from a valid OpenGL context.
         */
105
        virtual void createGLBuffers() const;
schultezub's avatar
schultezub committed
106
107

        /**
108
109
         * Creates a MeshGeometry building a cube with the given bounds and texture coordinates.
         * \note    The caller owns the returned pointer.
schultezub's avatar
schultezub committed
110
111
112
113
         * \param   bounds      coordinates of the cube bounds
         * \param   texBounds   texture coordinates at the cube bounds
         * \return  A MeshGeometry building a cube with the given bounds and texture coordinates
         */
114
        static MeshGeometry createCube(const tgt::Bounds& bounds, const tgt::Bounds& texBounds);
schultezub's avatar
schultezub committed
115
116
117
118
119
120
121
122
123
124
125

    protected:

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

        static const std::string loggerCat_;
    };

}

#endif // MESHGEOMETRY_H__