source: trunk/source/visualization/OpenGL/src/G4OpenGLBitMapStore.cc@ 1271

Last change on this file since 1271 was 1160, checked in by garnier, 16 years ago

mise en place de Vis dans UI

  • Property svn:mime-type set to text/cpp
File size: 3.7 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4OpenGLBitMapStore.cc,v 1.5 2009/01/19 16:53:42 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// John Allison 6th January 2007
32
33#ifdef G4VIS_BUILD_OPENGL_DRIVER
34
35#include "G4OpenGLBitMapStore.hh"
36
37namespace G4OpenGLBitMapStore {
38
39std::map<Key, GLubyte*> fStore;
40
41void SetBit(G4int i, G4int j, GLubyte* bitmap, G4int byteColumns)
42{
43 G4int k = i / 8 + byteColumns * j;
44 bitmap[k] |= 0x80 >> i % 8;
45}
46
47const GLubyte* GetBitMap(Shape shape, G4double& size, G4bool filled)
48{
49 // Rationalise size
50 G4int bitSize = G4int(std::abs(size) + 0.49);
51 if (bitSize < 1) bitSize = 1;
52
53 // Modify size in calling function (passed by reference).
54 size = bitSize;
55
56 Key key(shape, bitSize, filled);
57
58 // If previously encountered, return.
59 if (fStore.find(key) != fStore.end()) return fStore[key];
60
61 // Create and store new bitmap.
62 G4int byteColumns = (G4int(bitSize - 1) / 8) + 1;
63 G4int byteRows = bitSize;
64 G4int nBytes = byteColumns*byteRows;
65 GLubyte* bitmap = new GLubyte[nBytes];
66 fStore[key] = bitmap;
67
68 if (shape == square && filled) { // Set all bits and return.
69 for (G4int i = 0; i < nBytes; ++i) bitmap[i] = 0xff;
70 return bitmap;
71 } else { // Clear ready for setting bits.
72 for (G4int i = 0; i < nBytes; ++i) bitmap[i] = 0x00;
73 }
74
75 // Fill bitmap.
76 GLint linewidth;
77 glGetIntegerv(GL_LINE_WIDTH, &linewidth);
78 if (linewidth > bitSize) linewidth = bitSize;
79 G4double outer = bitSize / 2.;
80 G4double outer2 = outer * outer;
81 G4double inner = bitSize / 2. - linewidth;
82 G4double inner2 = inner * inner;
83 for (G4int i = 0; i < bitSize; ++i) {
84 for (G4int j = 0; j < bitSize; ++j) {
85 G4double x = i - (bitSize - 1) * 0.5;
86 G4double y = j - (bitSize - 1) * 0.5;
87 G4double r2 = x * x + y * y;
88 if (shape == circle) {
89 if (filled) {
90 if (r2 < outer2) SetBit(i, j, bitmap, byteColumns);
91 } else {
92 if (r2 < outer2 && r2 > inner2) SetBit(i, j, bitmap, byteColumns);
93 }
94 } else { // Unfilled square.
95 if (x < -inner || x > inner || y < -inner || y > inner)
96 SetBit(i, j, bitmap, byteColumns);
97 }
98 }
99 }
100
101 return bitmap;
102}
103
104} // End namespace G4OpenGLBitMapStore.
105
106#endif
Note: See TracBrowser for help on using the repository browser.