Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
HyodaGL.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*****************************************************************************
8 * HyodaGL.cc from GLUT (C) 2000-2012 *
9 *****************************************************************************/
10//#include "arcane/IMesh.h"
11#include "arcane/IApplication.h"
12#include "arcane/IParallelMng.h"
13#include "arcane/FactoryService.h"
14#include "arcane/ServiceFinder2.h"
15#include "arcane/SharedVariable.h"
16#include "arcane/CommonVariables.h"
17#include "arcane/utils/ScopedPtr.h"
18#include "arcane/AbstractService.h"
20#include "arcane/AbstractService.h"
22#include "arcane/hyoda/HyodaIceT.h"
23
24#include <IceTConfig.h>
25#include <IceT.h>
26#include <IceTGL.h>
27
28#include <GL/osmesa.h>
29#include "GL/glu.h"
30
31
32void ppmWrite(const char *filename,
33 const unsigned char *image,
34 int width, int height){
35 FILE *fd;
36 const unsigned char *color;
37 fd = fopen(filename, "wb");
38 fprintf(fd, "P6\n");
39 fprintf(fd, "%d %d\n", width, height);
40 fprintf(fd, "255\n");
41 for(int y = height-1; y >= 0; y--) {
42 color = image + y*width*4;
43 for(int x = 0; x < width; x++) {
44 fwrite(color, 1, 3, fd);
45 color += 4;
46 }
47 }
48 fclose(fd);
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54ARCANE_BEGIN_NAMESPACE
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59
60void HyodaIceT::gluSphere(float radius, int slices, int stacks){
61 GLUquadric *q = gluNewQuadric();
62 gluQuadricNormals(q, GLU_SMOOTH);
63 ::gluSphere(q, radius, slices, stacks);
64 gluDeleteQuadric(q);
65}
66
67
68void HyodaIceT::gluCone(float base, float height, int slices, int stacks){
69 GLUquadric *q = gluNewQuadric();
70 gluQuadricDrawStyle(q, GLU_FILL);
71 gluQuadricNormals(q, GLU_SMOOTH);
72 gluCylinder(q, base, 0.0, height, slices, stacks);
73 gluDeleteQuadric(q);
74}
75
76
77void HyodaIceT::gluTorus(float innerRadius, float outerRadius, int sides, int rings){
78 int i, j;
79 GLfloat theta, phi, theta1;
80 GLfloat cosTheta, sinTheta;
81 GLfloat cosTheta1, sinTheta1;
82 const GLfloat ringDelta = 2.0 * M_PI / rings;
83 const GLfloat sideDelta = 2.0 * M_PI / sides;
84
85 theta = 0.0;
86 cosTheta = 1.0;
87 sinTheta = 0.0;
88 for (i = rings - 1; i >= 0; i--) {
89 theta1 = theta + ringDelta;
90 cosTheta1 = cos(theta1);
91 sinTheta1 = sin(theta1);
92 glBegin(GL_QUAD_STRIP);
93 phi = 0.0;
94 for (j = sides; j >= 0; j--) {
95 GLfloat cosPhi, sinPhi, dist;
96
97 phi += sideDelta;
98 cosPhi = cos(phi);
99 sinPhi = sin(phi);
100 dist = outerRadius + innerRadius * cosPhi;
101
102 glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
103 glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, innerRadius * sinPhi);
104 glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
105 glVertex3f(cosTheta * dist, -sinTheta * dist, innerRadius * sinPhi);
106 }
107 glEnd();
108 theta = theta1;
109 cosTheta = cosTheta1;
110 sinTheta = sinTheta1;
111 }
112}
113
114
115void HyodaIceT::renderSphereConeTorus(void){
116 GLfloat red_mat[] = { 1.0, 0.2, 0.2, 1.0 };
117 GLfloat green_mat[] = { 0.2, 1.0, 0.2, 1.0 };
118 GLfloat blue_mat[] = { 0.2, 0.2, 1.0, 1.0 };
119
120 glRotatef(20.0, 1.0, 0.0, 0.0);
121
122 glPushMatrix();
123 glTranslatef(-0.75, 0.5, 0.0);
124 glRotatef(90.0, 1.0, 0.0, 0.0);
125 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat );
126 gluTorus(0.275, 0.85, 20, 20);
127 glPopMatrix();
128
129 glPushMatrix();
130 glTranslatef(-0.75, -0.5, 0.0);
131 glRotatef(270.0, 1.0, 0.0, 0.0);
132 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat );
133 gluCone(1.0, 2.0, 16, 1);
134 glPopMatrix();
135
136 glPushMatrix();
137 glTranslatef(0.75, 0.0, -1.0);
138 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
139 gluSphere(1.0, 20, 20);
140 glPopMatrix();
141
142 /* This is very important!!!
143 * Make sure buffered commands are finished!!!
144 */
145 glFinish();
146}
147
148
149/* Encode image position in color. */
150#define ACTIVE_COLOR(x, y) ((((x) & 0xFFFF) | 0x8000) | ((((y) & 0xFFFF) | 0x8000) << 16))
151void HyodaIceT::LowerTriangleImage(void *img){
152 IceTImage image=*(IceTImage*)(&img);
153 //IceTUInt *data = icetImageGetColorui(image);
154 IceTUByte *data = icetImageGetColorub(image);
155 IceTSizeType width = icetImageGetWidth(image);
156 IceTSizeType height = icetImageGetHeight(image);
157 IceTSizeType x, y;
158
159 for (y = 0; y < height; y++) {
160 for (x = 0; x < width; x++) {
161 if (x < (height-y)) {
162 data[0] = ACTIVE_COLOR(x, y);
163 }
164 data++;
165 }
166 }
167}
168
169
170void HyodaIceT::UpperTriangleImage(void *img){
171 IceTImage image=*(IceTImage*)(&img);
172 //IceTUInt *data = icetImageGetColorui(image);
173 IceTUByte *data = icetImageGetColorub(image);
174 IceTSizeType width = icetImageGetWidth(image);
175 IceTSizeType height = icetImageGetHeight(image);
176 IceTSizeType x, y;
177
178 for (y = 0; y < height; y++) {
179 for (x = 0; x < width; x++) {
180 if ((height-y) < x) {
181 data[0] = ACTIVE_COLOR(x, y);
182 }
183 data++;
184 }
185 }
186}
187
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
192ARCANE_END_NAMESPACE
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
Fichier de configuration d'Arcane.