Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PluginFunctionsTriangleMesh.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision: 13237 $ *
38 * $LastChangedBy: moebius $ *
39 * $Date: 2012-01-06 10:36:40 +0100 (Fr, 06 Jan 2012) $ *
40 * *
41 \*===========================================================================*/
42 
43 
44 
45 
46 //=============================================================================
47 //
48 // Plugin Functions
49 //
50 //=============================================================================
51 
53 
56 
57 namespace PluginFunctions {
58 
59 bool getSourceMeshes( std::vector<TriMesh*>& _meshes ) {
60  _meshes.clear();
61 
63  if (! o_it->source() )
64  continue;
65  _meshes.push_back ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() );
66  }
67 
68  return ( !_meshes.empty() );
69 }
70 
71 bool getTargetMeshes( std::vector<TriMesh*>& _meshes ) {
72  _meshes.clear();
73 
75  if (! o_it->target() )
76  continue;
77  if ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() )
78  _meshes.push_back ( dynamic_cast< TriMeshObject* >( *o_it )->mesh() );
79  }
80 
81  return ( !_meshes.empty() );
82 }
83 
84 
85 bool getObject( int _identifier , TriMeshObject*& _object ) {
86 
87  if ( _identifier == -1 ) {
88  _object = 0;
89  return false;
90  }
91 
92  BaseObject* object = objectRoot()->childExists( _identifier );
93  _object = dynamic_cast< TriMeshObject* >(object);
94  return ( _object != 0 );
95 }
96 
97 // ===============================================================================
98 // ===============================================================================
99 
100 
101 bool getMesh( int _identifier , TriMesh*& _mesh ) {
102 
103  if ( _identifier == -1 ) {
104  _mesh = 0;
105  return false;
106  }
107 
108  BaseObject* object = objectRoot()->childExists( _identifier );
109 
110  // Unable to find object
111  if ( object == 0)
112  return false;
113 
114  TriMeshObject* triangleMeshObject = dynamic_cast< TriMeshObject* > (object);
115 
116  // Object is not a triangle mesh
117  if ( triangleMeshObject == 0)
118  return false;
119 
120  _mesh = triangleMeshObject->mesh();
121  return true;
122 }
123 
124 
125 // ===============================================================================
126 // Getting data from objects and casting between them
127 // ===============================================================================
128 
129 TriMesh* triMesh( BaseObjectData* _object ) {
130 
131  if ( _object == 0 )
132  return 0;
133 
134  if ( _object->dataType(DATA_TRIANGLE_MESH) ) {
135  TriMeshObject* object = dynamic_cast< TriMeshObject* >(_object);
136  return object->mesh();
137  } else
138  return 0;
139 }
140 
141 
142 TriMesh* triMesh( int _identifier ) {
143  TriMeshObject* object = triMeshObject(_identifier);
144 
145  if ( object == 0)
146  return 0;
147  else
148  return object->mesh();
149 }
150 
152  if ( _object == 0 )
153  return 0;
154 
155  if ( ! _object->dataType(DATA_TRIANGLE_MESH) )
156  return 0;
157  return dynamic_cast< TriMeshObject* >( _object );
158 }
159 
160 
161 TriMeshObject* triMeshObject( int _objectId ) {
162  if (_objectId == -1)
163  return 0;
164 
165  BaseObject* object = objectRoot()->childExists( _objectId );
166 
167  if ( object == 0 )
168  return 0;
169 
170  TriMeshObject* meshObject = dynamic_cast< TriMeshObject* >(object);
171 
172  return meshObject;
173 }
174 
175 
176 }