00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef G4VIS_BUILD_OI_DRIVER
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00119
00120
00121
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
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