CustusX  22.04-rc5
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
vtkSmartPointer< class vtkActor > vtkActorPtr
vtkSmartPointer< class vtkPolyDataMapper > vtkPolyDataMapperPtr
Transform3D createTransformScale(const Vector3D &scale_)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
Definition: cxVector3D.cpp:41
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D &center)
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Transform3D createTransformTranslate(const Vector3D &translation)
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Definition: cxVector3D.cpp:46
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
GraphicalObjectWithDirection(vtkRendererPtr renderer=vtkRendererPtr())
Namespace for all CustusX production code.
void setRenderer(vtkRendererPtr renderer=vtkRendererPtr())