1 // Copyright (C) 2007-2012 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);
56 vtkMath::UninitializeBounds(myVisibleBounds);
60 //----------------------------------------------------------------------------
64 if(MYDEBUG) MESSAGE("VISU_PipeLine::~VISU_PipeLine - "<<this);
68 //----------------------------------------------------------------------------
73 unsigned long int aTime = Superclass::GetMTime();
75 if(myMapperHolder.GetPointer())
76 aTime = std::max(aTime, myMapperHolder->GetMTime());
82 //----------------------------------------------------------------------------
87 unsigned long int aSize = 0;
89 if(myMapperHolder.GetPointer())
90 aSize += myMapperHolder->GetMemorySize();
96 //----------------------------------------------------------------------------
99 ::ShallowCopy(VISU_PipeLine *thePipeLine,
102 SetImplicitFunction(thePipeLine->GetImplicitFunction());
103 DoShallowCopy(thePipeLine, theIsCopyInput);
108 //----------------------------------------------------------------------------
111 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
114 GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
116 for( int i =0 ; i < 6 ; i++)
117 myVisibleBounds[i] = thePipeLine->myVisibleBounds[i];
119 myVisibleComputeTime = thePipeLine->myVisibleComputeTime;
123 //----------------------------------------------------------------------------
126 ::SameAs(VISU_PipeLine *thePipeLine)
128 DoShallowCopy(thePipeLine, false);
133 //----------------------------------------------------------------------------
138 if(!myMapperHolder.GetPointer())
139 OnCreateMapperHolder();
141 return myMapperHolder.GetPointer();
145 //----------------------------------------------------------------------------
146 const VISU::PIDMapper&
150 return GetMapperHolder()->GetIDMapper();
154 //----------------------------------------------------------------------------
159 return GetMapperHolder()->GetInput();
163 //----------------------------------------------------------------------------
168 return GetMapperHolder()->GetMapper();
172 //----------------------------------------------------------------------------
177 return GetMapperHolder()->GetOutput();
181 //----------------------------------------------------------------------------
187 GetInput()->GetBounds( aBounds ); // xmin,xmax, ymin,ymax, zmin,zmax
188 if (fabs( aBounds[0] - aBounds[1] ) <= FLT_MIN ||
189 fabs( aBounds[2] - aBounds[3] ) <= FLT_MIN ||
190 fabs( aBounds[4] - aBounds[5] ) <= FLT_MIN )
197 //----------------------------------------------------------------------------
200 ::SetMapperHolder(VISU_MapperHolder* theHolder)
202 myMapperHolder = theHolder;
203 theHolder->SetPipeLine(this);
207 //----------------------------------------------------------------------------
214 //----------------------------------------------------------------------------
219 GetMapperHolder()->Update();
223 //----------------------------------------------------------------------------
226 ::GetNodeObjID(vtkIdType theID)
228 return GetMapperHolder()->GetNodeObjID(theID);
231 //----------------------------------------------------------------------------
234 ::GetNodeVTKID(vtkIdType theID)
236 return GetMapperHolder()->GetNodeVTKID(theID);
239 //----------------------------------------------------------------------------
242 ::GetNodeCoord(vtkIdType theObjID)
244 return GetMapperHolder()->GetNodeCoord(theObjID);
248 //----------------------------------------------------------------------------
251 ::GetElemObjID(vtkIdType theID)
253 return GetMapperHolder()->GetElemObjID(theID);
256 //----------------------------------------------------------------------------
259 ::GetElemVTKID(vtkIdType theID)
261 return GetMapperHolder()->GetElemVTKID(theID);
264 //----------------------------------------------------------------------------
267 ::GetElemCell(vtkIdType theObjID)
269 return GetMapperHolder()->GetElemCell(theObjID);
273 //----------------------------------------------------------------------------
278 return myIsShrinkable;
283 ::SetIsShrinkable(bool theIsShrinkable)
285 if(myIsShrinkable == theIsShrinkable)
288 myIsShrinkable = theIsShrinkable;
293 //----------------------------------------------------------------------------
296 ::IsFeatureEdgesAllowed()
298 return myIsFeatureEdgesAllowed;
303 ::SetIsFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
305 if(myIsFeatureEdgesAllowed == theIsFeatureEdgesAllowed)
308 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
313 //----------------------------------------------------------------------------
316 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
318 GetMapperHolder()->SetImplicitFunction(theFunction);
321 //----------------------------------------------------------------------------
322 vtkImplicitFunction *
324 ::GetImplicitFunction()
326 return GetMapperHolder()->GetImplicitFunction();
329 //----------------------------------------------------------------------------
332 ::SetExtractInside(bool theMode)
334 GetMapperHolder()->SetExtractInside(theMode);
337 //----------------------------------------------------------------------------
340 ::SetExtractBoundaryCells(bool theMode)
342 GetMapperHolder()->SetExtractBoundaryCells(theMode);
346 //----------------------------------------------------------------------------
349 ::RemoveAllClippingPlanes()
351 GetMapperHolder()->RemoveAllClippingPlanes();
354 //----------------------------------------------------------------------------
357 ::GetNumberOfClippingPlanes()
359 return GetMapperHolder()->GetNumberOfClippingPlanes();
362 //----------------------------------------------------------------------------
365 ::AddClippingPlane(vtkPlane* thePlane)
367 return GetMapperHolder()->AddClippingPlane(thePlane);
370 //----------------------------------------------------------------------------
373 ::GetClippingPlane(vtkIdType theID)
375 return GetMapperHolder()->GetClippingPlane(theID);
378 //----------------------------------------------------------------------------
379 void VISU_PipeLine::RemoveClippingPlane(vtkIdType theID)
381 return GetMapperHolder()->RemoveClippingPlane(theID);
384 //----------------------------------------------------------------------------
389 return GetMapperHolder()->GetClippedInput();
392 //----------------------------------------------------------------------------
395 ::GetClippedInputPort()
397 return GetMapperHolder()->GetClippedInputPort();
401 //----------------------------------------------------------------------------
404 ::SetPlaneParam(double theDir[3],
408 thePlane->SetNormal(theDir);
412 //Make sure that bounds are calculated
413 ComputeVisibleBounds();
414 VISU::DistanceToPosition(myVisibleBounds,
419 thePlane->SetOrigin(anOrigin);
423 //----------------------------------------------------------------------------
426 ::GetPlaneParam(double theDir[3],
430 thePlane->GetNormal(theDir);
433 thePlane->GetOrigin(anOrigin);
435 //Make sure that bounds are calculated
436 ComputeVisibleBounds();
437 VISU::PositionToDistance(myVisibleBounds,
444 //----------------------------------------------------------------------------
447 ::CheckAvailableMemory(double theSize)
449 if(theSize < ULONG_MAX){
451 size_t aSize = size_t(theSize);
452 if(char *aCheck = new char[aSize]){
456 }catch(std::bad_alloc& exc){
464 //----------------------------------------------------------------------------
467 ::GetAvailableMemory(double theSize,
470 // Finds acceptable memory size by half-deflection methods
471 static double EPSILON = 2 * 1024;
472 double aMax = std::max(theSize, theMinSize);
473 double aMin = std::min(theSize, theMinSize);
474 //cout<<"GetAvailableMemory - "<<aMax<<"; "<<aMin;
475 while(!CheckAvailableMemory(aMax) && CheckAvailableMemory(aMin) && (aMax - aMin) > EPSILON){
476 double aRoot = (aMax + aMin) / 2.;
477 if(CheckAvailableMemory(aRoot))
482 //cout<<"; "<<aMax<<endl;
487 //----------------------------------------------------------------------------
488 // Re-compute visible bounds if need
489 void VISU_PipeLine::ComputeVisibleBounds() {
490 if(GetMTime() > myVisibleComputeTime) {
491 VISU::ComputeVisibleBounds(GetMapperHolder()->GetOutput(), myVisibleBounds);
492 myVisibleComputeTime.Modified();
496 //----------------------------------------------------------------------------
497 void VISU_PipeLine::GetVisibleBounds(double theBounds[6]) {
498 // Compute or get cached bounds
499 ComputeVisibleBounds();
500 for (int i=0; i<6; i++) {
501 theBounds[i] = myVisibleBounds[i];
505 //----------------------------------------------------------------------------