12 #include <vtkAxisActor2D.h>
13 #include <vtkCoordinate.h>
15 #include <vtkObjectFactory.h>
16 #include <vtkPointHandleRepresentation3D.h>
17 #include <vtkProperty.h>
18 #include <vtkProperty2D.h>
19 #include <vtkRenderer.h>
20 #include <vtkTextProperty.h>
21 #include <vtkWindow.h>
36 NumberOfRulerTicks(5),
48 this->
AxisActor->GetPoint1Coordinate()->SetCoordinateSystemToWorld();
49 this->
AxisActor->GetPoint2Coordinate()->SetCoordinateSystemToWorld();
65 this->
AxisActor->GetTitleTextProperty()->SetFontSize(
67 this->
AxisActor->GetTitleTextProperty()->SetBold(0);
68 this->
AxisActor->GetTitleTextProperty()->SetItalic(0);
69 this->
AxisActor->GetTitleTextProperty()->SetShadow(1);
70 this->
AxisActor->GetTitleTextProperty()->SetFontFamilyToArial();
71 this->
AxisActor->GetTitleTextProperty()->SetColor(1.0, 1.0, 1.0);
82 this->SetLabelFormat(
"%-#6.3g");
105 this->GetPoint1WorldPosition(p1);
106 this->GetPoint2WorldPosition(p2);
107 return sqrt(vtkMath::Distance2BetweenPoints(p1, p2));
112 if (this->
Scale != scale && scale > 0.0) {
121 this->Superclass::BuildRepresentation();
128 this->GetPoint1WorldPosition(p1);
129 this->GetPoint2WorldPosition(p2);
130 this->
Distance = sqrt(vtkMath::Distance2BetweenPoints(p1, p2));
133 this->
AxisActor->GetPoint1Coordinate()->SetValue(p1);
134 this->
AxisActor->GetPoint2Coordinate()->SetValue(p2);
138 if (this->
Scale != 0.0) {
154 char labelString[512];
155 snprintf(labelString,
sizeof(labelString), this->
LabelFormat,
161 sizeof(labelString) - strlen(labelString) - 1);
183 int count = this->Superclass::RenderOverlay(viewport);
186 count += this->
AxisActor->RenderOverlay(viewport);
194 vtkViewport* viewport) {
199 int count = this->Superclass::RenderOpaqueGeometry(viewport);
202 count += this->
AxisActor->RenderOpaqueGeometry(viewport);
210 vtkPointHandleRepresentation3D* handle) {
216 double p1[3] = {0, 0, 0};
217 double p2[3] = {0, 0, 0};
218 if (this->Point1Representation) {
219 this->Point1Representation->GetWorldPosition(p1);
221 if (this->Point2Representation) {
222 this->Point2Representation->GetWorldPosition(p2);
226 const char* className = handle->GetClassName();
228 (strcmp(className,
"cvCustomAxisHandleRepresentation") == 0);
231 if (this->Point1Representation) {
232 this->Point1Representation->Delete();
236 this->Point1Representation =
237 static_cast<vtkPointHandleRepresentation3D*
>(
238 handle->NewInstance());
241 this->Point1Representation = handle->NewInstance();
243 this->Point1Representation->ShallowCopy(handle);
244 this->Point1Representation->SetWorldPosition(p1);
247 if (this->Point2Representation) {
248 this->Point2Representation->Delete();
251 this->Point2Representation =
252 static_cast<vtkPointHandleRepresentation3D*
>(
253 handle->NewInstance());
255 this->Point2Representation = handle->NewInstance();
257 this->Point2Representation->ShallowCopy(handle);
258 this->Point2Representation->SetWorldPosition(p2);
261 if (this->LineHandleRepresentation) {
262 this->LineHandleRepresentation->Delete();
265 this->LineHandleRepresentation =
266 static_cast<vtkPointHandleRepresentation3D*
>(
267 handle->NewInstance());
269 this->LineHandleRepresentation = handle->NewInstance();
271 this->LineHandleRepresentation->ShallowCopy(handle);
278 this->Superclass::PrintSelf(os, indent);
280 os << indent <<
"Show Label: " << this->
ShowLabel <<
"\n";
284 os << indent <<
"Ruler Mode: " << this->
RulerMode <<
"\n";
285 os << indent <<
"Ruler Distance: " << this->
RulerDistance <<
"\n";
288 os << indent <<
"Scale: " << this->
Scale <<
"\n";
Extended LineRepresentation with distance display and ruler features.
vtkAxisActor2D * AxisActor
void ReplaceHandleRepresentations(vtkPointHandleRepresentation3D *handle)
Replace handle representations with custom types (runtime version)
vtkProperty2D * AxisProperty
cvConstrainedLineRepresentation()
void BuildRepresentation() override
Override BuildRepresentation to update distance display.
void SetScale(double scale)
Set/Get scale factor.
~cvConstrainedLineRepresentation() override
virtual double GetDistance()
Get distance between the two points.
int RenderOpaqueGeometry(vtkViewport *viewport) override
int RenderOverlay(vtkViewport *viewport) override
Override to render distance label and ticks.
void PrintSelf(ostream &os, vtkIndent indent) override
vtkStandardNewMacro(cvConstrainedLineRepresentation)