Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / CONVERTOR / VISU_IDMapper.cxx
1 //  Copyright (C) 2007-2010  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
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File:
25 //  Author:
26 //  Module : VISU
27 //
28 #include "VISU_IDMapper.hxx"
29
30 #include <vtkUnstructuredGrid.h>
31 #include <vtkPolyData.h>
32 #include <vtkDataSet.h>
33
34 namespace VISU
35 {
36   //---------------------------------------------------------------
37   TStructuredId
38   ::TStructuredId()
39   {
40     myData[0] = myData[1] = myData[2] = -1;
41   }
42
43   vtkIdType&
44   TStructuredId
45   ::operator [] ( size_t theId )
46   {
47     return myData[ theId ];
48   }
49
50   const vtkIdType&
51   TStructuredId
52   ::operator [] ( size_t theId ) const
53   {
54     return myData[ theId ];
55   }
56
57   bool
58   TStructuredId
59   ::operator == ( const TStructuredId& theId ) const
60   {
61     return 
62       theId[0] == myData[0] &&
63       theId[1] == myData[1] &&
64       theId[2] == myData[2];
65   }
66
67   //---------------------------------------------------------------
68   void
69   TStructured
70   ::CopyStructure(PStructured theStructured)
71   {
72     myIsPolarType = theStructured->myIsPolarType;
73     myIsStructured = theStructured->myIsStructured;
74     myGrilleStructure = theStructured->myGrilleStructure;
75     myObj2StructuredId = theStructured->myObj2StructuredId;    
76   }
77
78   bool
79   TStructured
80   ::IsStructured() const
81   {
82     return myIsStructured;
83   }
84   
85   TStructuredId
86   TStructured
87   ::GetStructure()
88   {
89     return myGrilleStructure;
90   }
91
92   vtkIdType
93   TStructured
94   ::GetStructureDim()
95   {
96     return 
97       vtkIdType( myGrilleStructure[0] >= 0) +
98       vtkIdType( myGrilleStructure[1] >= 0) +
99       vtkIdType( myGrilleStructure[2] >= 0);
100   }
101
102   TStructuredId
103   TStructured
104   ::GetIndexesOfNode(vtkIdType theNodeId)
105   {
106     if ( IsStructured() ) {
107       TObj2StructuredId::const_iterator aIter = myObj2StructuredId.find( theNodeId );
108       if ( aIter != myObj2StructuredId.end() )
109         return aIter->second;
110     }
111
112     return TStructuredId();
113   }
114   
115   vtkIdType
116   TStructured
117   ::GetObjectIDByIndexes(TStructuredId theVec)
118   {
119     TObj2StructuredId::const_iterator aIter = myObj2StructuredId.begin();
120     for (; aIter != myObj2StructuredId.end(); aIter++ ) {
121       if ( theVec == aIter->second )
122         return aIter->first;
123     }
124
125     return -1;
126   }
127
128
129   //---------------------------------------------------------------
130   vtkFloatingPointType*  
131   TIDMapper
132   ::GetNodeCoord(vtkIdType theObjID)
133   {
134     vtkIdType aVTKID = GetNodeVTKID(theObjID);
135     return GetOutput()->GetPoint(aVTKID);
136   }
137
138   vtkIdType
139   TIDMapper
140   ::GetNodeVTKID(vtkIdType theID) const
141   {
142     return theID;
143   }
144
145   vtkIdType
146   TIDMapper
147   ::GetNodeObjID(vtkIdType theID) const
148   {
149     return theID;
150   }
151
152   vtkCell* 
153   TIDMapper
154   ::GetElemCell(vtkIdType theObjID)
155   {
156     vtkIdType aVtkID = GetElemVTKID(theObjID);
157     return GetOutput()->GetCell(aVtkID);
158   }
159
160   vtkIdType
161   TIDMapper
162   ::GetElemVTKID(vtkIdType theID) const
163   {
164     return theID;
165   }
166
167   vtkIdType
168   TIDMapper
169   ::GetElemObjID(vtkIdType theID) const
170   {
171     return theID;
172   }  
173   //---------------------------------------------------------------
174
175
176   vtkDataSet* 
177   TUnstructuredGridIDMapper
178   ::GetOutput()
179   {
180     return GetUnstructuredGridOutput();
181   }
182   //---------------------------------------------------------------
183
184
185   vtkDataSet* 
186   TPolyDataIDMapper
187   ::GetOutput()
188   {
189     return GetPolyDataOutput();
190   }
191
192
193   //---------------------------------------------------------------
194 }