ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvConstrainedLineRepresentation.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #ifndef cvConstrainedLineRepresentation_h
9 #define cvConstrainedLineRepresentation_h
10 
11 #include <vtkLineRepresentation.h>
12 #include <vtkPointHandleRepresentation3D.h>
13 
14 class vtkAxisActor2D;
15 class vtkProperty2D;
16 
30 class cvConstrainedLineRepresentation : public vtkLineRepresentation {
31 public:
34  void PrintSelf(ostream& os, vtkIndent indent) override;
35 
39  virtual double GetDistance();
40 
45  vtkSetMacro(RulerMode, vtkTypeBool);
46  vtkGetMacro(RulerMode, vtkTypeBool);
47  vtkBooleanMacro(RulerMode, vtkTypeBool);
48 
52  vtkSetClampMacro(RulerDistance, double, 0, VTK_FLOAT_MAX);
54 
58  vtkSetClampMacro(NumberOfRulerTicks, int, 1, VTK_INT_MAX);
60 
64  void SetScale(double scale);
65  vtkGetMacro(Scale, double);
66 
72 
78 
82  vtkSetMacro(ShowLabel, vtkTypeBool);
83  vtkGetMacro(ShowLabel, vtkTypeBool);
84  vtkBooleanMacro(ShowLabel, vtkTypeBool);
85 
89  vtkGetObjectMacro(AxisActor, vtkAxisActor2D);
90 
95 
99  void BuildRepresentation() override;
100 
104  int RenderOverlay(vtkViewport* viewport) override;
105  int RenderOpaqueGeometry(vtkViewport* viewport) override;
106 
114  template <typename T>
116  // Save current positions
117  double p1[3] = {0, 0, 0};
118  double p2[3] = {0, 0, 0};
119  if (this->Point1Representation) {
120  this->Point1Representation->GetWorldPosition(p1);
121  }
122  if (this->Point2Representation) {
123  this->Point2Representation->GetWorldPosition(p2);
124  }
125 
126  // Create a prototype for copying attributes
127  T* prototype = T::New();
128 
129  // Replace Point1Representation
130  if (this->Point1Representation) {
131  this->Point1Representation->Delete();
132  }
133  this->Point1Representation = T::New();
134  this->Point1Representation->ShallowCopy(prototype);
135  this->Point1Representation->SetWorldPosition(p1);
136 
137  // Replace Point2Representation
138  if (this->Point2Representation) {
139  this->Point2Representation->Delete();
140  }
141  this->Point2Representation = T::New();
142  this->Point2Representation->ShallowCopy(prototype);
143  this->Point2Representation->SetWorldPosition(p2);
144 
145  // Replace LineHandleRepresentation
146  if (this->LineHandleRepresentation) {
147  this->LineHandleRepresentation->Delete();
148  }
149  this->LineHandleRepresentation = T::New();
150  this->LineHandleRepresentation->ShallowCopy(prototype);
151 
152  prototype->Delete();
153  this->Modified();
154  }
155 
159  void ReplaceHandleRepresentations(vtkPointHandleRepresentation3D* handle);
160 
161 protected:
164 
165  // Distance label related (following ParaView vtkDistanceRepresentation2D)
166  vtkTypeBool ShowLabel;
167  char* LabelFormat;
168  char* LabelSuffix; // Instance label suffix (e.g., " #1", " #2")
169 
170  // Ruler and axis related (following ParaView)
171  vtkTypeBool RulerMode;
174  vtkAxisActor2D* AxisActor;
175  vtkProperty2D* AxisProperty;
176  double Scale;
177  double Distance;
178 
179 private:
181  delete;
182  void operator=(const cvConstrainedLineRepresentation&) = delete;
183 };
184 
185 #endif // cvConstrainedLineRepresentation_h
Extended LineRepresentation with distance display and ruler features.
vtkSetStringMacro(LabelSuffix)
Set/Get distance label suffix (e.g., " #1", " #2")
vtkGetMacro(NumberOfRulerTicks, int)
static cvConstrainedLineRepresentation * New()
vtkBooleanMacro(RulerMode, vtkTypeBool)
vtkGetMacro(RulerMode, vtkTypeBool)
vtkGetMacro(RulerDistance, double)
vtkBooleanMacro(ShowLabel, vtkTypeBool)
vtkGetMacro(ShowLabel, vtkTypeBool)
vtkSetClampMacro(RulerDistance, double, 0, VTK_FLOAT_MAX)
Set/Get Ruler distance (tick spacing)
void ReplaceHandleRepresentations(vtkPointHandleRepresentation3D *handle)
Replace handle representations with custom types (runtime version)
vtkSetMacro(RulerMode, vtkTypeBool)
Set/Get Ruler mode Ruler mode displays tick marks.
void BuildRepresentation() override
Override BuildRepresentation to update distance display.
void SetScale(double scale)
Set/Get scale factor.
vtkTypeMacro(cvConstrainedLineRepresentation, vtkLineRepresentation)
virtual double GetDistance()
Get distance between the two points.
vtkSetMacro(ShowLabel, vtkTypeBool)
Show/Hide distance label.
int RenderOpaqueGeometry(vtkViewport *viewport) override
int RenderOverlay(vtkViewport *viewport) override
Override to render distance label and ticks.
void ReplaceHandleRepresentationsTyped()
Replace handle representations with custom types This is needed because vtkLineRepresentation's const...
vtkSetStringMacro(LabelFormat)
Set/Get distance label format.
void PrintSelf(ostream &os, vtkIndent indent) override
vtkGetObjectMacro(AxisProperty, vtkProperty2D)
Get axis property (ParaView way)
vtkSetClampMacro(NumberOfRulerTicks, int, 1, VTK_INT_MAX)
Set/Get number of ruler ticks.
vtkGetObjectMacro(AxisActor, vtkAxisActor2D)
Get Axis Actor (for tick display)