]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_IDMapper.cxx
Salome HOME
untabify
[modules/visu.git] / src / CONVERTOR / VISU_IDMapper.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File:
24 //  Author:
25 //  Module : VISU
26 //
27 #include "VISU_IDMapper.hxx"
28
29 #include <vtkUnstructuredGrid.h>
30 #include <vtkPolyData.h>
31 #include <vtkDataSet.h>
32
33 namespace VISU
34 {
35   //---------------------------------------------------------------
36   TStructuredId
37   ::TStructuredId()
38   {
39     myData[0] = myData[1] = myData[2] = -1;
40   }
41
42   vtkIdType&
43   TStructuredId
44   ::operator [] ( size_t theId )
45   {
46     return myData[ theId ];
47   }
48
49   const vtkIdType&
50   TStructuredId
51   ::operator [] ( size_t theId ) const
52   {
53     return myData[ theId ];
54   }
55
56   bool
57   TStructuredId
58   ::operator == ( const TStructuredId& theId ) const
59   {
60     return 
61       theId[0] == myData[0] &&
62       theId[1] == myData[1] &&
63       theId[2] == myData[2];
64   }
65
66   //---------------------------------------------------------------
67   void
68   TStructured
69   ::CopyStructure(PStructured theStructured)
70   {
71     myIsPolarType = theStructured->myIsPolarType;
72     myIsStructured = theStructured->myIsStructured;
73     myGrilleStructure = theStructured->myGrilleStructure;
74     myObj2StructuredId = theStructured->myObj2StructuredId;    
75   }
76
77   bool
78   TStructured
79   ::IsStructured() const
80   {
81     return myIsStructured;
82   }
83   
84   TStructuredId
85   TStructured
86   ::GetStructure()
87   {
88     return myGrilleStructure;
89   }
90
91   vtkIdType
92   TStructured
93   ::GetStructureDim()
94   {
95     return 
96       vtkIdType( myGrilleStructure[0] >= 0) +
97       vtkIdType( myGrilleStructure[1] >= 0) +
98       vtkIdType( myGrilleStructure[2] >= 0);
99   }
100
101   TStructuredId
102   TStructured
103   ::GetIndexesOfNode(vtkIdType theNodeId)
104   {
105     if ( IsStructured() ) {
106       TObj2StructuredId::const_iterator aIter = myObj2StructuredId.find( theNodeId );
107       if ( aIter != myObj2StructuredId.end() )
108         return aIter->second;
109     }
110
111     return TStructuredId();
112   }
113   
114   vtkIdType
115   TStructured
116   ::GetObjectIDByIndexes(TStructuredId theVec)
117   {
118     TObj2StructuredId::const_iterator aIter = myObj2StructuredId.begin();
119     for (; aIter != myObj2StructuredId.end(); aIter++ ) {
120       if ( theVec == aIter->second )
121         return aIter->first;
122     }
123
124     return -1;
125   }
126
127
128   //---------------------------------------------------------------
129   vtkFloatingPointType*  
130   TIDMapper
131   ::GetNodeCoord(vtkIdType theObjID)
132   {
133     vtkIdType aVTKID = GetNodeVTKID(theObjID);
134     return GetOutput()->GetPoint(aVTKID);
135   }
136
137   vtkIdType
138   TIDMapper
139   ::GetNodeVTKID(vtkIdType theID) const
140   {
141     return theID;
142   }
143
144   vtkIdType
145   TIDMapper
146   ::GetNodeObjID(vtkIdType theID) const
147   {
148     return theID;
149   }
150
151   vtkCell* 
152   TIDMapper
153   ::GetElemCell(vtkIdType theObjID)
154   {
155     vtkIdType aVtkID = GetElemVTKID(theObjID);
156     return GetOutput()->GetCell(aVtkID);
157   }
158
159   vtkIdType
160   TIDMapper
161   ::GetElemVTKID(vtkIdType theID) const
162   {
163     return theID;
164   }
165
166   vtkIdType
167   TIDMapper
168   ::GetElemObjID(vtkIdType theID) const
169   {
170     return theID;
171   }  
172   //---------------------------------------------------------------
173
174
175   vtkDataSet* 
176   TUnstructuredGridIDMapper
177   ::GetOutput()
178   {
179     return GetUnstructuredGridOutput();
180   }
181   //---------------------------------------------------------------
182
183
184   vtkDataSet* 
185   TPolyDataIDMapper
186   ::GetOutput()
187   {
188     return GetPolyDataOutput();
189   }
190
191
192   //---------------------------------------------------------------
193 }