NorMIT-nav  22.09
An IGT application
cxGraphicalObjectWithDirection.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include "vtkMatrix4x4.h"
14 #include "cxVtkHelperClasses.h"
15 #include <vtkActor.h>
16 #include <vtkPolyDataMapper.h>
17 #include <vtkSuperquadricSource.h>
18 #include <vtkRenderer.h>
19 
20 
21 namespace cx
22 {
23 
25 {
26  mPoint = Vector3D(0,0,0);
27  mDirection = Vector3D(0,1,0);
28  mVectorUp = Vector3D(1,0,0);
29  mScale = Vector3D(1,1,1);
30  mSource = vtkSuperquadricSourcePtr::New();
31 
32  mMapper = vtkPolyDataMapperPtr::New();
33  mMapper->SetInputConnection(mSource->GetOutputPort());
34 
35  mActor = vtkActorPtr::New();
36  mActor->SetMapper(mMapper);
37 
38  this->setRenderer(renderer);
39 }
40 
42 {
43  this->setRenderer(NULL);
44 }
45 
47 {
48  return mActor;
49 }
50 
52 {
53  return mSource->GetOutput();
54 }
55 
57 {
58  return mMapper;
59 }
60 
62 {
63  mPoint = point;
64  this->updateOrientation();
65 }
66 
68 {
69  mDirection = direction;
70  this->updateOrientation();
71 }
72 
74 {
75  mVectorUp = up;
76  this->updateOrientation();
77 }
78 
80 {
81  mScale = scale;
82  this->updateOrientation();
83 }
84 
86 {
87  if (mRenderer)
88  mRenderer->RemoveActor(mActor);
89  mRenderer = renderer;
90  if (mRenderer)
91  mRenderer->AddActor(mActor);
92 }
93 
95 {
96  Transform3D R;
97  bool directionAlongUp = similar(dot(mVectorUp, mDirection.normal()), 1.0);
98 
99  if (directionAlongUp)
100  {
101  R = Transform3D::Identity();
102  }
103 
104  else
105  {
106  Vector3D jvec = mDirection.normal();
107  Vector3D kvec = cross(mVectorUp, mDirection).normal();
108  Vector3D ivec = cross(jvec, kvec).normal();
109  Vector3D center = Vector3D::Zero();
110  R = createTransformIJC(ivec, jvec, center);
111  }
112 
115  Transform3D M = T*R*S;
116  mActor->SetUserMatrix(M.getVtkMatrix());
117 }
118 
119 
120 } // namespace cx
cx::GraphicalObjectWithDirection::setScale
void setScale(Vector3D scale)
Definition: cxGraphicalObjectWithDirection.cpp:79
cxGraphicalObjectWithDirection.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::GraphicalObjectWithDirection::getActor
vtkActorPtr getActor() const
Definition: cxGraphicalObjectWithDirection.cpp:46
cx::createTransformScale
Transform3D createTransformScale(const Vector3D &scale_)
Definition: cxTransform3D.cpp:157
cx::GraphicalObjectWithDirection::setPosition
void setPosition(Vector3D point)
Definition: cxGraphicalObjectWithDirection.cpp:61
cx::GraphicalObjectWithDirection::getPolyData
vtkPolyDataPtr getPolyData() const
Definition: cxGraphicalObjectWithDirection.cpp:51
cx::GraphicalObjectWithDirection::mVectorUp
Vector3D mVectorUp
Definition: cxGraphicalObjectWithDirection.h:56
cx::GraphicalObjectWithDirection::GraphicalObjectWithDirection
GraphicalObjectWithDirection(vtkRendererPtr renderer=vtkRendererPtr())
Definition: cxGraphicalObjectWithDirection.cpp:24
cx::GraphicalObjectWithDirection::getMapper
vtkPolyDataMapperPtr getMapper() const
Definition: cxGraphicalObjectWithDirection.cpp:56
cx::createTransformIJC
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D &center)
Definition: cxTransform3D.cpp:255
vtkPolyDataMapperPtr
vtkSmartPointer< class vtkPolyDataMapper > vtkPolyDataMapperPtr
Definition: vtkForwardDeclarations.h:112
cx::GraphicalObjectWithDirection::mActor
vtkActorPtr mActor
Definition: cxGraphicalObjectWithDirection.h:51
cx::GraphicalObjectWithDirection::mPoint
Vector3D mPoint
Definition: cxGraphicalObjectWithDirection.h:54
cx::GraphicalObjectWithDirection::mDirection
Vector3D mDirection
Definition: cxGraphicalObjectWithDirection.h:55
cx::cross
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
Definition: cxVector3D.cpp:41
cx::GraphicalObjectWithDirection::mScale
Vector3D mScale
Definition: cxGraphicalObjectWithDirection.h:57
cx::GraphicalObjectWithDirection::setDirection
void setDirection(Vector3D direction)
Definition: cxGraphicalObjectWithDirection.cpp:67
cx::GraphicalObjectWithDirection::mSource
vtkSuperquadricSourcePtr mSource
Definition: cxGraphicalObjectWithDirection.h:49
cx::GraphicalObjectWithDirection::setRenderer
void setRenderer(vtkRendererPtr renderer=vtkRendererPtr())
Definition: cxGraphicalObjectWithDirection.cpp:85
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
vtkActorPtr
vtkSmartPointer< class vtkActor > vtkActorPtr
Definition: vtkForwardDeclarations.h:31
cxVtkHelperClasses.h
cx::GraphicalObjectWithDirection::~GraphicalObjectWithDirection
virtual ~GraphicalObjectWithDirection()
Definition: cxGraphicalObjectWithDirection.cpp:41
cx::GraphicalObjectWithDirection::mRenderer
vtkRendererPtr mRenderer
Definition: cxGraphicalObjectWithDirection.h:52
cx::createTransformTranslate
Transform3D createTransformTranslate(const Vector3D &translation)
Definition: cxTransform3D.cpp:164
cx::GraphicalObjectWithDirection::updateOrientation
void updateOrientation()
Definition: cxGraphicalObjectWithDirection.cpp:94
cx::GraphicalObjectWithDirection::setVectorUp
void setVectorUp(const Vector3D &up)
Definition: cxGraphicalObjectWithDirection.cpp:73
cx::dot
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Definition: cxVector3D.cpp:46
cx::GraphicalObjectWithDirection::mMapper
vtkPolyDataMapperPtr mMapper
Definition: cxGraphicalObjectWithDirection.h:50
cx::similar
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Definition: cxCameraStyleForView.cpp:506
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
vtkRendererPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Definition: vtkForwardDeclarations.h:122