1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #include "VISU_PointCoords.hxx"
28 #include "VISU_ConvertorUtils.hxx"
30 #include <vtkUnstructuredGrid.h>
31 #include <vtkPointData.h>
32 #include <vtkIntArray.h>
35 static int MYDEBUG = 0;
37 static int MYDEBUG = 0;
42 //---------------------------------------------------------------
45 ::Init(vtkIdType theNbPoints,
49 myNbPoints = theNbPoints;
70 return GetNbPoints() * GetDim();
77 return sizeof(TCoord) * size();
81 //---------------------------------------------------------------
84 myPointSet(vtkUnstructuredGrid::New())
86 vtkPoints* aPoints = vtkPoints::New();
87 myPointSet->SetPoints(aPoints);
88 aPoints->SetDataType(VTK_DOUBLE);
96 ::Init(const PCoordHolder& theCoord)
98 myPointSet->GetPoints()->SetNumberOfPoints(theCoord->GetNbPoints());
104 ::GetNbPoints() const
106 return myCoord->GetNbPoints();
113 return myCoord->GetDim();
118 ::GetCoordSlice(vtkIdType theNodeId) const
120 return myCoord->GetCoordSlice(theNodeId);
125 ::GetCoordSlice(vtkIdType theNodeId)
127 return myCoord->GetCoordSlice(theNodeId);
132 ::GetObjID(vtkIdType theID) const
139 ::GetVTKID(vtkIdType theID) const
146 ::SetVoidArray() const
148 vtkDataArray* aDataArray = myPointSet->GetPoints()->GetData();
149 aDataArray->SetVoidArray(myCoord->GetValuePtr(), myCoord->size(), true);
154 ::GetPointSet() const
157 TTimerLog aTimerLog(MYDEBUG,"TPointCoords::GetPoints()");
158 vtkIdType aNbPoints = GetNbPoints();
159 vtkIdType aDim = GetDim();
161 INITMSG(MYDEBUG,"TPointCoords::GetPoints - aNbPoints = "<<aNbPoints<<
166 INITMSG(MYDEBUG,"TPointCoords::GetPoints - SetVoidArray()"<<endl);
169 vtkPoints* aPoints = myPointSet->GetPoints();
170 for(vtkIdType aPointId = 0; aPointId < aNbPoints; aPointId++){
171 TCCoordSlice aSlice = GetCoordSlice(aPointId);
173 vtkFloatingPointType aCoords[3] = {0.0, 0.0, 0.0};
174 for(vtkIdType aDimId = 0; aDimId < aDim; aDimId++)
175 aCoords[aDimId] = aSlice[aDimId];
177 aPoints->SetPoint(aPointId, aCoords);
184 return myPointSet.GetPointer();
191 size_t aSize = myCoord->GetMemorySize();
192 aSize += myPointSet->GetActualMemorySize() * 1024;
197 //---------------------------------------------------------------
200 ::Init(const PCoordHolder& theCoord)
202 TPointCoords::Init(theCoord);
203 myPointsDim.resize(theCoord->GetDim());
208 ::GetName(vtkIdType theDim)
210 return myPointsDim[theDim];
215 ::GetName(vtkIdType theDim) const
217 return myPointsDim[theDim];
222 ::GetNodeName(vtkIdType theObjID) const
228 //---------------------------------------------------------------
229 enum ECoordName{eX, eY, eZ, eNoneCoord};
230 typedef VISU::TCoord (*TGetCoord)(const VISU::TCCoordSlice& theCoordSlice);
232 template<ECoordName TCoordId>
234 GetCoord(const VISU::TCCoordSlice& theCoordSlice)
236 return theCoordSlice[TCoordId];
241 GetCoord<eNoneCoord>(const VISU::TCCoordSlice& theCoordSlice)
247 TGetCoord aXYZGetCoord[3] = {
254 TGetCoord aXYGetCoord[3] = {
257 &GetCoord<eNoneCoord>
260 TGetCoord aYZGetCoord[3] = {
261 &GetCoord<eNoneCoord>,
266 TGetCoord aXZGetCoord[3] = {
268 &GetCoord<eNoneCoord>,
273 TGetCoord aXGetCoord[3] = {
275 &GetCoord<eNoneCoord>,
276 &GetCoord<eNoneCoord>
279 TGetCoord aYGetCoord[3] = {
280 &GetCoord<eNoneCoord>,
282 &GetCoord<eNoneCoord>
285 TGetCoord aZGetCoord[3] = {
286 &GetCoord<eNoneCoord>,
287 &GetCoord<eNoneCoord>,
293 TGetCoord* myGetCoord;
295 TCoordHelper(TGetCoord* theGetCoord):
296 myGetCoord(theGetCoord)
304 GetCoord(VISU::TCCoordSlice& theCoordSlice,
307 return (*myGetCoord[theCoordId])(theCoordSlice);
310 typedef std::auto_ptr<TCoordHelper> TCoordHelperPtr;
313 //---------------------------------------------------------------
316 ::GetPointSet() const
319 TTimerLog aTimerLog(MYDEBUG,"TNamedPointCoords::GetPoints()");
320 TCoordHelperPtr aCoordHelperPtr;
321 bool anIsDimPresent[3] = {false, false, false};
322 for(int iDim = 0; iDim < GetDim(); iDim++){
323 // PAL16857(SMESH not conform to the MED convention) ->
324 // 1D - always along X
325 // 2D - always in XOY plane
326 anIsDimPresent[iDim] = iDim < GetDim();
327 // std::string aName = GetName(iDim);
328 // if ( aName.size() > 1 ) // PAL13021 (PAL12148), aName has size 8 or 16
329 // aName = aName.substr(0,1);
330 // if(aName == "x" || aName == "X")
331 // anIsDimPresent[eX] = true;
332 // else if(aName == "y" || aName == "Y")
333 // anIsDimPresent[eY] = true;
334 // else if(aName == "z" || aName == "Z")
335 // anIsDimPresent[eZ] = true;
340 aCoordHelperPtr.reset(new TCoordHelper(aXYZGetCoord));
343 if(anIsDimPresent[eY] && anIsDimPresent[eZ])
344 aCoordHelperPtr.reset(new TCoordHelper(aYZGetCoord));
345 else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
346 aCoordHelperPtr.reset(new TCoordHelper(aXZGetCoord));
348 aCoordHelperPtr.reset(new TCoordHelper(aXYGetCoord));
351 if(anIsDimPresent[eY])
352 aCoordHelperPtr.reset(new TCoordHelper(aYGetCoord));
353 else if(anIsDimPresent[eZ])
354 aCoordHelperPtr.reset(new TCoordHelper(aZGetCoord));
356 aCoordHelperPtr.reset(new TCoordHelper(aXGetCoord));
360 INITMSG(MYDEBUG,"TNamedPointCoords::GetPoints - aNbPoints = "<<GetNbPoints()<<
361 "; aDim = "<<GetDim()<<
364 if(anIsDimPresent[eX] && anIsDimPresent[eY] && anIsDimPresent[eZ]){
365 INITMSG(MYDEBUG,"TNamedPointCoords::GetPoints - SetVoidArray()"<<endl);
368 vtkPoints* aPoints = myPointSet->GetPoints();
369 for(vtkIdType aNodeId = 0; aNodeId < GetNbPoints(); aNodeId++){
370 TCCoordSlice aCoordSlice = GetCoordSlice(aNodeId);
371 aPoints->SetPoint(aNodeId,
372 aCoordHelperPtr->GetCoord(aCoordSlice,eX),
373 aCoordHelperPtr->GetCoord(aCoordSlice,eY),
374 aCoordHelperPtr->GetCoord(aCoordSlice,eZ));
379 vtkIdType aNbTuples = GetNbPoints();
380 int anEntity = int(VISU::NODE_ENTITY);
381 vtkIntArray *aDataArray = vtkIntArray::New();
382 aDataArray->SetName("VISU_POINTS_MAPPER");
383 aDataArray->SetNumberOfComponents(2);
384 aDataArray->SetNumberOfTuples(aNbTuples);
385 int *aPtr = aDataArray->GetPointer(0);
386 for(vtkIdType aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
387 vtkIdType anObjID = GetObjID(aTupleId);
391 myPointSet->GetPointData()->AddArray(aDataArray);
392 aDataArray->Delete();
398 return myPointSet.GetPointer();
405 return TPointCoords::GetMemorySize();
409 //---------------------------------------------------------------