PluginFunctions.cc 18.3 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16
17
18
19
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  Plugin Functions
//
//=============================================================================

#include <OpenFlipper/common/Types.hh>

#include "PluginFunctions.hh"

namespace PluginFunctions {

 /** \brief DONT USE DIRECTLY!!
  *
  * This Pointer will be used to access the data trees root in the plugin. Never use it directly as
 *  the internal Structure will change. Use the Access functions instead */
static BaseObject* objectRoot_;

/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is internally used to acces the examiner widget in the main apllication
 */
Jan Möbius's avatar
Jan Möbius committed
57
58
59
60
61
62
static std::vector< ACG::QtWidgets::QtExaminerViewer* > examiner_widgets_;

/// TODO : Remove this variable and implement multiView correctly here
static ACG::QtWidgets::QtExaminerViewer*  examiner_widget_;

static unsigned int activeExaminer_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
63
64
65
66
67
68
69

/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is internally used to access the scenegraphs root node
 */
static SeparatorNode* root_node_;

Dirk Wilden's avatar
Dirk Wilden committed
70
71
static SeparatorNode* sceneGraph_root_node_;

Jan Möbius's avatar
 
Jan Möbius committed
72
73
74
75
void setDataRoot( BaseObject* _root ) {
   objectRoot_ = _root;
}

Jan Möbius's avatar
Jan Möbius committed
76
77
78
79
80
81
82
void set_examiner( std::vector< ACG::QtWidgets::QtExaminerViewer* > _examiner_widgets ) {
   PluginFunctions::examiner_widgets_ = _examiner_widgets;
   PluginFunctions::examiner_widget_ =  examiner_widgets_[0];
}

void setActiveExaminer( unsigned int _id ) {
  activeExaminer_ = _id;
Jan Möbius's avatar
 
Jan Möbius committed
83
84
85
86
87
88
}

void set_rootNode( SeparatorNode* _root_node ) {
   PluginFunctions::root_node_ = _root_node;
}

Dirk Wilden's avatar
Dirk Wilden committed
89
90
91
92
void set_sceneGraphRootNode( SeparatorNode* _root_node ) {
   PluginFunctions::sceneGraph_root_node_ = _root_node;
}

Jan Möbius's avatar
 
Jan Möbius committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
bool get_source_meshes( std::vector<TriMesh*>& _meshes  ) {
  _meshes.clear();

  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    if (! o_it->source() )
      continue;
    _meshes.push_back ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() );
  }

  return (_meshes.size() > 0 );
}

bool get_source_meshes( std::vector<PolyMesh*>& _meshes  ) {
  _meshes.clear();

  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_POLY_MESH) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    if (! o_it->source() )
      continue;
    _meshes.push_back ( dynamic_cast< PolyMeshObject* >( *o_it )->mesh() );
  }

  return (_meshes.size() > 0 );
}


bool get_target_meshes( std::vector<TriMesh*>& _meshes  ) {
  _meshes.clear();

  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    if (! o_it->target() )
      continue;
    if ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() )
      _meshes.push_back ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() );
  }

  return (_meshes.size() > 0 );
}

bool get_target_meshes( std::vector<PolyMesh*>& _meshes  ) {
  _meshes.clear();

  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_POLY_MESH) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    if (! o_it->target() )
      continue;
    if ( dynamic_cast< PolyMeshObject* >( *o_it )->mesh() )
      _meshes.push_back ( dynamic_cast< PolyMeshObject* >( *o_it )->mesh() );
  }

  return (_meshes.size() > 0 );
}


bool get_picked_object(uint _node_idx , BaseObjectData*& _object) {
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    if ( o_it->picked( _node_idx ) ) {
      _object = *o_it;
      return true;
    }
  }
  return false;
}


bool get_source_identifiers( std::vector<int>& _identifiers  ) {
  _identifiers.clear();

  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    if ( o_it->source() )
      _identifiers.push_back ( o_it->id() );
  }
  return (_identifiers.size() >0 );
}

bool get_target_identifiers( std::vector<int>& _identifiers  ) {
  _identifiers.clear();

  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    if ( o_it->target() )
      _identifiers.push_back ( o_it->id() );
  }
  return (_identifiers.size() >0 );
}

// ===============================================================================
// Get objects
// ===============================================================================

bool get_object(  int _identifier , BaseObject*& _object ) {
181

Jan Möbius's avatar
 
Jan Möbius committed
182
183
  if ( _identifier == -1 )
    return false;
184

Jan Möbius's avatar
 
Jan Möbius committed
185
186
187
188
189
  _object = objectRoot_->childExists( _identifier );
  return ( _object != 0 );
}

