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
24 // File: VISU_PipeLine.cxx
25 // Author: Alexey PETROV
29 #include "VISU_PipeLine.hxx"
30 #include "VISU_MapperHolder.hxx"
32 #include "VISU_PipeLineUtils.hxx"
34 #include <vtkObjectFactory.h>
41 static int MYDEBUG = 0;
43 static int MYDEBUG = 0;
47 //----------------------------------------------------------------------------
52 if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
56 //----------------------------------------------------------------------------
60 if(MYDEBUG) MESSAGE("VISU_PipeLine::~VISU_PipeLine - "<<this);
64 //----------------------------------------------------------------------------
69 unsigned long int aTime = Superclass::GetMTime();
71 if(myMapperHolder.GetPointer())
72 aTime = std::max(aTime, myMapperHolder->GetMTime());
78 //----------------------------------------------------------------------------
83 unsigned long int aSize = 0;
85 if(myMapperHolder.GetPointer())
86 aSize += myMapperHolder->GetMemorySize();
92 //----------------------------------------------------------------------------
95 ::ShallowCopy(VISU_PipeLine *thePipeLine,
98 SetImplicitFunction(thePipeLine->GetImplicitFunction());
99 DoShallowCopy(thePipeLine, theIsCopyInput);
104 //----------------------------------------------------------------------------
107 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
110 GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
115 //----------------------------------------------------------------------------
118 ::SameAs(VISU_PipeLine *thePipeLine)
120 DoShallowCopy(thePipeLine, false);
125 //----------------------------------------------------------------------------
130 if(!myMapperHolder.GetPointer())
131 OnCreateMapperHolder();
133 return myMapperHolder.GetPointer();
137 //----------------------------------------------------------------------------
138 const VISU::PIDMapper&
142 return GetMapperHolder()->GetIDMapper();
146 //----------------------------------------------------------------------------
151 return GetMapperHolder()->GetInput();
155 //----------------------------------------------------------------------------
160 return GetMapperHolder()->GetMapper();
164 //----------------------------------------------------------------------------
169 return GetMapperHolder()->GetOutput();
173 //----------------------------------------------------------------------------
178 vtkFloatingPointType aBounds[6];
179 GetInput()->GetBounds( aBounds ); // xmin,xmax, ymin,ymax, zmin,zmax
180 if (fabs( aBounds[0] - aBounds[1] ) <= FLT_MIN ||
181 fabs( aBounds[2] - aBounds[3] ) <= FLT_MIN ||
182 fabs( aBounds[4] - aBounds[5] ) <= FLT_MIN )
189 //----------------------------------------------------------------------------
192 ::SetMapperHolder(VISU_MapperHolder* theHolder)
194 myMapperHolder = theHolder;
195 theHolder->SetPipeLine(this);
199 //----------------------------------------------------------------------------
206 //----------------------------------------------------------------------------
211 GetMapperHolder()->Update();
215 //----------------------------------------------------------------------------
218 ::GetNodeObjID(vtkIdType theID)
220 return GetMapperHolder()->GetNodeObjID(theID);
223 //----------------------------------------------------------------------------
226 ::GetNodeVTKID(vtkIdType theID)
228 return GetMapperHolder()->GetNodeVTKID(theID);
231 //----------------------------------------------------------------------------
232 vtkFloatingPointType*
234 ::GetNodeCoord(int theObjID)
236 return GetMapperHolder()->GetNodeCoord(theObjID);
240 //----------------------------------------------------------------------------
243 ::GetElemObjID(vtkIdType theID)
245 return GetMapperHolder()->GetElemObjID(theID);
248 //----------------------------------------------------------------------------
251 ::GetElemVTKID(vtkIdType theID)
253 return GetMapperHolder()->GetElemVTKID(theID);
256 //----------------------------------------------------------------------------
259 ::GetElemCell(vtkIdType theObjID)
261 return GetMapperHolder()->GetElemCell(theObjID);
265 //----------------------------------------------------------------------------
270 return myIsShrinkable;
275 ::SetIsShrinkable(bool theIsShrinkable)
277 if(myIsShrinkable == theIsShrinkable)
280 myIsShrinkable = theIsShrinkable;
285 //----------------------------------------------------------------------------
288 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
290 GetMapperHolder()->SetImplicitFunction(theFunction);
293 //----------------------------------------------------------------------------
294 vtkImplicitFunction *
296 ::GetImplicitFunction()
298 return GetMapperHolder()->GetImplicitFunction();
301 //----------------------------------------------------------------------------
304 ::SetExtractInside(bool theMode)
306 GetMapperHolder()->SetExtractInside(theMode);
309 //----------------------------------------------------------------------------
312 ::SetExtractBoundaryCells(bool theMode)
314 GetMapperHolder()->SetExtractBoundaryCells(theMode);
318 //----------------------------------------------------------------------------
321 ::RemoveAllClippingPlanes()
323 GetMapperHolder()->RemoveAllClippingPlanes();
326 //----------------------------------------------------------------------------
329 ::GetNumberOfClippingPlanes()
331 return GetMapperHolder()->GetNumberOfClippingPlanes();
334 //----------------------------------------------------------------------------
337 ::AddClippingPlane(vtkPlane* thePlane)
339 return GetMapperHolder()->AddClippingPlane(thePlane);
342 //----------------------------------------------------------------------------
345 ::GetClippingPlane(vtkIdType theID)
347 return GetMapperHolder()->GetClippingPlane(theID);
350 //----------------------------------------------------------------------------
355 return GetMapperHolder()->GetClippedInput();
359 //----------------------------------------------------------------------------
362 ::SetPlaneParam(vtkFloatingPointType theDir[3],
363 vtkFloatingPointType theDist,
366 thePlane->SetNormal(theDir);
368 vtkFloatingPointType anOrigin[3];
369 VISU::DistanceToPosition(GetInput(),
374 thePlane->SetOrigin(anOrigin);
378 //----------------------------------------------------------------------------
381 ::GetPlaneParam(vtkFloatingPointType theDir[3],
382 vtkFloatingPointType& theDist,
385 thePlane->GetNormal(theDir);
387 vtkFloatingPointType anOrigin[3];
388 thePlane->GetOrigin(anOrigin);
390 VISU::PositionToDistance(GetInput(),
397 //----------------------------------------------------------------------------
400 ::CheckAvailableMemory(double theSize)
402 if(theSize < ULONG_MAX){
404 size_t aSize = size_t(theSize);
405 if(char *aCheck = new char[aSize]){
409 }catch(std::bad_alloc& exc){
417 //----------------------------------------------------------------------------
420 ::GetAvailableMemory(size_t theSize,
423 // Finds acceptable memory size by half-deflection methods
424 static double EPSILON = 2 * 1024;
425 double aMax = std::max(theSize, theMinSize);
426 double aMin = std::min(theSize, theMinSize);
427 //cout<<"GetAvailableMemory - "<<aMax<<"; "<<aMin;
428 while(!CheckAvailableMemory(aMax) && CheckAvailableMemory(aMin) && (aMax - aMin) > EPSILON){
429 double aRoot = (aMax + aMin) / 2.;
430 if(CheckAvailableMemory(aRoot))
435 //cout<<"; "<<aMax<<endl;
440 //----------------------------------------------------------------------------