0031458: Visualization - refine classes across Prs3d and StdPrs packages
[occt.git] / src / Graphic3d / Graphic3d_CubeMapSeparate.cxx
CommitLineData
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>
16#include <Image_AlienPixMap.hxx>
17#include <Message.hxx>
18#include <Message_Messenger.hxx>
19#include <OSD_File.hxx>
20
21IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMapSeparate, Graphic3d_CubeMap)
22
23// =======================================================================
24// function : Graphic3d_CubeMapSeparate
25// purpose :
26// =======================================================================
27Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<TCollection_AsciiString>& thePaths)
28{
29 if (thePaths.Size() == 6)
30 {
31 for (unsigned int i = 0; i < 6; ++i)
32 {
33 myPaths[i] = thePaths[i];
34 }
35 }
36 else
37 {
38 throw Standard_Failure("Invalid number of paths to load Graphic3d_CubeMapSeparate");
39 }
40}
41
42// =======================================================================
43// function : Graphic3d_CubeMapSeparate
44// purpose :
45// =======================================================================
46Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<Handle(Image_PixMap)>& theImages)
47{
48 if (theImages.Size() == 6)
49 {
50 if (theImages[0].IsNull())
51 {
52 return;
53 }
54
55 if (theImages[0]->SizeX() != theImages[0]->SizeY())
56 {
57 return;
58 }
59
60 myImages[0] = theImages[0];
61 myIsTopDown = myImages[0]->IsTopDown();
62
63 for (unsigned int i = 1; i < 6; ++i)
64 {
65 if (!theImages[i].IsNull())
66 {
67 if (theImages[i]->SizeX() == myImages[0]->SizeX()
68 && theImages[i]->SizeY() == myImages[0]->SizeY()
69 && theImages[i]->Format() == myImages[0]->Format()
70 && theImages[i]->IsTopDown() == myImages[0]->IsTopDown())
71 {
72 myImages[i] = theImages[i];
73 continue;
74 }
75 }
76 resetImages();
77 return;
78 }
79 }
80 else
81 {
82 throw Standard_Failure("Invalid number of images in Graphic3d_CubeMapSeparate initialization");
83 }
84}
85
86// =======================================================================
87// function : Value
88// purpose :
89// =======================================================================
90Handle(Image_PixMap) Graphic3d_CubeMapSeparate::Value()
91{
92 Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default();
93 if (!myIsTopDown)
94 {
95 anOrder.Swap(Graphic3d_CMS_POS_Y, Graphic3d_CMS_NEG_Y);
96 }
97
98 if (!myImages[anOrder[myCurrentSide]].IsNull())
99 {
100 return myImages[anOrder[myCurrentSide]];
101 }
102 else
103 {
104 TCollection_AsciiString aFilePath;
105 myPaths[anOrder[myCurrentSide]].SystemName(aFilePath);
106 if (!aFilePath.IsEmpty())
107 {
108 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap;
109 if (anImage->Load(aFilePath))
110 {
111 if (anImage->SizeX() == anImage->SizeY())
112 {
113 if (myCurrentSide == 0)
114 {
115 mySize = anImage->SizeX();
116 myFormat = anImage->Format();
117 myIsTopDown = anImage->IsTopDown();
118 return anImage;
119 }
120 else
121 {
122 if (anImage->Format() == myFormat
123 && anImage->SizeX() == mySize
124 && anImage->IsTopDown() == myIsTopDown)
125 {
126 return anImage;
127 }
128 else
129 {
130 Message::DefaultMessenger()->Send(TCollection_AsciiString() +
131 "'" + aFilePath + "' inconsistent image format or dimension in Graphic3d_CubeMapSeparate");
132 }
133 }
134 }
135 }
136 else
137 {
138 Message::DefaultMessenger()->Send(TCollection_AsciiString() +
139 "Unable to load '" + aFilePath + "' image of Graphic3d_CubeMapSeparate");
140 }
141 }
142 else
143 {
144 Message::DefaultMessenger()->Send(TCollection_AsciiString() +
145 "[" + myCurrentSide + "] path of Graphic3d_CubeMapSeparate is invalid");
146 }
147 }
148
149 return Handle(Image_PixMap)();
150}
151
152// =======================================================================
153// function : IsDone
154// purpose :
155// =======================================================================
156Standard_Boolean Graphic3d_CubeMapSeparate::IsDone() const
157{
158 if (!myImages[0].IsNull())
159 {
160 return Standard_True;
161 }
162
163 for (unsigned int i = 0; i < 6; ++i)
164 {
165 OSD_File aCubeMapFile(myPaths[i]);
166 if (!aCubeMapFile.Exists())
167 {
168 return Standard_False;
169 }
170 }
171
172 return Standard_True;
173}
174
175// =======================================================================
176// function : resetImages
177// purpose :
178// =======================================================================
179void Graphic3d_CubeMapSeparate::resetImages()
180{
181 for (unsigned int i = 0; i < 6; ++i)
182 {
183 myImages[i].Nullify();
184 }
185}