1 // Created on: 2003-11-12
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <Graphic3d_ArrayOfPolygons.hxx>
18 #include <Graphic3d_ArrayOfPolylines.hxx>
19 #include <Graphic3d_ArrayOfSegments.hxx>
20 #include <Graphic3d_ArrayOfTriangles.hxx>
21 #include <Graphic3d_AspectFillArea3d.hxx>
22 #include <Graphic3d_AspectLine3d.hxx>
23 #include <Graphic3d_Group.hxx>
24 #include <MeshVS_Buffer.hxx>
25 #include <MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger.hxx>
26 #include <MeshVS_DataMapIteratorOfDataMapOfIntegerColor.hxx>
27 #include <MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors.hxx>
28 #include <MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger.hxx>
29 #include <MeshVS_DataMapOfColorMapOfInteger.hxx>
30 #include <MeshVS_DataMapOfTwoColorsMapOfInteger.hxx>
31 #include <MeshVS_DataSource.hxx>
32 #include <MeshVS_DisplayModeFlags.hxx>
33 #include <MeshVS_Drawer.hxx>
34 #include <MeshVS_DrawerAttribute.hxx>
35 #include <MeshVS_ElementalColorPrsBuilder.hxx>
36 #include <MeshVS_HArray1OfSequenceOfInteger.hxx>
37 #include <MeshVS_Mesh.hxx>
38 #include <MeshVS_MeshPrsBuilder.hxx>
39 #include <Prs3d_LineAspect.hxx>
40 #include <Prs3d_Presentation.hxx>
41 #include <Prs3d_Root.hxx>
42 #include <Prs3d_ShadingAspect.hxx>
43 #include <Quantity_Color.hxx>
44 #include <Standard_Type.hxx>
45 #include <TColStd_Array1OfReal.hxx>
46 #include <TColStd_HArray1OfReal.hxx>
47 #include <TColStd_HPackedMapOfInteger.hxx>
48 #include <TColStd_ListIteratorOfListOfInteger.hxx>
49 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_PackedMapOfInteger.hxx>
52 #include <TColStd_SequenceOfInteger.hxx>
54 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_ElementalColorPrsBuilder,MeshVS_PrsBuilder)
56 //================================================================
57 // Function : Constructor MeshVS_ElementalColorPrsBuilder
59 //================================================================
60 MeshVS_ElementalColorPrsBuilder::MeshVS_ElementalColorPrsBuilder
61 ( const Handle(MeshVS_Mesh)& Parent,
62 const MeshVS_DisplayModeFlags& Flags,
63 const Handle (MeshVS_DataSource)& DS,
64 const Standard_Integer Id,
65 const MeshVS_BuilderPriority& Priority )
66 : MeshVS_PrsBuilder ( Parent, Flags, DS, Id, Priority )
68 SetExcluding ( Standard_True );
71 //================================================================
74 //================================================================
75 void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& Prs,
76 const TColStd_PackedMapOfInteger& IDs,
77 TColStd_PackedMapOfInteger& IDsToExclude,
78 const Standard_Boolean IsElement,
79 const Standard_Integer DisplayMode) const
81 Handle (MeshVS_DataSource) aSource = GetDataSource();
82 Handle (MeshVS_Drawer) aDrawer = GetDrawer();
84 if ( aSource.IsNull() || aDrawer.IsNull() )
87 Standard_Integer aMaxFaceNodes;
88 if ( !aDrawer->GetInteger ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) && aMaxFaceNodes<=0 )
91 MeshVS_DataMapOfIntegerColor* anElemColorMap = (MeshVS_DataMapOfIntegerColor*) &myElemColorMap1;
92 MeshVS_DataMapOfIntegerTwoColors* anElemTwoColorsMap = (MeshVS_DataMapOfIntegerTwoColors*)&myElemColorMap2;
94 MeshVS_DataMapOfColorMapOfInteger aColorsOfElements;
95 MeshVS_DataMapOfTwoColorsMapOfInteger aTwoColorsOfElements;
97 MeshVS_Buffer aCoordsBuf (3*aMaxFaceNodes*sizeof(Standard_Real));
98 TColStd_Array1OfReal aCoords (aCoordsBuf, 1, 3*aMaxFaceNodes);
99 Standard_Integer NbNodes;
100 MeshVS_EntityType aType;
102 if ( !( DisplayMode & GetFlags() ) || !IsElement ||
103 ( myElemColorMap1.IsEmpty() && myElemColorMap2.IsEmpty() ) )
106 // subtract the hidden elements and ids to exclude (to minimise allocated memory)
107 TColStd_PackedMapOfInteger anIDs;
109 Handle(TColStd_HPackedMapOfInteger) aHiddenElems = myParentMesh->GetHiddenElems();
110 if ( !aHiddenElems.IsNull() )
111 anIDs.Subtract( aHiddenElems->Map() );
112 anIDs.Subtract( IDsToExclude );
114 // STEP 0: We looking for two colored elements, who has equal two colors and move it
115 // to map of elements with one assigned color
116 TColStd_ListOfInteger aColorOne;
117 for ( MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors anIter ( *anElemTwoColorsMap ); anIter.More(); anIter.Next () )
119 Standard_Integer aKey = anIter.Key ();
120 MeshVS_TwoColors aValue = anIter.Value ();
121 Quantity_Color aCol1, aCol2;
122 ExtractColors ( aValue, aCol1, aCol2 );
123 if ( aCol1 == aCol2 )
125 aColorOne.Append ( aKey );
126 anElemColorMap->Bind ( aKey, aCol1 );
130 for ( TColStd_ListIteratorOfListOfInteger aLIter ( aColorOne ); aLIter.More(); aLIter.Next() )
131 anElemTwoColorsMap->UnBind ( aLIter.Value() );
133 // The map is to resort itself by colors.
134 // STEP 1: We start sorting elements with one assigned color
135 for ( MeshVS_DataMapIteratorOfDataMapOfIntegerColor anIterM ( *anElemColorMap ); anIterM.More(); anIterM.Next () )
137 Standard_Integer aMKey = anIterM.Key ();
138 // The ID of current element
139 Standard_Boolean IsExist = Standard_False;
140 for ( MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger anIterC ( aColorsOfElements );
141 anIterC.More() && !IsExist; anIterC.Next () )
142 if ( anIterC.Key()==anIterM.Value() )
144 TColStd_MapOfInteger& aChangeValue = (TColStd_MapOfInteger&) anIterC.Value();
145 aChangeValue.Add ( aMKey );
146 IsExist = Standard_True;
151 TColStd_MapOfInteger aNewMap; aNewMap.Add ( aMKey );
152 aColorsOfElements.Bind ( anIterM.Value(), aNewMap );
156 // STEP 2: We start sorting elements with two assigned colors
157 for ( MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors anIterM2 ( *anElemTwoColorsMap ); anIterM2.More();
160 Standard_Integer aMKey = anIterM2.Key ();
161 // The ID of current element
162 Standard_Boolean IsExist = Standard_False;
163 for ( MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger anIterC2 ( aTwoColorsOfElements );
164 anIterC2.More() && !IsExist; anIterC2.Next () )
165 if ( IsEqual ( anIterC2.Key(), anIterM2.Value() ) )
167 TColStd_MapOfInteger& aChangeValue = (TColStd_MapOfInteger&) anIterC2.Value();
168 aChangeValue.Add ( aMKey );
169 IsExist = Standard_True;
174 TColStd_MapOfInteger aNewMap; aNewMap.Add ( aMKey );
175 aTwoColorsOfElements.Bind ( anIterM2.Value(), aNewMap );
179 //Now we are ready to draw faces with equal colors
180 Aspect_TypeOfLine anEdgeType = Aspect_TOL_SOLID;
181 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
182 Standard_Integer anEdgeInt, aLineInt;
183 Standard_Real anEdgeWidth, aLineWidth;
184 Quantity_Color anInteriorColor;
185 Quantity_Color anEdgeColor, aLineColor;
186 Standard_Boolean anEdgeOn = Standard_True, IsReflect = Standard_False,
187 IsMeshSmoothShading = Standard_False;
189 aDrawer->GetColor ( MeshVS_DA_InteriorColor, anInteriorColor );
190 aDrawer->GetColor ( MeshVS_DA_EdgeColor, anEdgeColor );
191 aDrawer->GetColor ( MeshVS_DA_BeamColor, aLineColor );
192 aDrawer->GetDouble ( MeshVS_DA_EdgeWidth, anEdgeWidth );
193 aDrawer->GetDouble ( MeshVS_DA_BeamWidth, aLineWidth );
194 aDrawer->GetBoolean( MeshVS_DA_ShowEdges, anEdgeOn );
195 aDrawer->GetBoolean( MeshVS_DA_ColorReflection, IsReflect );
196 aDrawer->GetBoolean( MeshVS_DA_SmoothShading, IsMeshSmoothShading );
198 if ( aDrawer->GetInteger ( MeshVS_DA_EdgeType, anEdgeInt) )
199 anEdgeType = (Aspect_TypeOfLine) anEdgeInt;
201 if ( aDrawer->GetInteger ( MeshVS_DA_BeamType, aLineInt) )
202 aLineType = (Aspect_TypeOfLine) aLineInt;
204 Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo;
205 Standard_Integer PolygonVerticesFor3D = 0, PolygonBoundsFor3D = 0;
206 TColStd_MapIteratorOfPackedMapOfInteger it (anIDs);
207 for( ; it.More(); it.Next() )
209 Standard_Integer aKey = it.Key();
210 if( aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
211 MeshVS_MeshPrsBuilder::HowManyPrimitives
212 ( aTopo, Standard_True, Standard_False, NbNodes,
213 PolygonVerticesFor3D, PolygonBoundsFor3D );
216 Graphic3d_MaterialAspect aMaterial[2];
217 for (Standard_Integer i = 0; i < 2; i++)
219 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
220 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
221 // color from AspectFillArea3d to calculate all material colors
222 aMaterial[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC );
224 // OCC21720 For single-colored elements turning all material components off is a good idea,
225 // as anyhow the normals are not computed and the lighting will be off,
226 // the element color will be taken from Graphic3d_AspectFillArea3d's interior color,
227 // and there is no need to spend time on updating material properties
230 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
231 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
232 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
233 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_EMISSION);
237 // OCC20644 This stuff is important in order for elemental and nodal colors
238 // to produce similar visual impression and also to make colors match
239 // those in the color scale most exactly (the sum of all reflection
240 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
241 // class for more explanations.
242 aMaterial[i].SetAmbient( .5 );
243 aMaterial[i].SetDiffuse( .5 );
244 aMaterial[i].SetSpecular( 0. );
245 aMaterial[i].SetEmissive( 0. );
249 // Draw elements with one color
250 for ( MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger aColIter ( aColorsOfElements ); aColIter.More();
253 Standard_Integer aSize = aColIter.Value().Extent();
257 TColStd_PackedMapOfInteger aCustomElements;
259 Prs3d_Root::NewGroup ( Prs );
260 Handle ( Graphic3d_Group ) aGGroup = Prs3d_Root::CurrentGroup ( Prs );
261 Prs3d_Root::NewGroup ( Prs );
262 Handle ( Graphic3d_Group ) aLGroup = Prs3d_Root::CurrentGroup ( Prs );
263 Prs3d_Root::NewGroup ( Prs );
264 Handle ( Graphic3d_Group ) aSGroup = Prs3d_Root::CurrentGroup ( Prs );
266 Standard_Integer aNbFacePrimitives = 0;
267 Standard_Integer aNbVolmPrimitives = 0;
268 Standard_Integer aNbEdgePrimitives = 0;
269 Standard_Integer aNbLinkPrimitives = 0;
271 for (it.Reset(); it.More(); it.Next())
273 Standard_Integer aNbNodes = 0;
275 if (!aColIter.Value().Contains (it.Key()))
278 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
281 if (aType == MeshVS_ET_Volume)
283 if (aSource->Get3DGeom (it.Key(), aNbNodes, aTopo))
285 for (Standard_Integer aFaceIdx = aTopo->Lower(); aFaceIdx <= aTopo->Upper(); ++aFaceIdx)
287 const TColStd_SequenceOfInteger& aFaceNodes = aTopo->Value (aFaceIdx);
289 if (anEdgeOn) // add edge segments
291 aNbEdgePrimitives += aFaceNodes.Length();
294 aNbVolmPrimitives += aFaceNodes.Length() - 2;
298 else if (aType == MeshVS_ET_Link)
302 aNbLinkPrimitives += aNbNodes - 1; // add link segments
305 else if (aType == MeshVS_ET_Face)
309 aNbEdgePrimitives += aNbNodes; // add edge segments
312 aNbFacePrimitives += aNbNodes - 2; // add face triangles
316 // Here we do not use indices arrays because they are not effective for some mesh
317 // drawing modes: shrinking mode (displaces the vertices inside the polygon), 3D
318 // cell rendering (normal interpolation is not always applicable - flat shading),
319 // elemental coloring (color interpolation is impossible)
321 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles (
322 (aNbFacePrimitives + aNbVolmPrimitives) * 3, 0, IsReflect );
323 Standard_Boolean IsPolyG = Standard_False;
325 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments (aNbEdgePrimitives * 2);
326 Handle (Graphic3d_ArrayOfSegments) aLinkSegments = new Graphic3d_ArrayOfSegments (aNbLinkPrimitives * 2);
327 Standard_Boolean IsPolyL = Standard_False;
329 // OCC20644 NOTE: aColIter.Key() color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
330 // using the material reflection coefficients. This affects the visual result.
331 Handle(Graphic3d_AspectFillArea3d) aFillAspect =
332 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aColIter.Key(), anEdgeColor,
333 anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1] );
335 Handle(Graphic3d_AspectLine3d) aLinkAspect =
336 new Graphic3d_AspectLine3d ( aColIter.Key(), aLineType, aLineWidth );
338 Handle(Graphic3d_AspectLine3d) anEdgeAspect =
339 new Graphic3d_AspectLine3d ( anEdgeColor, anEdgeType, anEdgeWidth );
341 aFillAspect->SetDistinguishOff ();
342 aFillAspect->SetInteriorColor ( aColIter.Key() );
344 aFillAspect->SetEdgeOn();
346 aFillAspect->SetEdgeOff();
348 for (it.Reset(); it.More(); it.Next())
350 Standard_Integer aKey = it.Key();
352 if (aColIter.Value().Contains (aKey))
354 if (!aSource->GetGeom (aKey, Standard_True, aCoords, NbNodes, aType))
357 if (aType != MeshVS_ET_Face && aType != MeshVS_ET_Link && aType != MeshVS_ET_Volume)
359 aCustomElements.Add (aKey);
364 IDsToExclude.Add (aKey);
366 if (aType == MeshVS_ET_Volume)
368 if (!aSource->Get3DGeom (aKey, NbNodes, aTopo))
373 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
374 NbNodes, aFaceTriangles, IsReflect, Standard_False, Standard_False, 1.0);
378 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
379 NbNodes, anEdgeSegments, IsReflect, Standard_False, Standard_False, 1.0);
382 IsPolyG = Standard_True;
384 else if (aType == MeshVS_ET_Face)
387 Handle(TColStd_HArray1OfReal) aNormals;
388 Standard_Boolean aHasNormals = IsReflect && aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
390 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
392 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
396 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
397 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
398 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3),
399 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1) : 0.0,
400 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2) : 0.0,
401 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3) : 1.0);
405 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
406 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
407 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3));
414 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
416 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
418 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
419 aCoords (3 * aNodeIdx + 2),
420 aCoords (3 * aNodeIdx + 3));
422 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
423 aCoords (3 * aNextIdx + 2),
424 aCoords (3 * aNextIdx + 3));
428 IsPolyG = Standard_True;
430 else if (aType == MeshVS_ET_Link)
432 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 1; ++aNodeIdx)
434 const Standard_Integer aNextIdx = aNodeIdx + 1;
436 aLinkSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
437 aCoords (3 * aNodeIdx + 2),
438 aCoords (3 * aNodeIdx + 3));
440 aLinkSegments->AddVertex (aCoords (3 * aNextIdx + 1),
441 aCoords (3 * aNextIdx + 2),
442 aCoords (3 * aNextIdx + 3));
444 IsPolyL = Standard_True;
452 aFillAspect->SetEdgeOff();
453 aGGroup->SetPrimitivesAspect (aFillAspect);
454 aGGroup->AddPrimitiveArray (aFaceTriangles);
458 aFillAspect->SetEdgeOff();
459 aSGroup->AddPrimitiveArray (anEdgeSegments);
460 aSGroup->SetGroupPrimitivesAspect (anEdgeAspect);
465 aFillAspect->SetEdgeOff();
466 aLGroup->SetPrimitivesAspect (aFillAspect);
467 aLGroup->SetPrimitivesAspect (aLinkAspect);
468 aLGroup->AddPrimitiveArray (aLinkSegments);
470 aFillAspect->SetEdgeOn();
472 aFillAspect->SetEdgeOff();
475 if (!aCustomElements.IsEmpty())
476 CustomBuild(Prs, aCustomElements, IDsToExclude, DisplayMode);
479 Graphic3d_MaterialAspect aMaterial2[2];
480 for (Standard_Integer i = 0; i < 2; i++)
482 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
483 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
484 // color from AspectFillArea3d to calculate all material colors
485 aMaterial2[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC );
489 // OCC21720 Cannot turn ALL material components off, as such a material
490 // would be ignored by TelUpdateMaterial(), but we need it in order
491 // to have different materials for front and back sides!
492 // Instead, trying to make material color "nondirectional" with
493 // only ambient component on.
494 aMaterial2[i].SetReflectionModeOn ( Graphic3d_TOR_AMBIENT );
495 aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_DIFFUSE );
496 aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_SPECULAR );
497 aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_EMISSION );
498 aMaterial2[i].SetAmbient ( 1. );
499 aMaterial2[i].SetDiffuse ( 0. );
500 aMaterial2[i].SetSpecular( 0. );
501 aMaterial2[i].SetEmissive( 0. );
505 // OCC20644 This stuff is important in order for elemental and nodal colors
506 // to produce similar visual impression and also to make colors match
507 // those in the color scale most exactly (the sum of all reflection
508 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
509 // class for more explanations.
510 aMaterial2[i].SetAmbient( .5 );
511 aMaterial2[i].SetDiffuse( .5 );
512 aMaterial2[i].SetSpecular( 0. );
513 aMaterial2[i].SetEmissive( 0. );
517 // Draw faces with two color
518 for ( MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger aColIter2 ( aTwoColorsOfElements );
519 aColIter2.More(); aColIter2.Next() )
521 Prs3d_Root::NewGroup ( Prs );
522 Handle ( Graphic3d_Group ) aGroup2 = Prs3d_Root::CurrentGroup ( Prs );
523 Prs3d_Root::NewGroup ( Prs );
524 Handle ( Graphic3d_Group ) aGroup3 = Prs3d_Root::CurrentGroup ( Prs );
526 Standard_Integer aSize = aColIter2.Value().Extent();
530 Standard_Integer aNbFacePrimitives = 0;
531 Standard_Integer aNbEdgePrimitives = 0;
533 for (it.Reset(); it.More(); it.Next())
535 Standard_Integer aNbNodes = 0;
537 if (!aColIter2.Value().Contains (it.Key()))
540 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
543 if ( aType == MeshVS_ET_Face && aNbNodes > 0 )
547 aNbEdgePrimitives += aNbNodes; // add edge segments
550 aNbFacePrimitives += aNbNodes - 2; // add face triangles
554 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles
555 (aNbFacePrimitives * 3, 0, IsReflect);
557 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments
558 (aNbEdgePrimitives * 2);
560 MeshVS_TwoColors aTC = aColIter2.Key();
561 Quantity_Color aMyIntColor, aMyBackColor;
562 ExtractColors ( aTC, aMyIntColor, aMyBackColor );
564 // OCC20644 NOTE: aMyIntColor color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
565 // using the material reflection coefficients. This affects the visual result.
566 Handle(Graphic3d_AspectFillArea3d) anAsp =
567 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aMyIntColor, anEdgeColor,
568 anEdgeType, anEdgeWidth, aMaterial2[0], aMaterial2[1] );
569 anAsp->SetDistinguishOn ();
570 anAsp->SetInteriorColor ( aMyIntColor );
571 anAsp->SetBackInteriorColor ( aMyBackColor );
575 anAsp->SetEdgeOff();*/
577 Handle(Graphic3d_AspectLine3d) anEdgeAspect =
578 new Graphic3d_AspectLine3d (anEdgeColor, anEdgeType, anEdgeWidth);
580 for( it.Reset(); it.More(); it.Next() )
582 Standard_Integer aKey = it.Key();
583 if( aColIter2.Value().Contains( aKey ) )
585 if ( !aSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ) )
588 if( IsExcludingOn() )
589 IDsToExclude.Add( aKey );
591 if (aType == MeshVS_ET_Face && NbNodes > 0)
593 // Preparing normal(s) to show reflections if requested
594 Handle(TColStd_HArray1OfReal) aNormals;
595 // OCC21720 Always passing normals to OpenGL to make materials work
596 // For OpenGL: "No normals" -> "No lighting" -> "no materials taken into account"
597 Standard_Boolean aHasNormals = /*IsReflect &&*/
598 aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
600 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
602 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
606 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
607 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
608 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3),
609 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1) : 0.0,
610 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2) : 0.0,
611 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3) : 1.0);
615 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
616 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
617 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3));
624 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
626 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
628 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
629 aCoords (3 * aNodeIdx + 2),
630 aCoords (3 * aNodeIdx + 3));
632 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
633 aCoords (3 * aNextIdx + 2),
634 aCoords (3 * aNextIdx + 3));
641 aGroup2->AddPrimitiveArray (aFaceTriangles);
642 aGroup2->SetGroupPrimitivesAspect (anAsp);
643 aGroup3->AddPrimitiveArray (anEdgeSegments);
644 aGroup3->SetGroupPrimitivesAspect (anEdgeAspect);
648 //================================================================
649 // Function : SetColors
651 //================================================================
652 void MeshVS_ElementalColorPrsBuilder::SetColors1 ( const MeshVS_DataMapOfIntegerColor& theColorMap )
654 myElemColorMap1 = theColorMap;
657 //================================================================
658 // Function : GetColors
660 //================================================================
661 const MeshVS_DataMapOfIntegerColor& MeshVS_ElementalColorPrsBuilder::GetColors1 () const
663 return myElemColorMap1;
666 //================================================================
667 // Function : HasColors1
669 //================================================================
670 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors1 () const
672 return ( myElemColorMap1.Extent() >0 );
675 //================================================================
676 // Function : GetColor1
678 //================================================================
679 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor1 ( const Standard_Integer ID,
680 Quantity_Color& theColor ) const
682 Standard_Boolean aRes = myElemColorMap1.IsBound ( ID );
684 theColor = myElemColorMap1.Find ( ID );
689 //================================================================
690 // Function : SetColor1
692 //================================================================
693 void MeshVS_ElementalColorPrsBuilder::SetColor1 ( const Standard_Integer theID,
694 const Quantity_Color& theCol )
696 Standard_Boolean aRes = myElemColorMap1.IsBound ( theID );
698 myElemColorMap1.ChangeFind ( theID ) = theCol;
700 myElemColorMap1.Bind ( theID, theCol );
703 //================================================================
704 // Function : SetColors2
706 //================================================================
707 void MeshVS_ElementalColorPrsBuilder::SetColors2 ( const MeshVS_DataMapOfIntegerTwoColors& theColorMap )
709 myElemColorMap2 = theColorMap;
712 //================================================================
713 // Function : GetColors2
715 //================================================================
716 const MeshVS_DataMapOfIntegerTwoColors& MeshVS_ElementalColorPrsBuilder::GetColors2 () const
718 return myElemColorMap2;
721 //================================================================
722 // Function : HasColors2
724 //================================================================
725 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors2 () const
727 return (myElemColorMap2.Extent()>0);
730 //================================================================
731 // Function : GetColor2
733 //================================================================
734 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
735 MeshVS_TwoColors& theColor ) const
737 Standard_Boolean aRes = myElemColorMap2.IsBound ( ID );
739 theColor = myElemColorMap2.Find ( ID );
744 //================================================================
745 // Function : GetColor2
747 //================================================================
748 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
749 Quantity_Color& theColor1,
750 Quantity_Color& theColor2 ) const
752 MeshVS_TwoColors aTC;
753 Standard_Boolean aRes = GetColor2 ( ID, aTC );
755 ExtractColors ( aTC, theColor1, theColor2 );
759 //================================================================
760 // Function : SetColor2
762 //================================================================
763 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
764 const Quantity_Color& theCol1,
765 const Quantity_Color& theCol2 )
767 SetColor2 ( theID, BindTwoColors ( theCol1, theCol2 ) );
770 //================================================================
771 // Function : SetColor2
773 //================================================================
774 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
775 const MeshVS_TwoColors& theCol )
777 Standard_Boolean aRes = myElemColorMap2.IsBound ( theID );
779 myElemColorMap2.ChangeFind ( theID ) = theCol;
781 myElemColorMap2.Bind ( theID, theCol );