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;
188 Standard_Boolean toSupressBackFaces = Standard_False;
190 aDrawer->GetColor ( MeshVS_DA_InteriorColor, anInteriorColor );
191 aDrawer->GetColor ( MeshVS_DA_EdgeColor, anEdgeColor );
192 aDrawer->GetColor ( MeshVS_DA_BeamColor, aLineColor );
193 aDrawer->GetDouble ( MeshVS_DA_EdgeWidth, anEdgeWidth );
194 aDrawer->GetDouble ( MeshVS_DA_BeamWidth, aLineWidth );
195 aDrawer->GetBoolean( MeshVS_DA_ShowEdges, anEdgeOn );
196 aDrawer->GetBoolean( MeshVS_DA_ColorReflection, IsReflect );
197 aDrawer->GetBoolean( MeshVS_DA_SmoothShading, IsMeshSmoothShading );
198 aDrawer->GetBoolean (MeshVS_DA_SupressBackFaces, toSupressBackFaces);
200 if ( aDrawer->GetInteger ( MeshVS_DA_EdgeType, anEdgeInt) )
201 anEdgeType = (Aspect_TypeOfLine) anEdgeInt;
203 if ( aDrawer->GetInteger ( MeshVS_DA_BeamType, aLineInt) )
204 aLineType = (Aspect_TypeOfLine) aLineInt;
206 Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo;
207 Standard_Integer PolygonVerticesFor3D = 0, PolygonBoundsFor3D = 0;
208 TColStd_MapIteratorOfPackedMapOfInteger it (anIDs);
209 for( ; it.More(); it.Next() )
211 Standard_Integer aKey = it.Key();
212 if( aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
213 MeshVS_MeshPrsBuilder::HowManyPrimitives
214 ( aTopo, Standard_True, Standard_False, NbNodes,
215 PolygonVerticesFor3D, PolygonBoundsFor3D );
218 Graphic3d_MaterialAspect aMaterial[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC };
219 for (Standard_Integer i = 0; i < 2; i++)
221 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
222 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
223 // color from AspectFillArea3d to calculate all material colors
224 aMaterial[i].SetSpecularColor (Quantity_NOC_BLACK);
225 aMaterial[i].SetEmissiveColor (Quantity_NOC_BLACK);
227 // OCC21720 For single-colored elements turning all material components off is a good idea,
228 // as anyhow the normals are not computed and the lighting will be off,
229 // the element color will be taken from Graphic3d_AspectFillArea3d's interior color,
230 // and there is no need to spend time on updating material properties
233 aMaterial[i].SetAmbientColor (Quantity_NOC_BLACK);
234 aMaterial[i].SetDiffuseColor (Quantity_NOC_BLACK);
238 // OCC20644 This stuff is important in order for elemental and nodal colors
239 // to produce similar visual impression and also to make colors match
240 // those in the color scale most exactly (the sum of all reflection
241 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
242 // class for more explanations.
243 aMaterial[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
244 aMaterial[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
248 // Draw elements with one color
249 Handle(Graphic3d_Group) aGGroup, aGroup2, aLGroup, aSGroup;
250 if (!aTwoColorsOfElements.IsEmpty())
252 aGroup2 = Prs3d_Root::NewGroup (Prs);
254 if (!aColorsOfElements.IsEmpty())
256 Handle(Graphic3d_AspectFillArea3d) aGroupFillAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, anInteriorColor, anEdgeColor,
257 anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1]);
258 aGGroup = Prs3d_Root::NewGroup (Prs);
259 aLGroup = Prs3d_Root::NewGroup (Prs);
260 aGGroup->SetClosed (toSupressBackFaces == Standard_True);
261 aGGroup->SetGroupPrimitivesAspect (aGroupFillAspect);
266 Handle(Graphic3d_AspectLine3d) anEdgeAspect = new Graphic3d_AspectLine3d (anEdgeColor, anEdgeType, anEdgeWidth);
267 aSGroup = Prs3d_Root::NewGroup (Prs);
268 aSGroup->SetGroupPrimitivesAspect (anEdgeAspect);
271 for (MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger aColIter (aColorsOfElements);
272 aColIter.More(); aColIter.Next())
274 if (aColIter.Value().IsEmpty())
279 TColStd_PackedMapOfInteger aCustomElements;
281 Standard_Integer aNbFacePrimitives = 0;
282 Standard_Integer aNbVolmPrimitives = 0;
283 Standard_Integer aNbEdgePrimitives = 0;
284 Standard_Integer aNbLinkPrimitives = 0;
286 for (it.Reset(); it.More(); it.Next())
288 Standard_Integer aNbNodes = 0;
290 if (!aColIter.Value().Contains (it.Key()))
293 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
296 if (aType == MeshVS_ET_Volume)
298 if (aSource->Get3DGeom (it.Key(), aNbNodes, aTopo))
300 for (Standard_Integer aFaceIdx = aTopo->Lower(); aFaceIdx <= aTopo->Upper(); ++aFaceIdx)
302 const TColStd_SequenceOfInteger& aFaceNodes = aTopo->Value (aFaceIdx);
304 if (anEdgeOn) // add edge segments
306 aNbEdgePrimitives += aFaceNodes.Length();
309 aNbVolmPrimitives += aFaceNodes.Length() - 2;
313 else if (aType == MeshVS_ET_Link)
317 aNbLinkPrimitives += aNbNodes - 1; // add link segments
320 else if (aType == MeshVS_ET_Face)
324 aNbEdgePrimitives += aNbNodes; // add edge segments
327 aNbFacePrimitives += aNbNodes - 2; // add face triangles
331 // Here we do not use indices arrays because they are not effective for some mesh
332 // drawing modes: shrinking mode (displaces the vertices inside the polygon), 3D
333 // cell rendering (normal interpolation is not always applicable - flat shading),
334 // elemental coloring (color interpolation is impossible)
336 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles (
337 (aNbFacePrimitives + aNbVolmPrimitives) * 3, 0, IsReflect );
338 Standard_Boolean IsPolyG = Standard_False;
340 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments (aNbEdgePrimitives * 2);
341 Handle (Graphic3d_ArrayOfSegments) aLinkSegments = new Graphic3d_ArrayOfSegments (aNbLinkPrimitives * 2);
342 Standard_Boolean IsPolyL = Standard_False;
344 // OCC20644 NOTE: aColIter.Key() color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
345 // using the material reflection coefficients. This affects the visual result.
346 Handle(Graphic3d_AspectFillArea3d) aFillAspect =
347 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aColIter.Key(), anEdgeColor,
348 anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1] );
350 Handle(Graphic3d_AspectLine3d) aLinkAspect =
351 new Graphic3d_AspectLine3d ( aColIter.Key(), aLineType, aLineWidth );
353 aFillAspect->SetDistinguishOff ();
354 aFillAspect->SetInteriorColor ( aColIter.Key() );
355 aFillAspect->SetEdgeOff();
357 for (it.Reset(); it.More(); it.Next())
359 Standard_Integer aKey = it.Key();
361 if (aColIter.Value().Contains (aKey))
363 if (!aSource->GetGeom (aKey, Standard_True, aCoords, NbNodes, aType))
366 if (aType != MeshVS_ET_Face && aType != MeshVS_ET_Link && aType != MeshVS_ET_Volume)
368 aCustomElements.Add (aKey);
373 IDsToExclude.Add (aKey);
375 if (aType == MeshVS_ET_Volume)
377 if (!aSource->Get3DGeom (aKey, NbNodes, aTopo))
382 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
383 NbNodes, aFaceTriangles, IsReflect, Standard_False, Standard_False, 1.0);
387 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
388 NbNodes, anEdgeSegments, IsReflect, Standard_False, Standard_False, 1.0);
391 IsPolyG = Standard_True;
393 else if (aType == MeshVS_ET_Face)
396 Handle(TColStd_HArray1OfReal) aNormals;
397 Standard_Boolean aHasNormals = IsReflect && aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
399 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
401 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
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),
408 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1) : 0.0,
409 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2) : 0.0,
410 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3) : 1.0);
414 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
415 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
416 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3));
423 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
425 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
427 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
428 aCoords (3 * aNodeIdx + 2),
429 aCoords (3 * aNodeIdx + 3));
431 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
432 aCoords (3 * aNextIdx + 2),
433 aCoords (3 * aNextIdx + 3));
437 IsPolyG = Standard_True;
439 else if (aType == MeshVS_ET_Link)
441 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 1; ++aNodeIdx)
443 const Standard_Integer aNextIdx = aNodeIdx + 1;
445 aLinkSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
446 aCoords (3 * aNodeIdx + 2),
447 aCoords (3 * aNodeIdx + 3));
449 aLinkSegments->AddVertex (aCoords (3 * aNextIdx + 1),
450 aCoords (3 * aNextIdx + 2),
451 aCoords (3 * aNextIdx + 3));
453 IsPolyL = Standard_True;
461 aGGroup->SetPrimitivesAspect (aFillAspect);
462 aGGroup->AddPrimitiveArray (aFaceTriangles);
463 aGGroup->SetClosed (toSupressBackFaces == Standard_True);
467 aSGroup->AddPrimitiveArray (anEdgeSegments);
472 aLGroup->SetPrimitivesAspect (aFillAspect);
473 aLGroup->SetPrimitivesAspect (aLinkAspect);
474 aLGroup->AddPrimitiveArray (aLinkSegments);
477 if (!aCustomElements.IsEmpty())
478 CustomBuild(Prs, aCustomElements, IDsToExclude, DisplayMode);
481 Graphic3d_MaterialAspect aMaterial2[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC };
482 for (Standard_Integer i = 0; i < 2; i++)
484 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
485 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
486 // color from AspectFillArea3d to calculate all material colors
487 aMaterial2[i].SetSpecularColor (Quantity_NOC_BLACK);
488 aMaterial2[i].SetEmissiveColor (Quantity_NOC_BLACK);
492 // OCC21720 Cannot turn ALL material components off, as such a material
493 // would be ignored by TelUpdateMaterial(), but we need it in order
494 // to have different materials for front and back sides!
495 // Instead, trying to make material color "nondirectional" with
496 // only ambient component on.
497 aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (1.0f)));
498 aMaterial2[i].SetDiffuseColor (Quantity_NOC_BLACK);
502 // OCC20644 This stuff is important in order for elemental and nodal colors
503 // to produce similar visual impression and also to make colors match
504 // those in the color scale most exactly (the sum of all reflection
505 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
506 // class for more explanations.
507 aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
508 aMaterial2[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
512 // Draw faces with two color
513 if (!aTwoColorsOfElements.IsEmpty())
515 Handle(Graphic3d_AspectFillArea3d) aGroupFillAspect2 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, anInteriorColor, anEdgeColor,
516 anEdgeType, anEdgeWidth, aMaterial2[0], aMaterial2[1]);
517 aGroup2->SetClosed (Standard_False); // ignore toSupressBackFaces
518 aGroup2->SetGroupPrimitivesAspect (aGroupFillAspect2);
520 for ( MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger aColIter2 ( aTwoColorsOfElements );
521 aColIter2.More(); aColIter2.Next() )
523 if (aColIter2.Value().IsEmpty())
528 Standard_Integer aNbFacePrimitives = 0;
529 Standard_Integer aNbEdgePrimitives = 0;
531 for (it.Reset(); it.More(); it.Next())
533 Standard_Integer aNbNodes = 0;
535 if (!aColIter2.Value().Contains (it.Key()))
538 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
541 if ( aType == MeshVS_ET_Face && aNbNodes > 0 )
545 aNbEdgePrimitives += aNbNodes; // add edge segments
548 aNbFacePrimitives += aNbNodes - 2; // add face triangles
552 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles
553 (aNbFacePrimitives * 3, 0, IsReflect);
555 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments
556 (aNbEdgePrimitives * 2);
558 MeshVS_TwoColors aTC = aColIter2.Key();
559 Quantity_Color aMyIntColor, aMyBackColor;
560 ExtractColors ( aTC, aMyIntColor, aMyBackColor );
562 // OCC20644 NOTE: aMyIntColor color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
563 // using the material reflection coefficients. This affects the visual result.
564 Handle(Graphic3d_AspectFillArea3d) anAsp =
565 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aMyIntColor, anEdgeColor,
566 anEdgeType, anEdgeWidth, aMaterial2[0], aMaterial2[1] );
567 anAsp->SetDistinguishOn ();
568 anAsp->SetInteriorColor ( aMyIntColor );
569 anAsp->SetBackInteriorColor ( aMyBackColor );
573 anAsp->SetEdgeOff();*/
574 aGroup2->SetPrimitivesAspect (anAsp);
576 for( it.Reset(); it.More(); it.Next() )
578 Standard_Integer aKey = it.Key();
579 if( aColIter2.Value().Contains( aKey ) )
581 if ( !aSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ) )
584 if( IsExcludingOn() )
585 IDsToExclude.Add( aKey );
587 if (aType == MeshVS_ET_Face && NbNodes > 0)
589 // Preparing normal(s) to show reflections if requested
590 Handle(TColStd_HArray1OfReal) aNormals;
591 // OCC21720 Always passing normals to OpenGL to make materials work
592 // For OpenGL: "No normals" -> "No lighting" -> "no materials taken into account"
593 Standard_Boolean aHasNormals = /*IsReflect &&*/
594 aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
596 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
598 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
602 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
603 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
604 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3),
605 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1) : 0.0,
606 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2) : 0.0,
607 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3) : 1.0);
611 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
612 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
613 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3));
620 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
622 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
624 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
625 aCoords (3 * aNodeIdx + 2),
626 aCoords (3 * aNodeIdx + 3));
628 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
629 aCoords (3 * aNextIdx + 2),
630 aCoords (3 * aNextIdx + 3));
637 aGroup2->AddPrimitiveArray (aFaceTriangles);
638 aSGroup->AddPrimitiveArray (anEdgeSegments);
642 //================================================================
643 // Function : SetColors
645 //================================================================
646 void MeshVS_ElementalColorPrsBuilder::SetColors1 ( const MeshVS_DataMapOfIntegerColor& theColorMap )
648 myElemColorMap1 = theColorMap;
651 //================================================================
652 // Function : GetColors
654 //================================================================
655 const MeshVS_DataMapOfIntegerColor& MeshVS_ElementalColorPrsBuilder::GetColors1 () const
657 return myElemColorMap1;
660 //================================================================
661 // Function : HasColors1
663 //================================================================
664 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors1 () const
666 return ( myElemColorMap1.Extent() >0 );
669 //================================================================
670 // Function : GetColor1
672 //================================================================
673 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor1 ( const Standard_Integer ID,
674 Quantity_Color& theColor ) const
676 Standard_Boolean aRes = myElemColorMap1.IsBound ( ID );
678 theColor = myElemColorMap1.Find ( ID );
683 //================================================================
684 // Function : SetColor1
686 //================================================================
687 void MeshVS_ElementalColorPrsBuilder::SetColor1 ( const Standard_Integer theID,
688 const Quantity_Color& theCol )
690 Standard_Boolean aRes = myElemColorMap1.IsBound ( theID );
692 myElemColorMap1.ChangeFind ( theID ) = theCol;
694 myElemColorMap1.Bind ( theID, theCol );
697 //================================================================
698 // Function : SetColors2
700 //================================================================
701 void MeshVS_ElementalColorPrsBuilder::SetColors2 ( const MeshVS_DataMapOfIntegerTwoColors& theColorMap )
703 myElemColorMap2 = theColorMap;
706 //================================================================
707 // Function : GetColors2
709 //================================================================
710 const MeshVS_DataMapOfIntegerTwoColors& MeshVS_ElementalColorPrsBuilder::GetColors2 () const
712 return myElemColorMap2;
715 //================================================================
716 // Function : HasColors2
718 //================================================================
719 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors2 () const
721 return (myElemColorMap2.Extent()>0);
724 //================================================================
725 // Function : GetColor2
727 //================================================================
728 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
729 MeshVS_TwoColors& theColor ) const
731 Standard_Boolean aRes = myElemColorMap2.IsBound ( ID );
733 theColor = myElemColorMap2.Find ( ID );
738 //================================================================
739 // Function : GetColor2
741 //================================================================
742 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
743 Quantity_Color& theColor1,
744 Quantity_Color& theColor2 ) const
746 MeshVS_TwoColors aTC;
747 Standard_Boolean aRes = GetColor2 ( ID, aTC );
749 ExtractColors ( aTC, theColor1, theColor2 );
753 //================================================================
754 // Function : SetColor2
756 //================================================================
757 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
758 const Quantity_Color& theCol1,
759 const Quantity_Color& theCol2 )
761 SetColor2 ( theID, BindTwoColors ( theCol1, theCol2 ) );
764 //================================================================
765 // Function : SetColor2
767 //================================================================
768 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
769 const MeshVS_TwoColors& theCol )
771 Standard_Boolean aRes = myElemColorMap2.IsBound ( theID );
773 myElemColorMap2.ChangeFind ( theID ) = theCol;
775 myElemColorMap2.Bind ( theID, theCol );