MeVisLabToolboxReference
|
00001 #ifndef __SoView2D_H 00002 #define __SoView2D_H 00003 //---------------------------------------------------------------------------------- 00004 // **InsertLicense** code 00005 //---------------------------------------------------------------------------------- 00007 00013 //---------------------------------------------------------------------------------- 00014 00015 // define the below to compile in debug output of field changes on SoView2D nodes 00016 //#define SOVIEW2D_TRACE 00017 00018 #ifndef __SoSFMLImage_H 00019 #include "SoSFMLImage.h" 00020 #endif 00021 #ifndef __SoView2DSystem_H 00022 #include "SoView2DSystem.h" 00023 #endif 00024 #ifndef __SoView2DExtension_H 00025 #include "SoView2DExtension.h" 00026 #endif 00027 00028 #include <Inventor/fields/SoFields.h> 00029 #include <Inventor/nodes/SoSubNode.h> 00030 #include <Inventor/nodes/SoShape.h> 00031 #include <Inventor/sensors/SoTimerSensor.h> 00032 #include <Inventor/sensors/SoAlarmSensor.h> 00033 #include <Inventor/sensors/SoFieldSensor.h> 00034 #include <Inventor/sensors/SoNodeSensor.h> 00035 #include <Inventor/nodes/SoSubNode.h> 00036 #include <Inventor/elements/SoCacheElement.h> 00037 00038 class View2DSliceList; 00039 class View2DFont; 00040 00041 class SoInteractionHandler; 00042 class SoInteractionProvider; 00043 00044 ML_START_NAMESPACE 00045 00046 class LUTFunction; 00047 template <typename T> class LUTData; 00048 00049 ML_END_NAMESPACE 00050 00051 typedef enum View2DCineMode { 00052 CINE_Z=0, CINE_T, CINE_ZT, 00053 } View2DCineModeType; 00054 00055 typedef enum View2DCineDir { 00056 CINE_FORWARD=0, CINE_PINGPONG 00057 } View2DCineDirType; 00058 00059 typedef enum View2DCineRepeat { 00060 CINE_ONCE=0, CINE_REPEAT 00061 } View2DCineRepeatType; 00062 00063 typedef enum View2DZoomMode { 00064 VIEW2D_AUTO_ZOOM, 00065 VIEW2D_AUTO_ZOOM_X, 00066 VIEW2D_AUTO_ZOOM_Y, 00067 VIEW2D_FIXED_PIXELS_PER_VOXEL_X, 00068 VIEW2D_FIXED_PIXELS_PER_VOXEL_Y, 00069 VIEW2D_FIXED_PIXELS_PER_MM, 00070 VIEW2D_FIXED_MM_PER_VIEWER_HEIGHT, 00071 VIEW2D_FIXED_MM_PER_VIEWER_WIDTH, 00072 VIEW2D_SCALE_TO_VIEWER_IGNORE_RATIO 00073 } View2DZoomModeType; 00074 00076 enum View2DLutPrecision { 00077 VIEW2D_LUT_AUTO, 00078 VIEW2D_LUT_8BIT, 00079 VIEW2D_LUT_12BIT, 00080 VIEW2D_LUT_16BIT 00081 }; 00082 00084 typedef int (*SliceInitFunc) (const SoView2D *view2D, SoSFMLImage *image, void *user); 00085 00086 00087 //============================================================= 00090 00095 //============================================================= 00096 class SOVIEW2D_API SoView2D : public SoShape { 00097 00098 SO_NODE_HEADER(SoView2D); 00099 00100 public: 00102 00104 SoSFMLImage image; 00105 00107 SoSFBool drawImageData; 00108 00110 SoSFString viewerId; 00111 00113 SoSFEnum blendMode; 00115 SoSFEnum filterMode; 00117 SoSFEnum cacheMode; 00119 SoSFFloat alphaFactor; 00121 SoSFColor baseColor; 00124 SoSFBool useShaders; 00126 SoSFBool applyLut; 00128 SoSFEnum lutPrecision; 00129 00131 SoSFInt32 startSlice; 00133 SoSFInt32 sliceStep; 00135 SoSFInt32 numSlices; 00137 SoSFInt32 numXSlices; 00139 SoSFInt32 maxSlice; 00142 SoSFBool keepSlicesInView; 00144 SoSFInt32 timePoint; 00146 SoSFInt32 maxTimePoint; 00148 SoSFInt32 slab; 00150 SoSFBool unzoomOnImageChange; 00151 00152 00154 SoSFVec2f margin; 00156 SoSFVec2f spacing; 00157 00159 SoSFPlane plane; 00160 00162 SoSFVec2f lowerLeft; 00164 SoSFVec2f upperRight; 00165 00167 SoSFBool snapToCenter; 00168 00170 SoSFBool standardKeys; 00172 SoSFBool standardKeysNumbers; 00174 SoSFBool standardKeysNeedValidPosition; 00175 00179 SoSFBool passHandledFlagToInventor; 00180 00182 SoSFBool reverseExtensionDrawingOrder; 00183 00185 SoSFVec2f sliceOrigin; 00187 SoSFFloat sliceZoom; 00189 SoSFFloat sliceZoomSynchronized; 00191 SoSFVec2f zoomCenter; 00192 00194 SoSFVec3f viewingCenter; 00195 00197 SoSFBool enableViewingCenter; 00198 00200 SoSFFloat minSliceZoomKeyboard; 00201 00203 SoSFTrigger unzoom; 00204 00206 SoSFColor backgroundColor; 00208 SoSFFloat backgroundAlphaFactor; 00209 00211 SoSFBool handle2DEvents; 00212 00214 SoSFBool handle3DEvents; 00215 00217 SoSFBool useManagedInteraction; 00218 00220 SoSFBool enableZBuffer; 00221 00223 SoSFBool enableZWrite; 00224 00226 SoSFFloat devicePixelSize; 00227 00229 00231 00233 SoSFTrigger startCine; 00235 SoSFTrigger stopCine; 00237 SoSFInt32 cineCenterT; 00239 SoSFInt32 cineIntervalT; 00241 SoSFInt32 cineCenterZ; 00243 SoSFInt32 cineIntervalZ; 00245 SoSFEnum cineMode; 00247 SoSFEnum cineDirection; 00249 SoSFEnum cineRepeat; 00251 SoSFFloat cineSpeed; 00252 00254 SoSFBool cineFullRangeZ; 00256 SoSFBool cineFullRangeT; 00257 00260 SoSFBool cineAlwaysReset; 00261 00263 SoSFEnum sliceAlignX; 00265 SoSFEnum sliceAlignY; 00266 00267 00269 SoSFEnum zoomMode; 00271 SoSFFloat zoomModeParameter; 00272 00274 SoSFBool invertKeyPanningDirections; 00275 00277 SoSFBool overrideAspectRatio; 00279 SoSFFloat overrideAspectRatioValue; 00280 00282 00284 SoSFTrigger deleteSelected; 00286 SoSFTrigger edit; 00287 00289 SoSFString status; 00290 00292 SoSFString seriesInstanceUID; 00293 00295 SoSFBool deletingEnabled; 00296 00297 00299 00301 static void initClass(); 00302 00304 SoView2D(); 00305 00307 SbString getViewerId() const { return viewerId.getValue(); } 00309 View2DSliceList* getSliceList(); 00310 00312 SbVec2f getSliceSize(); 00313 00316 SoAction *getAction() { return _action; } 00317 00319 virtual void GLRender(SoGLRenderAction *action); 00321 virtual void handleEvent(SoHandleEventAction *action); 00323 virtual void computeBBox(SoAction * action, SbBox3f &box, SbVec3f ¢er); 00325 virtual void generatePrimitives(SoAction *action); 00326 00334 bool getEventLocation(SoHandleEventAction* action, 00335 bool& hit, float& dx, float& dy, SbVec3f& voxelHit, 00336 int& sliceID); 00337 00338 00340 static View2DFont* globalFont(); 00341 00343 static View2DFont* globalFont(int /*cacheContext*/) { return globalFont(); } 00344 00347 static View2DFont& globalFontRef(); 00348 00350 int currentContext() { return _currentContext; } 00351 00359 void setSliceInitFunc (SliceInitFunc fn, void *user) 00360 { _sliceInitFunc = fn; _sliceInitUser = user; } 00361 00363 SliceInitFunc getSliceInitFunc (void) { return _sliceInitFunc; } 00364 00366 int getCurrentCenterSlice(); 00367 00370 void adjustSliceOriginToCenter(float newSliceZoom); 00371 00373 void translateInnerSlice(float x, float y); 00374 00376 void getStatusString(SbString& string); 00377 00379 ml::LUTFunction* getDefaultLut() { return _localLut; } 00380 00382 ml::LUTFunction* getLutFromScene(SoAction* action); 00383 00388 bool updateLutData(ml::LUTFunction* lut, ml::LUTData<MLuint8>* data, SoSFMLImage* img, View2DLutPrecision precision); 00389 00391 void startCineMode(); 00392 00394 void stopCineMode(); 00395 00398 SbVec2f getSingleSliceSize (int windowX, int windowY); 00399 00401 int getMaxStartSlice(); 00402 00403 protected: 00405 virtual ~SoView2D(); 00406 00410 SbBool isMouseButtonPressed(int i); 00411 00413 bool isDeviceCoordInViewerArea (float dx, float dy, SoHandleEventAction *action); 00414 00416 static void imageChangedCB(void *data, SoSensor* a); 00418 void imageChanged(); 00419 00421 static void sliceUnzoomCB(void *data, SoSensor* a); 00423 void sliceUnzoomAction (void); 00424 00426 static void updateViewingCenterCB(void *data, SoSensor* a); 00428 void updateViewingCenter(); 00429 00432 static void enableViewingCenterChangedCB(void *data, SoSensor* a); 00433 00435 static void viewingCenterChangedCB(void *data, SoSensor* a); 00438 void viewingCenterChanged(); 00439 00441 static void sliceZoomChangedCB(void *data, SoSensor* a); 00443 void sliceZoomChanged(); 00444 00446 static void sliceZoomSynchronizedChangedCB(void *data, SoSensor* a); 00448 void sliceZoomSynchronizedChanged(); 00449 00451 static void keepSlicesInViewCB (void *data, SoSensor* a); 00452 00456 int setStartSlice (int slice, bool keepInView = false, bool noCB = false); 00457 00459 static void minSliceZoomKeyboardCB(void *data, SoSensor* a); 00460 00462 static void cineTimerSensorCB(void *data, SoSensor* a); 00464 void cineTimerSensor(); 00465 00467 static void startCineModeCB(void *data, SoSensor* a); 00469 static void stopCineModeCB(void *data, SoSensor* a); 00470 00472 static void deleteSelectedObjectCB(void *data, SoSensor* a); 00474 void deleteSelectedObjectAction(); 00476 static void editObjectsCB(void *data, SoSensor* a); 00478 void editObjectsAction(); 00479 00481 void handleScheduledActions(const SoNodeList* primitives); 00482 00484 int getCineStartZ(); 00486 int getCineEndZ(); 00488 int getCineStartT(); 00490 int getCineEndT(); 00491 00493 void getLutFromScene(SoAction* action, ml::LUTData<MLuint8>* data); 00494 00496 void layoutSlices(int wx, int wy); 00497 00499 void updateLayoutAndDraw(int originX, int originY, int width, int height, bool updateLayoutOnly, 00500 SoNodeList* primitives=0,int sharedCacheContext=-1, bool is3D = false, bool reverse = false); 00501 00503 bool handleKeyboardEvent(int nKey, bool shift, bool alt, bool ctrl); 00504 00506 SoAction *_action; 00507 00509 View2DSliceList *_sliceList; 00511 ml::LUTFunction *_localLut; 00513 ml::LUTData<MLuint8> *_lutData; 00514 00516 MLDataType _currentLUTImageDataType; 00517 double _currentLUTImageMin; 00518 double _currentLUTImageMax; 00519 int _currentLUTImageNumChannels; 00521 00522 00524 SbBool _mouseButton[3]; 00525 00527 SoTimerSensor *_cineTimer; 00529 SoFieldSensor *_imageSensor; 00531 SoFieldSensor *_startCine; 00533 SoFieldSensor *_stopCine; 00535 SoFieldSensor *_sliceUnzoom; 00537 SoFieldSensor *_minSliceZoomKeyboardSensor; 00539 SoFieldSensor *_editObjects; 00541 SoFieldSensor *_deleteSelectedObject; 00542 00544 SoFieldSensor *_viewingCenterSensor; 00546 SoFieldSensor *_enableViewingCenterSensor; 00547 00549 SoFieldSensor *_sliceAlignXSensor; 00551 SoFieldSensor *_sliceAlignYSensor; 00552 00554 SoFieldSensor *_startSliceSensor; 00556 SoFieldSensor *_numSlicesSensor; 00558 SoFieldSensor *_sliceStepSensor; 00560 SoFieldSensor *_keepSlicesInViewSensor; 00561 00563 SoFieldSensor *_sliceZoomSensor; 00564 00565 SoFieldSensor *_sliceZoomSynchronizedSensor; 00566 00568 SoFieldSensor *_sliceOriginSensor; 00569 00571 bool _cineStep; 00573 bool _cineBackward; 00574 00576 bool _editObjectsScheduled; 00578 bool _deleteSelectedObjectScheduled; 00579 00581 bool _dragging; 00582 00584 View2DEvent _lastPressEvent; 00585 00587 SliceInitFunc _sliceInitFunc; 00589 void *_sliceInitUser; 00590 00592 unsigned int _imageSerialNumber; 00593 00595 static View2DFont* _globalFont; 00597 int _currentContext; 00598 00600 friend class View2DInteractionHandler; 00601 friend class View2DInteractionProvider; 00602 00604 SoInteractionHandler* _interactionHandler; 00606 SoInteractionProvider* _interactionProvider; 00608 00609 #ifdef SOVIEW2D_TRACE 00610 00611 SoNodeSensor *_debugSensor; 00612 00614 static void debugSensorCB(void *data, SoSensor *sensor); 00616 void debugSensor(SoNodeSensor* sensor); 00617 #endif 00618 }; 00619 00620 #endif 00621 00622 00623 00624 00625