0022819: Redesign of OpenGl driver
[occt.git] / src / QADBMReflex / QADBMReflex_OCC749PrsUseVertexCABV.cxx
1 // File:        QADBMReflex_OCC749PrsUseVertexCABV.cxx
2 // Created:     Mon Oct  7 15:01:41 2002
3 // Author:      QA Admin
4 //              <qa@russox>
5
6
7 #include <QADBMReflex_OCC749PrsUseVertexCABV.ixx>
8
9 #include <Prs3d_Root.hxx>
10 #include <Graphic3d_Group.hxx>
11 #include <Graphic3d_Vertex.hxx>
12 #include <Aspect_Array1OfEdge.hxx>
13 #include <Graphic3d_AspectFillArea3d.hxx>
14 #include <Graphic3d_MaterialAspect.hxx>
15 #include <Quantity_Color.hxx>
16 #include <Graphic3d_Array1OfVertexC.hxx>
17 #include <Aspect_Edge.hxx>
18
19
20 #include <Graphic3d_Array1OfVertex.hxx>
21 #include <OSD_Timer.hxx>
22
23
24 //=======================================================================
25 //function : QADBMReflex_OCC749PrsUseVertex
26 //purpose  : 
27 //=======================================================================
28
29   QADBMReflex_OCC749PrsUseVertexCABV::QADBMReflex_OCC749PrsUseVertexCABV( const Standard_Boolean Reflection,const Quantity_Color& InteriorColor,const Quantity_Color& EdgeColor,const Quantity_Color& EdgeColor2,const Standard_Integer XCount,const Standard_Integer YCount,const Standard_Integer BoxSize,const Graphic3d_MaterialAspect& MaterialAspect,const Standard_Boolean Material,const Standard_Boolean Timer ):QADBMReflex_OCC749Prs(Reflection,InteriorColor,EdgeColor,EdgeColor2,XCount,YCount,BoxSize,MaterialAspect,Material,Timer) {
30 }
31
32 static OSD_Timer Timer;
33
34 //=======================================================================
35 //function : Compute
36 //purpose  : 
37 //=======================================================================
38
39 void QADBMReflex_OCC749PrsUseVertexCABV::Compute(const Handle(PrsMgr_PresentationManager3d)& aPrsMgr,
40                                               const Handle(Prs3d_Presentation)& aPresentation,
41                                               const Standard_Integer aMode )
42 {
43   Standard_Boolean BooleanTimer = GetTimer();
44   if (BooleanTimer) {
45     Timer.Reset ();
46     Timer.Start ();
47   }
48
49   aPresentation->Clear();
50   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(aPresentation);
51
52   Graphic3d_MaterialAspect aFlatMat; 
53   Standard_Boolean BooleanMaterial = GetMaterial();
54   if (BooleanMaterial) {
55     aFlatMat = GetMaterialAspect(); 
56   }
57
58   Standard_Boolean BooleanReflection = GetReflection();
59   if (BooleanReflection) {
60     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_AMBIENT);
61     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_DIFFUSE);
62     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_SPECULAR);
63     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_EMISSION);
64   } else {
65     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
66     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
67     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
68     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_EMISSION);
69   }
70
71   Quantity_Color InteriorColor = GetInteriorColor();
72   Quantity_Color EdgeColor     = GetEdgeColor();
73   Quantity_Color EdgeColor2    = GetEdgeColor2();
74
75   Standard_Integer XCOUNT = GetXCount();
76   Standard_Integer YCOUNT = GetYCount();
77   Standard_Integer BOXSIZE = GetBoxSize();
78
79   Handle(Graphic3d_AspectFillArea3d) Fill3d;
80   Fill3d = new Graphic3d_AspectFillArea3d(Aspect_IS_SOLID,
81                                           InteriorColor,
82                                           EdgeColor,
83                                           Aspect_TOL_SOLID,
84                                           1.5,
85                                           aFlatMat,
86                                           aFlatMat);
87
88   //////////////////Fill3d->SetInteriorColor(InteriorColor);
89
90   //Handle(Graphic3d_AspectFillArea3d) Fill3d = new Graphic3d_AspectFillArea3d();
91   //Fill3d->SetInteriorStyle(Aspect_IS_SOLID);
92
93   aGroup->SetGroupPrimitivesAspect(Fill3d);
94   aGroup->SetPrimitivesAspect(Fill3d);
95
96   aGroup->BeginPrimitives();
97
98   Standard_Integer i,j,z1=0,z2,zmax=XCOUNT;
99   if (YCOUNT > XCOUNT) zmax = YCOUNT;
100
101   Standard_Integer HMAX = 100;
102   BOXSIZE = HMAX / zmax;
103   if (BOXSIZE ==0)
104     BOXSIZE = 1;
105
106   for (i=0; i < XCOUNT; i++){
107     for (j=0; j < YCOUNT; j++){
108       //Quantity_NameOfColor aColor = Quantity_Color::Name(1., 
109       //                                                   (double)j/YCOUNT, 
110       //                                                   (double)i/XCOUNT);
111
112       Graphic3d_Array1OfVertexC aVertexes(1, 8); 
113       
114       //////////////////z2 = BOXSIZE +(i*zmax - j*((Standard_Integer) zmax/2));
115       z2 = BOXSIZE +(i*BOXSIZE - j*BOXSIZE/2);
116       aVertexes(1).SetCoord(i*BOXSIZE, j*BOXSIZE, z1);
117       aVertexes(2).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE, z1);
118       aVertexes(3).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE + BOXSIZE, z1);
119       aVertexes(4).SetCoord(i*BOXSIZE, j*BOXSIZE + BOXSIZE, z1);
120       aVertexes(5).SetCoord(i*BOXSIZE, j*BOXSIZE, z2);
121       aVertexes(6).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE, z2);
122       aVertexes(7).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE + BOXSIZE, z2);
123       aVertexes(8).SetCoord(i*BOXSIZE, j*BOXSIZE + BOXSIZE, z2);
124
125       //aVertexes(1).SetColor(EdgeColor);
126       //aVertexes(2).SetColor(EdgeColor);
127       //aVertexes(3).SetColor(EdgeColor2);
128       //aVertexes(4).SetColor(EdgeColor2);
129       //aVertexes(5).SetColor(EdgeColor2);
130       //aVertexes(6).SetColor(EdgeColor2);
131       //aVertexes(7).SetColor(EdgeColor);
132       //aVertexes(8).SetColor(EdgeColor);
133
134       //////////////////if (!(i == 0 && j ==0)) {
135         aVertexes(1).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
136         aVertexes(2).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
137         aVertexes(3).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
138         aVertexes(4).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
139         aVertexes(5).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
140         aVertexes(6).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
141         aVertexes(7).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
142         aVertexes(8).SetColor(Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB));
143       //////////////////}
144
145       Aspect_Array1OfEdge aEdges(1, 24);
146       aEdges(1) = Aspect_Edge(1, 2, Aspect_TOE_VISIBLE);
147       aEdges(2) = Aspect_Edge(2, 3, Aspect_TOE_VISIBLE);
148       aEdges(3) = Aspect_Edge(3, 4, Aspect_TOE_VISIBLE);
149       aEdges(4) = Aspect_Edge(4, 1, Aspect_TOE_VISIBLE);
150
151       aEdges(5) = Aspect_Edge(5, 6, Aspect_TOE_VISIBLE);
152       aEdges(6) = Aspect_Edge(6, 7, Aspect_TOE_VISIBLE);
153       aEdges(7) = Aspect_Edge(7, 8, Aspect_TOE_VISIBLE);
154       aEdges(8) = Aspect_Edge(8, 5, Aspect_TOE_VISIBLE);
155
156       aEdges(9) = Aspect_Edge(1, 5, Aspect_TOE_VISIBLE);
157       aEdges(10) = Aspect_Edge(5, 6, Aspect_TOE_VISIBLE);
158       aEdges(11) = Aspect_Edge(6, 2, Aspect_TOE_VISIBLE);
159       aEdges(12) = Aspect_Edge(2, 1, Aspect_TOE_VISIBLE);
160
161       aEdges(13) = Aspect_Edge(6, 7, Aspect_TOE_VISIBLE);
162       aEdges(14) = Aspect_Edge(7, 3, Aspect_TOE_VISIBLE);
163       aEdges(15) = Aspect_Edge(3, 2, Aspect_TOE_VISIBLE);
164       aEdges(16) = Aspect_Edge(2, 6, Aspect_TOE_VISIBLE);
165
166       aEdges(17) = Aspect_Edge(3, 7, Aspect_TOE_VISIBLE);
167       aEdges(18) = Aspect_Edge(7, 8, Aspect_TOE_VISIBLE);
168       aEdges(19) = Aspect_Edge(8, 4, Aspect_TOE_VISIBLE);
169       aEdges(20) = Aspect_Edge(4, 3, Aspect_TOE_VISIBLE);
170
171       aEdges(21) = Aspect_Edge(4, 8, Aspect_TOE_VISIBLE);
172       aEdges(22) = Aspect_Edge(8, 5, Aspect_TOE_VISIBLE);
173       aEdges(23) = Aspect_Edge(5, 1, Aspect_TOE_VISIBLE);
174       aEdges(24) = Aspect_Edge(1, 4, Aspect_TOE_VISIBLE);
175
176       aGroup->QuadrangleSet(aVertexes, aEdges);
177     }
178   }
179   aGroup->EndPrimitives();
180
181   if (BooleanTimer) {
182     Timer.Stop ();
183     Timer.Show (cout);
184   }
185
186 }