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_Real anEdgeWidth = 1.0, aLineWidth = 1.0;
183 Quantity_Color anInteriorColor;
184 Quantity_Color anEdgeColor, aLineColor;
185 Standard_Boolean anEdgeOn = Standard_True, IsReflect = Standard_False,
186 IsMeshSmoothShading = Standard_False;
187 Standard_Boolean toSupressBackFaces = 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 );
197 aDrawer->GetBoolean (MeshVS_DA_SupressBackFaces, toSupressBackFaces);
199 Standard_Integer anEdgeInt = Aspect_TOL_SOLID;
200 if ( aDrawer->GetInteger ( MeshVS_DA_EdgeType, anEdgeInt) )
201 anEdgeType = (Aspect_TypeOfLine) anEdgeInt;
203 Standard_Integer aLineInt = Aspect_TOL_SOLID;
204 if ( aDrawer->GetInteger ( MeshVS_DA_BeamType, aLineInt) )
205 aLineType = (Aspect_TypeOfLine) aLineInt;
207 Handle( MeshVS_HArray1OfSequenceOfInteger ) aTopo;
208 Standard_Integer PolygonVerticesFor3D = 0, PolygonBoundsFor3D = 0;
209 TColStd_MapIteratorOfPackedMapOfInteger it (anIDs);
210 for( ; it.More(); it.Next() )
212 Standard_Integer aKey = it.Key();
213 if( aSource->Get3DGeom( aKey, NbNodes, aTopo ) )
214 MeshVS_MeshPrsBuilder::HowManyPrimitives
215 ( aTopo, Standard_True, Standard_False, NbNodes,
216 PolygonVerticesFor3D, PolygonBoundsFor3D );
219 Graphic3d_MaterialAspect aMaterial[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC };
220 for (Standard_Integer i = 0; i < 2; i++)
222 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
223 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
224 // color from AspectFillArea3d to calculate all material colors
225 aMaterial[i].SetSpecularColor (Quantity_NOC_BLACK);
226 aMaterial[i].SetEmissiveColor (Quantity_NOC_BLACK);
228 // OCC21720 For single-colored elements turning all material components off is a good idea,
229 // as anyhow the normals are not computed and the lighting will be off,
230 // the element color will be taken from Graphic3d_AspectFillArea3d's interior color,
231 // and there is no need to spend time on updating material properties
234 aMaterial[i].SetAmbientColor (Quantity_NOC_BLACK);
235 aMaterial[i].SetDiffuseColor (Quantity_NOC_BLACK);
239 // OCC20644 This stuff is important in order for elemental and nodal colors
240 // to produce similar visual impression and also to make colors match
241 // those in the color scale most exactly (the sum of all reflection
242 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
243 // class for more explanations.
244 aMaterial[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
245 aMaterial[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
249 // Draw elements with one color
250 Handle(Graphic3d_Group) aGGroup, aGroup2, aLGroup, aSGroup;
251 if (!aTwoColorsOfElements.IsEmpty())
253 aGroup2 = Prs3d_Root::NewGroup (Prs);
255 if (!aColorsOfElements.IsEmpty())
257 Handle(Graphic3d_AspectFillArea3d) aGroupFillAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, anInteriorColor, anEdgeColor,
258 anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1]);
259 aGGroup = Prs3d_Root::NewGroup (Prs);
260 aLGroup = Prs3d_Root::NewGroup (Prs);
261 aGGroup->SetClosed (toSupressBackFaces == Standard_True);
262 aGGroup->SetGroupPrimitivesAspect (aGroupFillAspect);
267 Handle(Graphic3d_AspectLine3d) anEdgeAspect = new Graphic3d_AspectLine3d (anEdgeColor, anEdgeType, anEdgeWidth);
268 aSGroup = Prs3d_Root::NewGroup (Prs);
269 aSGroup->SetGroupPrimitivesAspect (anEdgeAspect);
272 for (MeshVS_DataMapIteratorOfDataMapOfColorMapOfInteger aColIter (aColorsOfElements);
273 aColIter.More(); aColIter.Next())
275 if (aColIter.Value().IsEmpty())
280 TColStd_PackedMapOfInteger aCustomElements;
282 Standard_Integer aNbFacePrimitives = 0;
283 Standard_Integer aNbVolmPrimitives = 0;
284 Standard_Integer aNbEdgePrimitives = 0;
285 Standard_Integer aNbLinkPrimitives = 0;
287 for (it.Reset(); it.More(); it.Next())
289 Standard_Integer aNbNodes = 0;
291 if (!aColIter.Value().Contains (it.Key()))
294 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
297 if (aType == MeshVS_ET_Volume)
299 if (aSource->Get3DGeom (it.Key(), aNbNodes, aTopo))
301 for (Standard_Integer aFaceIdx = aTopo->Lower(); aFaceIdx <= aTopo->Upper(); ++aFaceIdx)
303 const TColStd_SequenceOfInteger& aFaceNodes = aTopo->Value (aFaceIdx);
305 if (anEdgeOn) // add edge segments
307 aNbEdgePrimitives += aFaceNodes.Length();
310 aNbVolmPrimitives += aFaceNodes.Length() - 2;
314 else if (aType == MeshVS_ET_Link)
318 aNbLinkPrimitives += aNbNodes - 1; // add link segments
321 else if (aType == MeshVS_ET_Face)
325 aNbEdgePrimitives += aNbNodes; // add edge segments
328 aNbFacePrimitives += aNbNodes - 2; // add face triangles
332 // Here we do not use indices arrays because they are not effective for some mesh
333 // drawing modes: shrinking mode (displaces the vertices inside the polygon), 3D
334 // cell rendering (normal interpolation is not always applicable - flat shading),
335 // elemental coloring (color interpolation is impossible)
337 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles (
338 (aNbFacePrimitives + aNbVolmPrimitives) * 3, 0, IsReflect );
339 Standard_Boolean IsPolyG = Standard_False;
341 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments (aNbEdgePrimitives * 2);
342 Handle (Graphic3d_ArrayOfSegments) aLinkSegments = new Graphic3d_ArrayOfSegments (aNbLinkPrimitives * 2);
343 Standard_Boolean IsPolyL = Standard_False;
345 // OCC20644 NOTE: aColIter.Key() color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
346 // using the material reflection coefficients. This affects the visual result.
347 Handle(Graphic3d_AspectFillArea3d) aFillAspect =
348 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aColIter.Key(), anEdgeColor,
349 anEdgeType, anEdgeWidth, aMaterial[0], aMaterial[1] );
351 Handle(Graphic3d_AspectLine3d) aLinkAspect =
352 new Graphic3d_AspectLine3d ( aColIter.Key(), aLineType, aLineWidth );
354 aFillAspect->SetDistinguishOff ();
355 aFillAspect->SetInteriorColor ( aColIter.Key() );
356 aFillAspect->SetEdgeOff();
358 for (it.Reset(); it.More(); it.Next())
360 Standard_Integer aKey = it.Key();
362 if (aColIter.Value().Contains (aKey))
364 if (!aSource->GetGeom (aKey, Standard_True, aCoords, NbNodes, aType))
367 if (aType != MeshVS_ET_Face && aType != MeshVS_ET_Link && aType != MeshVS_ET_Volume)
369 aCustomElements.Add (aKey);
374 IDsToExclude.Add (aKey);
376 if (aType == MeshVS_ET_Volume)
378 if (!aSource->Get3DGeom (aKey, NbNodes, aTopo))
383 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
384 NbNodes, aFaceTriangles, IsReflect, Standard_False, Standard_False, 1.0);
388 MeshVS_MeshPrsBuilder::AddVolumePrs (aTopo, aCoords,
389 NbNodes, anEdgeSegments, IsReflect, Standard_False, Standard_False, 1.0);
392 IsPolyG = Standard_True;
394 else if (aType == MeshVS_ET_Face)
397 Handle(TColStd_HArray1OfReal) aNormals;
398 Standard_Boolean aHasNormals = IsReflect && aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
400 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
402 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
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),
409 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1) : 0.0,
410 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2) : 0.0,
411 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3) : 1.0);
415 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 1),
416 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 2),
417 aCoords (3 * (anIdx == 0 ? 0 : (aNodeIdx + anIdx)) + 3));
424 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
426 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
428 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
429 aCoords (3 * aNodeIdx + 2),
430 aCoords (3 * aNodeIdx + 3));
432 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
433 aCoords (3 * aNextIdx + 2),
434 aCoords (3 * aNextIdx + 3));
438 IsPolyG = Standard_True;
440 else if (aType == MeshVS_ET_Link)
442 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 1; ++aNodeIdx)
444 const Standard_Integer aNextIdx = aNodeIdx + 1;
446 aLinkSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
447 aCoords (3 * aNodeIdx + 2),
448 aCoords (3 * aNodeIdx + 3));
450 aLinkSegments->AddVertex (aCoords (3 * aNextIdx + 1),
451 aCoords (3 * aNextIdx + 2),
452 aCoords (3 * aNextIdx + 3));
454 IsPolyL = Standard_True;
462 aGGroup->SetPrimitivesAspect (aFillAspect);
463 aGGroup->AddPrimitiveArray (aFaceTriangles);
464 aGGroup->SetClosed (toSupressBackFaces == Standard_True);
468 aSGroup->AddPrimitiveArray (anEdgeSegments);
473 aLGroup->SetPrimitivesAspect (aFillAspect);
474 aLGroup->SetPrimitivesAspect (aLinkAspect);
475 aLGroup->AddPrimitiveArray (aLinkSegments);
478 if (!aCustomElements.IsEmpty())
479 CustomBuild(Prs, aCustomElements, IDsToExclude, DisplayMode);
482 Graphic3d_MaterialAspect aMaterial2[2] = { Graphic3d_NOM_PLASTIC, Graphic3d_NOM_PLASTIC };
483 for (Standard_Integer i = 0; i < 2; i++)
485 // OCC20644 "plastic" is most suitable here, as it is "non-physic"
486 // so TelUpdateMaterial() from OpenGl_attri.c uses the interior
487 // color from AspectFillArea3d to calculate all material colors
488 aMaterial2[i].SetSpecularColor (Quantity_NOC_BLACK);
489 aMaterial2[i].SetEmissiveColor (Quantity_NOC_BLACK);
493 // OCC21720 Cannot turn ALL material components off, as such a material
494 // would be ignored by TelUpdateMaterial(), but we need it in order
495 // to have different materials for front and back sides!
496 // Instead, trying to make material color "nondirectional" with
497 // only ambient component on.
498 aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (1.0f)));
499 aMaterial2[i].SetDiffuseColor (Quantity_NOC_BLACK);
503 // OCC20644 This stuff is important in order for elemental and nodal colors
504 // to produce similar visual impression and also to make colors match
505 // those in the color scale most exactly (the sum of all reflection
506 // coefficients is equal to 1). See also MeshVS_NodalColorPrsBuilder
507 // class for more explanations.
508 aMaterial2[i].SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
509 aMaterial2[i].SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
513 // Draw faces with two color
514 if (!aTwoColorsOfElements.IsEmpty())
516 Handle(Graphic3d_AspectFillArea3d) aGroupFillAspect2 = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, anInteriorColor, anEdgeColor,
517 anEdgeType, anEdgeWidth, aMaterial2[0], aMaterial2[1]);
518 aGroup2->SetClosed (Standard_False); // ignore toSupressBackFaces
519 aGroup2->SetGroupPrimitivesAspect (aGroupFillAspect2);
521 for ( MeshVS_DataMapIteratorOfDataMapOfTwoColorsMapOfInteger aColIter2 ( aTwoColorsOfElements );
522 aColIter2.More(); aColIter2.Next() )
524 if (aColIter2.Value().IsEmpty())
529 Standard_Integer aNbFacePrimitives = 0;
530 Standard_Integer aNbEdgePrimitives = 0;
532 for (it.Reset(); it.More(); it.Next())
534 Standard_Integer aNbNodes = 0;
536 if (!aColIter2.Value().Contains (it.Key()))
539 if (!aSource->GetGeom (it.Key(), Standard_True, aCoords, aNbNodes, aType))
542 if ( aType == MeshVS_ET_Face && aNbNodes > 0 )
546 aNbEdgePrimitives += aNbNodes; // add edge segments
549 aNbFacePrimitives += aNbNodes - 2; // add face triangles
553 Handle (Graphic3d_ArrayOfTriangles) aFaceTriangles = new Graphic3d_ArrayOfTriangles
554 (aNbFacePrimitives * 3, 0, IsReflect);
556 Handle (Graphic3d_ArrayOfSegments) anEdgeSegments = new Graphic3d_ArrayOfSegments
557 (aNbEdgePrimitives * 2);
559 MeshVS_TwoColors aTC = aColIter2.Key();
560 Quantity_Color aMyIntColor, aMyBackColor;
561 ExtractColors ( aTC, aMyIntColor, aMyBackColor );
563 // OCC20644 NOTE: aMyIntColor color is then scaled by TelUpdateMaterial() in OpenGl_attri.c
564 // using the material reflection coefficients. This affects the visual result.
565 Handle(Graphic3d_AspectFillArea3d) anAsp =
566 new Graphic3d_AspectFillArea3d ( Aspect_IS_SOLID, aMyIntColor, anEdgeColor,
567 anEdgeType, anEdgeWidth, aMaterial2[0], aMaterial2[1] );
568 anAsp->SetDistinguishOn ();
569 anAsp->SetInteriorColor ( aMyIntColor );
570 anAsp->SetBackInteriorColor ( aMyBackColor );
574 anAsp->SetEdgeOff();*/
575 aGroup2->SetPrimitivesAspect (anAsp);
577 for( it.Reset(); it.More(); it.Next() )
579 Standard_Integer aKey = it.Key();
580 if( aColIter2.Value().Contains( aKey ) )
582 if ( !aSource->GetGeom ( aKey, Standard_True, aCoords, NbNodes, aType ) )
585 if( IsExcludingOn() )
586 IDsToExclude.Add( aKey );
588 if (aType == MeshVS_ET_Face && NbNodes > 0)
590 // Preparing normal(s) to show reflections if requested
591 Handle(TColStd_HArray1OfReal) aNormals;
592 // OCC21720 Always passing normals to OpenGL to make materials work
593 // For OpenGL: "No normals" -> "No lighting" -> "no materials taken into account"
594 Standard_Boolean aHasNormals = /*IsReflect &&*/
595 aSource->GetNormalsByElement (aKey, IsMeshSmoothShading, aMaxFaceNodes, aNormals);
597 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes - 2; ++aNodeIdx)
599 for (Standard_Integer anIdx = 0; anIdx < 3; ++anIdx)
603 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
604 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
605 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3),
606 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1) : 0.0,
607 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2) : 0.0,
608 aHasNormals ? aNormals->Value (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3) : 1.0);
612 aFaceTriangles->AddVertex (aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 1),
613 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 2),
614 aCoords (3 * (anIdx == 0 ? 0 : aNodeIdx + anIdx) + 3));
621 for (Standard_Integer aNodeIdx = 0; aNodeIdx < NbNodes; ++aNodeIdx)
623 const Standard_Integer aNextIdx = (aNodeIdx + 1) % NbNodes;
625 anEdgeSegments->AddVertex (aCoords (3 * aNodeIdx + 1),
626 aCoords (3 * aNodeIdx + 2),
627 aCoords (3 * aNodeIdx + 3));
629 anEdgeSegments->AddVertex (aCoords (3 * aNextIdx + 1),
630 aCoords (3 * aNextIdx + 2),
631 aCoords (3 * aNextIdx + 3));
638 aGroup2->AddPrimitiveArray (aFaceTriangles);
639 aSGroup->AddPrimitiveArray (anEdgeSegments);
643 //================================================================
644 // Function : SetColors
646 //================================================================
647 void MeshVS_ElementalColorPrsBuilder::SetColors1 ( const MeshVS_DataMapOfIntegerColor& theColorMap )
649 myElemColorMap1 = theColorMap;
652 //================================================================
653 // Function : GetColors
655 //================================================================
656 const MeshVS_DataMapOfIntegerColor& MeshVS_ElementalColorPrsBuilder::GetColors1 () const
658 return myElemColorMap1;
661 //================================================================
662 // Function : HasColors1
664 //================================================================
665 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors1 () const
667 return ( myElemColorMap1.Extent() >0 );
670 //================================================================
671 // Function : GetColor1
673 //================================================================
674 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor1 ( const Standard_Integer ID,
675 Quantity_Color& theColor ) const
677 Standard_Boolean aRes = myElemColorMap1.IsBound ( ID );
679 theColor = myElemColorMap1.Find ( ID );
684 //================================================================
685 // Function : SetColor1
687 //================================================================
688 void MeshVS_ElementalColorPrsBuilder::SetColor1 ( const Standard_Integer theID,
689 const Quantity_Color& theCol )
691 Standard_Boolean aRes = myElemColorMap1.IsBound ( theID );
693 myElemColorMap1.ChangeFind ( theID ) = theCol;
695 myElemColorMap1.Bind ( theID, theCol );
698 //================================================================
699 // Function : SetColors2
701 //================================================================
702 void MeshVS_ElementalColorPrsBuilder::SetColors2 ( const MeshVS_DataMapOfIntegerTwoColors& theColorMap )
704 myElemColorMap2 = theColorMap;
707 //================================================================
708 // Function : GetColors2
710 //================================================================
711 const MeshVS_DataMapOfIntegerTwoColors& MeshVS_ElementalColorPrsBuilder::GetColors2 () const
713 return myElemColorMap2;
716 //================================================================
717 // Function : HasColors2
719 //================================================================
720 Standard_Boolean MeshVS_ElementalColorPrsBuilder::HasColors2 () const
722 return (myElemColorMap2.Extent()>0);
725 //================================================================
726 // Function : GetColor2
728 //================================================================
729 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
730 MeshVS_TwoColors& theColor ) const
732 Standard_Boolean aRes = myElemColorMap2.IsBound ( ID );
734 theColor = myElemColorMap2.Find ( ID );
739 //================================================================
740 // Function : GetColor2
742 //================================================================
743 Standard_Boolean MeshVS_ElementalColorPrsBuilder::GetColor2 ( const Standard_Integer ID,
744 Quantity_Color& theColor1,
745 Quantity_Color& theColor2 ) const
747 MeshVS_TwoColors aTC;
748 Standard_Boolean aRes = GetColor2 ( ID, aTC );
750 ExtractColors ( aTC, theColor1, theColor2 );
754 //================================================================
755 // Function : SetColor2
757 //================================================================
758 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
759 const Quantity_Color& theCol1,
760 const Quantity_Color& theCol2 )
762 SetColor2 ( theID, BindTwoColors ( theCol1, theCol2 ) );
765 //================================================================
766 // Function : SetColor2
768 //================================================================
769 void MeshVS_ElementalColorPrsBuilder::SetColor2 ( const Standard_Integer theID,
770 const MeshVS_TwoColors& theCol )
772 Standard_Boolean aRes = myElemColorMap2.IsBound ( theID );
774 myElemColorMap2.ChangeFind ( theID ) = theCol;
776 myElemColorMap2.Bind ( theID, theCol );