0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IVtkTools / IVtkTools.cxx
1 // Created on: 2011-12-20 
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS 
4 // 
5 //This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <IVtkTools.hxx>
17 #include <IVtkVTK_ShapeData.hxx>
18
19 // prevent disabling some MSVC warning messages by VTK headers 
20 #ifdef _MSC_VER
21 #pragma warning(push)
22 #endif
23 #include <vtkLookupTable.h>
24 #include <vtkMapper.h>
25 #ifdef _MSC_VER
26 #pragma warning(pop)
27 #endif
28
29 namespace IVtkTools
30 {
31 //============================================================================
32 // Method: InitLookupTable
33 // Purpose: Returns vtkLookupTable instance initialized by standrad OCCT colors.
34 //============================================================================
35 vtkSmartPointer<vtkLookupTable> InitLookupTable()
36 {
37   vtkSmartPointer<vtkLookupTable> aColorTable = 
38     vtkSmartPointer<vtkLookupTable>::New();
39   // Set colors table for 3D shapes
40   double aRange[2];
41   aRange[0] = MT_Undefined;
42   aRange[1] = MT_ShadedFace;
43   aColorTable->Allocate (9);
44   aColorTable->SetNumberOfTableValues (9);
45   aColorTable->SetTableRange (aRange);
46   aColorTable->SetValueRange (0, 1);
47 /*
48   MT_Undefined     = -1   Undefined
49   MT_IsoLine       =  0   IsoLine
50   MT_FreeVertex    =  1   Free vertex
51   MT_SharedVertex  =  2   Shared vertex
52   MT_FreeEdge      =  3   Free edge
53   MT_BoundaryEdge  =  4   Boundary edge (related to a single face)
54   MT_SharedEdge    =  5   Shared edge (related to several faces)
55   MT_WireFrameFace =  6   Wireframe face
56   MT_ShadedFace    =  7   Shaded face
57 */
58   aColorTable->SetTableValue (0, 0, 0, 0); // Undefined
59   aColorTable->SetTableValue (1, 0.5, 0.5, 0.5); // gray for IsoLine
60   aColorTable->SetTableValue (2, 1, 0, 0); // red for Free vertex
61   aColorTable->SetTableValue (3, 1, 1, 0); // yellow for Shared vertex
62   aColorTable->SetTableValue (4, 1, 0, 0); // red for Free edge
63   aColorTable->SetTableValue (5, 0, 1, 0); // green for Boundary edge (related to a single face)
64   aColorTable->SetTableValue (6, 1, 1, 0); // yellow for Shared edge (related to several faces)
65   aColorTable->SetTableValue (7, 1, 1, 0); // yellow for Wireframe face
66   aColorTable->SetTableValue (8, 1, 1, 0); // yellow for Shaded face
67   return aColorTable;
68 }
69
70 //============================================================================
71 //  Method: SetLookupTableColor
72 // Purpose: Set a color for given type of sub-shapes.
73 //============================================================================
74 void SetLookupTableColor (vtkLookupTable* theColorTable,
75                           const IVtk_MeshType theColorRole,
76                           const double theR, const double theG, const double theB,
77                           const double /*theA*/)
78 {
79   theColorTable->SetTableValue (theColorRole + 1, theR, theG, theB);
80 }
81
82 //============================================================================
83 //  Method: GetLookupTableColor
84 // Purpose: Get a color for given type of sub-shapes.
85 //============================================================================
86 void GetLookupTableColor (vtkLookupTable* theColorTable,
87                           const IVtk_MeshType theColorRole,
88                           double &theR, double &theG, double &theB)
89 {
90   double aRgb[3];
91   theColorTable->GetColor (theColorRole + 1, aRgb);
92   theR = aRgb[0];
93   theG = aRgb[1];
94   theB = aRgb[2];
95 }
96
97 //============================================================================
98 //  Method: GetLookupTableColor
99 // Purpose: Get a color for given type of sub-shapes.
100 //============================================================================
101 void GetLookupTableColor (vtkLookupTable* theColorTable, 
102                           const IVtk_MeshType theColorRole, 
103                           double &theR, double &theG, double &theB, 
104                           double &theA)
105 {
106   theA = theColorTable->GetOpacity (theColorRole + 1);
107   GetLookupTableColor (theColorTable, theColorRole, theR, theG, theB);
108 }
109
110 //============================================================================
111 //  Method: InitShapeMapper
112 // Purpose: Set up the initial shape mapper parameters with default OCC colors.
113 //============================================================================
114 void InitShapeMapper (vtkMapper* theMapper)
115 {
116   InitShapeMapper (theMapper, InitLookupTable());
117 }
118
119 //============================================================================
120 //  Method: InitShapeMapper
121 // Purpose: Set up the initial shape mapper parameters with user colors.
122 //============================================================================
123 void InitShapeMapper (vtkMapper* theMapper, vtkLookupTable* theColorTable)
124 {
125   theMapper->ScalarVisibilityOn();
126   theMapper->SetScalarModeToUseCellFieldData();
127   theMapper->SelectColorArray (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES());
128   theMapper->SetColorModeToMapScalars();
129   theMapper->SetScalarRange (theColorTable->GetRange());
130   theMapper->SetLookupTable (theColorTable);
131   theMapper->Update();
132 }
133
134 } // namespace IVtkTools