ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkFileSequenceParser.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkFileSequenceParser.cxx
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkFileSequenceParser.h"
16 
17 #include "vtkObjectFactory.h"
18 
19 #include <set>
20 #include <string>
21 #include <vtksys/RegularExpression.hxx>
22 #include <vtksys/SystemTools.hxx>
23 
25 //-----------------------------------------------------------------------------
27  : // sequence ending with numbers.
28  reg_ex(new vtksys::RegularExpression("^(.*)\\.([0-9.]+)$"))
29  ,
30  // sequence ending with extension.
31  reg_ex2(new vtksys::RegularExpression("^(.*)(\\.|_|-)([0-9.]+)\\.(.*)$"))
32  ,
33  // sequence ending with extension, but with no ". or _" before
34  // the series number.
35  reg_ex3(new vtksys::RegularExpression("^(.*)([a-zA-Z])([0-9.]+)\\.(.*)$"))
36  ,
37  // sequence ending with extension, and starting with series number
38  // followed by ". or _".
39  reg_ex4(new vtksys::RegularExpression("^([0-9.]+)(\\.|_|-)(.*)\\.(.*)$"))
40  ,
41  // sequence ending with extension, and starting with series number,
42  // but not followed by ". or _".
43  reg_ex5(new vtksys::RegularExpression("^([0-9.]+)([a-zA-Z])(.*)\\.(.*)$"))
44 
45  ,
46  // fallback: any sequence with a number in the middle (taking the last number
47  // if multiple exist).
48  reg_ex_last(new vtksys::RegularExpression("^(.*[^0-9])([0-9]+)([^0-9]*)$"))
49  , SequenceIndex(-1)
50  , SequenceName(NULL)
51 {
52 }
53 
54 //-----------------------------------------------------------------------------
56 {
57  delete this->reg_ex;
58  delete this->reg_ex2;
59  delete this->reg_ex3;
60  delete this->reg_ex4;
61  delete this->reg_ex5;
62  delete this->reg_ex_last;
63 
64  this->SetSequenceName(NULL);
65 }
66 
67 //-----------------------------------------------------------------------------
69 {
70  bool match = false;
71  if (this->reg_ex->find(file))
72  {
73  this->SetSequenceName(this->reg_ex->match(1).c_str());
74  this->SequenceIndex = atoi(reg_ex->match(2).c_str());
75  match = true;
76  }
77  else if (this->reg_ex2->find(file))
78  {
79  this->SetSequenceName(std::string(this->reg_ex2->match(1) + this->reg_ex2->match(2) + ".." +
80  this->reg_ex2->match(4))
81  .c_str());
82  this->SequenceIndex = atoi(reg_ex2->match(3).c_str());
83  match = true;
84  }
85  else if (this->reg_ex3->find(file))
86  {
87  this->SetSequenceName(std::string(this->reg_ex3->match(1) + this->reg_ex3->match(2) + ".." +
88  this->reg_ex3->match(4))
89  .c_str());
90  this->SequenceIndex = atoi(reg_ex3->match(3).c_str());
91  match = true;
92  }
93  else if (this->reg_ex4->find(file))
94  {
95  this->SetSequenceName(std::string(".." + this->reg_ex4->match(2) + this->reg_ex4->match(3) +
96  "." + this->reg_ex4->match(4))
97  .c_str());
98  this->SequenceIndex = atoi(reg_ex4->match(1).c_str());
99  match = true;
100  }
101  else if (this->reg_ex5->find(file))
102  {
103  this->SetSequenceName(std::string(".." + this->reg_ex5->match(2) + this->reg_ex5->match(3) +
104  "." + this->reg_ex5->match(4))
105  .c_str());
106  this->SequenceIndex = atoi(reg_ex5->match(1).c_str());
107  match = true;
108  }
109  else
110  {
111  std::string fname_wo_ext = vtksys::SystemTools::GetFilenameWithoutExtension(file);
112  std::string ext = vtksys::SystemTools::GetFilenameExtension(file);
113  if (this->reg_ex_last->find(fname_wo_ext))
114  {
115  this->SetSequenceName(
116  (this->reg_ex_last->match(1) + ".." + this->reg_ex_last->match(3) + ext).c_str());
117  this->SequenceIndex = atoi(reg_ex_last->match(2).c_str());
118  match = true;
119  }
120  }
121  return match;
122 }
123 
124 //-----------------------------------------------------------------------------
125 void vtkFileSequenceParser::PrintSelf(ostream& os, vtkIndent indent)
126 {
127  this->Superclass::PrintSelf(os, indent);
128 }
#define NULL
void PrintSelf(ostream &os, vtkIndent indent) override
bool ParseFileSequence(const char *file)
vtksys::RegularExpression * reg_ex_last
vtksys::RegularExpression * reg_ex
vtksys::RegularExpression * reg_ex4
vtksys::RegularExpression * reg_ex3
vtksys::RegularExpression * reg_ex5
vtksys::RegularExpression * reg_ex2
vtkStandardNewMacro(vtkFileSequenceParser)