MeVisLabToolboxReference
|
00001 #ifndef __SoView2DAnnotation_H 00002 #define __SoView2DAnnotation_H 00003 //---------------------------------------------------------------------------------- 00004 // **InsertLicense** code 00005 //---------------------------------------------------------------------------------- 00007 00013 //---------------------------------------------------------------------------------- 00014 #ifndef __SoView2DSystem_H 00015 #include "SoView2DSystem.h" 00016 #endif 00017 #ifndef __SoView2DExtension_H 00018 #include "SoView2DExtension.h" 00019 #endif 00020 00021 #include <Inventor/fields/SoSFString.h> 00022 #include <Inventor/fields/SoSFFloat.h> 00023 #include <Inventor/fields/SoSFDouble.h> 00024 #include <Inventor/fields/SoSFEnum.h> 00025 #include <Inventor/fields/SoSFInt32.h> 00026 #include <Inventor/fields/SoSFNode.h> 00027 #include <DCMTree_Tag.h> 00028 00029 class SoView2D; 00030 class View2DFont; 00031 class SoSeparator; 00032 class SoOrthographicCamera; 00033 class SoMatrixTransform; 00034 class SoDirectionalLight; 00035 00036 // Constant name definitions 00037 00038 enum AnnotationMode { 00039 ANNO_MODE_USER, 00040 ANNO_MODE_CT, 00041 ANNO_MODE_MR, 00042 ANNO_MODE_AUTO 00043 }; 00044 00045 enum AnnotationShowMode { 00046 ANNO_SHOW_HIDE = 0, 00047 ANNO_SHOW_SHORT = 1, 00048 ANNO_SHOW_DETAILED = 2 00049 }; 00050 00051 enum AnnotationFontSize { 00052 ANNO_SIZE_AUTO = -1, 00053 ANNO_SIZE_SMALL = 0, 00054 ANNO_SIZE_MEDIUM = 1, 00055 ANNO_SIZE_LARGE = 2, 00056 ANNO_SIZE_USER = 3 00057 }; 00058 00059 enum AnnotationOrientationMode { 00060 ANNO_ORIENTATION_OFF, 00061 ANNO_ORIENTATION_SIZE_FIXED, 00062 ANNO_ORIENTATION_SIZE_WEIGHTED 00063 }; 00064 00065 enum AnnotationOrientionModelPosition { 00066 ANNO_TOP_LEFT, 00067 ANNO_TOP_RIGHT, 00068 ANNO_BOTTOM_LEFT, 00069 ANNO_BOTTOM_RIGHT 00070 }; 00071 00072 //------------------------------------------------------------------------- 00074 00080 class SOVIEW2D_API SoView2DAnnotation : public SoView2DExtension { 00081 00082 SO_NODE_HEADER(SoView2DAnnotation); 00083 00084 public: 00085 00087 enum AlignPosition { 00088 TOP_LEFT, 00089 TOP_RIGHT, 00090 BOTTOM_LEFT, 00091 BOTTOM_RIGHT, 00092 BOTTOM_CENTER, 00093 CENTER_CENTER 00094 }; 00095 00097 00098 SoSFString annotationUserTopLeft; 00099 SoSFString annotationUserTopRight; 00100 SoSFString annotationUserBottomLeft; 00101 SoSFString annotationUserBottomRight; 00102 SoSFString annotationUserBottomCenter; 00103 00104 SoSFString annotationCTTopLeft; 00105 SoSFString annotationCTTopRight; 00106 SoSFString annotationCTBottomLeft; 00107 SoSFString annotationCTBottomRight; 00108 SoSFString annotationCTBottomCenter; 00109 00110 SoSFString annotationMRTopLeft; 00111 SoSFString annotationMRTopRight; 00112 SoSFString annotationMRBottomLeft; 00113 SoSFString annotationMRBottomRight; 00114 SoSFString annotationMRBottomCenter; 00115 00116 SoSFString shortTopLeft; 00117 SoSFString shortTopRight; 00118 SoSFString shortBottomLeft; 00119 SoSFString shortBottomRight; 00120 SoSFString shortBottomCenter; 00121 00122 SoSFInt32 minDetailFontSize; 00123 SoSFInt32 maxDetailFontSize; 00124 SoSFInt32 minShortFontSize; 00125 SoSFInt32 maxShortFontSize; 00126 SoSFInt32 userDetailFontSize; 00127 SoSFInt32 userShortFontSize; 00128 00129 SoSFEnum annotationMode; 00130 SoSFEnum showAnnotation; 00131 SoSFEnum annotationFontSize; 00132 SoSFBool textShadow; 00133 // new fields to influence font selection: 00134 SoSFString fontWidthDummyString; // fit this string into the target width instead of the real width if != "" 00135 SoSFInt32 targetWidth; // assume this to be the target width if != 0 00136 SoSFInt32 targetHeight; // assume this to be the target height if != 0 00137 00138 SoSFInt32 abreviateChars; 00139 SoSFInt32 abreviateShortChars; 00140 00141 SoSFEnum showOrientation; 00142 SoSFBool drawNegativeOrientation; 00143 SoSFBool drawPositiveOrientation; 00144 00145 SoSFBool verticalRuler; 00146 SoSFBool horizontalRuler; 00147 SoSFInt32 verticalRulerMarginRight; 00148 SoSFInt32 horizontalRulerMarginBottom; 00149 00150 SoSFBool orientationModel; 00151 SoSFEnum orientationModelPosition; 00152 SoSFFloat orientationModelRelativeSize; 00153 SoSFInt32 orientationModelMinSize; 00154 SoSFInt32 orientationModelMaxSize; 00155 SoSFColor orientationModelColor; 00156 00157 SoSFBool showTechnicalInfo; 00158 00159 SoSFString input00; 00160 SoSFString input01; 00161 SoSFString input02; 00162 SoSFString input03; 00163 SoSFString input04; 00164 SoSFString input05; 00165 SoSFString input06; 00166 SoSFString input07; 00167 SoSFString input08; 00168 SoSFString input09; 00169 00170 SoSFDouble numInput00; 00171 SoSFDouble numInput01; 00172 SoSFDouble numInput02; 00173 SoSFDouble numInput03; 00174 SoSFDouble numInput04; 00175 SoSFDouble numInput05; 00176 SoSFDouble numInput06; 00177 SoSFDouble numInput07; 00178 SoSFDouble numInput08; 00179 SoSFDouble numInput09; 00180 00181 // field for definition of background box 00182 SoSFBool drawBackgroundBox; 00183 SoSFColor backgroundColor; 00184 SoSFFloat backgroundOpacity; 00185 SoSFColor backgroundEdgeColor; 00186 SoSFFloat backgroundEdgeOpacity; 00187 00188 SoSFNode inOrientationModel; 00189 00192 SoSFBool orientationAndScaleFromCamera; 00194 00196 static void initClass(); 00197 00199 SoView2DAnnotation(); 00200 00201 ~SoView2DAnnotation(); 00202 00204 virtual void draw(View2DSliceList *dsl, View2DSlice* dslice, int slice); 00205 00207 virtual bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist, 00208 View2DEvent* ec, View2DEventPhase phase); 00209 00211 void toggleAnnotation(); 00212 void toggleTechnicalInfo(); 00213 00215 void parseString(View2DSliceList* list,View2DSlice* slice, const SbString &string , SbString &resultString, int limitToChars = -1); 00216 00218 void drawAnnotation(const char* string, float dx1,float dy1, float dx2, float dy2, 00219 View2DFont* font, int fontsize, AlignPosition pos, bool drawBox, float boxColor[4], float boxEdgeColor[4], 00220 int& outBoxWidth, int& outBoxHeight); 00221 00223 float decimalFloor(float number, SbString& result, int ÷r); 00224 00226 void drawVerticalRuler(View2DSliceList* dsl, View2DSlice* dslice, View2DFont* font, int marginRight, int dx1, int dy1, int dx2, int dy2); 00227 void drawHorizontalRuler(View2DSliceList* dsl, View2DSlice* dslice, View2DFont* font, int marginBottom, int dx1, int dy1, int dx2, int dy2); 00228 00231 static void getExtOrientation (int axis, SbMatrix &matrix, float *orWeights, 00232 char *negOrientation, char *posOrientation); 00233 00235 static void drawOrientation (const char *string, float posX, float posY, float fontSize, 00236 View2DFont* font, float relOffX, float relOffY, float *orWeights); 00237 00240 static SbVec2f getTargetSizeInScene (SoNode* scene, int width, int height); 00241 00243 struct Margins { 00244 Margins() { 00245 top = 0; bottom = 0; left = 0; right = 0; 00246 } 00247 Margins(int value) { 00248 top = value; bottom = value; left = value; right = value; 00249 } 00250 Margins(int top, int right, int bottom, int left) { 00251 this->top = top; 00252 this->right = right; 00253 this->bottom = bottom; 00254 this->left = left; 00255 } 00256 00257 int top; 00258 int bottom; 00259 int left; 00260 int right; 00261 }; 00262 00264 virtual Margins calculateTextMargins(int width, int height); 00265 00267 virtual Margins calculateCenterTextMargins(int width, int height); 00268 00270 virtual int calculateOrientationModelSize(int width, int height); 00271 00273 SbMatrix calculateOrientationModelRotationMatrix(View2DSlice* slice); 00274 00277 virtual void drawOrientationCube(const SbMatrix &rotationMatrix, int posX, int posY, int modelSize); 00278 00281 virtual void drawOrientationModelUsingInventor(SoAction* action, const SbMatrix &rotationMatrix, int posX, int posY, int modelSize); 00282 00286 virtual void drawOrientationCubeLetter(char letter, int modelSize, bool shadowPass); 00287 00289 virtual bool implementsManagedInteraction() const { return true; } 00290 00293 virtual bool implementsManagedInteractionAndClassicEventHandling() const { return true; } 00294 00296 virtual void fieldChanged(SoSensor* sensor); 00297 00298 protected: 00300 virtual SbString restrict(const SbString& value, int maxLength) const; 00301 00304 virtual SbString asString(int value) const; 00305 virtual SbString asString(double value, int precision) const; 00306 00309 virtual SbString getDicomTagValueAsString(DCMTree::Const_TagPtr tagPtr, unsigned int index, unsigned int precision) const; 00310 00311 private: 00313 SoSFString* _inputs[10]; 00314 SoSFDouble* _numInputs[10]; 00315 00317 long _lastEventSecs; 00319 long _lastEventUSecs; 00320 00322 int _spaceX; 00324 int _spaceY; 00326 int _lastFontSize; 00328 int _lastDetail; 00330 int _lastShowAnnotation; 00331 00332 SoSeparator* _orientationModelScene; 00333 SoSeparator* _orientationModelInnerScene; 00334 SoOrthographicCamera* _orientationModelCamera; 00335 SoDirectionalLight* _orientationModelHeadlight; 00336 00337 SoCommandAction* _toggleAnnotationAction; 00338 SoCommandAction* _toggleTechnicalInfoAction; 00339 }; 00340 00341 #endif