MCPcopy Create free account
hub / github.com/Kitware/VTK / CanReadFile

Method CanReadFile

IO/Image/vtkMetaImageReader.cxx:248–341  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

246
247//------------------------------------------------------------------------------
248int vtkMetaImageReader::CanReadFile(const char* fname)
249{
250
251 std::string filename = fname;
252 if (filename.empty())
253 {
254 return false;
255 }
256
257 bool extensionFound = false;
258 std::string::size_type mhaPos = filename.rfind(".mha");
259 if ((mhaPos != std::string::npos) && (mhaPos == filename.length() - 4))
260 {
261 extensionFound = true;
262 }
263 std::string::size_type mhdPos = filename.rfind(".mhd");
264 if ((mhdPos != std::string::npos) && (mhdPos == filename.length() - 4))
265 {
266 extensionFound = true;
267 }
268 if (!extensionFound)
269 {
270 return false;
271 }
272
273 // Now check the file content
274 vtksys::ifstream inputStream;
275
276 inputStream.open(fname, ios::in | ios::binary);
277
278 if (inputStream.fail())
279 {
280 return false;
281 }
282
283 char key[8000];
284
285 inputStream >> key;
286
287 if (inputStream.eof())
288 {
289 inputStream.close();
290 return false;
291 }
292
293 if (strcmp(key, "NDims") == 0)
294 {
295 inputStream.close();
296 return 3;
297 }
298 if (strcmp(key, "ObjectType") == 0)
299 {
300 inputStream.close();
301 return 3;
302 }
303 if (strcmp(key, "TransformType") == 0)
304 {
305 inputStream.close();

Callers

nothing calls this directly

Calls 5

emptyMethod · 0.45
lengthMethod · 0.45
openMethod · 0.45
eofMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected