SoStyleCache.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 #ifdef G4VIS_BUILD_OI_DRIVER
00027 
00028 /*----------------------------HEPVis----------------------------------------*/
00029 /*                                                                          */
00030 /* Node:             SoStyleCache                                           */
00031 /* Author:           Guy Barrand                                            */
00032 /*                                                                          */
00033 /*--------------------------------------------------------------------------*/
00034 
00035 // this :
00036 #include <HEPVis/misc/SoStyleCache.h>
00037 
00038 #include <Inventor/nodes/SoMaterial.h>
00039 #include <Inventor/nodes/SoDrawStyle.h>
00040 #include <Inventor/nodes/SoLightModel.h>
00041 #include <Inventor/nodes/SoResetTransform.h>
00042 
00044 SoStyleCache::SoStyleCache(
00045 ) 
00046 :fMaterials(0)
00047 ,fLineStyles(0)
00048 ,fLightModels(0)
00049 ,fResetTransform(0)
00052 {
00053   fMaterials = new SoGroup;
00054   addChild(fMaterials);
00055   fLineStyles = new SoGroup;
00056   addChild(fLineStyles);
00057   fLightModels = new SoGroup;
00058   addChild(fLightModels);
00059   fResetTransform = new SoResetTransform;
00060   addChild(fResetTransform);
00061 }
00063 SoStyleCache::~SoStyleCache(
00064 ) 
00065 
00066 
00067 {
00068 }
00070 SoMaterial* SoStyleCache::getMaterial(
00071  const SbColor& aRGB
00072 ,float aTransparency
00073 ) 
00074 
00075 
00076 {
00077   int number = fMaterials->getNumChildren();
00078   for(int index=0;index<number;index++) { 
00079     SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
00080     if( (material->diffuseColor[0]==aRGB) &&
00081         (material->transparency[0]==aTransparency) ) {
00082       return material;
00083     }
00084   }
00085   SoMaterial* material = new SoMaterial;
00086   material->diffuseColor.setValue(aRGB);
00087   material->transparency.setValue(aTransparency);
00088   fMaterials->addChild(material);
00089   return material;
00090 }
00092 SoMaterial* SoStyleCache::getMaterial(
00093  float aRed
00094 ,float aGreen
00095 ,float aBlue
00096 ,float aTransparency
00097 ) 
00098 
00099 
00100 {
00101   SbColor aRGB(aRed,aGreen,aBlue);
00102   int number = fMaterials->getNumChildren();
00103   for(int index=0;index<number;index++) { 
00104     SoMaterial* material = (SoMaterial*)fMaterials->getChild(index);
00105     if( (material->diffuseColor[0]==aRGB) &&
00106         (material->transparency[0]==aTransparency) ) {
00107       return material;
00108     }
00109   }
00110   SoMaterial* material = new SoMaterial;
00111   material->diffuseColor.setValue(aRGB);
00112   material->transparency.setValue(aTransparency);
00113   fMaterials->addChild(material);
00114   return material;
00115 }
00116 /*
00118 SoDrawStyle* SoStyleCache::getLineStyle(
00119  SbLineStyle aStyle
00120 ,float aWidth
00121 ) 
00124 {
00125   unsigned short pattern = 0xFFFF;
00126   switch(aStyle) {
00127   case SbLineDashed:
00128     pattern = 0x00FF;
00129     break;
00130   case SbLineDotted:
00131     pattern = 0x0101;
00132     break;
00133   case SbLineDashDotted:
00134     pattern = 0x1C47;
00135     break;
00136   default: //SbLineSolid:
00137     pattern = 0xFFFF;
00138     break;
00139   }
00140   int number = fLineStyles->getNumChildren();
00141   for(int index=0;index<number;index++) { 
00142     SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
00143     if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
00144         (drawStyle->lineWidth.getValue()==aWidth) &&
00145         (drawStyle->linePattern.getValue()==pattern) ) {
00146       return drawStyle;
00147     }
00148   }
00149   SoDrawStyle* drawStyle = new SoDrawStyle;
00150   drawStyle->style.setValue(SoDrawStyle::LINES);
00151   drawStyle->lineWidth.setValue(aWidth);
00152   drawStyle->linePattern.setValue(pattern);
00153   fLineStyles->addChild(drawStyle);
00154   return drawStyle;
00155 }
00156 */
00158 SoDrawStyle* SoStyleCache::getLineStyle(
00159  unsigned short aPattern
00160 ,float aWidth
00161 ) 
00162 
00163 
00164 {
00165   int number = fLineStyles->getNumChildren();
00166   for(int index=0;index<number;index++) { 
00167     SoDrawStyle* drawStyle = (SoDrawStyle*)fLineStyles->getChild(index);
00168     if( (drawStyle->style.getValue()==SoDrawStyle::LINES) &&
00169         (drawStyle->lineWidth.getValue()==aWidth) &&
00170         (drawStyle->linePattern.getValue()==aPattern) ) {
00171       return drawStyle;
00172     }
00173   }
00174   SoDrawStyle* drawStyle = new SoDrawStyle;
00175   drawStyle->style.setValue(SoDrawStyle::LINES);
00176   drawStyle->lineWidth.setValue(aWidth);
00177   drawStyle->linePattern.setValue(aPattern);
00178   fLineStyles->addChild(drawStyle);
00179   return drawStyle;
00180 }
00182 SoLightModel* SoStyleCache::getLightModelPhong(
00183 ) 
00184 
00185 
00186 {
00187   SoLightModel* lightModel = new SoLightModel;
00188   lightModel->model.setValue(SoLightModel::PHONG);
00189   fLightModels->addChild(lightModel);
00190   return lightModel;
00191 }
00193 SoLightModel* SoStyleCache::getLightModelBaseColor(
00194 ) 
00195 
00196 
00197 {
00198   SoLightModel* lightModel = new SoLightModel;
00199   lightModel->model.setValue(SoLightModel::BASE_COLOR);
00200   fLightModels->addChild(lightModel);
00201   return lightModel;
00202 }
00204 SoResetTransform* SoStyleCache::getResetTransform(
00205 ) 
00206 
00207 
00208 {
00209   return fResetTransform;
00210 }
00211 
00212 #endif

Generated on Mon May 27 17:50:34 2013 for Geant4 by  doxygen 1.4.7