Developer Documentation
PluginFunctionsPolyMesh.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 //
49 // Plugin Functions PolyMesh
50 //
51 //=============================================================================
52 
54 
56 
57 
58 namespace PluginFunctions {
59 
60 
61 bool getSourceMeshes( std::vector<PolyMesh*>& _meshes ) {
62  _meshes.clear();
63 
65  if (! o_it->source() )
66  continue;
67  _meshes.push_back ( dynamic_cast< PolyMeshObject* >( *o_it )->mesh() );
68  }
69 
70  return ( !_meshes.empty() );
71 }
72 
73 bool getTargetMeshes( std::vector<PolyMesh*>& _meshes ) {
74  _meshes.clear();
75 
77  if (! o_it->target() )
78  continue;
79  if ( dynamic_cast< PolyMeshObject* >( *o_it )->mesh() )
80  _meshes.push_back ( dynamic_cast< PolyMeshObject* >( *o_it )->mesh() );
81  }
82 
83  return ( !_meshes.empty() );
84 }
85 
86 bool getObject( int _identifier , PolyMeshObject*& _object ) {
87 
88  if ( _identifier == BaseObject::NOOBJECT ) {
89  _object = 0;
90  return false;
91  }
92 
93  // Get object by using the map accelerated plugin function
94  BaseObjectData* object = 0;
95  PluginFunctions::getObject(_identifier,object);
96 
97  _object = dynamic_cast< PolyMeshObject* >(object);
98  return ( _object != 0 );
99 }
100 
101 bool getMesh( int _identifier , PolyMesh*& _mesh ) {
102 
103  if ( _identifier == BaseObject::NOOBJECT ) {
104  _mesh = 0;
105  return false;
106  }
107 
108  // Get object by using the map accelerated plugin function
109  BaseObjectData* object = 0;
110  PluginFunctions::getObject(_identifier,object);
111 
112  // Unable to find object
113  if ( object == 0)
114  return false;
115 
116  PolyMeshObject* polyMeshObject = dynamic_cast< PolyMeshObject* > (object);
117 
118  // Object is not a triangle mesh
119  if ( polyMeshObject == 0) {
120  _mesh = 0;
121  return false;
122  }
123 
124  _mesh = polyMeshObject->mesh();
125  return true;
126 }
127 
128 PolyMesh* polyMesh( BaseObjectData* _object ) {
129 
130  if ( _object == 0 )
131  return 0;
132 
133  if ( _object->dataType(DATA_POLY_MESH) ) {
134  PolyMeshObject* object = dynamic_cast< PolyMeshObject* >(_object);
135  return object->mesh();
136  } else
137  return NULL;
138 }
139 
140 PolyMesh* polyMesh( int _identifier ) {
141  PolyMeshObject* object = polyMeshObject(_identifier);
142 
143  if ( object == 0)
144  return 0;
145  else
146  return object->mesh();
147 }
148 
150 
151  if ( _object == 0 )
152  return 0;
153 
154  if ( ! _object->dataType(DATA_POLY_MESH) )
155  return NULL;
156  return dynamic_cast< PolyMeshObject* >( _object );
157 }
158 
159 PolyMeshObject* polyMeshObject( int _objectId ) {
160 
161  if (_objectId == BaseObject::NOOBJECT)
162  return 0;
163 
164  // Get object by using the map accelerated plugin function
165  BaseObjectData* object = 0;
166  PluginFunctions::getObject(_objectId,object);
167 
168  if ( object == 0 )
169  return 0;
170 
171  PolyMeshObject* meshObject = dynamic_cast< PolyMeshObject* >(object);
172 
173  return meshObject;
174 }
175 
176 }
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Type for a Meshobject containing a poly mesh.
Definition: PolyMesh.hh:65
bool getSourceMeshes(std::vector< PolyMesh *> &_meshes)
Get a pointer to every Poly Mesh which is marked as a source mesh.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
const QStringList ALL_OBJECTS
Iterable object range.
MeshT * mesh()
return a pointer to the mesh
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
static int NOOBJECT
Definition: BaseObject.hh:106
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
bool getTargetMeshes(std::vector< PolyMesh *> &_meshes)
Get a pointer to every Poly Mesh which is marked as a target mesh.
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.