//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ #include #include #include #include #include #include #include #include #include #include #include namespace vtkm { namespace io { void WriteImageFile(const vtkm::cont::DataSet& dataSet, const std::string& fullPath, const std::string& fieldName) { std::unique_ptr writer; if (EndsWith(fullPath, ".ppm")) { writer = std::unique_ptr(new ImageWriterPNM(fullPath)); } else { writer = std::unique_ptr(new ImageWriterPNG(fullPath)); } writer->WriteDataSet(dataSet, fieldName); VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Wrote image data at: " << fullPath); } vtkm::cont::DataSet ReadImageFile(const std::string& fullPath, const std::string& fieldName) { std::ifstream check(fullPath.c_str()); if (!check.good()) { throw vtkm::cont::ErrorBadValue("File does not exist: " + fullPath); } std::unique_ptr reader; if (EndsWith(fullPath, ".png")) { reader = std::unique_ptr(new ImageReaderPNG(fullPath)); } else if (EndsWith(fullPath, ".ppm") || EndsWith(fullPath, ".pnm")) { reader = std::unique_ptr(new ImageReaderPNM(fullPath)); } else { throw vtkm::cont::ErrorBadValue("Unsupported file type: " + fullPath); } reader->SetPointFieldName(fieldName); return reader->ReadDataSet(); } } // namespace vtkm::io } // namespace vtkm: