Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #ifdef G4VIS_BUILD_OI_DRIVER
27 
28 /*----------------------------HEPVis----------------------------------------*/
29 /* */
30 /* Node: SoStyleCache */
31 /* Author: Guy Barrand */
32 /* */
33 /*--------------------------------------------------------------------------*/
34 
35 // this :
37 
38 #include <Inventor/nodes/SoMaterial.h>
39 #include <Inventor/nodes/SoDrawStyle.h>
40 #include <Inventor/nodes/SoLightModel.h>
41 #include <Inventor/nodes/SoResetTransform.h>
42 
45 )
46 :fMaterials(0)
47 ,fLineStyles(0)
48 ,fLightModels(0)
49 ,fResetTransform(0)
52 {
53  fMaterials = new SoGroup;
54  addChild(fMaterials);
55  fLineStyles = new SoGroup;
56  addChild(fLineStyles);
57  fLightModels = new SoGroup;
58  addChild(fLightModels);
59  fResetTransform = new SoResetTransform;
60  addChild(fResetTransform);
61 }
64 )
65 {
68 }
70 SoMaterial* SoStyleCache::getMaterial(
71  const SbColor& aRGB
72 ,float aTransparency
73 )
74 {
77  int number = fMaterials->getNumChildren();
78  for(int index=0;index<number;index++) {
79  SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
80  if( (material->diffuseColor[0]==aRGB) &&
81  (material->transparency[0]==aTransparency) ) {
82  return material;
83  }
84  }
85  SoMaterial* material = new SoMaterial;
86  material->diffuseColor.setValue(aRGB);
87  material->transparency.setValue(aTransparency);
88  fMaterials->addChild(material);
89  return material;
90 }
92 SoMaterial* SoStyleCache::getMaterial(
93  float aRed
94 ,float aGreen
95 ,float aBlue
96 ,float aTransparency
97 )
98 {
101  SbColor aRGB(aRed,aGreen,aBlue);
102  int number = fMaterials->getNumChildren();
103  for(int index=0;index<number;index++) {
104  SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
105  if( (material->diffuseColor[0]==aRGB) &&
106  (material->transparency[0]==aTransparency) ) {
107  return material;
108  }
109  }
110  SoMaterial* material = new SoMaterial;
111  material->diffuseColor.setValue(aRGB);
112  material->transparency.setValue(aTransparency);
113  fMaterials->addChild(material);
114  return material;
115 }
116 /*
118 SoDrawStyle* SoStyleCache::getLineStyle(
119  SbLineStyle aStyle
120 ,float aWidth
121 )
124 {
125  unsigned short pattern = 0xFFFF;
126  switch(aStyle) {
127  case SbLineDashed:
128  pattern = 0x00FF;
129  break;
130  case SbLineDotted:
131  pattern = 0x0101;
132  break;
133  case SbLineDashDotted:
134  pattern = 0x1C47;
135  break;
136  default: //SbLineSolid:
137  pattern = 0xFFFF;
138  break;
139  }
140  int number = fLineStyles->getNumChildren();
141  for(int index=0;index<number;index++) {
142  SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
143  if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
144  (drawStyle->lineWidth.getValue()==aWidth) &&
145  (drawStyle->linePattern.getValue()==pattern) ) {
146  return drawStyle;
147  }
148  }
149  SoDrawStyle* drawStyle = new SoDrawStyle;
150  drawStyle->style.setValue(SoDrawStyle::LINES);
151  drawStyle->lineWidth.setValue(aWidth);
152  drawStyle->linePattern.setValue(pattern);
153  fLineStyles->addChild(drawStyle);
154  return drawStyle;
155 }
156 */
158 SoDrawStyle* SoStyleCache::getLineStyle(
159  unsigned short aPattern
160 ,float aWidth
161 )
162 {
165  int number = fLineStyles->getNumChildren();
166  for(int index=0;index<number;index++) {
167  SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
168  if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
169  (drawStyle->lineWidth.getValue()==aWidth) &&
170  (drawStyle->linePattern.getValue()==aPattern) ) {
171  return drawStyle;
172  }
173  }
174  SoDrawStyle* drawStyle = new SoDrawStyle;
175  drawStyle->style.setValue(SoDrawStyle::LINES);
176  drawStyle->lineWidth.setValue(aWidth);
177  drawStyle->linePattern.setValue(aPattern);
178  fLineStyles->addChild(drawStyle);
179  return drawStyle;
180 }
183 )
184 {
187  SoLightModel* lightModel = new SoLightModel;
188  lightModel->model.setValue(SoLightModel::PHONG);
189  fLightModels->addChild(lightModel);
190  return lightModel;
191 }
194 )
195 {
198  SoLightModel* lightModel = new SoLightModel;
199  lightModel->model.setValue(SoLightModel::BASE_COLOR);
200  fLightModels->addChild(lightModel);
201  return lightModel;
202 }
204 SoResetTransform* SoStyleCache::getResetTransform(
205 )
206 {
209  return fResetTransform;
210 }
211 
212 #endif
SoLightModel * getLightModelBaseColor()
SoResetTransform * getResetTransform()
string material
Definition: eplot.py:19
SoMaterial * getMaterial(const SbColor &, float=0)
SoLightModel * getLightModelPhong()
SoDrawStyle * getLineStyle(unsigned short=0xFFFF, float=0)