00001 00002 // 00003 // SliceScaleBar utility class 00004 // 00005 // Mike Heck, VSG Inc, December 2011 00006 // 00008 00010 // 00011 // This class is part of the Open Inventor Medical utility library. 00012 // 00013 // The medical utility classes are provided as a prebuilt library named 00014 // "fei_inventor_medical", that can be used directly in an Open Inventor 00015 // application. The classes in the prebuilt library are documented and 00016 // supported by FEI. These classes are also provided as source code. 00017 // 00018 // Please see $OIVHOME/include/Medical/InventorMedical.h for the full text. 00019 // 00021 00022 #ifndef _SLICE_SCALE_BAR_H 00023 #define _SLICE_SCALE_BAR_H 00024 00025 #include <Inventor/nodes/SoAnnotation.h> 00026 00027 #include <Inventor/fields/SoSFEnum.h> 00028 #include <Inventor/fields/SoSFFloat.h> 00029 #include <Inventor/fields/SoSFInt32.h> 00030 #include <Inventor/fields/SoSFNode.h> 00031 #include <Inventor/fields/SoSFString.h> 00032 #include <Inventor/fields/SoSFVec2f.h> 00033 00034 class SoAction; 00035 class SoDrawStyle; 00036 class SoFont; 00037 class SoLineSet; 00038 class SoMaterial; 00039 class SoSeparator; 00040 class SoText2; 00041 class SoTranslation; 00042 class SoVertexProperty; 00043 class SoNodeSensor; 00044 00089 class INVENTORMEDICAL_API SliceScaleBar : public SoAnnotation { 00090 00091 SO_NODE_HEADER(SliceScaleBar); 00092 00093 public: 00094 00096 SoSFVec2f position; 00097 00105 SoSFFloat length; 00106 00112 SoSFInt32 numTickIntervals; 00113 00119 SoSFNode trackedCamera; 00120 00122 SoSFEnum orientation; 00123 00125 SoSFEnum alignment; 00126 00128 SoSFString label; 00129 00131 enum Orientation { 00133 HORIZONTAL = 0, 00135 VERTICAL = 1 00136 }; 00137 00139 enum Alignment { 00141 LEFT = 0, 00143 BOTTOM = 0, 00145 CENTER = 1, 00147 RIGHT = 2, 00149 TOP = 2 00150 }; 00151 00153 SliceScaleBar(); 00154 00156 static void initClass(); 00157 00159 static void exitClass(); 00160 00161 private: 00163 virtual ~SliceScaleBar(); 00164 00166 void buildSceneGraph(); 00167 00169 void computeEndPoints( SbVec3f& p0, SbVec3f& p1 ); 00170 00171 SoRef<SoSeparator> m_lineSep; 00172 SoRef<SoLineSet> m_axisLineSet; 00173 SoRef<SoVertexProperty> m_vertProp; 00174 00175 SoRef<SoSeparator> m_textSep; 00176 SoRef<SoTranslation> m_labelPos; 00177 SoRef<SoFont> m_labelFont; 00178 SoRef<SoText2> m_labelText; 00179 00180 // TODO: Add title and labels 00181 //SoRef<SoFont> m_fontNode; 00182 00183 bool m_fieldsChanged; // Set when fields have changed 00184 float m_ndcLength; // Same as length field if not tracked 00185 SbVec3f m_p0; // Current end-points in NDC 00186 SbVec3f m_p1; // (they depend on orientation and alignment) 00187 00188 int m_tickLenPix; // Target tick line length in pixels 00189 float m_tickLenNdc; // Tick line length in NDC (depends on viewport) 00190 SbVec2i32 m_winSizePix; // Window size in pixels 00191 SbVec2f m_pixelPerNdc; // Converts 1 ndc unit to pixels (but not a coordinate) 00192 00193 SoNodeSensor* m_sensor; // Monitors changes to our fields 00194 static void sensorCB( void* data, SoSensor* sensor ); 00195 00196 static void staticCB( void* data, SoAction* action ); // Called during traversal 00197 void renderCB( SoAction* action ); 00198 00199 void resetLines(); // Remove all lines 00200 void addLine( SbVec3f& p0, SbVec3f& p1 ); // Add a new line (e.g. tick) 00201 00202 void updateAxis(); // Recreate/reposition axis geometry 00203 }; 00204 00205 #endif