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 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 :
 34 #include <HEPVis/misc/SoStyleCache.h>
 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 //////////////////////////////////////////////////////////////////////////////
 42 SoStyleCache::SoStyleCache(
 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 //////////////////////////////////////////////////////////////////////////////
 61 SoStyleCache::~SoStyleCache(
 62 ) 
 63 //////////////////////////////////////////////////////////////////////////////
 64 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 65 {
 66 }
 67 //////////////////////////////////////////////////////////////////////////////
 68 SoMaterial* SoStyleCache::getMaterial(
 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 //////////////////////////////////////////////////////////////////////////////
 90 SoMaterial* SoStyleCache::getMaterial(
 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 //////////////////////////////////////////////////////////////////////////////
116 SoDrawStyle* 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 //////////////////////////////////////////////////////////////////////////////
156 SoDrawStyle* SoStyleCache::getLineStyle(
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 //////////////////////////////////////////////////////////////////////////////
180 SoLightModel* SoStyleCache::getLightModelPhong(
181 ) 
182 //////////////////////////////////////////////////////////////////////////////
183 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
184 {
185   SoLightModel* lightModel = new SoLightModel;
186   lightModel->model.setValue(SoLightModel::PHONG);
187   fLightModels->addChild(lightModel);
188   return lightModel;
189 }
190 //////////////////////////////////////////////////////////////////////////////
191 SoLightModel* SoStyleCache::getLightModelBaseColor(
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 //////////////////////////////////////////////////////////////////////////////
202 SoResetTransform* SoStyleCache::getResetTransform(
203 ) 
204 //////////////////////////////////////////////////////////////////////////////
205 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
206 {
207   return fResetTransform;
208 }
209