X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkMeshViewer.cxx;h=c21bc4e43f31cf7e9d64936076b1411ad4562d48;hb=01a0dd7b79c5e5d5b82878d9e64dcba12891b53d;hp=a56275a5bce4a861a89b0ad4cacc0bdd1151a380;hpb=cc9dd25626089b66646bab3d454e07a2bf2c624a;p=clitk.git diff --git a/tools/clitkMeshViewer.cxx b/tools/clitkMeshViewer.cxx index a56275a..c21bc4e 100644 --- a/tools/clitkMeshViewer.cxx +++ b/tools/clitkMeshViewer.cxx @@ -30,6 +30,9 @@ #include "vtkProperty.h" #include "vtkInteractorStyle.h" +#include "clitkCommon.h" +#include "clitkMeshViewer_ggo.h" + #include #include #include @@ -39,13 +42,17 @@ typedef vtkSmartPointer MapperType; typedef vtkSmartPointer ActorType; -void run(int argc, char** argv); +long run(const args_info_clitkMeshViewer& argsInfo); // Adapted from vtkAnimationCue example... class CueAnimator { public: - CueAnimator(std::vector& rActors) : m_Fps(1), m_LastTick(0), m_CurrentActor(0), m_rActors(rActors) { + CueAnimator(std::vector& rActors) : m_Fps(1), m_CurrentActor(0), m_rActors(rActors) { + m_rActors[0]->SetVisibility(1); + for (unsigned int i = 1; i < m_rActors.size(); i++) { + m_rActors[i]->SetVisibility(0); + } } ~CueAnimator() { @@ -58,45 +65,37 @@ public: void StartCue(vtkAnimationCue::AnimationCueInfo *vtkNotUsed(info), vtkRenderer *ren) { - std::cout << "StartCue" << std::endl; - m_LastTick = 0; - m_rActors[0]->SetVisibility(1); - - for (unsigned int i = 1; i < m_rActors.size(); i++) { - m_rActors[i]->SetVisibility(0); - } - + //std::cout << "StartCue" << std::endl; } void Tick(vtkAnimationCue::AnimationCueInfo *info, vtkRenderer *ren) { - std::cout << "Tick AT:" << info->AnimationTime << " DT:" << info->DeltaTime << " CT:" << info->ClockTime << std::endl; - if (info->AnimationTime - m_LastTick < 1/m_Fps) - return; - - m_LastTick = info->AnimationTime; + //std::cout << "Tick AT:" << info->AnimationTime << " DT:" << info->DeltaTime << " CT:" << info->ClockTime << std::endl; m_rActors[m_CurrentActor]->SetVisibility(0); - ++m_CurrentActor; - m_CurrentActor %= m_rActors.size(); - + int step = lrint(m_Fps * info->AnimationTime); + int actor = step % m_rActors.size(); + + //if (actor != m_CurrentActor) std::cout << "Showing frame: " << m_CurrentActor << std::endl; + m_CurrentActor = actor; m_rActors[m_CurrentActor]->SetVisibility(1); ren->Render(); } - void EndCue(vtkAnimationCue::AnimationCueInfo *vtkNotUsed(info), + void EndCue(vtkAnimationCue::AnimationCueInfo *info, vtkRenderer *ren) { - std::cout << "EndCue" << std::endl; + //std::cout << "EndCue" << std::endl; } protected: double m_Fps; - double m_LastTick; + clock_t m_LastTick; + double m_TotalTicks; int m_CurrentActor; std::vector& m_rActors; }; @@ -162,13 +161,13 @@ public: void *calldata) { vtkRenderWindowInteractor *isi = dynamic_cast(caller); - std::cout << "Execute" << std::endl; + //std::cout << "Execute" << std::endl; switch (event) { case vtkCommand::KeyPressEvent: { std::string key = isi->GetKeySym(); - std::cout << key[0] << std::endl; + //std::cout << key[0] << std::endl; switch (key[0]) { case 'P': @@ -204,30 +203,34 @@ public: int main(int argc, char** argv) { - if (argc == 0) - std::cout << "Usage: clitkMeshViewer FILE1 FILE2 ..." << std::endl; + GGO(clitkMeshViewer, args_info); - run(argc, argv); - - return EXIT_SUCCESS; + return run(args_info); } -void run(int argc, char** argv) +long run(const args_info_clitkMeshViewer& argsInfo) { std::vector objs; std::vector mappers; std::vector actors; - int nfiles = argc; - std::string animate = argv[argc-1]; - if (animate == "--animate") - nfiles = argc-1; + bool verbose = argsInfo.verbose_flag; + + int nfiles = argsInfo.inputs_num; + if (nfiles == 0) + { + std::cout << "At leas one mesh (.OBJ) file must be given. See clitkMeshViewer -h." << std::endl; + return -1; + } + + if (verbose) + std::cout << nfiles << " file(s) to be loaded..." << std::endl; vtkSmartPointer aRenderer = vtkRenderer::New(); - for (int i = 1; i < nfiles; i++) { - std::string file = argv[i]; - - std::cout << "Reading " << file << std::endl; + for (int i = 0; i < nfiles; i++) { + std::string file = argsInfo.inputs[i]; + if (verbose) + std::cout << "Reading " << file << std::endl; vtkSmartPointer preader = vtkOBJReader::New(); preader->SetFileName(file.c_str()); @@ -272,10 +275,11 @@ void run(int argc, char** argv) vtkSmartPointer window_observer; CueAnimator animator(actors); - double fps = 5; - animator.SetFps(fps); + bool animate = argsInfo.animate_flag; + if (animate) { + double fps = argsInfo.fps_arg; + animator.SetFps(fps); - if (animate == "--animate") { // Create an Animation Scene scene=vtkAnimationScene::New(); scene->SetModeToRealTime(); @@ -308,6 +312,7 @@ void run(int argc, char** argv) } iren->Start(); + return 0; }