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
24 // File: VISU_PipeLine.cxx
25 // Author: Alexey PETROV
28 #include "VISU_PipeLine.hxx"
29 #include "VISU_MapperHolder.hxx"
31 #include "VISU_PipeLineUtils.hxx"
33 #include <vtkObjectFactory.h>
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
48 //----------------------------------------------------------------------------
52 myIsFeatureEdgesAllowed(true)
54 if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
58 //----------------------------------------------------------------------------
62 if(MYDEBUG) MESSAGE("VISU_PipeLine::~VISU_PipeLine - "<<this);
66 //----------------------------------------------------------------------------
71 unsigned long int aTime = Superclass::GetMTime();
73 if(myMapperHolder.GetPointer())
74 aTime = std::max(aTime, myMapperHolder->GetMTime());
80 //----------------------------------------------------------------------------
85 unsigned long int aSize = 0;
87 if(myMapperHolder.GetPointer())
88 aSize += myMapperHolder->GetMemorySize();
94 //----------------------------------------------------------------------------
97 ::ShallowCopy(VISU_PipeLine *thePipeLine,
100 SetImplicitFunction(thePipeLine->GetImplicitFunction());
101 DoShallowCopy(thePipeLine, theIsCopyInput);
106 //----------------------------------------------------------------------------
109 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
112 GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
117 //----------------------------------------------------------------------------
120 ::SameAs(VISU_PipeLine *thePipeLine)
122 DoShallowCopy(thePipeLine, false);
127 //----------------------------------------------------------------------------
132 if(!myMapperHolder.GetPointer())
133 OnCreateMapperHolder();
135 return myMapperHolder.GetPointer();
139 //----------------------------------------------------------------------------
140 const VISU::PIDMapper&
144 return GetMapperHolder()->GetIDMapper();
148 //----------------------------------------------------------------------------
153 return GetMapperHolder()->GetInput();
157 //----------------------------------------------------------------------------
162 return GetMapperHolder()->GetMapper();
166 //----------------------------------------------------------------------------
171 return GetMapperHolder()->GetOutput();
175 //----------------------------------------------------------------------------
180 vtkFloatingPointType aBounds[6];
181 GetInput()->GetBounds( aBounds ); // xmin,xmax, ymin,ymax, zmin,zmax
182 if (fabs( aBounds[0] - aBounds[1] ) <= FLT_MIN ||
183 fabs( aBounds[2] - aBounds[3] ) <= FLT_MIN ||
184 fabs( aBounds[4] - aBounds[5] ) <= FLT_MIN )
191 //----------------------------------------------------------------------------
194 ::SetMapperHolder(VISU_MapperHolder* theHolder)
196 myMapperHolder = theHolder;
197 theHolder->SetPipeLine(this);
201 //----------------------------------------------------------------------------
208 //----------------------------------------------------------------------------
213 GetMapperHolder()->Update();
217 //----------------------------------------------------------------------------
220 ::GetNodeObjID(vtkIdType theID)
222 return GetMapperHolder()->GetNodeObjID(theID);
225 //----------------------------------------------------------------------------
228 ::GetNodeVTKID(vtkIdType theID)
230 return GetMapperHolder()->GetNodeVTKID(theID);
233 //----------------------------------------------------------------------------
234 vtkFloatingPointType*
236 ::GetNodeCoord(vtkIdType theObjID)
238 return GetMapperHolder()->GetNodeCoord(theObjID);
242 //----------------------------------------------------------------------------
245 ::GetElemObjID(vtkIdType theID)
247 return GetMapperHolder()->GetElemObjID(theID);
250 //----------------------------------------------------------------------------
253 ::GetElemVTKID(vtkIdType theID)
255 return GetMapperHolder()->GetElemVTKID(theID);
258 //----------------------------------------------------------------------------
261 ::GetElemCell(vtkIdType theObjID)
263 return GetMapperHolder()->GetElemCell(theObjID);
267 //----------------------------------------------------------------------------
272 return myIsShrinkable;
277 ::SetIsShrinkable(bool theIsShrinkable)
279 if(myIsShrinkable == theIsShrinkable)
282 myIsShrinkable = theIsShrinkable;
287 //----------------------------------------------------------------------------
290 ::IsFeatureEdgesAllowed()
292 return myIsFeatureEdgesAllowed;
297 ::SetIsFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
299 if(myIsFeatureEdgesAllowed == theIsFeatureEdgesAllowed)
302 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
307 //----------------------------------------------------------------------------
310 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
312 GetMapperHolder()->SetImplicitFunction(theFunction);
315 //----------------------------------------------------------------------------
316 vtkImplicitFunction *
318 ::GetImplicitFunction()
320 return GetMapperHolder()->GetImplicitFunction();
323 //----------------------------------------------------------------------------
326 ::SetExtractInside(bool theMode)
328 GetMapperHolder()->SetExtractInside(theMode);
331 //----------------------------------------------------------------------------
334 ::SetExtractBoundaryCells(bool theMode)
336 GetMapperHolder()->SetExtractBoundaryCells(theMode);
340 //----------------------------------------------------------------------------
343 ::RemoveAllClippingPlanes()
345 GetMapperHolder()->RemoveAllClippingPlanes();
348 //----------------------------------------------------------------------------
351 ::GetNumberOfClippingPlanes()
353 return GetMapperHolder()->GetNumberOfClippingPlanes();
356 //----------------------------------------------------------------------------
359 ::AddClippingPlane(vtkPlane* thePlane)
361 return GetMapperHolder()->AddClippingPlane(thePlane);
364 //----------------------------------------------------------------------------
367 ::GetClippingPlane(vtkIdType theID)
369 return GetMapperHolder()->GetClippingPlane(theID);
372 //----------------------------------------------------------------------------
373 void VISU_PipeLine::RemoveClippingPlane(vtkIdType theID)
375 return GetMapperHolder()->RemoveClippingPlane(theID);
378 //----------------------------------------------------------------------------
383 return GetMapperHolder()->GetClippedInput();
387 //----------------------------------------------------------------------------
390 ::SetPlaneParam(vtkFloatingPointType theDir[3],
391 vtkFloatingPointType theDist,
394 thePlane->SetNormal(theDir);
396 vtkFloatingPointType anOrigin[3];
397 VISU::DistanceToPosition(GetInput(),
402 thePlane->SetOrigin(anOrigin);
406 //----------------------------------------------------------------------------
409 ::GetPlaneParam(vtkFloatingPointType theDir[3],
410 vtkFloatingPointType& theDist,
413 thePlane->GetNormal(theDir);
415 vtkFloatingPointType anOrigin[3];
416 thePlane->GetOrigin(anOrigin);
418 VISU::PositionToDistance(GetInput(),
425 //----------------------------------------------------------------------------
428 ::CheckAvailableMemory(double theSize)
430 if(theSize < ULONG_MAX){
432 size_t aSize = size_t(theSize);
433 if(char *aCheck = new char[aSize]){
437 }catch(std::bad_alloc& exc){
445 //----------------------------------------------------------------------------
448 ::GetAvailableMemory(double theSize,
451 // Finds acceptable memory size by half-deflection methods
452 static double EPSILON = 2 * 1024;
453 double aMax = std::max(theSize, theMinSize);
454 double aMin = std::min(theSize, theMinSize);
455 //cout<<"GetAvailableMemory - "<<aMax<<"; "<<aMin;
456 while(!CheckAvailableMemory(aMax) && CheckAvailableMemory(aMin) && (aMax - aMin) > EPSILON){
457 double aRoot = (aMax + aMin) / 2.;
458 if(CheckAvailableMemory(aRoot))
463 //cout<<"; "<<aMax<<endl;
468 //----------------------------------------------------------------------------