MeVisLabToolboxReference
MeVisLab/Standard/Sources/Inventor/SoView2D/extensions/SoView2DMarkerEditor.h
Go to the documentation of this file.
00001 #ifndef __SoView2DMarkerEditor_H
00002 #define __SoView2DMarkerEditor_H
00003 //----------------------------------------------------------------------------------
00004 // **InsertLicense** code
00005 //----------------------------------------------------------------------------------
00008 
00014 //
00015 // Originally implemented by Florian Link, now handled by Lars Bornemann
00016 //
00017 // Implements an editor for an XMarkerList (from MLBase) to edit
00018 // markers (and vectors) on a SoView2D or SoOrthoView2D viewer
00019 //----------------------------------------------------------------------------------
00020 
00021 #ifndef __SoView2DSystem_H
00022 #include "SoView2DSystem.h"
00023 #endif
00024 #ifndef __SoView2DInteractionExtension_H
00025 #include "SoView2DInteractionExtension.h"
00026 #endif
00027 #ifndef __SoView2D_H
00028 #include "SoView2D.h"
00029 #endif
00030 #ifndef __SoSFMLBase_H
00031 #include "SoSFMLBase.h"
00032 #endif
00033 
00034 #ifndef __mlXMarkerList_H
00035 #include "mlXMarkerList.h"
00036 #endif
00037 #ifndef __mlStylePalette_H
00038 #include "mlStylePalette.h"
00039 #endif
00040 
00041 #ifndef __mlSphere_H
00042 #include "mlSphere.h"
00043 #endif
00044 #ifndef __mlDisc_H
00045 #include "mlDisc.h"
00046 #endif
00047 
00048 class View2DIcons;
00049 
00050 //=============================================================
00054 
00058 //=============================================================
00059 class SOVIEW2D_API SoView2DMarkerEditor : public SoView2DInteractionExtension {
00060 
00061   SO_NODE_HEADER(SoView2DMarkerEditor);
00062 
00063 public:
00064 
00066   enum vectorDragMode {
00067     VECTOR_DRAG_NONE,
00068     VECTOR_DRAG_STARTPOINT,
00069     VECTOR_DRAG_ENDPOINT,
00070     VECTOR_DRAG_OFFSET,
00071     VECTOR_DRAG_MOVE,
00072     VECTOR_DRAG_RESIZE
00073   };
00074 
00076   enum editorModeType {
00077   EDIT_VECTOR=0,
00078   EDIT_MARKER=1,
00079   EDIT_OBJECT=2
00080   };
00081 
00083   enum drawModeType {
00084   DRAW_VECTOR=0,
00085   DRAW_MARKER,
00086 //  DRAW_BOX,
00087   DRAW_DISC,
00088   DRAW_SPHERE,
00089   DRAW_VECTOR_AND_DISC
00090   };
00091 
00093   enum editorColorType {
00094   COLOR_BY_INDEX=0,
00095   COLOR_BY_TYPE=1,
00096   COLOR_BY_ID=2
00097   };
00098 
00100   enum textColorType {
00101   COLOR_LIKE_MARKER=0,
00102   COLOR_TEXT=1
00103   };
00104 
00106   enum textModeType {
00107   TEXT_OFF,
00108   TEXT_STYLEINDEX,
00109   TEXT_STYLENAME,
00110   TEXT_ITEMNAME,
00111   TEXT_ITEMID,
00112   TEXT_VOXELPOS,
00113   TEXT_WORLDPOS,
00114   TEXT_LENGTH,
00115   TEXT_MARKERTYPE,
00116   TEXT_MARKERLISTINDEX,
00117   };
00118 
00120   enum textPositionType {
00121   TEXT_POSITION_CENTER,
00122   TEXT_POSITION_ABOVE,
00123   TEXT_POSITION_RIGHT_ABOVE,
00124   TEXT_POSITION_RIGHT,
00125   TEXT_POSITION_RIGHT_BELOW,
00126   TEXT_POSITION_BELOW,
00127   TEXT_POSITION_LEFT_BELOW,
00128   TEXT_POSITION_LEFT,
00129   TEXT_POSITION_LEFT_ABOVE,
00130   };
00131 
00133   enum vectorArrowType {
00134       VECTOR_NO_ARROWS=0,
00135       VECTOR_END_ARROW=1,
00136       VECTOR_START_ARROW=2,
00137       VECTOR_BOTH_ARROWS=3,
00138       VECTOR_PLUS_MINUS=4,
00139       // draws vector and - vector biginning at the center,
00140       // e.g indication, center of mass and max expansion
00141       VECTOR_PM_WITH_ARR=5,
00142       // as above but with arrows
00143       BOX_START_TO_END=6,
00144       // draws an box with corners at the marker
00145       // and the marker plus vector location
00146       BOX_PLUS_MINUS=7,
00147       // draws an box with center at the marker
00148       // and corners at the marker plus vector
00149       // and marker - vector location
00150       // the drawing stype can be controled
00151       // by depthVisibility, where the bits 1..32
00152       // are used as flags turning on and off
00153       // different partes of the dephth clued
00154       // in the 2D projection of the box
00155 
00156       // draws a vector + a sphere which is defined by the vector
00157       // VECTOR_AND_SPHERE=8,
00158       // draws a vector + a dics which is defined by the vector
00159       // (interpreting it as its normal vector and the length of the vector as its radius)
00160       // VECTOR_AND_DISC=9
00161   };
00162 
00164   enum depthVectorDrawType
00165   {
00166     DRAW_NONE,      
00167     DRAW_HIGHLIGHT_SLICE_SEGMENT,
00168   };
00169 
00171   enum depthVisibilityType
00172   {
00174     DEPTH_IN_SLICES,
00176     DEPTH_IN_MM
00177   };
00178 
00180 
00183   SoSFFloat depthVisibility;
00184 
00186   SoSFEnum  depthVisibilityMode;
00187 
00189   SoSFBool  snapToVoxel;
00190 
00192   SoSFEnum  editorMode;
00193 
00195   SoSFBool  deleteOnClick;
00196 
00198   SoSFBool  addOnClick;
00199 
00201   SoSFBool  selectingOn;
00202 
00204   SoSFBool  actOnReleaseOnly;
00205 
00207   SoSFEnum  colorMode;
00208 
00210   SoSFEnum  textMode;
00212   SoSFEnum  textPosition;
00214   SoSFEnum  textColorMode;
00216   SoSFColor textColor;
00218   SoSFBool  textShadow;
00220   SoSFInt32 textFontSize;
00222   SoSFBool  showTextOnlyForSelectedMarker;
00224   SoSFBool  cutText;
00226   SoSFInt32 maxNumberOfLines;
00227 
00229   SoSFEnum vectorArrow;
00231   SoSFInt32 vectorLineWidth;
00232 
00234   SoSFFloat alphaFactor;
00235 
00237   SoSFFloat minimumAlpha;
00238 
00240   SoSFInt32 currentType;
00241 
00244   SoSFMLBase  outputMLModule;
00245 
00247   SoSFMLBase  stylePalette;
00248 
00252   SoSFBool drawMarkerShapesWithLines;
00253 
00255   SoSFBool    useIconFile;
00257   SoSFInt32   iconIdx;
00259   SoSFString  iconFile;
00261   SoSFString  internalIconFile;
00262 
00264   SoSFInt32   currentStyleIndex;
00265 
00267   SoSFEnum    depthVectorDrawMode;
00268 
00270   SoSFEnum    drawMode;
00271 
00273   SoSFBool    highlightSelection;
00274 
00276   SoSFBool useAntiAlias;
00277 
00279   SoSFBool useVectorLengthAsMarkerSize;
00280 
00283   SoSFBool    selectiveDrawing;
00284 
00287   SoSFBool selectionBoxesForCurrentOnly;
00288 
00293   SoSFBool  cooperative;
00294 
00297   SoSFBool busy;
00298 
00300   SoSFBool  snapToSlice;
00301     
00303   SoSFBool overwriteCurrentTimePoint;
00305   SoSFInt32 newCurrentTimePoint;
00306 
00308 
00310   static void   initClass();
00311 
00313   SoView2DMarkerEditor();
00314 
00316   void draw(View2DSliceList *dsl, View2DSlice* dslice, int slice);
00317 
00318 
00320   bool   evalEvent(SoView2D* view2d, View2DSliceList* slicelist,
00321                    View2DEvent* ec, View2DEventPhase phase);
00322 
00324   static bool handleNotificationCB(void *usrData, ml::Field* field);
00325 
00327   void deleteSelectedObject();
00328 
00330   bool isActive();
00331 
00333   void setupIcons();
00334 
00336   bool ignoreEvent(View2DEvent* ec);
00337 
00338 protected:
00339   // stores the last cursor position where the modification (movement, resizing) of the selected marker occured
00340   ml::vec3 _lastWorldPosition;
00341   // holds the index of the currently selected marker. Can be -1, so must be signed.
00342   MLssize_t _selectedObjectIndex;
00343 
00345   bool _pointDragged;
00347   vectorDragMode _vectorDragged;
00348 
00350   ml::ListBase::ActionClass _currAction;
00352   MLssize_t                 _currIndex;
00354   ml::XMarker               _currItem;
00355 
00357   View2DIcons*              _icons;
00358 
00360   ml::XMarkerListContainer  _container;
00362   ml::StylePalette*         _palette;
00363 
00365   MLssize_t performHitTest(float deviceX, float deviceY, const SbVec3f& eventVoxel, View2DSliceList* slicelist,
00366                            vectorDragMode& dragMode);
00367 
00369   void immediateItemAction(ml::ListBase::ActionClass action, MLssize_t index);
00370 
00373   void itemAction(ml::ListBase::ActionClass action, MLssize_t index);
00374 
00379   bool startDrag(float deviceX, float deviceY, const SbVec3f& eventVoxel, View2DSliceList* slicelist,
00380                  bool validLocation, bool performAction);
00381 
00384   void performDrag(const SbVec3f& eventVoxel, View2DSliceList* slicelist);
00385 
00387   void finishDrag();
00388 
00390 
00391   virtual int getCurrentCursor(SoViewerProxy* viewerProxy);
00392   virtual bool isSensitiveAt(const SoPointerPosition& pos);
00393   virtual void startPressAt(const SoPointerPosition& pos);
00394   virtual void dragMoveTo(const SoPointerPosition& pos);
00395   virtual SoPointingAction* endPress(int clickCount);
00397 
00399   int  calculateCurrentStyleIndex();
00401   MLssize_t  isDiscHit(const ml::vec3 &cursorPosition, View2DSliceList* slicelist, vectorDragMode& dragMode);
00403   MLssize_t  isSphereHit(const ml::vec3 &cursorPosition, View2DSliceList* slicelist, vectorDragMode& dragMode);
00405   MLssize_t  isBoxHit(const ml::vec3 &cursorPosition, View2DSliceList* slicelist, vectorDragMode& dragMode);
00407   void resizeObject(const ml::vec3 &startCursorPosition, const ml::vec3 &endCursorPosition, ml::XMarkerList* markers);
00409   void moveObject(const ml::vec3 &startCursorPosition, const ml::vec3 &endCursorPosition, ml::XMarkerList* markers);
00411   bool markerIsHit(float markerSize, float pointX, float pointY, float centerX, float centerY,
00412                    bool shouldSnapToVoxel, SbVec3f hitPositionVoxel, SbVec3f markerPositionVoxel);
00414   bool isDepthVisible(float depthValue, float voxelSizeZ);
00415 
00417   float getDepthVisibilityBlendValue(float distance, float voxelSizeZ);
00420   bool isVectorDepthVisible(float depthValue1, float depthValue2, int slice, float voxelSizeZ);
00422   bool isVectorCrossedBySlice(float depthValue1, float depthValue2, int slice, float voxelSizeZ);
00424   bool isDiscVisible(ml::Disc* disc, View2DSliceList* slicelist, int slice);
00426   bool isSphereVisible(View2DSliceList* slicelist, const ml::vec3 &center, float radius, int slice);
00428   void drawVector(const ml::XMarker& marker, bool isSelected, int markerIndex, 
00429                   View2DSliceList* slicelist, View2DSlice* dslice, int slice, float voxelSizeZ, const SbVec4f& originalMarkerColor);
00431   void drawVectorCrossedBySlices(const ml::XMarker& marker, bool isSelected, float lineWidth, int markerIndex, View2DSliceList* slicelist, View2DSlice* dslice, int slice);
00433   void drawVectorCross(float deviceX1, float deviceY1, float deviceX2, float deviceY2, float lineWidth);
00435   void drawVectorBelow(float deviceX1, float deviceY1, float deviceX2, float deviceY2, float lineWidth);
00437   void drawVectorAbove(float deviceX1, float deviceY1, float deviceX2, float deviceY2, float lineWidth);
00439   void drawVectorBox(const ml::XMarker& marker, bool isSelected, int markerIndex, int lineWidth, View2DSliceList* slicelist, View2DSlice* dslice, int slice);
00441   void drawVectorArrowHeads(const ml::XMarker& marker, bool isSelected, int markerIndex, View2DSliceList* slicelist, View2DSlice* dslice, int slice);
00443   void drawVectorArrowHead(const SbVec2f& deviceStart, const SbVec2f& deviceEnd, bool isEndArrow);
00445   void drawMarker(float deviceX, float deviceY, int size, bool selected, int markerindex, const ml::XMarker& marker);
00447   void drawMarkerWithLines (ml::StylePalette::MarkerType markertype, float deviceX, float deviceY, float size, int lineWidth, bool antiAlias, const ml::XMarker& marker);
00449   int getPaletteIndex(const ml::XMarker& marker, int i);
00451   void drawSphere(ml::Sphere* s, View2DSliceList *dsl, View2DSlice* dslice, int slice, float r, float g, float b, bool bHighlight, float alphaFactor=1.0f) ;
00453   void drawDisc(ml::Disc* d, View2DSliceList *dsl, View2DSlice* dslice, int slice, float r, float g, float b, bool bHighlight, float alphaFactor=1.0f);
00455   void drawTextForMarker(const ml::XMarker& marker, MLssize_t index, float vx, float vy, float vz, size_t i, View2DSlice* dslice, const ml::XMarkerList* markers, float * rgba );
00456 
00458   void updatePalette();
00463   virtual int getTimePoint(View2DSliceList* slicelist, int slice);
00465   void computeVoxelMinMaxZ(float& minz, float& maxz, const ml::XMarker& marker, View2DSliceList* slicelist);
00467   void getProjectedDeviceCoordinates(const ml::XMarker& marker, SbVec3f& voxelStartPosition, SbVec3f& voxelEndPosition, 
00468                                      float& deviceStartX, float& deviceStartY, float& deviceEndX, float& deviceEndY,
00469                                      int slice, View2DSliceList* slicelist);
00471   void getProjectedDeviceCoordinates(const ml::XMarker& marker, 
00472                                      float& deviceStartX, float& deviceStartY, float& deviceEndX, float& deviceEndY,
00473                                      int slice, View2DSliceList* slicelist);
00475   void getProjectedDeviceCoordinates(const SbVec3f& voxelStartPosition, const SbVec3f& voxelEndPosition, 
00476                                      float& deviceStartX, float& deviceStartY, float& deviceEndX, float& deviceEndY,
00477                                      int slice, View2DSliceList* slicelist);
00479   void getProjectedDeviceCoordinates(const SbVec3f& voxelPosition, float& deviceX, float& deviceY, int slice, View2DSliceList* slicelist);
00480 
00482   void convertMarkerVectorToVoxel(const ml::XMarker& marker, SbVec3f& voxelStartPosition, SbVec3f& voxelEndPosition, View2DSliceList* slicelist);
00484   GLushort getStipplePattern(GLint lineWidth);
00485 
00486 protected:
00488   virtual ~SoView2DMarkerEditor();
00489 };
00490 
00491 
00492 #endif