17 #ifndef IGNITION_RENDERING_BASE_BASEJOINTVISUAL_HH_ 18 #define IGNITION_RENDERING_BASE_BASEJOINTVISUAL_HH_ 36 inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
51 protected:
virtual void Init()
override;
54 protected:
virtual void PreRender()
override;
57 protected:
virtual void Destroy()
override;
61 bool _useParentFrame)
override;
67 public:
virtual void SetParentAxis(
70 bool _useParentFrame)
override;
77 bool _useParentFrame)
override;
80 public:
virtual bool UpdateParentAxis(
82 bool _useParentFrame)
override;
97 public:
virtual void SetVisible(
bool _visible)
override;
106 bool _useParentFrame);
109 protected:
void CreateAxis();
112 protected:
void CreateParentAxis();
115 protected:
void ScaleToChild();
138 protected:
bool dirtyJointType =
false;
141 protected:
bool dirtyAxis =
false;
144 protected:
bool dirtyParentAxis =
false;
152 protected:
bool useParentFrame =
false;
155 protected:
bool updateAxis =
false;
166 protected:
bool parentAxisUseParentFrame =
false;
169 protected:
bool updateParentAxis =
false;
190 if (this->ParentAxisVisual())
192 this->ParentAxisVisual()->PreRender();
195 if (this->dirtyJointType)
197 this->UpdateAxis(this->axis, this->useParentFrame);
198 this->UpdateParentAxis(this->parentAxis,
199 this->parentAxisUseParentFrame);
201 this->dirtyJointType =
false;
207 this->dirtyAxis =
false;
210 if (this->dirtyParentAxis)
212 this->CreateParentAxis();
213 this->dirtyParentAxis =
false;
216 if (this->updateAxis)
219 !this->UpdateAxis(this->axis, this->useParentFrame);
222 if (this->updateParentAxis)
224 this->updateParentAxis =
225 !this->UpdateParentAxis(this->parentAxis,
226 this->parentAxisUseParentFrame);
237 this->AddChild(this->axisVisual);
238 this->SetInheritScale(
false);
245 if (this->arrowVisual !=
nullptr)
247 this->arrowVisual->Destroy();
248 this->arrowVisual.reset();
251 if (this->axisVisual !=
nullptr)
253 this->axisVisual->Destroy();
254 this->axisVisual.reset();
257 if (this->parentAxisVis !=
nullptr)
259 this->parentAxisVis->Destroy();
260 this->parentAxisVis.reset();
263 this->dirtyJointType =
false;
264 this->dirtyAxis =
false;
265 this->dirtyParentAxis =
false;
272 bool _useParentFrame)
275 this->useParentFrame = _useParentFrame;
276 this->dirtyAxis =
true;
283 if (this->arrowVisual)
285 this->arrowVisual->Destroy();
286 this->arrowVisual.reset();
290 this->arrowVisual->SetMaterial(
"Default/TransYellow");
291 this->arrowVisual->SetLocalPosition(0, 0, 0);
292 this->arrowVisual->SetLocalRotation(0, 0, 0);
293 this->AddChild(this->arrowVisual);
295 this->updateAxis =
true;
296 this->ScaleToChild();
304 bool _useParentFrame)
309 ignlog <<
"Joint visual is not of type Revolute2 or " 311 <<
" so the parent axis will not be shown\n";
315 this->parentAxis = _axis;
316 this->parentAxisUseParentFrame = _useParentFrame;
317 this->jointParentName = _parentName;
318 this->dirtyParentAxis =
true;
325 auto jointParentVis = this->
Scene()->
NodeByName(this->jointParentName);
326 if (jointParentVis ==
nullptr)
328 ignlog <<
"Joint parent with name " << this->jointParentName
330 <<
" so the parent axis will not be shown\n";
334 if (this->parentAxisVis)
336 this->parentAxisVis->Destroy();
337 this->parentAxisVis.reset();
341 jointParentVis->AddChild(this->parentAxisVis);
342 this->parentAxisVis->SetType(this->Type());
343 this->parentAxisVis->SetAxis(this->parentAxis,
344 this->parentAxisUseParentFrame);
346 this->updateParentAxis =
true;
347 this->ScaleToChild();
353 bool _useParentFrame)
357 this->UpdateAxisImpl(this->
ArrowVisual(), _axis, _useParentFrame);
368 bool _useParentFrame)
370 if (this->ParentAxisVisual() &&
372 this->ParentAxisVisual()->HasParent())
374 this->UpdateAxisImpl(this->ParentAxisVisual()->
ArrowVisual(),
375 _axis, _useParentFrame);
386 bool _useParentFrame)
392 double cosTheta = v.
Dot(u);
393 double angle = acos(cosTheta);
399 quat.
Axis((v.
Cross(u)).Normalize(), angle);
400 _arrowVisual->SetLocalRotation(quat);
405 this->Parent()->InitialLocalPose();
409 (parentInitPose * this->LocalPose()).Rot();
413 _arrowVisual->SetLocalRotation(quatFromModel.
Inverse() *
414 _arrowVisual->LocalRotation());
417 _arrowVisual->ShowArrowRotation(
423 if (this->axisVisual)
424 _arrowVisual->SetVisible(
true);
433 auto axisWorldRotation = _arrowVisual->WorldPose().Rot();
434 auto jointWorldRotation = this->WorldPose().Rot();
436 this->axisVisual->ShowAxisHead(
true);
437 _arrowVisual->ShowArrowShaft(
true);
442 this->axisVisual->ShowAxisHead(0,
false);
443 _arrowVisual->ShowArrowShaft(
false);
445 else if (axisWorld ==
448 this->axisVisual->ShowAxisHead(1,
false);
449 _arrowVisual->ShowArrowShaft(
false);
451 else if (axisWorld ==
452 jointWorldRotation * ignition::math::Vector3d::UnitZ)
454 this->axisVisual->ShowAxisHead(2,
false);
455 _arrowVisual->ShowArrowShaft(
false);
463 if (!this->HasParent())
473 std::max(0.1, parentVisual->BoundingBox().Size().Length());
475 childSize * 0.2, childSize * 0.2);
476 this->SetLocalScale(this->scaleToChild);
477 if (this->ParentAxisVisual())
478 this->ParentAxisVisual()->SetLocalScale(this->scaleToChild);
486 this->jointVisualType = _type;
487 this->dirtyJointType =
true;
501 return this->parentAxis;
508 return this->jointVisualType;
515 return this->parentAxisVis;
522 return this->arrowVisual;
529 T::SetVisible(_visible);
537 if (this->ParentAxisVisual())
538 this->ParentAxisVisual()->SetVisible(_visible);
541 if (this->axisVisual)
542 this->axisVisual->SetVisible(_visible);
virtual NodePtr NodeByName(const std::string &_name) const =0
Get node with the given name. If no node exists with the given name, NULL will be returned...
Gearbox joint type.
Definition: JointVisual.hh:60
virtual bool UpdateParentAxis(const ignition::math::Vector3d &_axis, bool _useParentFrame) override
Update the parent axis' arrow visual if it exists.
Definition: BaseJointVisual.hh:366
Represents a arrow composite visual.
Definition: ArrowVisual.hh:31
virtual void SetVisible(bool _visible)=0
Specify if this visual is visible.
virtual ArrowVisualPtr ArrowVisual() const override
Get the arrow visual which represents the axis attached to the child.
Definition: BaseJointVisual.hh:520
void ScaleToChild()
Scale the joint visual according to the joint's child.
Definition: BaseJointVisual.hh:461
Revolute2 joint type.
Definition: JointVisual.hh:45
virtual bool UpdateAxis(const ignition::math::Vector3d &_axis, bool _useParentFrame) override
Update an axis' arrow visual.
Definition: BaseJointVisual.hh:352
static const Vector3 UnitZ
Represents a joint visual.
Definition: JointVisual.hh:69
JointVisualType
Enum for JointVisual types.
Definition: JointVisual.hh:36
Base implementation of a joint visual.
Definition: BaseJointVisual.hh:40
virtual ignition::math::Vector3d Axis() const override
Get axis vector.
Definition: BaseJointVisual.hh:492
virtual JointVisualPtr ParentAxisVisual() const override
Get the JointVisual which is attached to the parent.
Definition: BaseJointVisual.hh:513
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
No type.
Definition: JointVisual.hh:39
static const Vector3 UnitY
Vector3 Perpendicular() const
void CreateParentAxis()
Helper function to create parent axis visual.
Definition: BaseJointVisual.hh:323
virtual ~BaseJointVisual()
Destructor.
Definition: BaseJointVisual.hh:180
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: BaseJointVisual.hh:243
void Axis(T _ax, T _ay, T _az, T _aa)
T Dot(const Vector3< T > &_v) const
Vector3 Cross(const Vector3< T > &_v) const
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:49
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseJointVisual.hh:186
virtual JointVisualType Type() const override
Get joint visual type.
Definition: BaseJointVisual.hh:506
virtual void SetType(const JointVisualType _type) override
Set type for joint visual.
Definition: BaseJointVisual.hh:484
T dynamic_pointer_cast(T... args)
virtual void SetVisible(bool _visible) override
Specify if this visual is visible.
Definition: BaseJointVisual.hh:527
Universal joint type.
Definition: JointVisual.hh:51
void UpdateAxisImpl(ArrowVisualPtr _arrowVisual, const ignition::math::Vector3d &_axis, bool _useParentFrame)
Implementation for updating an axis' arrow visual.
Definition: BaseJointVisual.hh:384
Represents a visual node in a scene graph. A Visual is the only node that can have Geometry and other...
Definition: Visual.hh:33
virtual AxisVisualPtr CreateAxisVisual()=0
Create new axis visual. A unique ID and name will automatically be assigned to the visual...
Vector3< double > Vector3d
virtual void Init() override
Definition: BaseJointVisual.hh:232
static const Vector3 UnitX
virtual ignition::math::Vector3d ParentAxis() const override
Get parent axis vector.
Definition: BaseJointVisual.hh:499
static const Vector3 Zero
virtual JointVisualPtr CreateJointVisual()=0
Create new joint visual. A unique ID and name will automatically be assigned to the Joint visual...
Quaternion< T > Inverse() const
virtual ArrowVisualPtr CreateArrowVisual()=0
Create new arrow visual. A unique ID and name will automatically be assigned to the visual...
Revolute joint type.
Definition: JointVisual.hh:42
void CreateAxis()
Helper function to create axis visual.
Definition: BaseJointVisual.hh:281
BaseJointVisual()
Constructor.
Definition: BaseJointVisual.hh:174
virtual void SetAxis(const ignition::math::Vector3d &_axis, bool _useParentFrame) override
Create an axis and attach it to the joint visual.
Definition: BaseJointVisual.hh:270
virtual void SetParentAxis(const ignition::math::Vector3d &_axis, const std::string &_parentName, bool _useParentFrame) override
Create a parent axis for hinge2 and universal joint types and attach it to the joint visual...
Definition: BaseJointVisual.hh:301