root/cgm/trunk/geom/virtual/CompositeBody.cpp

Revision 1040, 8.9 KB (checked in by tautges, 2 years ago)

Version 10.2 of cgm.

Line 
1//-------------------------------------------------------------------------
2// Filename      : CompositeBody.cpp
3//
4// Purpose       : Composite of BodySMs
5//
6// Special Notes :
7//
8// Creator       : Jason Kraftcheck
9//
10// Creation Date : 01/11/02
11//-------------------------------------------------------------------------
12
13#include "DLIList.hpp"
14#include "CompositeBody.hpp"
15#include "CompositeLump.hpp"
16#include "VirtualQueryEngine.hpp"
17#include "CompositeEngine.hpp"
18
19CompositeBody::CompositeBody()
20  : firstLump(0)
21{
22}
23
24CompositeBody::~CompositeBody()
25{
26  int i;
27 
28  for( i = 0; i < realBodies.size(); i++ )
29    if( realBodies[i]->owner() == this )
30      realBodies[i]->owner(0);
31 
32  while( firstLump )
33    remove( firstLump );
34}
35
36
37CompositeLump* CompositeBody::next_lump( CompositeLump* prev ) const
38{
39  return prev ? prev->nextLump : firstLump;
40}
41
42CubitStatus CompositeBody::add( CompositeLump* lump )
43{
44  if( lump->myBody != 0 )
45    return CUBIT_FAILURE;
46   
47  lump->myBody = this;
48  lump->nextLump = firstLump;
49  firstLump = lump;
50  return CUBIT_SUCCESS;
51}
52
53CubitStatus CompositeBody::remove( CompositeLump* lump )
54{
55  if( lump->myBody != this )
56    return CUBIT_FAILURE;
57 
58  if( firstLump == lump )
59  {
60    firstLump = lump->nextLump;
61  }
62  else
63  {
64    CompositeLump* prev = firstLump; 
65    while( prev && prev->nextLump != lump )
66      prev = prev->nextLump;
67    assert( prev != NULL );
68   
69    prev->nextLump = lump->nextLump;
70  }
71 
72  lump->myBody = 0;
73  lump->nextLump = 0;
74  return CUBIT_SUCCESS;
75}
76
77CubitStatus CompositeBody::add( BodySM* body )
78{
79  if( index_of( body ) >= 0  )
80    return CUBIT_FAILURE;
81   
82  if( body->owner() )
83    body->owner()->swap_bridge( body, this, false );
84  body->owner(this);
85 
86  realBodies.push( body );
87  return CUBIT_SUCCESS;
88}
89
90CubitStatus CompositeBody::remove( BodySM* body )
91  { return remove_body( index_of( body ) ); }
92
93CubitStatus CompositeBody::remove_body( int index )
94{
95  if( index < 0 ) return CUBIT_FAILURE;
96 
97  if( realBodies[index]->owner() == this )
98    realBodies[index]->owner(0);
99  realBodies.remove(index);
100  return CUBIT_SUCCESS;
101}
102/*
103CubitStatus CompositeBody::move( const CubitVector& offset )
104{
105  int i;
106  for (i = 0; i < realBodies.size(); i++)
107    if (CUBIT_SUCCESS != realBodies[i]->move( offset ))
108      break;
109 
110  if (i == realBodies.size())
111    return CUBIT_SUCCESS;
112 
113  for (int j = 0; j < i; j++)
114    realBodies[j]->move( -offset );
115  return CUBIT_FAILURE;
116}
117
118
119CubitStatus CompositeBody::rotate( const CubitVector& axis, double angle )
120{
121  int i;
122  for (i = 0; i < realBodies.size(); i++)
123    if (CUBIT_SUCCESS != realBodies[i]->rotate( axis, angle ))
124      break;
125 
126  if (i == realBodies.size())
127    return CUBIT_SUCCESS;
128 
129  for (int j = 0; j < i; j++)
130    realBodies[j]->rotate( axis, -angle );
131  return CUBIT_FAILURE;
132}
133
134CubitStatus CompositeBody::scale( double factor )
135{
136  int i;
137  for (i = 0; i < realBodies.size(); i++)
138    if (CUBIT_SUCCESS != realBodies[i]->scale( factor ))
139      break;
140 
141  if (i == realBodies.size())
142    return CUBIT_SUCCESS;
143 
144  for (int j = 0; j < i; j++)
145    realBodies[j]->scale( 1.0/factor );
146  return CUBIT_FAILURE;
147}
148
149CubitStatus CompositeBody::scale( const CubitVector& factors )
150{
151  int i;
152  for (i = 0; i < realBodies.size(); i++)
153    if (CUBIT_SUCCESS != realBodies[i]->scale( factors ))
154      break;
155 
156  if (i == realBodies.size())
157    return CUBIT_SUCCESS;
158 
159  const CubitVector unscale( 1.0/factors.x(), 1.0/factors.y(), 1.0/factors.z() );
160  for (int j = 0; j < i; j++)
161    realBodies[j]->scale( unscale );
162  return CUBIT_FAILURE;
163}
164
165 
166CubitStatus CompositeBody::reflect( const CubitVector& axis )
167{
168  int i;
169  for (i = 0; i < realBodies.size(); i++)
170    if (CUBIT_SUCCESS != realBodies[i]->reflect( axis ))
171      break;
172 
173  if (i == realBodies.size())
174    return CUBIT_SUCCESS;
175 
176  for (int j = 0; j < i; j++)
177    realBodies[j]->reflect( axis );
178  return CUBIT_FAILURE;
179}
180   
181
182CubitStatus CompositeBody::restore()
183  { return CUBIT_FAILURE; }
184
185CubitStatus CompositeBody::reverse()
186  { return CUBIT_FAILURE; }
187*/
188CubitStatus CompositeBody::get_transforms( CubitTransformMatrix& )
189  { return CUBIT_FAILURE; }
190
191void CompositeBody::get_parents_virt( DLIList<TopologyBridge*>& )
192  { }
193
194void CompositeBody::get_children_virt( DLIList<TopologyBridge*>& children )
195{
196  for( CompositeLump* lump = firstLump; lump; lump = lump->nextLump )
197    children.append( lump );
198}
199
200
201//-------------------------------------------------------------------------
202// Purpose       : Get CompositeEngine
203//
204// Special Notes :
205//
206// Creator       : Jason Kraftcheck
207//
208// Creation Date : 01/11/02
209//-------------------------------------------------------------------------
210GeometryQueryEngine* CompositeBody::get_geometry_query_engine() const
211  { return VirtualQueryEngine::instance(); }
212
213 
214CubitStatus CompositeBody::remove_bridge( TopologyBridge* bridge )
215{
216  int i;
217  for (i = realBodies.size() - 1; i >= 0 && realBodies[i] != bridge; --i);
218  if (i < 0)
219    return CUBIT_FAILURE;
220 
221  assert( bridge->owner() == this );
222  bridge->owner( 0 );
223  realBodies.remove( i );
224 
225  if (realBodies.size() == 0)
226    CompositeEngine::instance().notify_deactivated( this );
227 
228  return CUBIT_SUCCESS;
229}
230 
231 
232CubitStatus CompositeBody::swap_bridge( TopologyBridge* old_tb, 
233                                        TopologyBridge* new_tb,
234                                        bool )
235{
236  if( new_tb->owner() )
237    return CUBIT_FAILURE;
238 
239  BodySM* new_body = dynamic_cast<BodySM*>(new_tb);
240  BodySM* old_body = dynamic_cast<BodySM*>(old_tb);
241  int index = realBodies.find( old_body );
242  if( index >= 0 && new_body != 0 && realBodies.find(new_body) < 0 )
243  {
244    if( old_body->owner() == this )
245      old_body->owner(0);
246    new_body->owner(this);
247    realBodies[index] = new_body;
248    return CUBIT_SUCCESS;
249  }
250 
251  return CUBIT_FAILURE;
252}
253 
254CubitBoolean CompositeBody::contains_bridge( TopologyBridge* bridge ) const
255{
256  return index_of(dynamic_cast<BodySM*>(bridge)) < 0 ? CUBIT_FALSE : CUBIT_TRUE;
257}
258
259void CompositeBody::notify_reversed( TopologyBridge* )
260  { assert(0); }
261
262//-------------------------------------------------------------------------
263// Purpose       : Attribute functions
264//
265// Special Notes :
266//
267// Creator       : Jason Kraftcheck
268//
269// Creation Date : 01/11/02
270//-------------------------------------------------------------------------
271void CompositeBody::append_simple_attribute_virt( CubitSimpleAttrib* )
272{ }
273void CompositeBody::remove_simple_attribute_virt( CubitSimpleAttrib* )
274{ }
275void CompositeBody::remove_all_simple_attribute_virt()
276{ }
277CubitStatus CompositeBody::get_simple_attribute( DLIList<CubitSimpleAttrib*>& )
278{ return CUBIT_FAILURE; }
279CubitStatus CompositeBody::get_simple_attribute(
280                                        const CubitString& , DLIList<CubitSimpleAttrib*>& )
281{ return CUBIT_FAILURE; }
282
283//-------------------------------------------------------------------------
284// Purpose       :
285//
286// Special Notes :
287//
288// Creator       : Jason Kraftcheck
289//
290// Creation Date : 05/10/04
291//-------------------------------------------------------------------------
292CubitPointContainment CompositeBody::point_containment( const CubitVector& pos )
293{
294  int inside = 0;
295  int boundary = 0;
296 
297  for (int i = 0; i < realBodies.size(); ++i)
298  {
299    switch( realBodies[i]->point_containment( pos ) )
300    {
301      case CUBIT_PNT_BOUNDARY:
302        boundary++;
303        break;
304      case CUBIT_PNT_INSIDE:
305        inside++;
306        break;
307      case CUBIT_PNT_OUTSIDE:
308        break;
309      default:
310        return CUBIT_PNT_UNKNOWN;
311    }
312  }
313 
314  if (inside)
315    return CUBIT_PNT_INSIDE;
316  else if (boundary > 1)
317    return CUBIT_PNT_INSIDE;
318  else if (boundary)
319    return CUBIT_PNT_BOUNDARY;
320  else
321    return CUBIT_PNT_OUTSIDE;
322}
323
324//-------------------------------------------------------------------------
325// Purpose       :
326//
327// Special Notes :
328//
329// Creator       : Jason Kraftcheck
330//
331// Creation Date : 05/10/04
332//-------------------------------------------------------------------------
333CubitStatus CompositeBody::mass_properties( CubitVector& result,
334                                            double& volume )
335{
336  double vol;
337  CubitVector centroid;
338  result.set( 0.0, 0.0, 0.0 );
339  volume = 0;
340 
341  for (int i = 0; i < realBodies.size(); ++i)
342  {
343    if (CUBIT_FAILURE == realBodies[i]->mass_properties( centroid, vol ))
344      return CUBIT_FAILURE;
345   
346    result += vol * centroid;
347    volume += vol;
348  }
349 
350  if (volume > CUBIT_RESABS)
351    result /= volume;
352  return CUBIT_SUCCESS;
353}
354
355//-------------------------------------------------------------------------
356// Purpose       : Combine
357//
358// Special Notes :
359//
360// Creator       : Jason Kraftcheck
361//
362// Creation Date : 06/11/04
363//-------------------------------------------------------------------------
364void CompositeBody::combine( CompositeBody* other )
365{
366  int oldsize = realBodies.size();
367  realBodies.size( oldsize + other->realBodies.size() );
368  for (int i = 0; i < other->realBodies.size(); i++)
369  {
370    BodySM* bod = other->realBodies[i];
371    realBodies[i+oldsize] = bod;
372    bod->owner(this);
373  }
374  other->realBodies.size(0);
375}
376 
Note: See TracBrowser for help on using the browser.