------------------------------------------------------------------------------ This function sets the name of the file.
| 95 | //------------------------------------------------------------------------------ |
| 96 | // This function sets the name of the file. |
| 97 | void vtkImageReader2::ComputeInternalFileName(int slice) |
| 98 | { |
| 99 | // delete any old filename |
| 100 | delete[] this->InternalFileName; |
| 101 | this->InternalFileName = nullptr; |
| 102 | |
| 103 | if (!this->FileName && !this->FilePattern && !this->FileNames) |
| 104 | { |
| 105 | vtkErrorMacro(<< "Either a FileName, FileNames, or FilePattern" |
| 106 | << " must be specified."); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | // make sure we figure out a filename to open |
| 111 | if (this->FileNames) |
| 112 | { |
| 113 | auto filename = this->FileNames->GetValue(slice); |
| 114 | size_t size = filename.size() + 10; |
| 115 | this->InternalFileName = new char[size]; |
| 116 | auto result = vtk::format_to_n(this->InternalFileName, size, "{:s}", filename); |
| 117 | *result.out = '\0'; |
| 118 | } |
| 119 | else if (this->FileName) |
| 120 | { |
| 121 | size_t size = strlen(this->FileName) + 10; |
| 122 | this->InternalFileName = new char[size]; |
| 123 | auto result = vtk::format_to_n(this->InternalFileName, size, "{:s}", this->FileName); |
| 124 | *result.out = '\0'; |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | int slicenum = slice * this->FileNameSliceSpacing + this->FileNameSliceOffset; |
| 129 | std::string filePattern = this->FilePattern ? vtk::to_std_format(this->FilePattern) : ""; |
| 130 | if (this->FilePrefix && !filePattern.empty()) |
| 131 | { |
| 132 | size_t size = strlen(this->FilePrefix) + filePattern.size() + 10; |
| 133 | this->InternalFileName = new char[size]; |
| 134 | VTK_FORMAT_IF_ERROR_RETURN(auto result = vtk::format_to_n(this->InternalFileName, size, |
| 135 | filePattern, this->FilePrefix, slicenum); |
| 136 | *result.out = '\0', ); |
| 137 | } |
| 138 | else if (!filePattern.empty()) |
| 139 | { |
| 140 | size_t size = filePattern.size() + 10; |
| 141 | this->InternalFileName = new char[size]; |
| 142 | VTK_FORMAT_IF_ERROR_RETURN( |
| 143 | auto result = vtk::format_to_n(this->InternalFileName, size, filePattern, "", slicenum); |
| 144 | *result.out = '\0', ); |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | delete[] this->InternalFileName; |
| 149 | this->InternalFileName = nullptr; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | //------------------------------------------------------------------------------ |
no test coverage detected