1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_PipeLine.cxx
24 // Author: Alexey PETROV
27 #include "VISU_PipeLine.hxx"
28 #include "VISU_MapperHolder.hxx"
30 #include "VISU_PipeLineUtils.hxx"
32 #include <vtkObjectFactory.h>
41 static int MYDEBUG = 0;
43 static int MYDEBUG = 0;
47 //----------------------------------------------------------------------------
51 myIsFeatureEdgesAllowed(true)
53 if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
57 //----------------------------------------------------------------------------
61 if(MYDEBUG) MESSAGE("VISU_PipeLine::~VISU_PipeLine - "<<this);
65 //----------------------------------------------------------------------------
70 unsigned long int aTime = Superclass::GetMTime();
72 if(myMapperHolder.GetPointer())
73 aTime = std::max(aTime, myMapperHolder->GetMTime());
79 //----------------------------------------------------------------------------
84 unsigned long int aSize = 0;
86 if(myMapperHolder.GetPointer())
87 aSize += myMapperHolder->GetMemorySize();
93 //----------------------------------------------------------------------------
96 ::ShallowCopy(VISU_PipeLine *thePipeLine,
99 SetImplicitFunction(thePipeLine->GetImplicitFunction());
100 DoShallowCopy(thePipeLine, theIsCopyInput);
105 //----------------------------------------------------------------------------
108 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
111 GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
116 //----------------------------------------------------------------------------
119 ::SameAs(VISU_PipeLine *thePipeLine)
121 DoShallowCopy(thePipeLine, false);
126 //----------------------------------------------------------------------------
131 if(!myMapperHolder.GetPointer())
132 OnCreateMapperHolder();
134 return myMapperHolder.GetPointer();
138 //----------------------------------------------------------------------------
139 const VISU::PIDMapper&
143 return GetMapperHolder()->GetIDMapper();
147 //----------------------------------------------------------------------------
152 return GetMapperHolder()->GetInput();
156 //----------------------------------------------------------------------------
161 return GetMapperHolder()->GetMapper();
165 //----------------------------------------------------------------------------
170 return GetMapperHolder()->GetOutput();
174 //----------------------------------------------------------------------------
179 vtkFloatingPointType aBounds[6];
180 GetInput()->GetBounds( aBounds ); // xmin,xmax, ymin,ymax, zmin,zmax
181 if (fabs( aBounds[0] - aBounds[1] ) <= FLT_MIN ||
182 fabs( aBounds[2] - aBounds[3] ) <= FLT_MIN ||
183 fabs( aBounds[4] - aBounds[5] ) <= FLT_MIN )
190 //----------------------------------------------------------------------------
193 ::SetMapperHolder(VISU_MapperHolder* theHolder)
195 myMapperHolder = theHolder;
196 theHolder->SetPipeLine(this);
200 //----------------------------------------------------------------------------
207 //----------------------------------------------------------------------------
212 GetMapperHolder()->Update();
216 //----------------------------------------------------------------------------
219 ::GetNodeObjID(vtkIdType theID)
221 return GetMapperHolder()->GetNodeObjID(theID);
224 //----------------------------------------------------------------------------
227 ::GetNodeVTKID(vtkIdType theID)
229 return GetMapperHolder()->GetNodeVTKID(theID);
232 //----------------------------------------------------------------------------
233 vtkFloatingPointType*
235 ::GetNodeCoord(vtkIdType theObjID)
237 return GetMapperHolder()->GetNodeCoord(theObjID);
241 //----------------------------------------------------------------------------
244 ::GetElemObjID(vtkIdType theID)
246 return GetMapperHolder()->GetElemObjID(theID);
249 //----------------------------------------------------------------------------
252 ::GetElemVTKID(vtkIdType theID)
254 return GetMapperHolder()->GetElemVTKID(theID);
257 //----------------------------------------------------------------------------
260 ::GetElemCell(vtkIdType theObjID)
262 return GetMapperHolder()->GetElemCell(theObjID);
266 //----------------------------------------------------------------------------
271 return myIsShrinkable;
276 ::SetIsShrinkable(bool theIsShrinkable)
278 if(myIsShrinkable == theIsShrinkable)
281 myIsShrinkable = theIsShrinkable;
286 //----------------------------------------------------------------------------
289 ::IsFeatureEdgesAllowed()
291 return myIsFeatureEdgesAllowed;
296 ::SetIsFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
298 if(myIsFeatureEdgesAllowed == theIsFeatureEdgesAllowed)
301 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
306 //----------------------------------------------------------------------------
309 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
311 GetMapperHolder()->SetImplicitFunction(theFunction);
314 //----------------------------------------------------------------------------
315 vtkImplicitFunction *
317 ::GetImplicitFunction()
319 return GetMapperHolder()->GetImplicitFunction();
322 //----------------------------------------------------------------------------
325 ::SetExtractInside(bool theMode)
327 GetMapperHolder()->SetExtractInside(theMode);
330 //----------------------------------------------------------------------------
333 ::SetExtractBoundaryCells(bool theMode)
335 GetMapperHolder()->SetExtractBoundaryCells(theMode);
339 //----------------------------------------------------------------------------
342 ::RemoveAllClippingPlanes()
344 GetMapperHolder()->RemoveAllClippingPlanes();
347 //----------------------------------------------------------------------------
350 ::GetNumberOfClippingPlanes()
352 return GetMapperHolder()->GetNumberOfClippingPlanes();
355 //----------------------------------------------------------------------------
358 ::AddClippingPlane(vtkPlane* thePlane)
360 return GetMapperHolder()->AddClippingPlane(thePlane);
363 //----------------------------------------------------------------------------
366 ::GetClippingPlane(vtkIdType theID)
368 return GetMapperHolder()->GetClippingPlane(theID);
371 //----------------------------------------------------------------------------
372 void VISU_PipeLine::RemoveClippingPlane(vtkIdType theID)
374 return GetMapperHolder()->RemoveClippingPlane(theID);
377 //----------------------------------------------------------------------------
382 return GetMapperHolder()->GetClippedInput();
386 //----------------------------------------------------------------------------
389 ::SetPlaneParam(vtkFloatingPointType theDir[3],
390 vtkFloatingPointType theDist,
393 thePlane->SetNormal(theDir);
395 vtkFloatingPointType anOrigin[3];
396 VISU::DistanceToPosition(GetInput(),
401 thePlane->SetOrigin(anOrigin);
405 //----------------------------------------------------------------------------
408 ::GetPlaneParam(vtkFloatingPointType theDir[3],
409 vtkFloatingPointType& theDist,
412 thePlane->GetNormal(theDir);
414 vtkFloatingPointType anOrigin[3];
415 thePlane->GetOrigin(anOrigin);
417 VISU::PositionToDistance(GetInput(),
424 //----------------------------------------------------------------------------
427 ::CheckAvailableMemory(double theSize)
429 if(theSize < ULONG_MAX){
431 size_t aSize = size_t(theSize);
432 if(char *aCheck = new char[aSize]){
436 }catch(std::bad_alloc& exc){
444 //----------------------------------------------------------------------------
447 ::GetAvailableMemory(size_t theSize,
450 // Finds acceptable memory size by half-deflection methods
451 static double EPSILON = 2 * 1024;
452 double aMax = std::max(theSize, theMinSize);
453 double aMin = std::min(theSize, theMinSize);
454 //cout<<"GetAvailableMemory - "<<aMax<<"; "<<aMin;
455 while(!CheckAvailableMemory(aMax) && CheckAvailableMemory(aMin) && (aMax - aMin) > EPSILON){
456 double aRoot = (aMax + aMin) / 2.;
457 if(CheckAvailableMemory(aRoot))
462 //cout<<"; "<<aMax<<endl;
467 //----------------------------------------------------------------------------