1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
* @class vtkSortFileNames
* @brief Group and sort a set of filenames
*
* vtkSortFileNames will take a list of filenames (e.g. from
* a file load dialog) and sort them into one or more series. If
* the input list of filenames contains any directories, these can
* be removed before sorting using the SkipDirectories flag. This
* class should be used where information about the series groupings
* can be determined by the filenames, but it might not be successful
* in cases where the information about the series groupings is
* stored in the files themselves (e.g DICOM).
* @sa
* vtkImageReader2
*/
#ifndef vtkSortFileNames_h
#define vtkSortFileNames_h
#include "vtkIOCoreModule.h" // For export macro
#include "vtkObject.h"
VTK_ABI_NAMESPACE_BEGIN
class vtkStringArray;
// this is a helper class defined in the .cxx file
class vtkStringArrayVector;
class VTKIOCORE_EXPORT vtkSortFileNames : public vtkObject
{
public:
vtkTypeMacro(vtkSortFileNames, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkSortFileNames* New();
///@{
/**
* Sort the file names into groups, according to similarity in
* filename name and path. Files in different directories,
* or with different extensions, or which do not fit into the same
* numbered series will be placed into different groups. This is
* off by default.
*/
vtkSetMacro(Grouping, vtkTypeBool);
vtkGetMacro(Grouping, vtkTypeBool);
vtkBooleanMacro(Grouping, vtkTypeBool);
///@}
///@{
/**
* Sort the files numerically, rather than lexicographically.
* For filenames that contain numbers, this means the order will be
* ["file8.dat", "file9.dat", "file10.dat"]
* instead of the usual alphabetic sorting order
* ["file10.dat" "file8.dat", "file9.dat"].
* NumericSort is off by default.
*/
vtkSetMacro(NumericSort, vtkTypeBool);
vtkGetMacro(NumericSort, vtkTypeBool);
vtkBooleanMacro(NumericSort, vtkTypeBool);
///@}
///@{
/**
* Ignore case when sorting. This flag is honored by both
* the sorting and the grouping. This is off by default.
*/
vtkSetMacro(IgnoreCase, vtkTypeBool);
vtkGetMacro(IgnoreCase, vtkTypeBool);
vtkBooleanMacro(IgnoreCase, vtkTypeBool);
///@}
///@{
/**
* Skip directories. If this flag is set, any input item that
* is a directory rather than a file will not be included in
* the output. This is off by default.
*/
vtkSetMacro(SkipDirectories, vtkTypeBool);
vtkGetMacro(SkipDirectories, vtkTypeBool);
vtkBooleanMacro(SkipDirectories, vtkTypeBool);
///@}
///@{
/**
* Set a list of file names to group and sort.
*/
void SetInputFileNames(vtkStringArray* input);
vtkGetObjectMacro(InputFileNames, vtkStringArray);
///@}
/**
* Get the full list of sorted filenames.
*/
virtual vtkStringArray* GetFileNames();
/**
* Get the number of groups that the names were split into, if
* grouping is on. The filenames are automatically split into
* groups, where the filenames in each group will be identical
* except for their series numbers. If grouping is not on, this
* method will return zero.
*/
virtual int GetNumberOfGroups();
/**
* Get the Nth group of file names. This method should only
* be used if grouping is on. If grouping is off, it will always
* return null.
*/
virtual vtkStringArray* GetNthGroup(int i);
/**
* Update the output filenames from the input filenames.
* This method is called automatically by GetFileNames()
* and GetNumberOfGroups() if the input names have changed.
*/
virtual void Update();
protected:
vtkSortFileNames();
~vtkSortFileNames() override;
vtkTypeBool NumericSort;
vtkTypeBool IgnoreCase;
vtkTypeBool Grouping;
vtkTypeBool SkipDirectories;
vtkTimeStamp UpdateTime;
vtkStringArray* InputFileNames;
vtkStringArray* FileNames;
vtkStringArrayVector* Groups;
/**
* Fill the output.
*/
virtual void Execute();
/**
* Sort the input string array, and append the results to the output.
*/
virtual void SortFileNames(vtkStringArray* input, vtkStringArray* output);
/**
* Separate a string array into groups and append them to the output.
*/
virtual void GroupFileNames(vtkStringArray* input, vtkStringArrayVector* output);
private:
vtkSortFileNames(const vtkSortFileNames&) = delete;
void operator=(const vtkSortFileNames&) = delete;
};
VTK_ABI_NAMESPACE_END
#endif
|