VTK
dox/Charts/vtkControlPointsItem.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkControlPointsItem.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00030 #ifndef __vtkControlPointsItem_h
00031 #define __vtkControlPointsItem_h
00032 
00033 #include "vtkCommand.h" // For vtkCommand enum
00034 #include "vtkPlot.h"
00035 #include "vtkVector.h" // For vtkVector2f
00036 
00037 class vtkCallbackCommand;
00038 class vtkContext2D;
00039 class vtkPoints2D;
00040 class vtkTransform2D;
00041 
00042 class VTK_CHARTS_EXPORT vtkControlPointsItem: public vtkPlot
00043 {
00044 public:
00045   vtkTypeMacro(vtkControlPointsItem, vtkPlot);
00046   virtual void PrintSelf(ostream &os, vtkIndent indent);
00047 
00048   enum {
00049     CurrentPointChangedEvent = vtkCommand::UserEvent,
00050     CurrentPointEditEvent
00051   };
00052 
00055   virtual void GetBounds(double bounds[4]);
00056 
00058 
00061   vtkSetVector4Macro(UserBounds, double);
00062   vtkGetVector4Macro(UserBounds, double);
00064 
00066 
00069   vtkSetVector4Macro(ValidBounds, double);
00070   vtkGetVector4Macro(ValidBounds, double);
00072 
00074 
00075   vtkGetMacro(ScreenPointRadius, float);
00076   vtkSetMacro(ScreenPointRadius, float);
00078 
00082   virtual bool Paint(vtkContext2D *painter);
00083 
00085   void SelectPoint(vtkIdType pointId);
00086 
00090   void SelectPoint(double* currentPoint);
00091 
00093   void SelectAllPoints();
00094 
00096   void DeselectPoint(vtkIdType pointId);
00097 
00101   void DeselectPoint(double* currentPoint);
00102 
00104   void DeselectAllPoints();
00105 
00108   void ToggleSelectPoint(vtkIdType pointId);
00109 
00113   void ToggleSelectPoint(double* currentPoint);
00114 
00116   virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
00117 
00119   vtkIdType GetNumberOfSelectedPoints()const;
00120 
00123   vtkIdType FindPoint(double* pos);
00124 
00128   bool IsOverPoint(double* pos, vtkIdType pointId);
00129 
00132   vtkIdType GetControlPointId(double* pos);
00133 
00137   vtkIdTypeArray* GetControlPointsIds()const;
00138 
00141   vtkIdTypeArray* GetControlPointsIds(bool excludeFirstAndLast)const;
00142 
00144 
00146   vtkGetMacro(StrokeMode, bool);
00148 
00150 
00154   vtkSetMacro(SwitchPointsMode, bool);
00155   vtkGetMacro(SwitchPointsMode, bool);
00157 
00159 
00161   vtkSetMacro(EndPointsXMovable, bool);
00162   vtkGetMacro(EndPointsXMovable, bool);
00163   vtkSetMacro(EndPointsYMovable, bool);
00164   vtkGetMacro(EndPointsYMovable, bool);
00165   virtual bool GetEndPointsMovable();
00167 
00169 
00171   vtkSetMacro(EndPointsRemovable, bool);
00172   vtkGetMacro(EndPointsRemovable, bool);
00174 
00178   virtual vtkIdType AddPoint(double* newPos) = 0;
00179 
00183   virtual vtkIdType RemovePoint(double* pos) = 0;
00184 
00187   vtkIdType RemovePoint(vtkIdType pointId);
00188 
00190   inline void RemoveCurrentPoint();
00191 
00193   virtual vtkIdType GetNumberOfPoints()const = 0;
00194 
00198   virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
00199 
00202   virtual void SetControlPoint(vtkIdType index, double *point) = 0;
00203 
00210   void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
00211 
00215   void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
00216 
00223   void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
00224 
00228   void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
00229 
00232   vtkIdType GetCurrentPoint()const;
00233 
00235   void SetCurrentPoint(vtkIdType index);
00236 
00238 
00239   vtkGetObjectMacro(SelectedPointPen, vtkPen);
00241 
00243 
00245   vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
00247 
00250   void ResetBounds();
00251 
00253 
00254   virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
00255   virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse);
00257 
00259   virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
00260 
00261   virtual bool KeyPressEvent(const vtkContextKeyEvent &key);
00262   virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key);
00263 
00264 protected:
00265   vtkControlPointsItem();
00266   virtual ~vtkControlPointsItem();
00267 
00268   void StartChanges();
00269   void EndChanges();
00270   void StartInteraction();
00271   void StartInteractionIfNotStarted();
00272   void Interaction();
00273   void EndInteraction();
00274   int GetInteractionsCount()const;
00275   virtual void emitEvent(unsigned long event, void* params = 0) = 0;
00276 
00277   static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
00278 
00280 
00282   virtual void ComputePoints();
00283   virtual unsigned long int GetControlPointsMTime() =0;
00285 
00287   virtual bool Hit(const vtkContextMouseEvent &mouse);
00288 
00290 
00292   bool ClampPos(double pos[2], double bounds[4]);
00293   bool ClampValidPos(double pos[2]);
00295 
00297 
00299   void DrawUnselectedPoints(vtkContext2D* painter);
00300   void DrawSelectedPoints(vtkContext2D* painter);
00301   virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
00303 
00304   void SetCurrentPointPos(const vtkVector2f& newPos);
00305   vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
00306   void MoveCurrentPoint(const vtkVector2f& translation);
00307   vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
00308 
00309   inline vtkVector2f GetSelectionCenterOfMass()const;
00310   vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
00311 
00312   void Stroke(const vtkVector2f& newPos);
00313   virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
00315   virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
00316 
00317   void AddPointId(vtkIdType addedPointId);
00318 
00321   bool IsEndPointPicked();
00322   
00324   bool IsPointRemovable(vtkIdType pointId);
00325 
00326   vtkCallbackCommand* Callback;
00327   vtkPen*             SelectedPointPen;
00328   vtkBrush*           SelectedPointBrush;
00329   int                 BlockUpdates;
00330   int                 StartedInteractions;
00331   vtkIdType           CurrentPoint;
00332 
00333   double              Bounds[4];
00334   double              UserBounds[4];
00335   double              ValidBounds[4];
00336 
00337   vtkTransform2D*     Transform;
00338   float               ScreenPointRadius;
00339 
00340   bool                StrokeMode;
00341   bool                SwitchPointsMode;
00342   bool                MouseMoved;
00343   bool                EnforceValidFunction;
00344   vtkIdType           PointToDelete;
00345   bool                PointAboutToBeDeleted;
00346   vtkIdType           PointToToggle;
00347   bool                PointAboutToBeToggled;
00348   bool                InvertShadow;
00349   bool                EndPointsXMovable;
00350   bool                EndPointsYMovable;
00351   bool                EndPointsRemovable;
00352 private:
00353   vtkControlPointsItem(const vtkControlPointsItem &); // Not implemented.
00354   void operator=(const vtkControlPointsItem &);   // Not implemented.
00355 
00356   void      ComputeBounds();
00357   void      ComputeBounds(double* bounds);
00358 
00359   vtkIdType RemovePointId(vtkIdType removedPointId);
00360 };
00361 
00362 //-----------------------------------------------------------------------------
00363 void vtkControlPointsItem::RemoveCurrentPoint()
00364 {
00365   this->RemovePoint(this->GetCurrentPoint());
00366 }
00367 
00368 //-----------------------------------------------------------------------------
00369 vtkVector2f vtkControlPointsItem::GetSelectionCenterOfMass()const
00370 {
00371   return this->GetCenterOfMass(this->Selection);
00372 }
00373 
00374 #endif