1 // Author: Ilya Khramov
2 // Copyright (c) 2019 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <Graphic3d_CubeMapSeparate.hxx>
16 #include <Image_AlienPixMap.hxx>
17 #include <Message.hxx>
18 #include <Message_Messenger.hxx>
19 #include <OSD_File.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMapSeparate, Graphic3d_CubeMap)
23 // =======================================================================
24 // function : Graphic3d_CubeMapSeparate
26 // =======================================================================
27 Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<TCollection_AsciiString>& thePaths)
29 if (thePaths.Size() == 6)
31 for (unsigned int i = 0; i < 6; ++i)
33 myPaths[i] = thePaths[i];
38 throw Standard_Failure("Invalid number of paths to load Graphic3d_CubeMapSeparate");
42 // =======================================================================
43 // function : Graphic3d_CubeMapSeparate
45 // =======================================================================
46 Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<Handle(Image_PixMap)>& theImages)
48 if (theImages.Size() == 6)
50 if (theImages[0].IsNull())
55 if (theImages[0]->SizeX() != theImages[0]->SizeY())
60 myImages[0] = theImages[0];
61 myIsTopDown = myImages[0]->IsTopDown();
63 for (unsigned int i = 1; i < 6; ++i)
65 if (!theImages[i].IsNull())
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())
72 myImages[i] = theImages[i];
82 throw Standard_Failure("Invalid number of images in Graphic3d_CubeMapSeparate initialization");
86 // =======================================================================
89 // =======================================================================
90 Handle(Image_PixMap) Graphic3d_CubeMapSeparate::Value()
92 Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default();
95 anOrder.Swap(Graphic3d_CMS_POS_Y, Graphic3d_CMS_NEG_Y);
98 if (!myImages[anOrder[myCurrentSide]].IsNull())
100 return myImages[anOrder[myCurrentSide]];
104 TCollection_AsciiString aFilePath;
105 myPaths[anOrder[myCurrentSide]].SystemName(aFilePath);
106 if (!aFilePath.IsEmpty())
108 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap;
109 if (anImage->Load(aFilePath))
111 if (anImage->SizeX() == anImage->SizeY())
113 if (myCurrentSide == 0)
115 mySize = anImage->SizeX();
116 myFormat = anImage->Format();
117 myIsTopDown = anImage->IsTopDown();
122 if (anImage->Format() == myFormat
123 && anImage->SizeX() == mySize
124 && anImage->IsTopDown() == myIsTopDown)
130 Message::SendWarning (TCollection_AsciiString() + "'" + aFilePath + "' inconsistent image format or dimension in Graphic3d_CubeMapSeparate");
137 Message::SendWarning (TCollection_AsciiString() + "Unable to load '" + aFilePath + "' image of Graphic3d_CubeMapSeparate");
142 Message::SendWarning (TCollection_AsciiString() + "[" + myCurrentSide + "] path of Graphic3d_CubeMapSeparate is invalid");
146 return Handle(Image_PixMap)();
149 // =======================================================================
152 // =======================================================================
153 Standard_Boolean Graphic3d_CubeMapSeparate::IsDone() const
155 if (!myImages[0].IsNull())
157 return Standard_True;
160 for (unsigned int i = 0; i < 6; ++i)
162 OSD_File aCubeMapFile(myPaths[i]);
163 if (!aCubeMapFile.Exists())
165 return Standard_False;
169 return Standard_True;
172 // =======================================================================
173 // function : resetImages
175 // =======================================================================
176 void Graphic3d_CubeMapSeparate::resetImages()
178 for (unsigned int i = 0; i < 6; ++i)
180 myImages[i].Nullify();