1 //****************************************************************************** 2 /// 3 /// @file backend/scene/backendscenedata.h 4 /// 5 /// @todo What's in here? 6 /// 7 /// @copyright 8 /// @parblock 9 /// 10 /// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8. 11 /// Copyright 1991-2021 Persistence of Vision Raytracer Pty. Ltd. 12 /// 13 /// POV-Ray is free software: you can redistribute it and/or modify 14 /// it under the terms of the GNU Affero General Public License as 15 /// published by the Free Software Foundation, either version 3 of the 16 /// License, or (at your option) any later version. 17 /// 18 /// POV-Ray is distributed in the hope that it will be useful, 19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of 20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 /// GNU Affero General Public License for more details. 22 /// 23 /// You should have received a copy of the GNU Affero General Public License 24 /// along with this program. If not, see <http://www.gnu.org/licenses/>. 25 /// 26 /// ---------------------------------------------------------------------------- 27 /// 28 /// POV-Ray is based on the popular DKB raytracer version 2.12. 29 /// DKBTrace was originally written by David K. Buck. 30 /// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. 31 /// 32 /// @endparblock 33 /// 34 //------------------------------------------------------------------------------ 35 // SPDX-License-Identifier: AGPL-3.0-or-later 36 //****************************************************************************** 37 38 #ifndef POVRAY_BACKEND_BACKENDSCENEDATA_H 39 #define POVRAY_BACKEND_BACKENDSCENEDATA_H 40 41 // Module config header file must be the first file included within POV-Ray unit header files 42 #include "backend/configbackend.h" 43 44 // POV-Ray header files (core module) 45 #include "core/scene/scenedata.h" 46 47 // POV-Ray header files (backend module) 48 #include "backend/control/renderbackend.h" 49 50 namespace pov 51 { 52 53 class BackendSceneData : public SceneData 54 { 55 // Scene needs access to the private scene data constructor! 56 friend class Scene; 57 58 public: 59 60 typedef std::map<UCS2String, UCS2String> FilenameToFilenameMap; 61 62 /// scene id 63 RenderBackend::SceneId sceneId; 64 /// backend address 65 POVMSAddress backendAddress; 66 /// frontend address 67 POVMSAddress frontendAddress; 68 69 /** 70 * Find a file for reading. 71 * If the file is not available locally, the frontend will be queried. 72 * Variants of the filename with extensions matching file type will 73 * be tried. Only the first file found is returned. 74 * @param ctx POVMS message context for the current thread. 75 * @param filename Name and optional (partial) path. 76 * @param stype File type. 77 * @return Name of found file or empty string. 78 */ 79 UCS2String FindFile(POVMSContext ctx, const UCS2String& filename, unsigned int stype); 80 81 /** 82 * Open a file for reading. 83 * If the file is not available locally, the frontend will be queried. 84 * If the frontend has the file, it will be assigned a local temporary 85 * name that is mapped to the specified file name (so repeated access 86 * does not require contacting the frontend) and the file will be 87 * transferred from the frontend to the local system as necessary. 88 * Note that for their first access the frontend will always be asked 89 * to provide the location of the file. Local files are only accessed 90 * within the system specific temporary directory. This prevents 91 * access to files on local systems in case of remote rendering. 92 * Returns `nullptr` if the file could not be found. 93 * @param ctx POVMS message context for the current thread. 94 * @param origname The original name of the file as in the scene file (could be relative). // TODO FIXME - not needed, just a hack, the source [trf] 95 * @param filename Name and optional (partial) path. 96 * @param stype File type. 97 * @return Pointer to the file or `nullptr`. The caller is 98 * responsible for freeing the pointer! 99 */ 100 IStream *ReadFile(POVMSContext ctx, const UCS2String& origname, const UCS2String& filename, unsigned int stype); // TODO FIXME - see above and source code [trf] 101 102 /** 103 * Open a file given by name and optional (partial) path for writing. 104 * Rather than creating the file in the specified location, a temporary 105 * file will be created and the specified name will be mapped to that 106 * local file. Local files are only accessed within the system specific 107 * temporary directory. This prevents access to files on local systems 108 * in case of remote rendering. For each newly created file the 109 * frontend is notified and after rendering the frontend can decide 110 * which files to access. In addition, this allows parsing the same 111 * scene simultaneously more than once as each scene manages its own 112 * set of unique temporary files and thus at no time a file is written 113 * to or read from by more than one scene. 114 * @param ctx POVMS message context for the current thread. 115 * @param filename Name and optional (partial) path. 116 * @param stype File type. 117 * @param append True to append data to the file, false otherwise. 118 * @return Pointer to the file or `nullptr`. The caller is 119 * responsible for freeing the pointer! 120 */ 121 OStream *CreateFile(POVMSContext ctx, const UCS2String& filename, unsigned int stype, bool append); 122 123 private: 124 #ifdef USE_SCENE_FILE_MAPPING 125 /// maps scene file names to local file names 126 FilenameToFilenameMap scene2LocalFiles; 127 /// maps local file names to scene file names 128 FilenameToFilenameMap local2SceneFiles; 129 /// maps scene file names to temporary file names 130 FilenameToFilenameMap scene2TempFiles; 131 /// maps temporary file names to scene file names 132 FilenameToFilenameMap temp2SceneFiles; 133 #endif 134 135 /** 136 * Create new scene specific data. 137 */ 138 BackendSceneData(); 139 140 /// not available 141 BackendSceneData(const BackendSceneData&); 142 143 /// not available 144 BackendSceneData& operator=(const BackendSceneData&); 145 }; 146 147 } // end of namespace 148 149 #endif // POVRAY_BACKEND_BACKENDSCENEDATA_H 150