File: christmastree.cpp

package info (click to toggle)
tulip 4.6.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 139,284 kB
  • ctags: 35,942
  • sloc: cpp: 289,758; ansic: 27,264; python: 1,256; sh: 923; yacc: 522; xml: 337; makefile: 258; php: 66; lex: 55
file content (146 lines) | stat: -rw-r--r-- 4,990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
66
67
68
69
70
71
72
73
74
75
76
77
78
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */
#include <cmath>

#include <string>

#include <tulip/StringProperty.h>
#include <tulip/ColorProperty.h>
#include <tulip/Size.h>
#include <tulip/Coord.h>
#include <tulip/Glyph.h>
#include <tulip/EdgeExtremityGlyph.h>
#include <tulip/GlDisplayListManager.h>
#include <tulip/GlTextureManager.h>
#include <tulip/GlGraphInputData.h>
#include <tulip/Graph.h>
#include <tulip/GlTools.h>
#include <tulip/TulipViewSettings.h>

using namespace std;
using namespace tlp;

void drawTree() {
  if (GlDisplayListManager::getInst().beginNewDisplayList(
        "ChristmasTree_tree")) {
    GLUquadricObj *quadratic1;
    GLUquadricObj *quadratic2;
    GLUquadricObj *quadratic3;
    GLUquadricObj *quadratic4;
    setMaterial(Color(125, 80, 0, 255));
    quadratic1 = gluNewQuadric();
    gluQuadricNormals(quadratic1, GLU_SMOOTH);
    gluQuadricTexture(quadratic1, GL_TRUE);
    glTranslatef(0.0f, 0.0f, -0.5f);
    gluQuadricOrientation(quadratic1, GLU_INSIDE);
    gluDisk(quadratic1, 0.0f, 0.1f, 10, 10);
    gluQuadricOrientation(quadratic1, GLU_OUTSIDE);
    gluCylinder(quadratic1, 0.1f, 0.1f, 0.2f, 10, 10);
    glTranslatef(0.0f, 0.0f, 0.5f);

    setMaterial(Color(26, 121, 0, 255));
    quadratic2 = gluNewQuadric();
    gluQuadricNormals(quadratic2, GLU_SMOOTH);
    gluQuadricTexture(quadratic2, GL_TRUE);
    glTranslatef(0.0f, 0.0f, -0.3f);
    gluQuadricOrientation(quadratic2, GLU_OUTSIDE);
    gluCylinder(quadratic2, 0.4f, 0.0f, 0.5f, 10, 10);
    gluQuadricOrientation(quadratic2, GLU_INSIDE);
    gluDisk(quadratic2, 0.0f, 0.4f, 10, 10);
    glTranslatef(0.0f, 0.0f, 0.3f);

    quadratic3 = gluNewQuadric();
    gluQuadricNormals(quadratic3, GLU_SMOOTH);
    gluQuadricTexture(quadratic3, GL_TRUE);
    glTranslatef(0.0f, 0.0f, -0.1f);
    gluQuadricOrientation(quadratic3, GLU_OUTSIDE);
    gluCylinder(quadratic3, 0.3f, 0.0f, 0.4f, 10, 10);
    gluQuadricOrientation(quadratic3, GLU_INSIDE);
    gluDisk(quadratic3, 0.0f, 0.3f, 10, 10);
    glTranslatef(0.0f, 0.0f, 0.1f);

    quadratic4 = gluNewQuadric();
    gluQuadricNormals(quadratic4, GLU_SMOOTH);
    gluQuadricTexture(quadratic4, GL_TRUE);
    glTranslatef(0.0f, 0.0f, 0.1f);
    gluQuadricOrientation(quadratic4, GLU_OUTSIDE);
    gluCylinder(quadratic4, 0.2f, 0.0f, 0.3f, 10, 10);
    gluQuadricOrientation(quadratic4, GLU_INSIDE);
    gluDisk(quadratic4, 0.0f, 0.2f, 10, 10);
    glTranslatef(0.0f, 0.0f, -0.1f);

    GlDisplayListManager::getInst().endNewDisplayList();
    gluDeleteQuadric(quadratic1);
    gluDeleteQuadric(quadratic2);
    gluDeleteQuadric(quadratic3);
    gluDeleteQuadric(quadratic4);
  }

  if (GlDisplayListManager::getInst().beginNewDisplayList(
        "ChristmasTree_sphere")) {
    GLUquadricObj *quadratic = gluNewQuadric();
    gluQuadricNormals(quadratic, GLU_SMOOTH);
    gluQuadricTexture(quadratic, GL_TRUE);
    glTranslatef(0.0f, 0.0f, 0.45f);
    gluSphere(quadratic, 0.05f, 30, 30);
    glTranslatef(0.0f, 0.0f, -0.45f);
    GlDisplayListManager::getInst().endNewDisplayList();
    gluDeleteQuadric(quadratic);
  }

  if (GlDisplayListManager::getInst().beginNewDisplayList(
        "ChristmasTree_outsphere")) {
    GLUquadricObj *quadratic = gluNewQuadric();
    gluQuadricNormals(quadratic, GLU_SMOOTH);
    gluQuadricTexture(quadratic, GL_TRUE);
    gluSphere(quadratic, 0.5f, 30, 30);
    GlDisplayListManager::getInst().endNewDisplayList();
    gluDeleteQuadric(quadratic);
  }
}

/** \addtogroup glyph */

/// A 3D glyph.
/** This glyph draws a christmas tree special for christmas release of 2008
 */
class ChristmasTree: public Glyph {
public:
  GLYPHINFORMATION("3D - ChristmasTree", "Morgan Mathiaut", "16/12/2008", "Christmas tree", "1.0" , NodeShape::ChristmasTree)
  ChristmasTree(const tlp::PluginContext* context = NULL);
  virtual void draw(node n, float lod);
};
PLUGIN(ChristmasTree)

ChristmasTree::ChristmasTree(const tlp::PluginContext* context) :
  Glyph(context) {
}
void ChristmasTree::draw(node n, float) {
  drawTree();
  glRotatef(-90., 1., 0., 0.);
  GlDisplayListManager::getInst().callDisplayList("ChristmasTree_tree");
  setMaterial(glGraphInputData->getElementColor()->getNodeValue(n));
  GlDisplayListManager::getInst().callDisplayList("ChristmasTree_sphere");
  setMaterial(Color(255, 255, 255, 50));
  GlDisplayListManager::getInst().callDisplayList("ChristmasTree_outsphere");
}