1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // VISU OBJECT : interactive object for VISU entities implementation
28 #include "VISU_PointCoords.hxx"
29 #include "VISU_ConvertorUtils.hxx"
31 #include <vtkUnstructuredGrid.h>
32 #include <vtkPointData.h>
33 #include <vtkIntArray.h>
36 static int MYDEBUG = 0;
38 static int MYDEBUG = 0;
43 //---------------------------------------------------------------
46 ::Init(vtkIdType theNbPoints,
50 myNbPoints = theNbPoints;
71 return GetNbPoints() * GetDim();
78 return sizeof(TCoord) * size();
82 //---------------------------------------------------------------
85 myPointSet(vtkUnstructuredGrid::New())
87 vtkPoints* aPoints = vtkPoints::New();
88 myPointSet->SetPoints(aPoints);
89 aPoints->SetDataType(VTK_DOUBLE);
97 ::Init(const PCoordHolder& theCoord)
99 myPointSet->GetPoints()->SetNumberOfPoints(theCoord->GetNbPoints());
105 ::GetNbPoints() const
107 return myCoord->GetNbPoints();
114 return myCoord->GetDim();
119 ::GetCoordSlice(vtkIdType theNodeId) const
121 return myCoord->GetCoordSlice(theNodeId);
126 ::GetCoordSlice(vtkIdType theNodeId)
128 return myCoord->GetCoordSlice(theNodeId);
133 ::GetObjID(vtkIdType theID) const
140 ::GetVTKID(vtkIdType theID) const
147 ::SetVoidArray() const
149 vtkDataArray* aDataArray = myPointSet->GetPoints()->GetData();
150 aDataArray->SetVoidArray(myCoord->GetValuePtr(), myCoord->size(), true);
155 ::GetPointSet() const
158 TTimerLog aTimerLog(MYDEBUG,"TPointCoords::GetPoints()");
159 vtkIdType aNbPoints = GetNbPoints();
160 vtkIdType aDim = GetDim();
162 INITMSG(MYDEBUG,"TPointCoords::GetPoints - aNbPoints = "<<aNbPoints<<
167 INITMSG(MYDEBUG,"TPointCoords::GetPoints - SetVoidArray()"<<endl);
170 vtkPoints* aPoints = myPointSet->GetPoints();
171 for(vtkIdType aPointId = 0; aPointId < aNbPoints; aPointId++){
172 TCCoordSlice aSlice = GetCoordSlice(aPointId);
174 vtkFloatingPointType aCoords[3] = {0.0, 0.0, 0.0};
175 for(vtkIdType aDimId = 0; aDimId < aDim; aDimId++)
176 aCoords[aDimId] = aSlice[aDimId];
178 aPoints->SetPoint(aPointId, aCoords);
185 return myPointSet.GetPointer();
192 size_t aSize = myCoord->GetMemorySize();
193 aSize += myPointSet->GetActualMemorySize() * 1024;
198 //---------------------------------------------------------------
201 ::Init(const PCoordHolder& theCoord)
203 TPointCoords::Init(theCoord);
204 myPointsDim.resize(theCoord->GetDim());
209 ::GetName(vtkIdType theDim)
211 return myPointsDim[theDim];
216 ::GetName(vtkIdType theDim) const
218 return myPointsDim[theDim];
223 ::GetNodeName(vtkIdType theObjID) const
229 //---------------------------------------------------------------
230 enum ECoordName{eX, eY, eZ, eNoneCoord};
231 typedef VISU::TCoord (*TGetCoord)(const VISU::TCCoordSlice& theCoordSlice);
233 template<ECoordName TCoordId>
235 GetCoord(const VISU::TCCoordSlice& theCoordSlice)
237 return theCoordSlice[TCoordId];
242 GetCoord<eNoneCoord>(const VISU::TCCoordSlice& theCoordSlice)
248 TGetCoord aXYZGetCoord[3] = {
255 TGetCoord aXYGetCoord[3] = {
258 &GetCoord<eNoneCoord>
261 TGetCoord aYZGetCoord[3] = {
262 &GetCoord<eNoneCoord>,
267 TGetCoord aXZGetCoord[3] = {
269 &GetCoord<eNoneCoord>,
274 TGetCoord aXGetCoord[3] = {
276 &GetCoord<eNoneCoord>,
277 &GetCoord<eNoneCoord>
280 TGetCoord aYGetCoord[3] = {
281 &GetCoord<eNoneCoord>,
283 &GetCoord<eNoneCoord>
286 TGetCoord aZGetCoord[3] = {
287 &GetCoord<eNoneCoord>,
288 &GetCoord<eNoneCoord>,
294 TGetCoord* myGetCoord;
296 TCoordHelper(TGetCoord* theGetCoord):
297 myGetCoord(theGetCoord)
305 GetCoord(VISU::TCCoordSlice& theCoordSlice,
308 return (*myGetCoord[theCoordId])(theCoordSlice);
311 typedef std::auto_ptr<TCoordHelper> TCoordHelperPtr;
314 //---------------------------------------------------------------
317 ::GetPointSet() const
320 TTimerLog aTimerLog(MYDEBUG,"TNamedPointCoords::GetPoints()");
321 TCoordHelperPtr aCoordHelperPtr;
322 bool anIsDimPresent[3] = {false, false, false};
323 for(int iDim = 0; iDim < GetDim(); iDim++){
324 // PAL16857(SMESH not conform to the MED convention) ->
325 // 1D - always along X
326 // 2D - always in XOY plane
327 anIsDimPresent[iDim] = iDim < GetDim();
328 // std::string aName = GetName(iDim);
329 // if ( aName.size() > 1 ) // PAL13021 (PAL12148), aName has size 8 or 16
330 // aName = aName.substr(0,1);
331 // if(aName == "x" || aName == "X")
332 // anIsDimPresent[eX] = true;
333 // else if(aName == "y" || aName == "Y")
334 // anIsDimPresent[eY] = true;
335 // else if(aName == "z" || aName == "Z")
336 // anIsDimPresent[eZ] = true;
341 aCoordHelperPtr.reset(new TCoordHelper(aXYZGetCoord));
344 if(anIsDimPresent[eY] && anIsDimPresent[eZ])
345 aCoordHelperPtr.reset(new TCoordHelper(aYZGetCoord));
346 else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
347 aCoordHelperPtr.reset(new TCoordHelper(aXZGetCoord));
349 aCoordHelperPtr.reset(new TCoordHelper(aXYGetCoord));
352 if(anIsDimPresent[eY])
353 aCoordHelperPtr.reset(new TCoordHelper(aYGetCoord));
354 else if(anIsDimPresent[eZ])
355 aCoordHelperPtr.reset(new TCoordHelper(aZGetCoord));
357 aCoordHelperPtr.reset(new TCoordHelper(aXGetCoord));
361 INITMSG(MYDEBUG,"TNamedPointCoords::GetPoints - aNbPoints = "<<GetNbPoints()<<
362 "; aDim = "<<GetDim()<<
365 if(anIsDimPresent[eX] && anIsDimPresent[eY] && anIsDimPresent[eZ]){
366 INITMSG(MYDEBUG,"TNamedPointCoords::GetPoints - SetVoidArray()"<<endl);
369 vtkPoints* aPoints = myPointSet->GetPoints();
370 for(vtkIdType aNodeId = 0; aNodeId < GetNbPoints(); aNodeId++){
371 TCCoordSlice aCoordSlice = GetCoordSlice(aNodeId);
372 aPoints->SetPoint(aNodeId,
373 aCoordHelperPtr->GetCoord(aCoordSlice,eX),
374 aCoordHelperPtr->GetCoord(aCoordSlice,eY),
375 aCoordHelperPtr->GetCoord(aCoordSlice,eZ));
380 vtkIdType aNbTuples = GetNbPoints();
381 int anEntity = int(VISU::NODE_ENTITY);
382 vtkIntArray *aDataArray = vtkIntArray::New();
383 aDataArray->SetName("VISU_POINTS_MAPPER");
384 aDataArray->SetNumberOfComponents(2);
385 aDataArray->SetNumberOfTuples(aNbTuples);
386 int *aPtr = aDataArray->GetPointer(0);
387 for(vtkIdType aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
388 vtkIdType anObjID = GetObjID(aTupleId);
392 myPointSet->GetPointData()->AddArray(aDataArray);
393 aDataArray->Delete();
399 return myPointSet.GetPointer();
406 return TPointCoords::GetMemorySize();
410 //---------------------------------------------------------------