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 QActionGroup* group =
new QActionGroup(
this);
155 this->addStandard3DViewAction(
"A",
"Anterior View",
Vector3D(0, 1, 0), group);
156 this->addStandard3DViewAction(
"P",
"Posterior View",
Vector3D(0, -1, 0), group);
157 this->addStandard3DViewAction(
"S",
"Superior View",
Vector3D(0, 0, -1), group);
158 this->addStandard3DViewAction(
"I",
"Inferior View",
Vector3D(0, 0, 1), group);
159 this->addStandard3DViewAction(
"L",
"Left View",
Vector3D(-1, 0, 0), group);
160 this->addStandard3DViewAction(
"R",
"Right View",
Vector3D(1, 0, 0), group);
161 this->addStandard3DViewAction(
"O",
"Orthogonal View",
Vector3D(-1, 1, -1).
normal(), group);
167 QAction* CameraControl::addStandard3DViewAction(QString caption, QString help,
Vector3D viewDirection,
170 QAction* action =
new QAction(help, group);
171 action->setStatusTip(help);
172 action->setWhatsThis(help);
173 action->setIcon(QIcon(
":/icons/camera_view_" + caption +
".png"));
193 return mView->getRenderer();
197 if (!this->getRenderer())
199 return this->getRenderer()->GetActiveCamera();
204 QAction* action =
dynamic_cast<QAction*
> (sender());
207 Vector3D viewDirection = Vector3D::fromString(action->data().toString());
214 renderer->ResetCamera();
216 Vector3D focus(camera->GetFocalPoint());
217 Vector3D pos = focus - 500 * viewDirection;
222 if (
similar(left.length(), 0.0))
224 vup =
cross(viewDirection, left).normal();
226 camera->SetPosition(pos.begin());
227 camera->SetViewUp(vup.begin());
229 renderer->ResetCamera();
231 renderer->ResetCameraClippingRange();
QString qstring_cast(const T &val)
PlainObject normal() 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 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