]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_PipeLine.cxx
Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / PIPELINE / VISU_PipeLine.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 // File:    VISU_PipeLine.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27 //
28 #include "VISU_PipeLine.hxx"
29 #include "VISU_MapperHolder.hxx"
30
31 #include "VISU_PipeLineUtils.hxx"
32
33 #include <vtkObjectFactory.h>
34 #include <vtkPlane.h>
35
36 #include <float.h>
37 #include <algorithm>
38 #include <climits>
39 #include <limits>
40
41 #ifdef _DEBUG_
42 static int MYDEBUG = 0;
43 #else
44 static int MYDEBUG = 0;
45 #endif
46
47
48 //----------------------------------------------------------------------------
49 VISU_PipeLine
50 ::VISU_PipeLine():
51   myIsShrinkable(true),
52   myIsFeatureEdgesAllowed(true)
53 {
54   if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
55 }
56
57
58 //----------------------------------------------------------------------------
59 VISU_PipeLine
60 ::~VISU_PipeLine()
61 {
62   if(MYDEBUG) MESSAGE("VISU_PipeLine::~VISU_PipeLine - "<<this);
63 }
64
65
66 //----------------------------------------------------------------------------
67 unsigned long int 
68 VISU_PipeLine
69 ::GetMTime()
70 {
71   unsigned long int aTime = Superclass::GetMTime();
72
73   if(myMapperHolder.GetPointer())
74     aTime = std::max(aTime, myMapperHolder->GetMTime());
75
76   return aTime;
77 }
78
79
80 //----------------------------------------------------------------------------
81 unsigned long int
82 VISU_PipeLine
83 ::GetMemorySize()
84 {
85   unsigned long int aSize = 0;
86
87   if(myMapperHolder.GetPointer())
88     aSize += myMapperHolder->GetMemorySize();
89   
90   return aSize;
91 }
92
93
94 //----------------------------------------------------------------------------
95 void 
96 VISU_PipeLine
97 ::ShallowCopy(VISU_PipeLine *thePipeLine,
98               bool theIsCopyInput)
99 {
100   SetImplicitFunction(thePipeLine->GetImplicitFunction());
101   DoShallowCopy(thePipeLine, theIsCopyInput);
102   Update();
103 }
104
105
106 //----------------------------------------------------------------------------
107 void 
108 VISU_PipeLine
109 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
110                 bool theIsCopyInput)
111 {
112   GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
113                                  theIsCopyInput);
114 }
115
116
117 //----------------------------------------------------------------------------
118 void
119 VISU_PipeLine
120 ::SameAs(VISU_PipeLine *thePipeLine)
121 {
122   DoShallowCopy(thePipeLine, false);
123   Update();
124 }
125
126
127 //----------------------------------------------------------------------------
128 VISU_MapperHolder* 
129 VISU_PipeLine
130 ::GetMapperHolder()
131 {
132   if(!myMapperHolder.GetPointer())
133     OnCreateMapperHolder();
134
135   return myMapperHolder.GetPointer();
136 }
137
138
139 //----------------------------------------------------------------------------
140 const VISU::PIDMapper&  
141 VISU_PipeLine
142 ::GetIDMapper()
143 {
144   return GetMapperHolder()->GetIDMapper();
145 }
146
147
148 //----------------------------------------------------------------------------
149 vtkDataSet* 
150 VISU_PipeLine
151 ::GetInput()
152 {
153   return GetMapperHolder()->GetInput();
154 }
155
156
157 //----------------------------------------------------------------------------
158 vtkMapper* 
159 VISU_PipeLine
160 ::GetMapper()
161 {
162   return GetMapperHolder()->GetMapper();
163 }
164
165
166 //----------------------------------------------------------------------------
167 vtkDataSet* 
168 VISU_PipeLine
169 ::GetOutput()
170 {
171   return GetMapperHolder()->GetOutput();
172 }
173
174
175 //----------------------------------------------------------------------------
176 bool
177 VISU_PipeLine
178 ::IsPlanarInput()
179 {
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 )
185     return true;
186
187   return false;
188 }
189
190
191 //----------------------------------------------------------------------------
192 void 
193 VISU_PipeLine
194 ::SetMapperHolder(VISU_MapperHolder* theHolder)
195 {
196   myMapperHolder = theHolder;
197   theHolder->SetPipeLine(this);
198 }
199
200
201 //----------------------------------------------------------------------------
202 void 
203 VISU_PipeLine
204 ::Init()
205 {}
206
207
208 //----------------------------------------------------------------------------
209 void 
210 VISU_PipeLine
211 ::Update()
212 {
213   GetMapperHolder()->Update();
214 }
215
216
217 //----------------------------------------------------------------------------
218 vtkIdType 
219 VISU_PipeLine
220 ::GetNodeObjID(vtkIdType theID)
221 {
222   return GetMapperHolder()->GetNodeObjID(theID);
223 }
224
225 //----------------------------------------------------------------------------
226 vtkIdType 
227 VISU_PipeLine
228 ::GetNodeVTKID(vtkIdType theID)
229 {
230   return GetMapperHolder()->GetNodeVTKID(theID);
231 }
232
233 //----------------------------------------------------------------------------
234 vtkFloatingPointType* 
235 VISU_PipeLine
236 ::GetNodeCoord(vtkIdType theObjID)
237 {
238   return GetMapperHolder()->GetNodeCoord(theObjID);
239 }
240
241
242 //----------------------------------------------------------------------------
243 vtkIdType 
244 VISU_PipeLine
245 ::GetElemObjID(vtkIdType theID)
246 {
247   return GetMapperHolder()->GetElemObjID(theID);
248 }
249
250 //----------------------------------------------------------------------------
251 vtkIdType
252 VISU_PipeLine
253 ::GetElemVTKID(vtkIdType theID)
254 {
255   return GetMapperHolder()->GetElemVTKID(theID);
256 }
257
258 //----------------------------------------------------------------------------
259 vtkCell* 
260 VISU_PipeLine
261 ::GetElemCell(vtkIdType  theObjID)
262 {
263   return GetMapperHolder()->GetElemCell(theObjID);
264 }
265
266
267 //----------------------------------------------------------------------------
268 bool 
269 VISU_PipeLine
270 ::IsShrinkable()
271 {
272   return myIsShrinkable;
273 }
274
275 void 
276 VISU_PipeLine
277 ::SetIsShrinkable(bool theIsShrinkable)
278 {
279   if(myIsShrinkable == theIsShrinkable)
280     return;
281
282   myIsShrinkable = theIsShrinkable;
283   Modified();
284 }
285
286
287 //----------------------------------------------------------------------------
288 bool 
289 VISU_PipeLine
290 ::IsFeatureEdgesAllowed()
291 {
292   return myIsFeatureEdgesAllowed;
293 }
294
295 void 
296 VISU_PipeLine
297 ::SetIsFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
298 {
299   if(myIsFeatureEdgesAllowed == theIsFeatureEdgesAllowed)
300     return;
301
302   myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
303   Modified();
304 }
305
306
307 //----------------------------------------------------------------------------
308 void
309 VISU_PipeLine
310 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
311 {
312   GetMapperHolder()->SetImplicitFunction(theFunction);
313
314
315 //----------------------------------------------------------------------------
316 vtkImplicitFunction * 
317 VISU_PipeLine
318 ::GetImplicitFunction()
319 {
320   return GetMapperHolder()->GetImplicitFunction();
321 }
322
323 //----------------------------------------------------------------------------
324 void
325 VISU_PipeLine
326 ::SetExtractInside(bool theMode)
327 {
328   GetMapperHolder()->SetExtractInside(theMode);
329 }
330
331 //----------------------------------------------------------------------------
332 void
333 VISU_PipeLine
334 ::SetExtractBoundaryCells(bool theMode)
335 {
336   GetMapperHolder()->SetExtractBoundaryCells(theMode);
337 }
338
339
340 //----------------------------------------------------------------------------
341 void
342 VISU_PipeLine
343 ::RemoveAllClippingPlanes()
344 {
345   GetMapperHolder()->RemoveAllClippingPlanes();
346 }
347
348 //----------------------------------------------------------------------------
349 vtkIdType
350 VISU_PipeLine
351 ::GetNumberOfClippingPlanes()
352 {
353   return GetMapperHolder()->GetNumberOfClippingPlanes();
354 }
355
356 //----------------------------------------------------------------------------
357 bool 
358 VISU_PipeLine
359 ::AddClippingPlane(vtkPlane* thePlane)
360 {
361   return GetMapperHolder()->AddClippingPlane(thePlane);
362 }
363
364 //----------------------------------------------------------------------------
365 vtkPlane* 
366 VISU_PipeLine
367 ::GetClippingPlane(vtkIdType theID)
368 {
369   return GetMapperHolder()->GetClippingPlane(theID);
370 }
371
372 //----------------------------------------------------------------------------
373 void VISU_PipeLine::RemoveClippingPlane(vtkIdType theID)
374 {
375   return GetMapperHolder()->RemoveClippingPlane(theID);
376 }
377
378 //----------------------------------------------------------------------------
379 vtkDataSet* 
380 VISU_PipeLine
381 ::GetClippedInput()
382 {
383   return GetMapperHolder()->GetClippedInput();
384 }
385
386
387 //----------------------------------------------------------------------------
388 void
389 VISU_PipeLine
390 ::SetPlaneParam(vtkFloatingPointType theDir[3], 
391                 vtkFloatingPointType theDist, 
392                 vtkPlane* thePlane)
393 {
394   thePlane->SetNormal(theDir);
395
396   vtkFloatingPointType anOrigin[3];
397   VISU::DistanceToPosition(GetInput(),
398                            theDir,
399                            theDist,
400                            anOrigin);
401
402   thePlane->SetOrigin(anOrigin);
403 }
404
405
406 //----------------------------------------------------------------------------
407 void
408 VISU_PipeLine
409 ::GetPlaneParam(vtkFloatingPointType theDir[3], 
410                 vtkFloatingPointType& theDist, 
411                 vtkPlane* thePlane)
412 {
413   thePlane->GetNormal(theDir);
414
415   vtkFloatingPointType anOrigin[3];
416   thePlane->GetOrigin(anOrigin);
417
418   VISU::PositionToDistance(GetInput(),
419                              theDir,
420                              anOrigin,
421                              theDist);
422 }
423
424
425 //----------------------------------------------------------------------------
426 size_t
427 VISU_PipeLine
428 ::CheckAvailableMemory(double theSize)
429 {
430   if(theSize < ULONG_MAX){
431     try{
432       size_t aSize = size_t(theSize);
433       if(char *aCheck = new char[aSize]){
434         delete [] aCheck;
435         return aSize;
436       }
437     }catch(std::bad_alloc& exc){
438     }catch(...){
439     }
440   }
441   return 0;
442 }
443
444
445 //----------------------------------------------------------------------------
446 size_t
447 VISU_PipeLine
448 ::GetAvailableMemory(double theSize, 
449                      double theMinSize)
450 {
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))
459       aMin = aRoot;
460     else
461       aMax = aRoot;
462   }
463   //cout<<"; "<<aMax<<endl;
464   return (size_t)aMax;
465 }
466
467
468 //----------------------------------------------------------------------------