bool get_object(  int _identifier , BaseObjectData*& _object ) {
190

Jan Möbius's avatar
 
Jan Möbius committed
191
192
  if ( _identifier == -1 )
    return false;
193

Jan Möbius's avatar
 
Jan Möbius committed
194
195
196
197
198
199
  BaseObject* object = objectRoot_->childExists( _identifier );
  _object = dynamic_cast< BaseObjectData* >(object);
  return ( _object != 0 );
}

bool get_object(  int _identifier , TriMeshObject*& _object ) {
200

Jan Möbius's avatar
 
Jan Möbius committed
201
202
  if ( _identifier == -1 )
    return false;
203

Jan Möbius's avatar
 
Jan Möbius committed
204
205
206
207
208
209
  BaseObject* object = objectRoot_->childExists( _identifier );
  _object = dynamic_cast< TriMeshObject* >(object);
  return ( _object != 0 );
}

bool get_object(  int _identifier , PolyMeshObject*& _object ) {
210

Jan Möbius's avatar
 
Jan Möbius committed
211
212
  if ( _identifier == -1 )
    return false;
213

Jan Möbius's avatar
 
Jan Möbius committed
214
215
216
217
218
219
220
221
222
223
  BaseObject* object = objectRoot_->childExists( _identifier );
  _object = dynamic_cast< PolyMeshObject* >(object);
  return ( _object != 0 );
}

// ===============================================================================
// ===============================================================================


bool get_mesh(  int _identifier , TriMesh*& _mesh ) {
224

Jan Möbius's avatar
 
Jan Möbius committed
225
226
  if ( _identifier == -1 )
    return false;
227

Jan Möbius's avatar
 
Jan Möbius committed
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
  BaseObject* object = objectRoot_->childExists( _identifier );

  // Unable to find object
  if ( object == 0)
    return false;

  TriMeshObject* triangleMeshObject = dynamic_cast< TriMeshObject* > (object);

  // Object is not a triangle mesh
  if ( triangleMeshObject == 0)
    return false;

  _mesh = triangleMeshObject->mesh();
  return true;
}

bool get_mesh(  int _identifier , PolyMesh*& _mesh ) {
245

Jan Möbius's avatar
 
Jan Möbius committed
246
247
  if ( _identifier == -1 )
    return false;
248

Jan Möbius's avatar
 
Jan Möbius committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
  BaseObject* object = objectRoot_->childExists( _identifier );

  // Unable to find object
  if ( object == 0)
    return false;

  PolyMeshObject* polyMeshObject = dynamic_cast< PolyMeshObject* > (object);

  // Object is not a triangle mesh
  if ( polyMeshObject == 0)
    return false;

  _mesh = polyMeshObject->mesh();
  return true;
}

bool deleteObject( int _id ) {
266

Jan Möbius's avatar
 
Jan Möbius committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  if ( _id == -1 )
    return false;

  // get the node
  BaseObject* object = objectRoot_->childExists(_id);

  if ( !object || object == objectRoot() ) {
    std::cerr << "Error while deleting object, does not exist!!" << std::endl;
    return false;
  }

  // remove the whole subtree below this item
  object->deleteSubtree();

  // remove the item itself from the parent
  object->parent()->removeChild(object);

  // delete it
  delete object;

  return true;
}

void deleteAll( ) {
  objectRoot()->deleteSubtree();
}

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
int copyObject( int _id ) {
  if ( _id == -1 )
    return -1;

  // get the node
  BaseObject* object = objectRoot_->childExists(_id);

  if ( !object ) {
    std::cerr << "Error while copying object ... not found" << std::endl;
    return -1;
  }

  // remove the whole subtree below this item
  BaseObject* copy = object->copy();

  if ( copy == 0 ) {
    std::cerr << "Unable to create a copy of the object." << std::endl;
  }

  // Integrate into object tree
  copy->setParent( object->parent() );
  if ( object->parent() )
    object->parent()->appendChild(copy);
  else
    std::cerr << "Unable to add copy to object list" << std::endl;

  return copy->id();
}
Jan Möbius's avatar
 
Jan Möbius committed
322
323

bool object_exists(  int _identifier ) {
324

Jan Möbius's avatar
 
Jan Möbius committed
325
326
  if ( _identifier == -1 )
    return false;
327

Jan Möbius's avatar
 
Jan Möbius committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  BaseObject* object = objectRoot_->childExists( _identifier );
  return ( object != 0 );
}

//===============================================================================

bool get_all_meshes( std::vector<int>& _identifiers  ) {

  _identifiers.clear();

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ;
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
    _identifiers.push_back( o_it->id() );
  }

  return (_identifiers.size() > 0);
}

bool get_all_object_identifiers( std::vector<int>& _identifiers  ) {

  _identifiers.clear();

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
    _identifiers.push_back( o_it->id() );
  }

  return (_identifiers.size() > 0);
}

