Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 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*)fMater 78 if( (material->diffuseColor[0]==aRGB) && 79 (material->transparency[0]==aTranspare 80 return material; 81 } 82 } 83 SoMaterial* material = new SoMaterial; 84 material->diffuseColor.setValue(aRGB); 85 material->transparency.setValue(aTransparenc 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*)fMater 103 if( (material->diffuseColor[0]==aRGB) && 104 (material->transparency[0]==aTranspare 105 return material; 106 } 107 } 108 SoMaterial* material = new SoMaterial; 109 material->diffuseColor.setValue(aRGB); 110 material->transparency.setValue(aTransparenc 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*)fLi 141 if( (drawStyle->style.getValue()==SoDrawSt 142 (drawStyle->lineWidth.getValue()==aWid 143 (drawStyle->linePattern.getValue()==pa 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*)fLi 166 if( (drawStyle->style.getValue()==SoDrawSt 167 (drawStyle->lineWidth.getValue()==aWid 168 (drawStyle->linePattern.getValue()==aP 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::PHO 187 fLightModels->addChild(lightModel); 188 return lightModel; 189 } 190 ////////////////////////////////////////////// 191 SoLightModel* SoStyleCache::getLightModelBaseC 192 ) 193 ////////////////////////////////////////////// 194 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 195 { 196 SoLightModel* lightModel = new SoLightModel; 197 lightModel->model.setValue(SoLightModel::BAS 198 fLightModels->addChild(lightModel); 199 return lightModel; 200 } 201 ////////////////////////////////////////////// 202 SoResetTransform* SoStyleCache::getResetTransf 203 ) 204 ////////////////////////////////////////////// 205 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 206 { 207 return fResetTransform; 208 } 209