/usr/include/vtk-7.1/vtkControlPointsItem.h is in libvtk7-dev 7.1.1+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | /*=========================================================================
Program: Visualization Toolkit
Module: vtkControlPointsItem.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkControlPointsItem
* @brief Abstract class for control points items.
*
* vtkControlPointsItem provides control point painting and management for
* subclasses that provide points (typically control points of a transfer
* function)
* @sa
* vtkScalarsToColorsItem
* vtkPiecewiseControlPointsItem
*/
#ifndef vtkControlPointsItem_h
#define vtkControlPointsItem_h
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkCommand.h" // For vtkCommand enum
#include "vtkPlot.h"
#include "vtkVector.h" // For vtkVector2f
class vtkCallbackCommand;
class vtkContext2D;
class vtkPoints2D;
class vtkTransform2D;
class VTKCHARTSCORE_EXPORT vtkControlPointsItem: public vtkPlot
{
public:
vtkTypeMacro(vtkControlPointsItem, vtkPlot);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Events fires by this class (and subclasses).
// \li CurrentPointChangedEvent is fired when the current point index is changed.
// \li CurrentPointEditEvent is fired to request the application to show UI to
// edit the current point.
// \li vtkCommand::StartEvent and vtkCommand::EndEvent is fired
// to mark groups of changes to control points.
enum {
CurrentPointChangedEvent = vtkCommand::UserEvent,
CurrentPointEditEvent
};
/**
* Bounds of the item, typically the bound of all the control points
* except if custom bounds have been set \sa SetUserBounds.
*/
virtual void GetBounds(double bounds[4]);
//@{
/**
* Set custom bounds, except if bounds are invalid, bounds will be
* automatically computed based on the range of the control points
* Invalid bounds by default.
*/
vtkSetVector4Macro(UserBounds, double);
vtkGetVector4Macro(UserBounds, double);
//@}
//@{
/**
* Controls the valid range for the values.
* An invalid value (0, -1, 0., -1, 0, -1.) indicates that the valid
* range is the current bounds. It is the default behavior.
*/
vtkSetVector4Macro(ValidBounds, double);
vtkGetVector4Macro(ValidBounds, double);
//@}
//@{
/**
* Get/set the radius for screen points.
* Default is 6.f
*/
vtkGetMacro(ScreenPointRadius, float);
vtkSetMacro(ScreenPointRadius, float);
//@}
/**
* Paint the points with a fixed size (cosmetic) which doesn't depend
* on the scene zoom factor. Selected and unselected points are drawn
* with a different color.
*/
virtual bool Paint(vtkContext2D *painter);
/**
* Select a point by its ID
*/
void SelectPoint(vtkIdType pointId);
/**
* Utility function that selects a point providing its coordinates.
* To be found, the position of the point must be no further away than its
* painted point size
*/
void SelectPoint(double* currentPoint);
/**
* Select all the points
*/
void SelectAllPoints();
/**
* Unselect a point by its ID
*/
void DeselectPoint(vtkIdType pointId);
/**
* Utility function that unselects a point providing its coordinates.
* To be found, the position of the point must be no further away than its
* painted point size
*/
void DeselectPoint(double* currentPoint);
/**
* Unselect all the previously selected points
*/
void DeselectAllPoints();
/**
* Toggle the selection of a point by its ID. If the point was selected then
* unselect it, otherwise select it.
*/
void ToggleSelectPoint(vtkIdType pointId);
/**
* Utility function that toggles the selection a point providing its
* coordinates. To be found, the position of the point must be no further
* away than its painted point size
*/
void ToggleSelectPoint(double* currentPoint);
/**
* Select all points in the specified rectangle.
*/
virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);
/**
* Return the number of selected points.
*/
vtkIdType GetNumberOfSelectedPoints()const;
/**
* Returns the vtkIdType of the point given its coordinates and a tolerance
* based on the screen point size.
*/
vtkIdType FindPoint(double* pos);
/**
* Returns true if pos is above the pointId point, false otherwise.
* It uses the size of the drawn point. To search what point is under the pos,
* use the more efficient \sa FindPoint() instead.
*/
bool IsOverPoint(double* pos, vtkIdType pointId);
/**
* Returns the id of the control point exactly matching pos, -1 if not found.
*/
vtkIdType GetControlPointId(double* pos);
/**
* Utility function that returns an array of all the control points IDs
* Typically: [0, 1, 2, ... n -1] where n is the point count
* Can exclude the first and last point ids from the array.
*/
void GetControlPointsIds(vtkIdTypeArray* ids,
bool excludeFirstAndLast = false)const;
//@{
/**
* Controls whether or not control points are drawn (true) or clicked and
* moved (false).
* False by default.
*/
vtkGetMacro(StrokeMode, bool);
//@}
//@{
/**
* If DrawPoints is false, SwitchPoints controls the behavior when a control
* point is dragged past another point. The crossed point becomes current
* (true) or the current point is blocked/stopped (false).
* False by default.
*/
vtkSetMacro(SwitchPointsMode, bool);
vtkGetMacro(SwitchPointsMode, bool);
//@}
//@{
/**
* If EndPointsMovable is false, the two end points will not
* be moved. True by default.
*/
vtkSetMacro(EndPointsXMovable, bool);
vtkGetMacro(EndPointsXMovable, bool);
vtkSetMacro(EndPointsYMovable, bool);
vtkGetMacro(EndPointsYMovable, bool);
virtual bool GetEndPointsMovable();
//@}
//@{
/**
* If EndPointsRemovable is false, the two end points will not
* be be removed. True by default.
*/
vtkSetMacro(EndPointsRemovable, bool);
vtkGetMacro(EndPointsRemovable, bool);
//@}
//@{
/**
* When set to true, labels are shown on the current control point and the end
* points. Default is false.
*/
vtkSetMacro(ShowLabels, bool);
vtkGetMacro(ShowLabels, bool);
//@}
//@{
/**
* Get/Set the label format. Default is "%.4f, %.4f".
*/
vtkSetStringMacro(LabelFormat);
vtkGetStringMacro(LabelFormat);
//@}
/**
* Add a point to the function. Returns the index of the point (0 based),
* or -1 on error.
* Subclasses should reimplement this function to do the actual work.
*/
virtual vtkIdType AddPoint(double* newPos) = 0;
/**
* Remove a point of the function. Returns the index of the point (0 based),
* or -1 on error.
* Subclasses should reimplement this function to do the actual work.
*/
virtual vtkIdType RemovePoint(double* pos) = 0;
/**
* Remove a point give its id. It is a utility function that internally call
* the virtual method RemovePoint(double*) and return its result.
*/
vtkIdType RemovePoint(vtkIdType pointId);
/**
* Remove the current point.
*/
inline void RemoveCurrentPoint();
/**
* Returns the total number of points
*/
virtual vtkIdType GetNumberOfPoints()const = 0;
/**
* Returns the x and y coordinates as well as the midpoint and sharpness
* of the control point corresponding to the index.
* point must be a double array of size 4.
*/
virtual void GetControlPoint(vtkIdType index, double *point)const = 0;
/**
* Sets the x and y coordinates as well as the midpoint and sharpness
* of the control point corresponding to the index.
*/
virtual void SetControlPoint(vtkIdType index, double *point) = 0;
/**
* Move the points referred by pointIds by a given translation.
* The new positions won't be outside the bounds.
* MovePoints is typically called with GetControlPointsIds() or GetSelection().
* Warning: if you pass this->GetSelection(), the array is deleted after
* each individual point move. Increase the reference count of the array.
* See also MoveAllPoints()
*/
void MovePoints(const vtkVector2f& translation, vtkIdTypeArray* pointIds);
/**
* Utility function to move all the control points of the given translation
* If dontMoveFirstAndLast is true, then the first and last points won't be
* moved.
*/
void MovePoints(const vtkVector2f& translation, bool dontMoveFirstAndLast = false);
/**
* Spread the points referred by pointIds
* If factor > 0, points are moved away from each other.
* If factor < 0, points are moved closer to each other
* SpreadPoints is typically called with GetControlPointsIds() or GetSelection().
* Warning: if you pass this->GetSelection(), the array is deleted after
* each individual point move. Increase the reference count of the array.
*/
void SpreadPoints(float factor, vtkIdTypeArray* pointIds);
/**
* Utility function to spread all the control points of a given factor
* If dontSpreadFirstAndLast is true, then the first and last points won't be
* spread.
*/
void SpreadPoints(float factor, bool dontSpreadFirstAndLast = false);
/**
* Returns the current point ID selected or -1 if there is no point current.
* No current point by default.
*/
vtkIdType GetCurrentPoint()const;
/**
* Sets the current point selected.
*/
void SetCurrentPoint(vtkIdType index);
//@{
/**
* Gets the selected point pen and brush.
*/
vtkGetObjectMacro(SelectedPointPen, vtkPen);
//@}
//@{
/**
* Depending on the control points item, the brush might not be taken into
* account.
*/
vtkGetObjectMacro(SelectedPointBrush, vtkBrush);
//@}
/**
* Recompute the bounds next time they are requested.
* You shouldn't have to call it but it is provided for rare cases.
*/
void ResetBounds();
//@{
/**
* Mouse button down event.
*/
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
virtual bool MouseDoubleClickEvent(const vtkContextMouseEvent &mouse);
//@}
/**
* Mouse move event.
*/
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
virtual bool KeyPressEvent(const vtkContextKeyEvent &key);
virtual bool KeyReleaseEvent(const vtkContextKeyEvent &key);
protected:
vtkControlPointsItem();
virtual ~vtkControlPointsItem();
void StartChanges();
void EndChanges();
void StartInteraction();
void StartInteractionIfNotStarted();
void Interaction();
void EndInteraction();
int GetInteractionsCount()const;
virtual void emitEvent(unsigned long event, void* params = 0) = 0;
static void CallComputePoints(vtkObject* sender, unsigned long event, void* receiver, void* params);
//@{
/**
* Must be reimplemented by subclasses to calculate the points to draw.
* It's subclass responsibility to call ComputePoints() via the callback
*/
virtual void ComputePoints();
virtual vtkMTimeType GetControlPointsMTime() =0;
//@}
/**
* Returns true if the supplied x, y coordinate is on a control point.
*/
virtual bool Hit(const vtkContextMouseEvent &mouse);
//@{
/**
* Transform the mouse event in the control-points space. This is needed when
* ColorTransferFunction is using log-scale.
*/
virtual void TransformScreenToData(const vtkVector2f& in, vtkVector2f& out);
virtual void TransformDataToScreen(const vtkVector2f& in, vtkVector2f& out);
//@}
//@{
/**
* Clamp the given 2D pos into the bounds of the function.
* Return true if the pos has been clamped, false otherwise.
*/
virtual bool ClampPos(double pos[2], double bounds[4]);
bool ClampValidPos(double pos[2]);
//@}
//@{
/**
* Internal function that paints a collection of points and optionally
* excludes some.
*/
void DrawUnselectedPoints(vtkContext2D* painter);
void DrawSelectedPoints(vtkContext2D* painter);
virtual void DrawPoint(vtkContext2D* painter, vtkIdType index);
//@}
void SetCurrentPointPos(const vtkVector2f& newPos);
vtkIdType SetPointPos(vtkIdType point, const vtkVector2f& newPos);
void MoveCurrentPoint(const vtkVector2f& translation);
vtkIdType MovePoint(vtkIdType point, const vtkVector2f& translation);
inline vtkVector2f GetSelectionCenterOfMass()const;
vtkVector2f GetCenterOfMass(vtkIdTypeArray* pointIDs)const;
void Stroke(const vtkVector2f& newPos);
virtual void EditPoint(float vtkNotUsed(tX), float vtkNotUsed(tY));
/**
* Mouse button release event.
*/
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
/**
* Generate label for a control point.
*/
virtual vtkStdString GetControlPointLabel(vtkIdType index);
void AddPointId(vtkIdType addedPointId);
/**
* Return true if any of the end points is current point
* or part of the selection
*/
bool IsEndPointPicked();
/**
* Return true if the point is removable
*/
bool IsPointRemovable(vtkIdType pointId);
/**
* Compute the bounds for this item. Typically, the bounds should be aligned
* to the range of the vtkScalarsToColors or vtkPiecewiseFunction that is
* being controlled by the subclasses.
* Default implementation uses the range of the control points themselves.
*/
virtual void ComputeBounds(double* bounds);
/**
* Returns true if control points are to be rendered in log-space. This is
* true when vtkScalarsToColors is using log-scale, for example. Default
* implementation always return false.
*/
virtual bool UsingLogScale() { return false; }
vtkCallbackCommand* Callback;
vtkPen* SelectedPointPen;
vtkBrush* SelectedPointBrush;
int BlockUpdates;
int StartedInteractions;
int StartedChanges;
vtkIdType CurrentPoint;
double Bounds[4];
double UserBounds[4];
double ValidBounds[4];
vtkTransform2D* Transform;
float ScreenPointRadius;
bool StrokeMode;
bool SwitchPointsMode;
bool MouseMoved;
bool EnforceValidFunction;
vtkIdType PointToDelete;
bool PointAboutToBeDeleted;
vtkIdType PointToToggle;
bool PointAboutToBeToggled;
bool InvertShadow;
bool EndPointsXMovable;
bool EndPointsYMovable;
bool EndPointsRemovable;
bool ShowLabels;
char* LabelFormat;
private:
vtkControlPointsItem(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
void operator=(const vtkControlPointsItem &) VTK_DELETE_FUNCTION;
void ComputeBounds();
vtkIdType RemovePointId(vtkIdType removedPointId);
};
//-----------------------------------------------------------------------------
void vtkControlPointsItem::RemoveCurrentPoint()
{
this->RemovePoint(this->GetCurrentPoint());
}
//-----------------------------------------------------------------------------
vtkVector2f vtkControlPointsItem::GetSelectionCenterOfMass()const
{
return this->GetCenterOfMass(this->Selection);
}
#endif
|