21 #include "vtkRenderer.h" 22 #include "vtkCamera.h" 43 mCamera = vtkCameraPtr::New();
47 void CameraData::addTextElement(QDomNode parentNode, QString name, QString value)
const 49 QDomDocument doc = parentNode.ownerDocument();
50 QDomElement node = doc.createElement(name);
51 node.appendChild(doc.createTextNode(value));
52 parentNode.appendChild(node);
63 this->addTextElement(dataNode,
"nearClip",
qstring_cast(mCamera->GetClippingRange()[0]));
64 this->addTextElement(dataNode,
"farClip",
qstring_cast(mCamera->GetClippingRange()[1]));
65 this->addTextElement(dataNode,
"parallelScale",
qstring_cast(mCamera->GetParallelScale()));
70 Vector3D position = Vector3D::fromString(dataNode.namedItem(
"position").toElement().text());
71 Vector3D focalPoint = Vector3D::fromString(dataNode.namedItem(
"focalPoint").toElement().text());
72 Vector3D viewUp = Vector3D::fromString(dataNode.namedItem(
"viewUp").toElement().text());
73 double nearClip = dataNode.namedItem(
"nearClip").toElement().text().toDouble();
74 double farClip = dataNode.namedItem(
"farClip").toElement().text().toDouble();
75 double parallelScale = dataNode.namedItem(
"parallelScale").toElement().text().toDouble();
77 if (
similar(viewUp.length(), 0.0))
79 double LARGE_NUMBER = 1.0E6;
80 if ((position-focalPoint).length() > LARGE_NUMBER)
82 if (focalPoint.length() > LARGE_NUMBER)
84 if (fabs(parallelScale) > LARGE_NUMBER)
89 mCamera->SetClippingRange(nearClip, farClip);
90 mCamera->SetPosition(position.begin());
91 mCamera->SetFocalPoint(focalPoint.begin());
92 mCamera->ComputeViewPlaneNormal();
93 mCamera->SetViewUp(viewUp.begin());
94 mCamera->SetParallelScale(parallelScale);
104 mSuperiorViewAction(NULL),
105 mAnteriorViewAction(NULL)
123 Vector3D f(camera->GetFocalPoint());
128 camera->SetFocalPoint(f.begin());
129 camera->SetPosition(p.begin());
134 if(mSuperiorViewAction)
135 mSuperiorViewAction->trigger();
140 if(mAnteriorViewAction)
141 mAnteriorViewAction->trigger();
146 QActionGroup* group =
new QActionGroup(
this);
147 mAnteriorViewAction = this->addStandard3DViewAction(
"A",
"Anterior View",
Vector3D(0, 1, 0), group);
148 this->addStandard3DViewAction(
"P",
"Posterior View",
Vector3D(0, -1, 0), group);
149 mSuperiorViewAction = this->addStandard3DViewAction(
"S",
"Superior View",
Vector3D(0, 0, -1), group);
150 this->addStandard3DViewAction(
"I",
"Inferior View",
Vector3D(0, 0, 1), group);
151 this->addStandard3DViewAction(
"L",
"Left View",
Vector3D(-1, 0, 0), group);
152 this->addStandard3DViewAction(
"R",
"Right View",
Vector3D(1, 0, 0), group);
153 this->addStandard3DViewAction(
"O",
"Orthogonal View",
Vector3D(-1, 1, -1).
normal(), group);
159 QAction* CameraControl::addStandard3DViewAction(QString caption, QString help,
Vector3D viewDirection,
162 QAction* action =
new QAction(help, group);
163 action->setStatusTip(help);
164 action->setWhatsThis(help);
165 action->setIcon(QIcon(
":/icons/camera_view_" + caption +
".png"));
180 view->getRenderer()->ResetCameraClippingRange();
197 return mView->getRenderer();
201 if (!this->getRenderer())
203 return this->getRenderer()->GetActiveCamera();
208 QAction* action =
dynamic_cast<QAction*
> (sender());
211 Vector3D viewDirection = Vector3D::fromString(action->data().toString());
218 renderer->ResetCamera();
220 Vector3D focus(camera->GetFocalPoint());
221 Vector3D pos = focus - 500 * viewDirection;
227 if (
similar(left.length(), 0.0))
229 vup =
cross(viewDirection, left).normal();
236 camera->SetPosition(pos.begin());
237 camera->SetViewUp(vup.begin());
239 renderer->ResetCamera();
241 renderer->ResetCameraClippingRange();
QString qstring_cast(const T &val)
PlainObject normal() const
void setSuperiorView() const
vtkCameraPtr getCamera() const
void translateByFocusTo(Vector3D p_r)
boost::shared_ptr< class View > ViewPtr
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
QActionGroup * createStandard3DViewActions()
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
void setView(ViewPtr view)
void refreshView(ViewPtr view)
void parseXml(QDomNode dataNode)
load internal state info from dataNode
void addXml(QDomNode dataNode) const
store internal state info in dataNode
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
void setCamera(vtkCameraPtr camera)
void setAnteriorView() const
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
CameraControl(QObject *parent=NULL)
void setStandard3DViewActionSlot()
vtkSmartPointer< class vtkCamera > vtkCameraPtr
Namespace for all CustusX production code.