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