0032862: Visualization, Graphic3d_TextureMap - add 3D texture definition
[occt.git] / src / Graphic3d / Graphic3d_Texture1Dsegment.cxx
1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Graphic3d_Texture1Dsegment.hxx>
19 #include <Graphic3d_TextureParams.hxx>
20 #include <Graphic3d_TypeOfTextureMode.hxx>
21 #include <Standard_Type.hxx>
22 #include <TCollection_AsciiString.hxx>
23
24 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture1Dsegment,Graphic3d_Texture1D)
25
26 // =======================================================================
27 // function : Graphic3d_Texture1Dsegment
28 // purpose  :
29 // =======================================================================
30 Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const TCollection_AsciiString& theFileName)
31 : Graphic3d_Texture1D (theFileName, Graphic3d_TypeOfTexture_1D),
32   myX1 (0.0f),
33   myY1 (0.0f),
34   myZ1 (0.0f),
35   myX2 (0.0f),
36   myY2 (0.0f),
37   myZ2 (0.0f)
38 {
39   myParams->SetRepeat (Standard_True);
40   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
41                         Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
42                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
43 }
44
45 // =======================================================================
46 // function : Graphic3d_Texture1Dsegment
47 // purpose  :
48 // =======================================================================
49 Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTexture1D theNOT)
50 : Graphic3d_Texture1D (theNOT, Graphic3d_TypeOfTexture_1D),
51   myX1 (0.0f),
52   myY1 (0.0f),
53   myZ1 (0.0f),
54   myX2 (0.0f),
55   myY2 (0.0f),
56   myZ2 (0.0f)
57 {
58   myParams->SetRepeat (Standard_True);
59   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
60                         Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
61                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
62 }
63
64 // =======================================================================
65 // function : Graphic3d_Texture1Dsegment
66 // purpose  :
67 // =======================================================================
68 Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Handle(Image_PixMap)& thePixMap)
69 : Graphic3d_Texture1D (thePixMap, Graphic3d_TypeOfTexture_1D),
70   myX1 (0.0f),
71   myY1 (0.0f),
72   myZ1 (0.0f),
73   myX2 (0.0f),
74   myY2 (0.0f),
75   myZ2 (0.0f)
76 {
77   myParams->SetRepeat (Standard_True);
78   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
79                         Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
80                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
81 }
82
83 // =======================================================================
84 // function : SetSegment
85 // purpose  :
86 // =======================================================================
87 void Graphic3d_Texture1Dsegment::SetSegment (const Standard_ShortReal X1,
88                                              const Standard_ShortReal Y1,
89                                              const Standard_ShortReal Z1,
90                                              const Standard_ShortReal X2,
91                                              const Standard_ShortReal Y2,
92                                              const Standard_ShortReal Z2)
93 {
94   myX1 = X1;
95   myY1 = Y1;
96   myZ1 = Z1;
97   myX2 = X2;
98   myY2 = Y2;
99   myZ2 = Z2;
100   Graphic3d_Vec4 aPlaneX (X2 - X1, Y2 - Y1, Z2 - Z1, 0.0f);
101
102   Standard_ShortReal aSqNorm = aPlaneX.x() * aPlaneX.x()
103                              + aPlaneX.y() * aPlaneX.y()
104                              + aPlaneX.z() * aPlaneX.z();
105   aPlaneX.x() /= aSqNorm;
106   aPlaneX.y() /= aSqNorm;
107   aPlaneX.z() /= aSqNorm;
108   aPlaneX.w() = -aPlaneX.x() * X1
109                 -aPlaneX.y() * Y1
110                             -aPlaneX.z() * Z1;
111
112   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
113                         aPlaneX,
114                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
115 }
116
117 // =======================================================================
118 // function : Segment
119 // purpose  :
120 // =======================================================================
121 void Graphic3d_Texture1Dsegment::Segment (Standard_ShortReal& X1,
122                                           Standard_ShortReal& Y1,
123                                           Standard_ShortReal& Z1,
124                                           Standard_ShortReal& X2,
125                                           Standard_ShortReal& Y2,
126                                           Standard_ShortReal& Z2) const
127 {
128   X1 = myX1;
129   Y1 = myY1;
130   Z1 = myZ1;
131   X2 = myX2;
132   Y2 = myY2;
133   Z2 = myZ2;
134 }