void setBackColor( OpenMesh::Vec4f _color) {
Jan Möbius's avatar
Jan Möbius committed
361
  examiner_widgets_[activeExaminer_]->backgroundColor(_color);
Jan Möbius's avatar
 
Jan Möbius committed
362
363
364
}

QPoint mapToGlobal(QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
365
  return examiner_widgets_[activeExaminer_]->glMapToGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
366
367
368
}

QPoint mapToLocal( QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
369
  return examiner_widgets_[activeExaminer_]->glMapFromGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
370
371
372
373
374
375
376
377
}

/** Set the draw Mode of the examiner widget.\n
 *
 * The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
 * They can be combined.
 */
void setDrawMode( unsigned int _mode ) {
Jan Möbius's avatar
Jan Möbius committed
378
379
380
381
  for ( uint i = 0 ; i < examiner_widgets_.size() ; ++i ) {
    examiner_widgets_[i]->drawMode(_mode);
    examiner_widgets_[i]->updateGL();
  }
Jan Möbius's avatar
 
Jan Möbius committed
382
383
384
385
386
387
388
389
390
391
392
393
}

/** Get the current draw Mode of the examiner widget.\n
 *
 * The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
 * They can be combined.
 */
unsigned int drawMode( ) {
  return examiner_widget_->drawMode();
}

bool scenegraph_pick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
Jan Möbius's avatar
Jan Möbius committed
394
395
396
397
398
399
400
401
402
403
404

   return examiner_widgets_[activeExaminer_]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
}

bool scenegraph_pick( unsigned int _examiner, ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {

  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return false;
  }
  return examiner_widgets_[_examiner]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
Jan Möbius's avatar
 
Jan Möbius committed
405
406
407
408
409
}


//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction  &_action ) {
Jan Möbius's avatar
Jan Möbius committed
410
411
   ACG::SceneGraph::traverse(PluginFunctions::examiner_widgets_[activeExaminer_]->sceneGraph(),
                             _action,PluginFunctions::examiner_widgets_[activeExaminer_]->glState() );
Jan Möbius's avatar
 
Jan Möbius committed
412
413
}

Jan Möbius's avatar
Jan Möbius committed
414
415
416
417
418
419
420
421
422
423
424
425
//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse(  unsigned int _examiner, ACG::SceneGraph::MouseEventAction  &_action ) {

  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return;
  }

  ACG::SceneGraph::traverse(PluginFunctions::examiner_widgets_[_examiner]->sceneGraph(), _action,PluginFunctions::examiner_widgets_[_examiner]->glState() );
}


Jan Möbius's avatar
 
Jan Möbius committed
426
427
428
429
430
const std::string & pickMode () {
   return examiner_widget_->pickMode();
}

void pickMode ( std::string _mode) {
Jan Möbius's avatar
Jan Möbius committed
431
432
433
434
435
436
437
438
439
440
441
  for ( uint i = 0 ; i < examiner_widgets_.size() ; ++i )
    examiner_widgets_[i]->pickMode(_mode);
}

void pickMode ( unsigned int _examiner, std::string _mode) {
  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return;
  }

  examiner_widgets_[_examiner]->pickMode(_mode);
Jan Möbius's avatar
 
Jan Möbius committed
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
}

void actionMode ( ACG::QtWidgets::QtBaseViewer::ActionMode _mode) {
  examiner_widget_->actionMode(_mode);
}

ACG::GLState&  glState() {
   return examiner_widget_->glState();
}

void getCurrentViewImage(QImage& _image) {
  examiner_widget_->copyToImage( _image );
}

ACG::QtWidgets::QtBaseViewer::ActionMode actionMode() {
   return examiner_widget_->actionMode();
}

void perspectiveProjection() {
  examiner_widget_->perspectiveProjection();
}

void orthographicProjection() {
  examiner_widget_->orthographicProjection();
}

void allowRotation(bool _mode) {
  examiner_widget_->allowRotation(_mode);
}

void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up) {
  examiner_widget_->viewingDirection(_dir,_up);
}


void setScenePos(const ACG::Vec3d& _center, double _radius) {
  examiner_widget_->setScenePos( _center, _radius );
}

void setScenePos(const ACG::Vec3d& _center) {
  examiner_widget_->setScenePos( _center, examiner_widget_->scene_radius() );
}

const ACG::Vec3d& sceneCenter() {
   return examiner_widget_->scene_center();
}

double sceneRadius() {
   return examiner_widget_->scene_radius();
}

void translate( const ACG::Vec3d &_vector ) {
  examiner_widget_->translate(_vector);
}

497
498
void rotate(const ACG::Vec3d&  _axis,
            double             _angle,
Jan Möbius's avatar
 
Jan Möbius committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512
            const ACG::Vec3d&  _center)
{
  examiner_widget_->rotate(_axis,_angle,_center);
}

void viewHome() {
  examiner_widget_->home();
}

