00001
00002
00003 #include "Iguana/Inventor/interface/IgSoAxis.h"
00004 #include <Inventor/nodes/SoText2.h>
00005 #include <Inventor/nodes/SoSeparator.h>
00006 #include <Inventor/nodes/SoLineSet.h>
00007 #include <Inventor/nodes/SoFont.h>
00008 #include <Inventor/nodes/SoTranslation.h>
00009 #include <Inventor/nodes/SoCone.h>
00010 #include <Inventor/nodes/SoCylinder.h>
00011 #include <Inventor/nodes/SoTransform.h>
00012 #include <Inventor/nodes/SoRotation.h>
00013 #include <cmath>
00014
00015
00016
00017
00018
00019
00020
00021
00022 SO_KIT_SOURCE (IgSoAxis);
00023
00024
00025
00026
00027
00028 void
00029 IgSoAxis::initClass ()
00030 { SO_KIT_INIT_CLASS (IgSoAxis,IgSoShapeKit,"IgSoShapeKit"); }
00031
00032 IgSoAxis::IgSoAxis ()
00033 {
00034 SO_KIT_CONSTRUCTOR (IgSoAxis);
00035 SO_KIT_ADD_FIELD (divisions, (3));
00036 SO_KIT_ADD_FIELD (divisionLength, (0.5));
00037 SO_KIT_ADD_FIELD (label, ("Z"));
00038 SO_KIT_ADD_FIELD (totalLength, (2.0));
00039 SO_KIT_ADD_FIELD (offset, (false));
00040
00041 SO_KIT_ADD_CATALOG_ENTRY (line, SoLineSet, FALSE, separator,\x0, TRUE);
00042 SO_KIT_ADD_CATALOG_ENTRY (head, SoSeparator, FALSE, separator,\x0, TRUE);
00043 SO_KIT_ADD_CATALOG_ENTRY (headTrans, SoTransform, FALSE, head,\x0, TRUE);
00044 SO_KIT_ADD_CATALOG_ENTRY (headCone, SoCone, FALSE, head,\x0, TRUE);
00045 SO_KIT_ADD_CATALOG_ENTRY (markers, SoSeparator, FALSE, separator,\x0, TRUE);
00046 SO_KIT_ADD_CATALOG_ENTRY (font, SoFont, FALSE, separator,\x0, TRUE);
00047 SO_KIT_ADD_CATALOG_ENTRY (labelSep, SoSeparator, FALSE, separator,\x0, TRUE);
00048 SO_KIT_ADD_CATALOG_ENTRY (labelTrans, SoTranslation, FALSE, labelSep,\x0, TRUE);
00049 SO_KIT_ADD_CATALOG_ENTRY (labelText, SoText2, FALSE, labelSep,\x0, TRUE);
00050
00051 SO_KIT_INIT_INSTANCE ();
00052 setUpConnections (true, true);
00053 }
00054
00055 void
00056 IgSoAxis::refresh ()
00057 {
00058
00059 float axisLength ;
00060 axisLength = (offset.getValue ()) ? (totalLength.getValue ()): (divisionLength.getValue () * divisions.getValue ());
00061
00062
00063 SoVertexProperty *vtx = new SoVertexProperty;
00064 SoLineSet *line = new SoLineSet;
00065 SoTransform *headTrans = new SoTransform;
00066 SoCone *headCone = new SoCone;
00067 SoSeparator *markers = new SoSeparator;
00068 SoFont *font = new SoFont;
00069 SoTranslation *labelTrans = new SoTranslation;
00070 SoText2 *labelText = new SoText2;
00071
00072
00073 vtx->vertex.set1Value (0, SbVec3f (0, 0, 0));
00074 vtx->vertex.set1Value (1, SbVec3f (0, 0, axisLength));
00075 line->startIndex = 0;
00076 line->numVertices = 2;
00077 line->vertexProperty = vtx;
00078
00079
00080 float coneHeight;
00081
00082 if (offset.getValue ())
00083 {
00084
00085
00086 coneHeight = (axisLength >= 2.0) ? 0.25: axisLength / 8.0;
00087 }
00088 else
00089 {
00090 coneHeight = axisLength / 8.0;
00091 }
00092
00093 headCone->bottomRadius = divisionLength.getValue () / 10;
00094 headCone->height = coneHeight;
00095 if (offset.getValue ())
00096 {
00097 headTrans->translation.setValue (0, 0, axisLength - coneHeight / 2);
00098 }
00099 else
00100 {
00101 headTrans->translation.setValue (0, 0, axisLength + coneHeight / 2);
00102 }
00103
00104 headTrans->rotation.setValue (SbVec3f (1, 0, 0), M_PI / 2);
00105
00106
00107 SoRotation *markerRot = new SoRotation;
00108 markerRot->rotation.setValue (SbVec3f (1, 0, 0), M_PI / 2);
00109 markers->addChild (markerRot);
00110
00111 long divs = divisions.getValue () - 1;
00112 if (divs >= 1)
00113 {
00114 SoCylinder *marker = new SoCylinder;
00115 marker->radius.setValue (divisionLength.getValue () / 10);
00116 marker->height.setValue (axisLength / 200);
00117
00118 for (int div = 0; div < divs ; div++)
00119 {
00120 SoTranslation *offset = new SoTranslation;
00121 offset->translation.setValue (0, divisionLength.getValue (), 0);
00122 markers->addChild (offset);
00123 markers->addChild (marker);
00124 }
00125 }
00126
00127
00128 font->size.setValue (16.0);
00129 font->name.setValue ("Times-Roman");
00130 labelTrans->translation.setValue (0, 0, 1.05 * (axisLength + coneHeight));
00131 labelText->string = label.getValue ();
00132 labelText->justification = SoText2::CENTER;
00133
00134 setPart ("line", line);
00135 setPart ("headTrans", headTrans);
00136 setPart ("headCone", headCone);
00137 setPart ("markers", markers);
00138 setPart ("font", font);
00139 setPart ("labelTrans", labelTrans);
00140 setPart ("labelText", labelText);
00141 }