42 #include "vtkRenderer.h"
43 #include "vtkCamera.h"
63 mCamera = vtkCameraPtr::New();
67 void CameraData::addTextElement(QDomNode parentNode, QString name, QString value)
const
69 QDomDocument doc = parentNode.ownerDocument();
70 QDomElement node = doc.createElement(name);
71 node.appendChild(doc.createTextNode(value));
72 parentNode.appendChild(node);
83 this->addTextElement(dataNode,
"nearClip",
qstring_cast(mCamera->GetClippingRange()[0]));
84 this->addTextElement(dataNode,
"farClip",
qstring_cast(mCamera->GetClippingRange()[1]));
85 this->addTextElement(dataNode,
"parallelScale",
qstring_cast(mCamera->GetParallelScale()));
90 Vector3D position = Vector3D::fromString(dataNode.namedItem(
"position").toElement().text());
91 Vector3D focalPoint = Vector3D::fromString(dataNode.namedItem(
"focalPoint").toElement().text());
92 Vector3D viewUp = Vector3D::fromString(dataNode.namedItem(
"viewUp").toElement().text());
93 double nearClip = dataNode.namedItem(
"nearClip").toElement().text().toDouble();
94 double farClip = dataNode.namedItem(
"farClip").toElement().text().toDouble();
95 double parallelScale = dataNode.namedItem(
"parallelScale").toElement().text().toDouble();
97 if (
similar(viewUp.length(), 0.0))
99 double LARGE_NUMBER = 1.0E6;
100 if ((position-focalPoint).length() > LARGE_NUMBER)
102 if (focalPoint.length() > LARGE_NUMBER)
104 if (fabs(parallelScale) > LARGE_NUMBER)
109 mCamera->SetClippingRange(nearClip, farClip);
110 mCamera->SetPosition(position.begin());
111 mCamera->SetFocalPoint(focalPoint.begin());
112 mCamera->ComputeViewPlaneNormal();
113 mCamera->SetViewUp(viewUp.begin());
114 mCamera->SetParallelScale(parallelScale);
143 Vector3D f(camera->GetFocalPoint());
148 camera->SetFocalPoint(f.begin());
149 camera->SetPosition(p.begin());
154 mSuperiorViewAction->trigger();
159 QActionGroup* group =
new QActionGroup(
this);
160 this->addStandard3DViewAction(
"A",
"Anterior View",
Vector3D(0, 1, 0), group);
161 this->addStandard3DViewAction(
"P",
"Posterior View",
Vector3D(0, -1, 0), group);
162 mSuperiorViewAction = this->addStandard3DViewAction(
"S",
"Superior View",
Vector3D(0, 0, -1), group);
163 this->addStandard3DViewAction(
"I",
"Inferior View",
Vector3D(0, 0, 1), group);
164 this->addStandard3DViewAction(
"L",
"Left View",
Vector3D(-1, 0, 0), group);
165 this->addStandard3DViewAction(
"R",
"Right View",
Vector3D(1, 0, 0), group);
166 this->addStandard3DViewAction(
"O",
"Orthogonal View",
Vector3D(-1, 1, -1).
normal(), group);
172 QAction* CameraControl::addStandard3DViewAction(QString caption, QString help,
Vector3D viewDirection,
175 QAction* action =
new QAction(help, group);
176 action->setStatusTip(help);
177 action->setWhatsThis(help);
178 action->setIcon(QIcon(
":/icons/camera_view_" + caption +
".png"));
193 view->getRenderer()->ResetCameraClippingRange();
205 return mView->getRenderer();
209 if (!this->getRenderer())
211 return this->getRenderer()->GetActiveCamera();
216 QAction* action =
dynamic_cast<QAction*
> (sender());
219 Vector3D viewDirection = Vector3D::fromString(action->data().toString());
226 renderer->ResetCamera();
228 Vector3D focus(camera->GetFocalPoint());
229 Vector3D pos = focus - 500 * viewDirection;
234 if (
similar(left.length(), 0.0))
236 vup =
cross(viewDirection, left).normal();
238 camera->SetPosition(pos.begin());
239 camera->SetViewUp(vup.begin());
241 renderer->ResetCamera();
243 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
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
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)
CameraControl(QObject *parent=NULL)
void setStandard3DViewActionSlot()
vtkSmartPointer< class vtkCamera > vtkCameraPtr