------------------------------------------------------------------------------
| 792 | |
| 793 | //------------------------------------------------------------------------------ |
| 794 | std::string vtkJSONSceneExporter::WriteTexture(vtkTexture* texture) |
| 795 | { |
| 796 | // If this texture has already been written, just reuse the one |
| 797 | // we have. |
| 798 | if (this->TextureStrings.find(texture) != this->TextureStrings.end()) |
| 799 | { |
| 800 | return this->TextureStrings[texture]; |
| 801 | } |
| 802 | |
| 803 | std::string path = this->CurrentDataSetPath(); |
| 804 | |
| 805 | // Make sure it exists |
| 806 | if (!vtksys::SystemTools::MakeDirectory(path)) |
| 807 | { |
| 808 | vtkErrorMacro(<< "Cannot create directory " << path); |
| 809 | return ""; |
| 810 | } |
| 811 | |
| 812 | path += "/texture.jpg"; |
| 813 | path = vtksys::SystemTools::ConvertToOutputPath(path); |
| 814 | |
| 815 | vtkSmartPointer<vtkImageData> image = texture->GetInput(); |
| 816 | |
| 817 | vtkNew<vtkJPEGWriter> writer; |
| 818 | writer->SetFileName(path.c_str()); |
| 819 | writer->SetInputDataObject(image); |
| 820 | writer->Write(); |
| 821 | |
| 822 | constexpr const char* INDENT = " "; |
| 823 | std::stringstream config; |
| 824 | config << ",\n" << INDENT << "\"texture\": \"" << this->DatasetCount + 1 << "/texture.jpg\""; |
| 825 | this->TextureStrings[texture] = config.str(); |
| 826 | return config.str(); |
| 827 | } |
| 828 | |
| 829 | //------------------------------------------------------------------------------ |
| 830 | std::string vtkJSONSceneExporter::WriteTextureLODSeries(vtkTexture* texture) |
no test coverage detected