Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SoStyleCache.cc
Go to the documentation of this file.
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/*----------------------------HEPVis----------------------------------------*/
27/* */
28/* Node: SoStyleCache */
29/* Author: Guy Barrand */
30/* */
31/*--------------------------------------------------------------------------*/
32
33// this :
35
36#include <Inventor/nodes/SoMaterial.h>
37#include <Inventor/nodes/SoDrawStyle.h>
38#include <Inventor/nodes/SoLightModel.h>
39#include <Inventor/nodes/SoResetTransform.h>
40
41//////////////////////////////////////////////////////////////////////////////
43)
44:fMaterials(0)
45,fLineStyles(0)
46,fLightModels(0)
47,fResetTransform(0)
48//////////////////////////////////////////////////////////////////////////////
49//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
50{
51 fMaterials = new SoGroup;
52 addChild(fMaterials);
53 fLineStyles = new SoGroup;
54 addChild(fLineStyles);
55 fLightModels = new SoGroup;
56 addChild(fLightModels);
57 fResetTransform = new SoResetTransform;
58 addChild(fResetTransform);
59}
60//////////////////////////////////////////////////////////////////////////////
62)
63//////////////////////////////////////////////////////////////////////////////
64//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
65{
66}
67//////////////////////////////////////////////////////////////////////////////
69 const SbColor& aRGB
70,float aTransparency
71)
72//////////////////////////////////////////////////////////////////////////////
73//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
74{
75 int number = fMaterials->getNumChildren();
76 for(int index=0;index<number;index++) {
77 SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
78 if( (material->diffuseColor[0]==aRGB) &&
79 (material->transparency[0]==aTransparency) ) {
80 return material;
81 }
82 }
83 SoMaterial* material = new SoMaterial;
84 material->diffuseColor.setValue(aRGB);
85 material->transparency.setValue(aTransparency);
86 fMaterials->addChild(material);
87 return material;
88}
89//////////////////////////////////////////////////////////////////////////////
91 float aRed
92,float aGreen
93,float aBlue
94,float aTransparency
95)
96//////////////////////////////////////////////////////////////////////////////
97//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
98{
99 SbColor aRGB(aRed,aGreen,aBlue);
100 int number = fMaterials->getNumChildren();
101 for(int index=0;index<number;index++) {
102 SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
103 if( (material->diffuseColor[0]==aRGB) &&
104 (material->transparency[0]==aTransparency) ) {
105 return material;
106 }
107 }
108 SoMaterial* material = new SoMaterial;
109 material->diffuseColor.setValue(aRGB);
110 material->transparency.setValue(aTransparency);
111 fMaterials->addChild(material);
112 return material;
113}
114/*
115//////////////////////////////////////////////////////////////////////////////
116SoDrawStyle* SoStyleCache::getLineStyle(
117 SbLineStyle aStyle
118,float aWidth
119)
120//////////////////////////////////////////////////////////////////////////////
121//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
122{
123 unsigned short pattern = 0xFFFF;
124 switch(aStyle) {
125 case SbLineDashed:
126 pattern = 0x00FF;
127 break;
128 case SbLineDotted:
129 pattern = 0x0101;
130 break;
131 case SbLineDashDotted:
132 pattern = 0x1C47;
133 break;
134 default: //SbLineSolid:
135 pattern = 0xFFFF;
136 break;
137 }
138 int number = fLineStyles->getNumChildren();
139 for(int index=0;index<number;index++) {
140 SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
141 if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
142 (drawStyle->lineWidth.getValue()==aWidth) &&
143 (drawStyle->linePattern.getValue()==pattern) ) {
144 return drawStyle;
145 }
146 }
147 SoDrawStyle* drawStyle = new SoDrawStyle;
148 drawStyle->style.setValue(SoDrawStyle::LINES);
149 drawStyle->lineWidth.setValue(aWidth);
150 drawStyle->linePattern.setValue(pattern);
151 fLineStyles->addChild(drawStyle);
152 return drawStyle;
153}
154*/
155//////////////////////////////////////////////////////////////////////////////
157 unsigned short aPattern
158,float aWidth
159)
160//////////////////////////////////////////////////////////////////////////////
161//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
162{
163 int number = fLineStyles->getNumChildren();
164 for(int index=0;index<number;index++) {
165 SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
166 if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
167 (drawStyle->lineWidth.getValue()==aWidth) &&
168 (drawStyle->linePattern.getValue()==aPattern) ) {
169 return drawStyle;
170 }
171 }
172 SoDrawStyle* drawStyle = new SoDrawStyle;
173 drawStyle->style.setValue(SoDrawStyle::LINES);
174 drawStyle->lineWidth.setValue(aWidth);
175 drawStyle->linePattern.setValue(aPattern);
176 fLineStyles->addChild(drawStyle);
177 return drawStyle;
178}
179//////////////////////////////////////////////////////////////////////////////
181)
182//////////////////////////////////////////////////////////////////////////////
183//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
184{
185 SoLightModel* lightModel = new SoLightModel;
186 lightModel->model.setValue(SoLightModel::PHONG);
187 fLightModels->addChild(lightModel);
188 return lightModel;
189}
190//////////////////////////////////////////////////////////////////////////////
192)
193//////////////////////////////////////////////////////////////////////////////
194//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
195{
196 SoLightModel* lightModel = new SoLightModel;
197 lightModel->model.setValue(SoLightModel::BASE_COLOR);
198 fLightModels->addChild(lightModel);
199 return lightModel;
200}
201//////////////////////////////////////////////////////////////////////////////
203)
204//////////////////////////////////////////////////////////////////////////////
205//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
206{
207 return fResetTransform;
208}
SoLightModel * getLightModelPhong()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
~SoStyleCache()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SoLightModel * getLightModelBaseColor()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SoDrawStyle * getLineStyle(unsigned short=0xFFFF, float=0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SoResetTransform * getResetTransform()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SoMaterial * getMaterial(const SbColor &, float=0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//