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)
86 if(
similar(position, focalPoint))
91 mCamera->SetClippingRange(nearClip, farClip);
92 mCamera->SetPosition(position.begin());
93 mCamera->SetFocalPoint(focalPoint.begin());
94 mCamera->ComputeViewPlaneNormal();
95 mCamera->SetViewUp(viewUp.begin());
96 mCamera->SetParallelScale(parallelScale);
106 mSuperiorViewAction(NULL),
107 mAnteriorViewAction(NULL)
141 return Vector3D(-1, 1, -1).normal();
154 Vector3D f(camera->GetFocalPoint());
159 camera->SetFocalPoint(f.begin());
160 camera->SetPosition(p.begin());
165 if(mSuperiorViewAction)
166 mSuperiorViewAction->trigger();
171 if(mAnteriorViewAction)
172 mAnteriorViewAction->trigger();
177 QActionGroup* group =
new QActionGroup(
this);
178 mAnteriorViewAction = this->addStandard3DViewAction(
"A",
"Anterior View",
AnteriorDirection(), group);
180 mSuperiorViewAction = this->addStandard3DViewAction(
"S",
"Superior View",
SuperiorDirection(), group);
182 this->addStandard3DViewAction(
"L",
"Left View",
LeftDirection(), group);
183 this->addStandard3DViewAction(
"R",
"Right View",
RightDirection(), group);
190 QAction* CameraControl::addStandard3DViewAction(QString caption, QString help,
Vector3D viewDirection,
193 QAction* action =
new QAction(help, group);
194 action->setStatusTip(help);
195 action->setWhatsThis(help);
196 action->setIcon(QIcon(
":/icons/camera_view_" + caption +
".png"));
211 view->getRenderer()->ResetCameraClippingRange();
228 return mView->getRenderer();
232 if (!this->getRenderer())
234 return this->getRenderer()->GetActiveCamera();
239 QAction* action =
dynamic_cast<QAction*
> (sender());
242 Vector3D viewDirection = Vector3D::fromString(action->data().toString());
253 renderer->ResetCamera();
255 Vector3D focus(camera->GetFocalPoint());
256 Vector3D pos = focus - 500 * viewDirection;
260 if (
similar(left.length(), 0.0))
262 vup =
cross(viewDirection, left).normal();
264 camera->SetPosition(pos.begin());
265 camera->SetViewUp(vup.begin());
267 renderer->ResetCamera();
269 renderer->ResetCameraClippingRange();