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