077a220c |
1 | // Author: Ilya Khramov |
2 | // Copyright (c) 2019 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
15 | #include <Graphic3d_CubeMapSeparate.hxx> |
faff3767 |
16 | |
077a220c |
17 | #include <Image_AlienPixMap.hxx> |
faff3767 |
18 | #include <Image_DDSParser.hxx> |
077a220c |
19 | #include <Message.hxx> |
20 | #include <Message_Messenger.hxx> |
21 | #include <OSD_File.hxx> |
22 | |
23 | IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMapSeparate, Graphic3d_CubeMap) |
24 | |
25 | // ======================================================================= |
26 | // function : Graphic3d_CubeMapSeparate |
27 | // purpose : |
28 | // ======================================================================= |
29 | Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<TCollection_AsciiString>& thePaths) |
30 | { |
31 | if (thePaths.Size() == 6) |
32 | { |
33 | for (unsigned int i = 0; i < 6; ++i) |
34 | { |
35 | myPaths[i] = thePaths[i]; |
36 | } |
37 | } |
38 | else |
39 | { |
40 | throw Standard_Failure("Invalid number of paths to load Graphic3d_CubeMapSeparate"); |
41 | } |
42 | } |
43 | |
44 | // ======================================================================= |
45 | // function : Graphic3d_CubeMapSeparate |
46 | // purpose : |
47 | // ======================================================================= |
48 | Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<Handle(Image_PixMap)>& theImages) |
49 | { |
50 | if (theImages.Size() == 6) |
51 | { |
52 | if (theImages[0].IsNull()) |
53 | { |
54 | return; |
55 | } |
56 | |
57 | if (theImages[0]->SizeX() != theImages[0]->SizeY()) |
58 | { |
59 | return; |
60 | } |
61 | |
62 | myImages[0] = theImages[0]; |
63 | myIsTopDown = myImages[0]->IsTopDown(); |
64 | |
65 | for (unsigned int i = 1; i < 6; ++i) |
66 | { |
67 | if (!theImages[i].IsNull()) |
68 | { |
69 | if (theImages[i]->SizeX() == myImages[0]->SizeX() |
70 | && theImages[i]->SizeY() == myImages[0]->SizeY() |
71 | && theImages[i]->Format() == myImages[0]->Format() |
72 | && theImages[i]->IsTopDown() == myImages[0]->IsTopDown()) |
73 | { |
74 | myImages[i] = theImages[i]; |
75 | continue; |
76 | } |
77 | } |
78 | resetImages(); |
79 | return; |
80 | } |
81 | } |
82 | else |
83 | { |
84 | throw Standard_Failure("Invalid number of images in Graphic3d_CubeMapSeparate initialization"); |
85 | } |
86 | } |
87 | |
faff3767 |
88 | // ======================================================================= |
89 | // function : CompressedValue |
90 | // purpose : |
91 | // ======================================================================= |
92 | Handle(Image_CompressedPixMap) Graphic3d_CubeMapSeparate::CompressedValue (const Handle(Image_SupportedFormats)& theSupported) |
93 | { |
94 | if (!myImages[0].IsNull()) |
95 | { |
96 | return Handle(Image_CompressedPixMap)(); |
97 | } |
98 | |
99 | const Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default(); |
100 | TCollection_AsciiString aFilePath; |
101 | myPaths[anOrder[myCurrentSide]].SystemName(aFilePath); |
102 | if (aFilePath.IsEmpty()) |
103 | { |
104 | return Handle(Image_CompressedPixMap)(); |
105 | } |
106 | |
107 | Handle(Image_CompressedPixMap) anImage = Image_DDSParser::Load (theSupported, aFilePath, 0); |
108 | if (anImage.IsNull() |
109 | || anImage->SizeX() != anImage->SizeY()) |
110 | { |
111 | return Handle(Image_CompressedPixMap)(); |
112 | } |
113 | |
114 | if (myCurrentSide == 0) |
115 | { |
116 | mySize = anImage->SizeX(); |
117 | myFormat = anImage->BaseFormat(); |
118 | myIsTopDown = anImage->IsTopDown(); |
119 | return anImage; |
120 | } |
121 | |
122 | if (anImage->BaseFormat() == myFormat |
123 | && anImage->SizeX() == (Standard_Integer )mySize) |
124 | { |
125 | return anImage; |
126 | } |
127 | |
128 | Message::SendWarning (TCollection_AsciiString() + "'" + aFilePath + "' inconsistent image format or dimension in Graphic3d_CubeMapSeparate"); |
129 | return Handle(Image_CompressedPixMap)(); |
130 | } |
131 | |
077a220c |
132 | // ======================================================================= |
133 | // function : Value |
134 | // purpose : |
135 | // ======================================================================= |
faff3767 |
136 | Handle(Image_PixMap) Graphic3d_CubeMapSeparate::Value (const Handle(Image_SupportedFormats)& theSupported) |
077a220c |
137 | { |
138 | Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default(); |
139 | if (!myIsTopDown) |
140 | { |
141 | anOrder.Swap(Graphic3d_CMS_POS_Y, Graphic3d_CMS_NEG_Y); |
142 | } |
143 | |
144 | if (!myImages[anOrder[myCurrentSide]].IsNull()) |
145 | { |
146 | return myImages[anOrder[myCurrentSide]]; |
147 | } |
148 | else |
149 | { |
150 | TCollection_AsciiString aFilePath; |
151 | myPaths[anOrder[myCurrentSide]].SystemName(aFilePath); |
152 | if (!aFilePath.IsEmpty()) |
153 | { |
154 | Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap; |
155 | if (anImage->Load(aFilePath)) |
156 | { |
faff3767 |
157 | convertToCompatible (theSupported, anImage); |
077a220c |
158 | if (anImage->SizeX() == anImage->SizeY()) |
159 | { |
160 | if (myCurrentSide == 0) |
161 | { |
162 | mySize = anImage->SizeX(); |
163 | myFormat = anImage->Format(); |
164 | myIsTopDown = anImage->IsTopDown(); |
165 | return anImage; |
166 | } |
167 | else |
168 | { |
169 | if (anImage->Format() == myFormat |
170 | && anImage->SizeX() == mySize |
171 | && anImage->IsTopDown() == myIsTopDown) |
172 | { |
173 | return anImage; |
174 | } |
175 | else |
176 | { |
a87b1b37 |
177 | Message::SendWarning (TCollection_AsciiString() + "'" + aFilePath + "' inconsistent image format or dimension in Graphic3d_CubeMapSeparate"); |
077a220c |
178 | } |
179 | } |
180 | } |
181 | } |
182 | else |
183 | { |
a87b1b37 |
184 | Message::SendWarning (TCollection_AsciiString() + "Unable to load '" + aFilePath + "' image of Graphic3d_CubeMapSeparate"); |
077a220c |
185 | } |
186 | } |
187 | else |
188 | { |
a87b1b37 |
189 | Message::SendWarning (TCollection_AsciiString() + "[" + myCurrentSide + "] path of Graphic3d_CubeMapSeparate is invalid"); |
077a220c |
190 | } |
191 | } |
192 | |
193 | return Handle(Image_PixMap)(); |
194 | } |
195 | |
196 | // ======================================================================= |
197 | // function : IsDone |
198 | // purpose : |
199 | // ======================================================================= |
200 | Standard_Boolean Graphic3d_CubeMapSeparate::IsDone() const |
201 | { |
202 | if (!myImages[0].IsNull()) |
203 | { |
204 | return Standard_True; |
205 | } |
206 | |
207 | for (unsigned int i = 0; i < 6; ++i) |
208 | { |
209 | OSD_File aCubeMapFile(myPaths[i]); |
210 | if (!aCubeMapFile.Exists()) |
211 | { |
212 | return Standard_False; |
213 | } |
214 | } |
215 | |
216 | return Standard_True; |
217 | } |
218 | |
219 | // ======================================================================= |
220 | // function : resetImages |
221 | // purpose : |
222 | // ======================================================================= |
223 | void Graphic3d_CubeMapSeparate::resetImages() |
224 | { |
225 | for (unsigned int i = 0; i < 6; ++i) |
226 | { |
227 | myImages[i].Nullify(); |
228 | } |
229 | } |