42 #include "vtkRenderer.h" 43 #include "vtkCamera.h" 64 mCamera = vtkCameraPtr::New();
68 void CameraData::addTextElement(QDomNode parentNode, QString name, QString value)
const 70 QDomDocument doc = parentNode.ownerDocument();
71 QDomElement node = doc.createElement(name);
72 node.appendChild(doc.createTextNode(value));
73 parentNode.appendChild(node);
84 this->addTextElement(dataNode,
"nearClip",
qstring_cast(mCamera->GetClippingRange()[0]));
85 this->addTextElement(dataNode,
"farClip",
qstring_cast(mCamera->GetClippingRange()[1]));
86 this->addTextElement(dataNode,
"parallelScale",
qstring_cast(mCamera->GetParallelScale()));
91 Vector3D position = Vector3D::fromString(dataNode.namedItem(
"position").toElement().text());
92 Vector3D focalPoint = Vector3D::fromString(dataNode.namedItem(
"focalPoint").toElement().text());
93 Vector3D viewUp = Vector3D::fromString(dataNode.namedItem(
"viewUp").toElement().text());
94 double nearClip = dataNode.namedItem(
"nearClip").toElement().text().toDouble();
95 double farClip = dataNode.namedItem(
"farClip").toElement().text().toDouble();
96 double parallelScale = dataNode.namedItem(
"parallelScale").toElement().text().toDouble();
98 if (
similar(viewUp.length(), 0.0))
100 double LARGE_NUMBER = 1.0E6;
101 if ((position-focalPoint).length() > LARGE_NUMBER)
103 if (focalPoint.length() > LARGE_NUMBER)
105 if (fabs(parallelScale) > LARGE_NUMBER)
110 mCamera->SetClippingRange(nearClip, farClip);
111 mCamera->SetPosition(position.begin());
112 mCamera->SetFocalPoint(focalPoint.begin());
113 mCamera->ComputeViewPlaneNormal();
114 mCamera->SetViewUp(viewUp.begin());
115 mCamera->SetParallelScale(parallelScale);
125 mSuperiorViewAction(NULL),
126 mAnteriorViewAction(NULL)
144 Vector3D f(camera->GetFocalPoint());
149 camera->SetFocalPoint(f.begin());
150 camera->SetPosition(p.begin());
155 if(mSuperiorViewAction)
156 mSuperiorViewAction->trigger();
161 if(mAnteriorViewAction)
162 mAnteriorViewAction->trigger();
167 QActionGroup* group =
new QActionGroup(
this);
168 mAnteriorViewAction = this->addStandard3DViewAction(
"A",
"Anterior View",
Vector3D(0, 1, 0), group);
169 this->addStandard3DViewAction(
"P",
"Posterior View",
Vector3D(0, -1, 0), group);
170 mSuperiorViewAction = this->addStandard3DViewAction(
"S",
"Superior View",
Vector3D(0, 0, -1), group);
171 this->addStandard3DViewAction(
"I",
"Inferior View",
Vector3D(0, 0, 1), group);
172 this->addStandard3DViewAction(
"L",
"Left View",
Vector3D(-1, 0, 0), group);
173 this->addStandard3DViewAction(
"R",
"Right View",
Vector3D(1, 0, 0), group);
174 this->addStandard3DViewAction(
"O",
"Orthogonal View",
Vector3D(-1, 1, -1).
normal(), group);
180 QAction* CameraControl::addStandard3DViewAction(QString caption, QString help,
Vector3D viewDirection,
183 QAction* action =
new QAction(help, group);
184 action->setStatusTip(help);
185 action->setWhatsThis(help);
186 action->setIcon(QIcon(
":/icons/camera_view_" + caption +
".png"));
201 view->getRenderer()->ResetCameraClippingRange();
218 return mView->getRenderer();
222 if (!this->getRenderer())
224 return this->getRenderer()->GetActiveCamera();
229 QAction* action =
dynamic_cast<QAction*
> (sender());
232 Vector3D viewDirection = Vector3D::fromString(action->data().toString());
239 renderer->ResetCamera();
241 Vector3D focus(camera->GetFocalPoint());
242 Vector3D pos = focus - 500 * viewDirection;
248 if (
similar(left.length(), 0.0))
250 vup =
cross(viewDirection, left).normal();
257 camera->SetPosition(pos.begin());
258 camera->SetViewUp(vup.begin());
260 renderer->ResetCamera();
262 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.