void viewAll() {
  examiner_widget_->viewAll();
}

ACG::Vec3d viewingDirection() {
513
  return examiner_widget_->glState().viewing_direction();
Jan Möbius's avatar
 
Jan Möbius committed
514
515
516
}

ACG::Vec3d eyePos() {
517
  return examiner_widget_->glState().eye();
Jan Möbius's avatar
 
Jan Möbius committed
518
519
520
521
522
523
524
}

ACG::Vec3d upVector() {
  return examiner_widget_->glState().up();
}


Dirk Wilden's avatar
Dirk Wilden committed
525
526
527
528
ACG::SceneGraph::BaseNode* getSceneGraphRootNode() {
   return PluginFunctions::sceneGraph_root_node_;
}

Jan Möbius's avatar
 
Jan Möbius committed
529
530
531
532
ACG::SceneGraph::BaseNode* getRootNode() {
   return PluginFunctions::root_node_;
}

Dirk Wilden's avatar
Dirk Wilden committed
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
void addNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::root_node_)
    _node->set_parent( PluginFunctions::root_node_ );
}

void addGlobalNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::sceneGraph_root_node_){
    //set node as new parent for root's children
    while( PluginFunctions::sceneGraph_root_node_->nChildren() > 0 ){
      ACG::SceneGraph::BaseNode* child = *(PluginFunctions::sceneGraph_root_node_->childrenBegin());
      child->set_parent( _node );
    }

    _node->set_parent( PluginFunctions::sceneGraph_root_node_ );
  }
}

Jan Möbius's avatar
 
Jan Möbius committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
int object_count() {

  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
    ++count;
  }

  return ( count );

}

int target_count() {

  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
    ++count;
  }

  return ( count );
}

int source_count() {
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS) ;
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
    ++count;
  }

  return ( count );
}

int visible_count() {
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
    if ( o_it->visible() )
    ++count;
  }

  return ( count );

}


/** Returns a vector containing all currently available objects
 *
 * @param _objects vector of all objects
 */
void get_all_objects( std::vector < BaseObjectData*>& _objects ) {

   _objects.clear();

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ;
                                        o_it != PluginFunctions::objects_end(); ++o_it)  {
    _objects.push_back( *o_it );
  }

}

///   Fly to point and viewing direction (animated).
void   flyTo (const TriMesh::Point &_position, const TriMesh::Point &_center, double _time) {
   examiner_widget_->flyTo((ACG::Vec3d)_position,(ACG::Vec3d)_center,_time);
}


// ===============================================================================
// Getting data from objects and casting between them
// ===============================================================================

BaseObjectData* baseObjectData( BaseObject* _object ){
  if ( _object == 0 )
    return 0;
633

Jan Möbius's avatar
 
Jan Möbius committed
634
635
636
637
638
639
  return dynamic_cast< BaseObjectData* >(_object);
}

TriMesh* triMesh( BaseObjectData* _object ) {
  if ( _object == 0 )
    return 0;
640

Jan Möbius's avatar
 
Jan Möbius committed
641
642
643
644
645
646
647
648
649
650
  if ( _object->dataType(DATA_TRIANGLE_MESH) ) {
    TriMeshObject* object = dynamic_cast< TriMeshObject* >(_object);
    return object->mesh();
  } else
    return NULL;
}

PolyMesh* polyMesh( BaseObjectData* _object ) {
  if ( _object == 0 )
    return 0;
651

Jan Möbius's avatar
 
Jan Möbius committed
652
653
654
655
656
657
658
659
660
661
  if ( _object->dataType(DATA_POLY_MESH) ) {
    PolyMeshObject* object = dynamic_cast< PolyMeshObject* >(_object);
    return object->mesh();
  } else
    return NULL;
}

TriMeshObject* triMeshObject( BaseObjectData* _object ) {
  if ( _object == 0 )
    return 0;
662

Jan Möbius's avatar
 
Jan Möbius committed
663
664
665
666
667
668
669
670
  if ( ! _object->dataType(DATA_TRIANGLE_MESH) )
    return NULL;
  return dynamic_cast< TriMeshObject* >( _object );
}

PolyMeshObject* polyMeshObject( BaseObjectData* _object ) {
  if ( _object == 0 )
    return 0;
671

Jan Möbius's avatar
 
Jan Möbius committed
672
673
674
675
676
677
678
679
680
681
  if ( ! _object->dataType(DATA_POLY_MESH) )
    return NULL;
  return dynamic_cast< PolyMeshObject* >( _object );
}



// ===============================================================================
// Get the root of the object structure
// ===============================================================================
Jan Möbius's avatar
Jan Möbius committed
682
BaseObject*& objectRoot() {
Jan Möbius's avatar
 
Jan Möbius committed
683
684
685
686
  return (objectRoot_);
}

}