2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

tfgeometry1d.cpp 4.64 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, 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 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".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 
// 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 
// 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 
// 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.
// 
// ================================================================================================

schultezub's avatar
schultezub committed
30
#include "tfgeometry1d.h"
31
32
33
34
35

#include "tgt/assert.h"
#include "tgt/texture.h"
#include "tgt/tgt_math.h"

36
37
#include "core/datastructures/facegeometry.h"

38
39
#include <algorithm>

schultezub's avatar
schultezub committed
40
namespace campvis {
41

schultezub's avatar
schultezub committed
42
    bool operator< (const TFGeometry1D::KeyPoint& left, const TFGeometry1D::KeyPoint& right) {
43
44
45
        return left._position < right._position;
    }
    
schultezub's avatar
schultezub committed
46
    TFGeometry1D::TFGeometry1D(const std::vector<KeyPoint>& keyPoints)
47
48
49
50
51
        : _keyPoints(keyPoints)
    {
        std::sort(_keyPoints.begin(), _keyPoints.end());
    }

schultezub's avatar
schultezub committed
52
    TFGeometry1D::~TFGeometry1D() {
53
54
55

    }

56
57
58
59
    TFGeometry1D* TFGeometry1D::clone() const {
        return new TFGeometry1D(_keyPoints);
    }

schultezub's avatar
schultezub committed
60
    std::vector<TFGeometry1D::KeyPoint>& TFGeometry1D::getKeyPoints() {
61
62
63
        return _keyPoints;
    }

64
65
    void TFGeometry1D::renderIntoEditor() const {
        // TODO: get rid of intermediade mode?
66
67
68
        if (_keyPoints.size() < 2)
            return;

69
70
71
72
        glBegin(GL_QUADS);
        std::vector<KeyPoint>::const_iterator a = _keyPoints.begin();
        std::vector<KeyPoint>::const_iterator b = _keyPoints.begin()+1;
        for (/* already inited */; b != _keyPoints.end(); ++a, ++b) {
73
            glColor4ub(a->_color.r, a->_color.g, a->_color.b, 144);
74
75
76
            float y = static_cast<float>(a->_color.a) / 255.f;
            glVertex2f(a->_position, 0.f);
            glVertex2f(a->_position, y);
77

78
            glColor4ub(b->_color.r, b->_color.g, b->_color.b, 144);
79
80
81
            y = static_cast<float>(b->_color.a) / 255.f;
            glVertex2f(b->_position, y);
            glVertex2f(b->_position, 0.f);
82
        }
83
        glEnd();
84
85
    }

schultezub's avatar
schultezub committed
86
    void TFGeometry1D::render() const {
87
        // TODO: get rid of intermediade mode?
88
89
        if (_keyPoints.size() < 2)
            return;
90

91
92
93
        // TODO: regenerating these buffers each time is slow as hell
        std::vector<tgt::vec3> vertices;
        std::vector<tgt::vec4> colors;
94

95
96
97
98
99
100
        for (std::vector<KeyPoint>::const_iterator a = _keyPoints.begin(); a != _keyPoints.end(); ++a) {
            vertices.push_back(tgt::vec3(a->_position, 0.f, 0.f));
            vertices.push_back(tgt::vec3(a->_position, 1.f, 0.f));

            colors.push_back(tgt::vec4(a->_color) / 255.f);
            colors.push_back(tgt::vec4(a->_color) / 255.f);
101
        }
102
103
104

        FaceGeometry fg(vertices, vertices, colors);
        fg.render(GL_TRIANGLE_STRIP);
105
    }
schultezub's avatar
schultezub committed
106
    TFGeometry1D* TFGeometry1D::createQuad(const tgt::vec2& interval, const tgt::col4& leftColor, const tgt::vec4& rightColor) {
107
108
109
110
111
        tgtAssert(interval.x >= 0.f && interval.y <= 1.f, "Interval out of bounds");

        std::vector<KeyPoint> keyPoints;
        keyPoints.push_back(KeyPoint(interval.x, leftColor));
        keyPoints.push_back(KeyPoint(interval.y, rightColor));
schultezub's avatar
schultezub committed
112
        return new TFGeometry1D(keyPoints);
113
114
115
116
    }


}