28 #include <QFileDialog> 32 #include <vtkWindowToImageFilter.h> 33 #include <vtkPNGWriter.h> 41 m_renderWindowInteractor(renderWindowInteractor), m_pathCamera(pathCamera), m_treeWidget(treeWidget)
56 dialog->activateWindow();
66 QObject::connect(
m_dialog->addFrame_button, SIGNAL(pressed()),
this, SLOT(
addFrame()));
67 QObject::connect(
m_dialog->removeFrame_button, SIGNAL(pressed()),
this, SLOT(
removeFrame()));
68 QObject::connect(
m_dialog->clearFrames_button, SIGNAL(pressed()),
this, SLOT(
clearFrames()));
69 QObject::connect(
m_dialog->interpolation_box, SIGNAL(currentIndexChanged(
const QString&)),
this, SLOT(
changeInterpolation(
const QString&)));
70 QObject::connect(
m_dialog->savePath_button, SIGNAL(pressed()),
this, SLOT(
savePath()));
71 QObject::connect(
m_dialog->loadPath_button, SIGNAL(pressed()),
this, SLOT(
loadPath()));
72 QObject::connect(
m_dialog->saveVideo_button, SIGNAL(pressed()),
this, SLOT(
saveVideo()));
73 QObject::connect(
m_dialog->play_button, SIGNAL(pressed()),
this, SLOT(
play()));
75 QObject::connect(
m_dialog->timeline_list, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(
goToCamPosition(QListWidgetItem*)));
84 vtkRendererCollection* renderers = window->GetRenderers();
85 renderers->InitTraversal();
86 vtkRenderer* r = renderers->GetNextItem();
89 vtkCamera* ac = r->GetActiveCamera();
90 vtkCamera* frame = cam_item->
getFrame();
92 ac->SetPosition(frame->GetPosition());
93 ac->SetFocalPoint(frame->GetFocalPoint());
94 ac->SetViewUp(frame->GetViewUp());
97 r = renderers->GetNextItem();
105 QString frameCount = QString(
"Frame no. %1").arg(++
m_frameCounter);
112 QListWidgetItem* currentItem =
m_timeline->currentItem();
113 if(currentItem)
delete currentItem;
126 m_pathCamera->GetInterpolator()->SetInterpolationTypeToLinear();
128 else if(text ==
"Spline")
130 m_pathCamera->GetInterpolator()->SetInterpolationTypeToSpline();
137 unsigned int frameCount =
m_timeline->count();
141 for(
int i = 0; i < frameCount; i++)
148 unsigned int frameMultiplier =
m_dialog->frameMultiplier_box->value();
149 m_pathCamera->SetNumberOfFrames(frameCount * frameMultiplier);
159 QFile pfile(filename);
161 if (!pfile.open(QFile::WriteOnly | QIODevice::Text))
166 QTextStream out(&pfile);
168 QString interpolation =
m_dialog->interpolation_box->currentText();
169 QString transitionFrames = QString::number(
m_dialog->frameMultiplier_box->value());
170 out <<
"S:" << interpolation <<
";" << transitionFrames << endl;
173 for(
int row = 0; row <
m_timeline->count(); row++)
185 dialog.setAcceptMode(QFileDialog::AcceptOpen);
186 dialog.setOption(QFileDialog::Option::DontUseNativeDialog,
true);
187 dialog.setNameFilter(
"*.vcp");
194 QStringList files = dialog.selectedFiles();
196 QFile pfile(filename);
197 if (!pfile.open(QFile::ReadOnly | QIODevice::Text))
199 cout <<
"Error opening file " << filename.toStdString() << endl;
203 QTextStream in(&pfile);
204 QString line = in.readLine();
210 if(!line.startsWith(
"S:"))
212 cout <<
"Can't parse path settings from file!" << endl;
213 cout <<
"Reverting to defaults..." << endl;
214 m_dialog->frameMultiplier_box->setValue(30);
215 m_dialog->interpolation_box->setCurrentIndex(1);
216 m_pathCamera->GetInterpolator()->SetInterpolationTypeToSpline();
220 QStringList parameters = line.trimmed().split(
";");
222 cout << parameters[0].toStdString() << endl;
223 cout << parameters[1].toStdString() << endl;
225 if(parameters[0] ==
"Linear")
227 m_pathCamera->GetInterpolator()->SetInterpolationTypeToLinear();
228 m_dialog->interpolation_box->setCurrentIndex(0);
230 else if(parameters[0] ==
"Spline")
232 m_pathCamera->GetInterpolator()->SetInterpolationTypeToSpline();
233 m_dialog->interpolation_box->setCurrentIndex(1);
236 int transitionFrames = parameters[1].toInt();
237 m_dialog->frameMultiplier_box->setValue(transitionFrames);
260 vtkCameraInterpolator* i =
m_pathCamera->GetInterpolator();
262 unsigned int frameCount =
m_timeline->count();
265 for(
int i = 0; i < frameCount; i++)
272 unsigned int frameMultiplier =
m_dialog->frameMultiplier_box->value();
273 m_pathCamera->SetNumberOfFrames(frameCount * frameMultiplier);
278 double minT = i->GetMinimumT();
279 double maxT = i->GetMaximumT();
280 int n = frameMultiplier * frameCount;
281 double step = (maxT - minT) / (
double)n;
282 vtkSmartPointer<vtkCamera> i_cam = vtkSmartPointer<vtkCamera>::New();
288 vtkRenderer* renderer;
292 for(
double camT = 0; camT < maxT; camT +=
step)
294 i->InterpolateCamera(camT, i_cam);
296 collection->InitTraversal();
297 renderer = collection->GetNextItem();
300 renderer->GetActiveCamera()->DeepCopy(i_cam);
302 renderer = collection->GetNextItem();
305 vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
306 vtkSmartPointer<vtkWindowToImageFilter>::New();
309 windowToImageFilter->Update();
311 vtkSmartPointer<vtkPNGWriter> writer =
312 vtkSmartPointer<vtkPNGWriter>::New();
314 sprintf(buffer,
"frame%04d.png", c);
316 writer->SetFileName(buffer);
317 writer->SetInputConnection(windowToImageFilter->GetOutputPort());
320 cout << c <<
" / " << frameCount * frameMultiplier << endl;
AnimationDialog * m_dialog
LVRAnimationDialog(vtkSmartPointer< vtkRenderWindowInteractor > renderWindowInteractor, vtkSmartPointer< vtkCameraRepresentation > pathCamera, QTreeWidget *treeWidget)
void changeInterpolation(const QString &text)
void writeToStream(QTextStream &out)
void goToCamPosition(QListWidgetItem *item)
vtkSmartPointer< vtkRenderWindowInteractor > m_renderWindowInteractor
__kf_device__ Vec3f tr(const float4 &v)
vtkSmartPointer< vtkCamera > getFrame()
vtkSmartPointer< vtkCameraRepresentation > m_pathCamera
virtual ~LVRAnimationDialog()
QTreeWidget * m_treeWidget
static LVRRecordedFrameItem * createFromStream(QTextStream &in)
vtkSmartPointer< vtkCamera > m_mainCamera
void connectSignalsAndSlots()
unsigned int m_frameCounter