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.
16 #include <MeshVS_ElementalColorPrsBuilder.ixx>
18 #include <Graphic3d_AspectFillArea3d.hxx>
19 #include <Graphic3d_AspectLine3d.hxx>
20 #include <Graphic3d_ArrayOfPolygons.hxx>
21 #include <Graphic3d_ArrayOfPolylines.hxx>
22 #include <Graphic3d_ArrayOfSegments.hxx>
23 #include <Graphic3d_ArrayOfTriangles.hxx>
24 #include <Graphic3d_Group.hxx>
26 #include <Prs3d_ShadingAspect.hxx>
27 #include <Prs3d_Root.hxx>
28 #include <Prs3d_LineAspect.hxx>
30 #include <TColStd_MapOfInteger.hxx>
31 #include <TColStd_PackedMapOfInteger.hxx>
32 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
33 #include <TColStd_ListIteratorOfListOfInteger.hxx>
34 #include <TColStd_Array1OfReal.hxx>
35 #include <TColStd_SequenceOfInteger.hxx>
36 #include <TColStd_HArray1OfReal.hxx>
37 #include <TColStd_HPackedMapOfInteger.hxx>
39 #include <MeshVS_DisplayModeFlags.hxx>
40 #include <MeshVS_DataSource.hxx>
41 #include <MeshVS_Mesh.hxx>
42 #include <MeshVS_DataMapOfColorMapOfInteger.hxx>
43 #include <MeshVS_DataMapOfTwoColorsMapOfInteger.hxx>
44 #include <MeshVS_Drawer.hxx>
45 #include <MeshVS_DrawerAttribute.hxx>
46 #include <MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors.hxx>
47 #include <MeshVS_DataMapIteratorOfDataMapOfIntegerColor.hxx>
48 #include <MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger.hxx>
49 #include <MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger.hxx>
50 #include <MeshVS_MeshPrsBuilder.hxx>
51 #include <MeshVS_Buffer.hxx>
52 #include <MeshVS_HArray1OfSequenceOfInteger.hxx>
54 //================================================================
55 // Function : Constructor MeshVS_ElementalColorPrsBuilder
57 //================================================================
58 MeshVS_ElementalColorPrsBuilder::MeshVS_ElementalColorPrsBuilder
59 ( const Handle(MeshVS_Mesh)& Parent,
60 const MeshVS_DisplayModeFlags& Flags,
61 const Handle (MeshVS_DataSource)& DS,
62 const Standard_Integer Id,
63 const MeshVS_BuilderPriority& Priority )
64 : MeshVS_PrsBuilder ( Parent, Flags, DS, Id, Priority )
66 SetExcluding ( Standard_True );
69 //================================================================
72 //================================================================
73 void MeshVS_ElementalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& Prs,
74 const TColStd_PackedMapOfInteger& IDs,
75 TColStd_PackedMapOfInteger& IDsToExclude,
76 const Standard_Boolean IsElement,
77 const Standard_Integer DisplayMode) const
79 Handle (MeshVS_DataSource) aSource = GetDataSource();
80 Handle (MeshVS_Drawer) aDrawer = GetDrawer();
82 if ( aSource.IsNull() || aDrawer.IsNull() )
85 Standard_Integer aMaxFaceNodes;
86 if ( !aDrawer->GetInteger ( MeshVS_DA_MaxFaceNodes, aMaxFaceNodes ) && aMaxFaceNodes<=0 )
89 MeshVS_DataMapOfIntegerColor* anElemColorMap = (MeshVS_DataMapOfIntegerColor*) &myElemColorMap1;
90 MeshVS_DataMapOfIntegerTwoColors* anElemTwoColorsMap = (MeshVS_DataMapOfIntegerTwoColors*)&myElemColorMap2;
92 MeshVS_DataMapOfColorMapOfInteger aColorsOfElements;
93 MeshVS_DataMapOfTwoColorsMapOfInteger aTwoColorsOfElements;
95 MeshVS_Buffer aCoordsBuf (3*aMaxFaceNodes*sizeof(Standard_Real));
96 TColStd_Array1OfReal aCoords (aCoordsBuf, 1, 3*aMaxFaceNodes);
97 Standard_Integer NbNodes;
98 MeshVS_EntityType aType;
100 if ( !( DisplayMode & GetFlags() ) || !IsElement ||
101 ( myElemColorMap1.IsEmpty() && myElemColorMap2.IsEmpty() ) )
104 // subtract the hidden elements and ids to exclude (to minimise allocated memory)
105 TColStd_PackedMapOfInteger anIDs;
107 Handle(TColStd_HPackedMapOfInteger) aHiddenElems = myParentMesh->GetHiddenElems();
108 if ( !aHiddenElems.IsNull() )
109 anIDs.Subtract( aHiddenElems->Map() );
110 anIDs.Subtract( IDsToExclude );
112 // STEP 0: We looking for two colored elements, who has equal two colors and move it
113 // to map of elements with one assigned color
114 TColStd_ListOfInteger aColorOne;
115 for ( MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors anIter ( *anElemTwoColorsMap ); anIter.More(); anIter.Next () )
117 Standard_Integer aKey = anIter.Key ();
118 MeshVS_TwoColors aValue = anIter.Value ();
119 Quantity_Color aCol1, aCol2;
120 ExtractColors ( aValue, aCol1, aCol2 );
121 if ( aCol1 == aCol2 )
123 aColorOne.Append ( aKey );
124 anElemColorMap->Bind ( aKey, aCol1 );
128 for ( TColStd_ListIteratorOfListOfInteger aLIter ( aColorOne ); aLIter.More(); aLIter.Next() )
129 anElemTwoColorsMap->UnBind ( aLIter.Value() );
131 // The map is to resort itself by colors.
132 // STEP 1: We start sorting elements with one assigned color
133 for ( MeshVS_DataMapIteratorOfDataMapOfIntegerColor anIterM ( *anElemColorMap ); anIterM.More(); anIterM.Next () )
135 Standard_Integer aMKey = anIterM.Key ();
136 // The ID of current element
137 Standard_Boolean IsExist = Standard_False;
138 for ( MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger anIterC ( aColorsOfElements );
139 anIterC.More() && !IsExist; anIterC.Next () )
140 if ( anIterC.Key()==anIterM.Value() )
142 TColStd_MapOfInteger& aChangeValue = (TColStd_MapOfInteger&) anIterC.Value();
143 aChangeValue.Add ( aMKey );
144 IsExist = Standard_True;
149 TColStd_MapOfInteger aNewMap; aNewMap.Add ( aMKey );
150 aColorsOfElements.Bind ( anIterM.Value(), aNewMap );
154 // STEP 2: We start sorting elements with two assigned colors
155 for ( MeshVS_DataMapIteratorOfDataMapOfIntegerTwoColors anIterM2 ( *anElemTwoColorsMap ); anIterM2.More();
158 Standard_Integer aMKey = anIterM2.Key ();
159 // The ID of current element
160 Standard_Boolean IsExist = Standard_False;
161 for ( MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger anIterC2 ( aTwoColorsOfElements );
162 anIterC2.More() && !IsExist; anIterC2.Next () )
163 if ( IsEqual ( anIterC2.Key(), anIterM2.Value() ) )
165 TColStd_MapOfInteger& aChangeValue = (TColStd_MapOfInteger&) anIterC2.Value();
166 aChangeValue.Add ( aMKey );
167 IsExist = Standard_True;
172 TColStd_MapOfInteger aNewMap; aNewMap.Add ( aMKey );
173 aTwoColorsOfElements.Bind ( anIterM2.Value(), aNewMap );
177 //Now we are ready to draw faces with equal colors
178 Aspect_TypeOfLine anEdgeType = Aspect_TOL_SOLID;
179 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
180 Standard_Integer anEdgeInt, aLineInt;
181 Standard_Real anEdgeWidth, aLineWidth;
182 Quantity_Color anInteriorColor;
183 Quantity_Color anEdgeColor, aLineColor;
184 Standard_Boolean anEdgeOn = Standard_True, IsReflect = Standard_False,
185 IsMeshSmoothShading = Standard_False;
187 aDrawer->GetColor ( MeshVS_DA_InteriorColor, anInteriorColor );
188 aDrawer->GetColor ( MeshVS_DA_EdgeColor, anEdgeColor );
189 aDrawer->GetColor ( MeshVS_DA_BeamColor, aLineColor );
190 aDrawer->GetDouble ( MeshVS_DA_EdgeWidth, anEdgeWidth );
191 aDrawer->GetDouble ( MeshVS_DA_BeamWidth, aLineWidth );
192 aDrawer->GetBoolean( MeshVS_DA_ShowEdges, anEdgeOn );
193 aDrawer->GetBoolean( MeshVS_DA_ColorReflection, IsReflect );
194 aDrawer->GetBoolean( MeshVS_DA_SmoothShading, IsMeshSmoothShading );
196 if ( aDrawer->GetInteger ( MeshVS_DA_EdgeType, anEdgeInt) )
197 anEdgeType = (Aspect_TypeOfLine) anEdgeInt;
199 if ( aDrawer->GetInteger ( MeshVS_DA_BeamType, aLineInt) )
200 aLineType = (Aspect_TypeOfLine) aLineInt;
202 Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo;
203 Standard_Integer PolygonVerticesFor3D = 0, PolygonBoundsFor3D = 0;
204 TColStd_MapIteratorOfPackedMapOfInteger it (anIDs);
205 for( ; it.More(); it.Next() )
207 Standard_Integer aKey = it.Key();
208 if( aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
209 MeshVS_MeshPrsBuilder::HowManyPrimitives
210 ( aTopo, Standard_True, Standard_False, NbNodes,
211 PolygonVerticesFor3D, PolygonBoundsFor3D );
214 Graphic3d_MaterialAspect aMaterial[2];
215 for (Standard_Integer i = 0; i < 2; i++)
217 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
218 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
219 // color from AspectFillArea3d to calculate all material colors
220 aMaterial[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC );
222 // OCC21720 For single-colored elements turning all material components off is a good idea,
223 // as anyhow the normals are not computed and the lighting will be off,
224 // the element color will be taken from Graphic3d_AspectFillArea3d's interior color,
225 // and there is no need to spend time on updating material properties
228 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
229 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
230 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
231 aMaterial[i].SetReflectionModeOff(Graphic3d_TOR_EMISSION);
235 // OCC20644 This stuff is important in order for elemental and nodal colors
236 // to produce similar visual impression and also to make colors match
237 // those in the color scale most exactly (the sum of all reflection
238 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
239 // class for more explanations.
240 aMaterial[i].SetAmbient( .5 );
241 aMaterial[i].SetDiffuse( .5 );
242 aMaterial[i].SetSpecular( 0. );
243 aMaterial[i].SetEmissive( 0. );
247 // Draw elements with one color
248 for ( MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger aColIter ( aColorsOfElements ); aColIter.More();
251 Standard_Integer aSize = aColIter.Value().Extent();
255 TColStd_PackedMapOfInteger aCustomElements;
257 Prs3d_Root::NewGroup ( Prs );
258 Handle ( Graphic3d_Group ) aGGroup = Prs3d_Root::CurrentGroup ( Prs );
259 Prs3d_Root::NewGroup ( Prs );
260 Handle ( Graphic3d_Group ) aLGroup = Prs3d_Root::CurrentGroup ( Prs );
261 Prs3d_Root::NewGroup ( Prs );
262 Handle ( Graphic3d_Group ) aSGroup = Prs3d_Root::CurrentGroup ( Prs );
264 Standard_Integer aNbFacePrimitives = 0;
265 Standard_Integer aNbVolmPrimitives = 0;
266 Standard_Integer aNbEdgePrimitives = 0;
267 Standard_Integer aNbLinkPrimitives = 0;
269 for (it.Reset(); it.More(); it.Next())
271 Standard_Integer aNbNodes = 0;
273 if (!aColIter.Value().Contains (it.Key()))
276 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
279 if (aType == MeshVS_ET_Volume)
281 if (aSource->Get3DGeom (it.Key(), aNbNodes, aTopo))
283 for (Standard_Integer aFaceIdx = aTopo->Lower(); aFaceIdx <= aTopo->Upper(); ++aFaceIdx)
285 const TColStd_SequenceOfInteger& aFaceNodes = aTopo->Value (aFaceIdx);
287 if (anEdgeOn) // add edge segments
289 aNbEdgePrimitives += aFaceNodes.Length();
292 if (IsReflect) // add volumetric cell triangles
294 aNbVolmPrimitives += aFaceNodes.Length() - 2;
299 else if (aType == MeshVS_ET_Link)
303 aNbLinkPrimitives += aNbNodes - 1; // add link segments
306 else if (aType == MeshVS_ET_Face)
310 aNbEdgePrimitives += aNbNodes; // add edge segments
313 aNbFacePrimitives += aNbNodes - 2; // add face triangles
317 // Here we do not use indices arrays because they are not effective for some mesh
318 // drawing modes: shrinking mode (displaces the vertices inside the polygon), 3D
319 // cell rendering (normal interpolation is not always applicable - flat shading),
320 // elemental coloring (color interpolation is impossible)
322 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles (
323 (aNbFacePrimitives + aNbVolmPrimitives) * 3, 0, IsReflect );
324 Standard_Boolean IsPolyG = Standard_False;
326 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments (aNbEdgePrimitives * 2);
327 Handle (Graphic3d_ArrayOfSegments) aLinkSegments = new Graphic3d_ArrayOfSegments (aNbLinkPrimitives * 2);
328 Standard_Boolean IsPolyL = Standard_False;
330 // OCC20644 NOTE: aColIter.Key() color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
331 // using the material reflection coefficients. This affects the visual result.
332 Handle(Graphic3d_AspectFillArea3d) aFillAspect =
333 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aColIter.Key(), anEdgeColor,
334 anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1] );
336 Handle(Graphic3d_AspectLine3d) aLinkAspect =
337 new Graphic3d_AspectLine3d ( aColIter.Key(), aLineType, aLineWidth );
339 Handle(Graphic3d_AspectLine3d) anEdgeAspect =
340 new Graphic3d_AspectLine3d ( anEdgeColor, anEdgeType, anEdgeWidth );
342 aFillAspect->SetDistinguishOff ();
343 aFillAspect->SetInteriorColor ( aColIter.Key() );
345 aFillAspect->SetEdgeOn();
347 aFillAspect->SetEdgeOff();
349 for (it.Reset(); it.More(); it.Next())
351 Standard_Integer aKey = it.Key();
353 if (aColIter.Value().Contains (aKey))
355 if (!aSource->GetGeom (aKey, Standard_True, aCoords, NbNodes, aType))
358 if (aType != MeshVS_ET_Face && aType != MeshVS_ET_Link && aType != MeshVS_ET_Volume)
360 aCustomElements.Add (aKey);
365 IDsToExclude.Add (aKey);
367 if (aType == MeshVS_ET_Volume)
369 if (!aSource->Get3DGeom (aKey, NbNodes, aTopo))
374 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
375 NbNodes, aFaceTriangles, IsReflect, Standard_False, Standard_False, 1.0);
379 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
380 NbNodes, anEdgeSegments, IsReflect, Standard_False, Standard_False, 1.0);
383 IsPolyG = Standard_True;
385 else if (aType == MeshVS_ET_Face)
388 Handle(TColStd_HArray1OfReal) aNormals;
389 Standard_Boolean aHasNormals = IsReflect && aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
391 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
393 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
397 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
398 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
399 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3),
400 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1) : 0.0,
401 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2) : 0.0,
402 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3) : 1.0);
406 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
407 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
408 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3));
415 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
417 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
419 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
420 aCoords (3 * aNodeIdx + 2),
421 aCoords (3 * aNodeIdx + 3));
423 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
424 aCoords (3 * aNextIdx + 2),
425 aCoords (3 * aNextIdx + 3));
429 IsPolyG = Standard_True;
431 else if (aType == MeshVS_ET_Link)
433 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 1; ++aNodeIdx)
435 const Standard_Integer aNextIdx = aNodeIdx + 1;
437 aLinkSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
438 aCoords (3 * aNodeIdx + 2),
439 aCoords (3 * aNodeIdx + 3));
441 aLinkSegments->AddVertex (aCoords (3 * aNextIdx + 1),
442 aCoords (3 * aNextIdx + 2),
443 aCoords (3 * aNextIdx + 3));
445 IsPolyL = Standard_True;
453 aFillAspect->SetEdgeOff();
454 aGGroup->SetPrimitivesAspect (aFillAspect);
455 aGGroup->AddPrimitiveArray (aFaceTriangles);
459 aFillAspect->SetEdgeOff();
460 aSGroup->AddPrimitiveArray (anEdgeSegments);
461 aSGroup->SetGroupPrimitivesAspect (anEdgeAspect);
466 aFillAspect->SetEdgeOff();
467 aLGroup->SetPrimitivesAspect (aFillAspect);
468 aLGroup->SetPrimitivesAspect (aLinkAspect);
469 aLGroup->AddPrimitiveArray (aLinkSegments);
471 aFillAspect->SetEdgeOn();
473 aFillAspect->SetEdgeOff();
476 if (!aCustomElements.IsEmpty())
477 CustomBuild(Prs, aCustomElements, IDsToExclude, DisplayMode);
480 Graphic3d_MaterialAspect aMaterial2[2];
481 for (Standard_Integer i = 0; i < 2; i++)
483 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
484 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
485 // color from AspectFillArea3d to calculate all material colors
486 aMaterial2[i] = Graphic3d_MaterialAspect ( Graphic3d_NOM_PLASTIC );
490 // OCC21720 Cannot turn ALL material components off, as such a material
491 // would be ignored by TelUpdateMaterial(), but we need it in order
492 // to have different materials for front and back sides!
493 // Instead, trying to make material color "nondirectional" with
494 // only ambient component on.
495 aMaterial2[i].SetReflectionModeOn ( Graphic3d_TOR_AMBIENT );
496 aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_DIFFUSE );
497 aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_SPECULAR );
498 aMaterial2[i].SetReflectionModeOff( Graphic3d_TOR_EMISSION );
499 aMaterial2[i].SetAmbient ( 1. );
500 aMaterial2[i].SetDiffuse ( 0. );
501 aMaterial2[i].SetSpecular( 0. );
502 aMaterial2[i].SetEmissive( 0. );
506 // OCC20644 This stuff is important in order for elemental and nodal colors
507 // to produce similar visual impression and also to make colors match
508 // those in the color scale most exactly (the sum of all reflection
509 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
510 // class for more explanations.
511 aMaterial2[i].SetAmbient( .5 );
512 aMaterial2[i].SetDiffuse( .5 );
513 aMaterial2[i].SetSpecular( 0. );
514 aMaterial2[i].SetEmissive( 0. );
518 // Draw faces with two color
519 for ( MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger aColIter2 ( aTwoColorsOfElements );
520 aColIter2.More(); aColIter2.Next() )
522 Prs3d_Root::NewGroup ( Prs );
523 Handle ( Graphic3d_Group ) aGroup2 = Prs3d_Root::CurrentGroup ( Prs );
524 Prs3d_Root::NewGroup ( Prs );
525 Handle ( Graphic3d_Group ) aGroup3 = Prs3d_Root::CurrentGroup ( Prs );
527 Standard_Integer aSize = aColIter2.Value().Extent();
531 Standard_Integer aNbFacePrimitives = 0;
532 Standard_Integer aNbEdgePrimitives = 0;
534 for (it.Reset(); it.More(); it.Next())
536 Standard_Integer aNbNodes = 0;
538 if (!aColIter2.Value().Contains (it.Key()))
541 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
544 if ( aType == MeshVS_ET_Face && aNbNodes > 0 )
548 aNbEdgePrimitives += aNbNodes; // add edge segments
551 aNbFacePrimitives += aNbNodes - 2; // add face triangles
555 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles
556 (aNbFacePrimitives * 3, 0, IsReflect);
558 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments
559 (aNbEdgePrimitives * 2);
561 MeshVS_TwoColors aTC = aColIter2.Key();
562 Quantity_Color aMyIntColor, aMyBackColor;
563 ExtractColors ( aTC, aMyIntColor, aMyBackColor );
565 // OCC20644 NOTE: aMyIntColor color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
566 // using the material reflection coefficients. This affects the visual result.
567 Handle(Graphic3d_AspectFillArea3d) anAsp =
568 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aMyIntColor, anEdgeColor,
569 anEdgeType, anEdgeWidth, aMaterial2[0], aMaterial2[1] );
570 anAsp->SetDistinguishOn ();
571 anAsp->SetInteriorColor ( aMyIntColor );
572 anAsp->SetBackInteriorColor ( aMyBackColor );
576 anAsp->SetEdgeOff();*/
578 Handle(Graphic3d_AspectLine3d) anEdgeAspect =
579 new Graphic3d_AspectLine3d (anEdgeColor, anEdgeType, anEdgeWidth);
581 for( it.Reset(); it.More(); it.Next() )
583 Standard_Integer aKey = it.Key();
584 if( aColIter2.Value().Contains( aKey ) )
586 if ( !aSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ) )
589 if( IsExcludingOn() )
590 IDsToExclude.Add( aKey );
592 if (aType == MeshVS_ET_Face && NbNodes > 0)
594 // Preparing normal(s) to show reflections if requested
595 Handle(TColStd_HArray1OfReal) aNormals;
596 // OCC21720 Always passing normals to OpenGL to make materials work
597 // For OpenGL: "No normals" -> "No lighting" -> "no materials taken into account"
598 Standard_Boolean aHasNormals = /*IsReflect &&*/
599 aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
601 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
603 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
607 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
608 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
609 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3),
610 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1) : 0.0,
611 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2) : 0.0,
612 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3) : 1.0);
616 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
617 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
618 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3));
625 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
627 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
629 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
630 aCoords (3 * aNodeIdx + 2),
631 aCoords (3 * aNodeIdx + 3));
633 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
634 aCoords (3 * aNextIdx + 2),
635 aCoords (3 * aNextIdx + 3));
642 aGroup2->AddPrimitiveArray (aFaceTriangles);
643 aGroup2->SetGroupPrimitivesAspect (anAsp);
644 aGroup3->AddPrimitiveArray (anEdgeSegments);
645 aGroup3->SetGroupPrimitivesAspect (anEdgeAspect);
649 //================================================================
650 // Function : SetColors
652 //================================================================
653 void MeshVS_ElementalColorPrsBuilder::SetColors1 ( const MeshVS_DataMapOfIntegerColor& theColorMap )
655 myElemColorMap1 = theColorMap;
658 //================================================================
659 // Function : GetColors
661 //================================================================
662 const MeshVS_DataMapOfIntegerColor& MeshVS_ElementalColorPrsBuilder::GetColors1 () const
664 return myElemColorMap1;
667 //================================================================
668 // Function : HasColors1
670 //================================================================
671 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors1 () const
673 return ( myElemColorMap1.Extent() >0 );
676 //================================================================
677 // Function : GetColor1
679 //================================================================
680 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor1 ( const Standard_Integer ID,
681 Quantity_Color& theColor ) const
683 Standard_Boolean aRes = myElemColorMap1.IsBound ( ID );
685 theColor = myElemColorMap1.Find ( ID );
690 //================================================================
691 // Function : SetColor1
693 //================================================================
694 void MeshVS_ElementalColorPrsBuilder::SetColor1 ( const Standard_Integer theID,
695 const Quantity_Color& theCol )
697 Standard_Boolean aRes = myElemColorMap1.IsBound ( theID );
699 myElemColorMap1.ChangeFind ( theID ) = theCol;
701 myElemColorMap1.Bind ( theID, theCol );
704 //================================================================
705 // Function : SetColors2
707 //================================================================
708 void MeshVS_ElementalColorPrsBuilder::SetColors2 ( const MeshVS_DataMapOfIntegerTwoColors& theColorMap )
710 myElemColorMap2 = theColorMap;
713 //================================================================
714 // Function : GetColors2
716 //================================================================
717 const MeshVS_DataMapOfIntegerTwoColors& MeshVS_ElementalColorPrsBuilder::GetColors2 () const
719 return myElemColorMap2;
722 //================================================================
723 // Function : HasColors2
725 //================================================================
726 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors2 () const
728 return (myElemColorMap2.Extent()>0);
731 //================================================================
732 // Function : GetColor2
734 //================================================================
735 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
736 MeshVS_TwoColors& theColor ) const
738 Standard_Boolean aRes = myElemColorMap2.IsBound ( ID );
740 theColor = myElemColorMap2.Find ( ID );
745 //================================================================
746 // Function : GetColor2
748 //================================================================
749 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
750 Quantity_Color& theColor1,
751 Quantity_Color& theColor2 ) const
753 MeshVS_TwoColors aTC;
754 Standard_Boolean aRes = GetColor2 ( ID, aTC );
756 ExtractColors ( aTC, theColor1, theColor2 );
760 //================================================================
761 // Function : SetColor2
763 //================================================================
764 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
765 const Quantity_Color& theCol1,
766 const Quantity_Color& theCol2 )
768 SetColor2 ( theID, BindTwoColors ( theCol1, theCol2 ) );
771 //================================================================
772 // Function : SetColor2
774 //================================================================
775 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
776 const MeshVS_TwoColors& theCol )
778 Standard_Boolean aRes = myElemColorMap2.IsBound ( theID );
780 myElemColorMap2.ChangeFind ( theID ) = theCol;
782 myElemColorMap2.Bind ( theID, theCol );