00001
00002
00003 #include "Iguana/Inventor/interface/IgSoLegoTowers.h"
00004 #include <Inventor/nodes/SoText2.h>
00005 #include <Inventor/nodes/SoDrawStyle.h>
00006 #include <Inventor/nodes/SoTranslation.h>
00007 #include <Inventor/nodes/SoFont.h>
00008 #include <Inventor/nodes/SoIndexedLineSet.h>
00009 #include <Inventor/nodes/SoSeparator.h>
00010
00011
00012
00013
00014
00015
00016
00017
00018 SO_KIT_SOURCE (IgSoLegoTowers);
00019
00020
00021
00022
00023
00024 void
00025 IgSoLegoTowers::initClass (void)
00026 { SO_KIT_INIT_CLASS (IgSoLegoTowers, IgSoShapeKit, "IgSoShapeKit"); }
00027
00028 IgSoLegoTowers::IgSoLegoTowers (void)
00029 {
00030 SO_KIT_CONSTRUCTOR (IgSoLegoTowers);
00031 SO_KIT_ADD_FIELD (heightScale, (1.0f));
00032
00033 SO_KIT_ADD_CATALOG_ENTRY (font, SoFont, FALSE, separator,\x0, TRUE);
00034 SO_KIT_ADD_CATALOG_ENTRY (phiLabels, SoSeparator, FALSE, separator,\x0, TRUE);
00035 SO_KIT_ADD_CATALOG_ENTRY (etaLabels, SoSeparator, FALSE, separator,\x0, TRUE);
00036 SO_KIT_ADD_CATALOG_ENTRY (labels, SoSeparator, FALSE, separator,\x0, TRUE);
00037 SO_KIT_ADD_CATALOG_ENTRY (labelScale, SoSeparator, FALSE, labels,\x0, TRUE);
00038 SO_KIT_ADD_CATALOG_ENTRY (labelX, SoSeparator, FALSE, separator,\x0, TRUE);
00039 SO_KIT_ADD_CATALOG_ENTRY (labelZ, SoSeparator, FALSE, separator,\x0, TRUE);
00040 SO_KIT_ADD_CATALOG_ENTRY (grid, SoIndexedLineSet, FALSE, separator,\x0, TRUE);
00041 SO_KIT_ADD_CATALOG_ENTRY (minorGridSep, SoSeparator, FALSE, separator,\x0, TRUE);
00042 SO_KIT_ADD_CATALOG_ENTRY (legos, SoSeparator, FALSE, separator,\x0, TRUE);
00043 SO_KIT_INIT_INSTANCE ();
00044 setUpConnections (true, true);
00045 }
00046
00047 void
00048 IgSoLegoTowers::refresh (void)
00049 {
00050 static const float LABEL_OFFSET = 0.3F;
00051 float maxEta = 5.0F;
00052
00053 SoFont *font = new SoFont;
00054 font->name.setValue ("Times-Roman");
00055 font->size.setValue (14.0);
00056
00057 SoSeparator *phiLabels = new SoSeparator;
00058 SoSeparator *etaLabels = new SoSeparator;
00059 SoIndexedLineSet *grid = new SoIndexedLineSet;
00060 SoSeparator *minorGridSep = new SoSeparator;
00061 SoSeparator *labelScale = new SoSeparator;
00062 SoFont *labelScaleFont = new SoFont;
00063 labelScaleFont->name.setValue ("Times-Roman");
00064 labelScaleFont->size.setValue (18.0);
00065
00066 SoSeparator *labelX = new SoSeparator;
00067 SoSeparator *labelZ = new SoSeparator;
00068 SoTranslation *labelScaleOffset = new SoTranslation;
00069 SoText2 *labelScaleText = new SoText2;
00070 SoTranslation *labelXOffset = new SoTranslation;
00071 SoText2 *labelXText = new SoText2;
00072 SoTranslation *labelZOffset = new SoTranslation;
00073 SoText2 *labelZText = new SoText2;
00074 SoVertexProperty *vtx = new SoVertexProperty;
00075 SoVertexProperty *minorVtx = new SoVertexProperty;
00076 SoText2 *text;
00077 SoMFInt32 coords;
00078
00079 SoIndexedLineSet *minorGrid = new SoIndexedLineSet;
00080 SoMFInt32 minorCoords;
00081
00082
00083 float x = float (2 * M_PI);
00084 float z = 5.0;
00085 int vertex = 6;
00086 int coord = 0;
00087 int minorVertex = 0;
00088 int minorCoord = 0;
00089
00090 vtx->vertex.set1Value (0, SbVec3f (0, 0, -z));
00091 vtx->vertex.set1Value (1, SbVec3f (0, 0, z));
00092 vtx->vertex.set1Value (2, SbVec3f (x, 0, z));
00093 vtx->vertex.set1Value (3, SbVec3f (x, 0, -z));
00094 vtx->vertex.set1Value (4, SbVec3f (0, 0, -z));
00095 vtx->vertex.set1Value (5, SbVec3f (0, 1, -z));
00096 for (; coord < vertex; coord++)
00097 coords.set1Value (coord, coord);
00098 coords.set1Value (coord++, SO_END_LINE_INDEX);
00099
00100 x = 0;
00101 z = 5.0;
00102
00103 SoText2 *phiLabelText [19];
00104 SoTranslation *phiStart = new SoTranslation;
00105 SoTranslation *phiTranslation = new SoTranslation;
00106 int ticks = 18;
00107 int tick;
00108
00109 phiStart->translation = SbVec3f (M_PI / 4, 0, -z-2*LABEL_OFFSET);
00110 phiTranslation->translation = SbVec3f (M_PI / 4, 0, 0);
00111 phiLabels->addChild (phiStart);
00112
00113 for (tick = 0; tick < ticks; tick++, x += (2 * M_PI) / 18.0)
00114 {
00115 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, -z));
00116 coords.set1Value (coord++, vertex++);
00117 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, z));
00118 coords.set1Value (coord++, vertex++);
00119 coords.set1Value (coord++, SO_END_LINE_INDEX);
00120
00121 for (int ttow = 1; ttow < 4; ttow++)
00122 {
00123 minorVtx->vertex.set1Value (minorVertex, SbVec3f (x + ttow * ((2 * M_PI) / 18.0) / 4.0, 0, -3.0));
00124 minorCoords.set1Value (minorCoord++, minorVertex++);
00125 minorVtx->vertex.set1Value (minorVertex, SbVec3f (x + ttow * ((2 * M_PI) / 18.0) / 4.0, 0, 3.0));
00126 minorCoords.set1Value (minorCoord++, minorVertex++);
00127 minorCoords.set1Value (minorCoord++, SO_END_LINE_INDEX);
00128 }
00129
00130 text = phiLabelText [tick] = new SoText2;
00131 phiLabels->addChild (text);
00132 phiLabels->addChild (phiTranslation);
00133 }
00134
00135 text = phiLabelText [tick] = new SoText2;
00136 phiLabels->addChild (text);
00137
00138 phiLabelText [0]->string = "PI/4";
00139 phiLabelText [1]->string = "PI/2";
00140 phiLabelText [2]->string = "3PI/4";
00141 phiLabelText [3]->string = "PI";
00142 phiLabelText [4]->string = "5PI/4";
00143 phiLabelText [5]->string = "3PI/2";
00144 phiLabelText [6]->string = "7PI/4";
00145 phiLabelText [7]->string = "2PI";
00146
00147
00148 x = 2*M_PI;
00149 z = ceil (-5.0);
00150 if (z == -5.0)
00151 z += 1;
00152
00153 z = -5.0;
00154 for (tick = 1; tick < 5; tick++)
00155 {
00156 vtx->vertex.set1Value (vertex, SbVec3f (0, 0, z + tick * 0.5));
00157 coords.set1Value (coord++, vertex++);
00158 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, z + tick * 0.5));
00159 coords.set1Value (coord++, vertex++);
00160 coords.set1Value (coord++, SO_END_LINE_INDEX);
00161
00162 vtx->vertex.set1Value (vertex, SbVec3f (0, 0, -z - tick * 0.5));
00163 coords.set1Value (coord++, vertex++);
00164 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, -z - tick * 0.5));
00165 coords.set1Value (coord++, vertex++);
00166 coords.set1Value (coord++, SO_END_LINE_INDEX);
00167 }
00168
00169 ticks = 11;
00170 z = -1.74;
00171
00172 for (tick = 0; tick < ticks; tick++, z += 4 * 0.087)
00173 {
00174 vtx->vertex.set1Value (vertex, SbVec3f (0, 0, z));
00175 coords.set1Value (coord++, vertex++);
00176 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, z));
00177 coords.set1Value (coord++, vertex++);
00178 coords.set1Value (coord++, SO_END_LINE_INDEX);
00179
00180 for (int ttow = 0; ttow < 4 && z < 1.74; ttow++)
00181 {
00182 minorVtx->vertex.set1Value (minorVertex, SbVec3f (0, 0, z + ttow * ((2 * M_PI) / 18.0) / 4.0));
00183 minorCoords.set1Value (minorCoord++, minorVertex++);
00184 minorVtx->vertex.set1Value (minorVertex, SbVec3f (x, 0, z + ttow * ((2 * M_PI) / 18.0) / 4.0));
00185 minorCoords.set1Value (minorCoord++, minorVertex++);
00186 minorCoords.set1Value (minorCoord++, SO_END_LINE_INDEX);
00187 }
00188 }
00189
00190 z = -2.172;
00191
00192 vtx->vertex.set1Value (vertex, SbVec3f (0, 0, z));
00193 coords.set1Value (coord++, vertex++);
00194 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, z));
00195 coords.set1Value (coord++, vertex++);
00196 coords.set1Value (coord++, SO_END_LINE_INDEX);
00197
00198 vtx->vertex.set1Value (vertex, SbVec3f (0, 0, -z));
00199 coords.set1Value (coord++, vertex++);
00200 vtx->vertex.set1Value (vertex, SbVec3f (x, 0, -z));
00201 coords.set1Value (coord++, vertex++);
00202 coords.set1Value (coord++, SO_END_LINE_INDEX);
00203
00204 z = 1.74;
00205 float dz [8] = { 1.83, 1.93, 2.043, 2.172, 2.322, 2.50, 2.65, 3.0};
00206
00207 for (tick = 0; tick < 8; tick++)
00208 {
00209 minorVtx->vertex.set1Value (minorVertex, SbVec3f (0, 0, dz [tick]));
00210 minorCoords.set1Value (minorCoord++, minorVertex++);
00211 minorVtx->vertex.set1Value (minorVertex, SbVec3f (x, 0, dz [tick]));
00212 minorCoords.set1Value (minorCoord++, minorVertex++);
00213 minorCoords.set1Value (minorCoord++, SO_END_LINE_INDEX);
00214
00215 minorVtx->vertex.set1Value (minorVertex, SbVec3f (0, 0, -dz[tick]));
00216 minorCoords.set1Value (minorCoord++, minorVertex++);
00217 minorVtx->vertex.set1Value (minorVertex, SbVec3f (x, 0, -dz[tick]));
00218 minorCoords.set1Value (minorCoord++, minorVertex++);
00219 minorCoords.set1Value (minorCoord++, SO_END_LINE_INDEX);
00220 }
00221
00222 z = -5.0;
00223
00224 SoTranslation *etaStart = new SoTranslation;
00225 SoTranslation *etaTranslation = new SoTranslation;
00226
00227 etaStart->translation = SbVec3f (-2 * LABEL_OFFSET, 0, z);
00228 etaTranslation->translation = SbVec3f (0, 0, 1);
00229 etaLabels->addChild (etaStart);
00230
00231 ticks = int (2 * abs (int (z)) + 1);
00232 for (tick = 0; tick < ticks; tick++, z ++)
00233 {
00234 text = new SoText2;
00235 char textLabel [10];
00236 sprintf (textLabel, "%.0f", z);
00237 text->string = textLabel;
00238 etaLabels->addChild (text);
00239 etaLabels->addChild (etaTranslation);
00240 }
00241
00242 grid->vertexProperty = vtx;
00243 grid->coordIndex = coords;
00244 minorGrid->vertexProperty = minorVtx;
00245 minorGrid->coordIndex = minorCoords;
00246
00247
00248 char scaleChars[12] = "1.0 GeV";
00249 sprintf (scaleChars, "%.2G GeV", heightScale.getValue ());
00250 labelScaleText->string = scaleChars;
00251 labelScaleOffset->translation
00252 = SbVec3f (-LABEL_OFFSET, 1, -maxEta - LABEL_OFFSET);
00253
00254
00255 labelXOffset->translation = SbVec3f (M_PI, 0, -maxEta - 8 * LABEL_OFFSET);
00256 labelXText->string = "Phi";
00257 labelZOffset->translation = SbVec3f (-8 * LABEL_OFFSET, 0, 0);
00258 labelZText->string = "Eta";
00259
00260 labelScale->addChild (labelScaleFont);
00261 labelScale->addChild (labelScaleOffset);
00262 labelScale->addChild (labelScaleText);
00263
00264 labelX->addChild (labelXOffset);
00265 labelX->addChild (labelXText);
00266 labelZ->addChild (labelZOffset);
00267 labelZ->addChild (labelZText);
00268
00269
00270 setPart ("font", font);
00271 setPart ("phiLabels", phiLabels);
00272 setPart ("etaLabels", etaLabels);
00273 setPart ("labelScale", labelScale);
00274 setPart ("labelX", labelX);
00275 setPart ("labelZ", labelZ);
00276 setPart ("grid", grid);
00277
00278 SoDrawStyle *minorDrawStyle = new SoDrawStyle;
00279 minorDrawStyle->linePattern = 0x5555;
00280 minorGridSep->addChild (minorDrawStyle);
00281 minorGridSep->addChild (minorGrid);
00282
00283 setPart ("minorGridSep", minorGridSep);
00284 }