Developer Documentation

PluginFunctionsTriangleMesh.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
50 //
51 //=============================================================================
52
53 #include <OpenFlipper/common/Types.hh>
54
55 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
56
57 namespace PluginFunctions {
58
59 bool getSourceMeshes( std::vector<TriMesh*>& _meshes ) {
60 _meshes.clear();
61
62 for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
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
74 for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_TRIANGLE_MESH) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
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 == BaseObject::NOOBJECT ) {
88 _object = 0;
89 return false;
90 }
91
92 // Get object by using the map accelerated plugin function
93 BaseObjectData* object = 0;
94 PluginFunctions::getObject(_identifier,object);
95
96 _object = dynamic_cast< TriMeshObject* >(object);
97 return ( _object != 0 );
98 }
99
100 // ===============================================================================
101 // ===============================================================================
102
103
104 bool getMesh( int _identifier , TriMesh*& _mesh ) {
105
106 if ( _identifier == BaseObject::NOOBJECT ) {
107 _mesh = 0;
108 return false;
109 }
110
111 // Get object by using the map accelerated plugin function
112 BaseObjectData* object = 0;
113 PluginFunctions::getObject(_identifier,object);
114
115 // Unable to find object
116 if ( object == 0)
117 return false;
118
119 TriMeshObject* triangleMeshObject = dynamic_cast< TriMeshObject* > (object);
120
121 // Object is not a triangle mesh
122 if ( triangleMeshObject == 0)
123 return false;
124
125 _mesh = triangleMeshObject->mesh();
126 return true;
127 }
128
129
130 // ===============================================================================
131 // Getting data from objects and casting between them
132 // ===============================================================================
133
134 TriMesh* triMesh( BaseObjectData* _object ) {
135
136 if ( _object == 0 )
137 return 0;
138
139 if ( _object->dataType(DATA_TRIANGLE_MESH) ) {
140 TriMeshObject* object = dynamic_cast< TriMeshObject* >(_object);
141 return object->mesh();
142 } else
143 return 0;
144 }
145
146
147 TriMesh* triMesh( int _identifier ) {
148 TriMeshObject* object = triMeshObject(_identifier);
149
150 if ( object == 0)
151 return 0;
152 else
153 return object->mesh();
154 }
155
156 TriMeshObject* triMeshObject( BaseObjectData* _object ) {
157 if ( _object == 0 )
158 return 0;
159
160 if ( ! _object->dataType(DATA_TRIANGLE_MESH) )
161 return 0;
162 return dynamic_cast< TriMeshObject* >( _object );
163 }
164
165
166 TriMeshObject* triMeshObject( int _objectId ) {
167 if (_objectId == BaseObject::NOOBJECT)
168 return 0;
169
170 // Get object by using the map accelerated plugin function
171 BaseObjectData* object = 0;
172 PluginFunctions::getObject(_objectId,object);
173
174 if ( object == 0 )
175 return 0;
176
177 TriMeshObject* meshObject = dynamic_cast< TriMeshObject* >(object);
178
179 return meshObject;
180 }
181
182
183 }
TriangleMesh.hh
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
MeshObject::mesh
MeshT * mesh()
return a pointer to the mesh
Definition: MeshObjectT_impl.hh:350
PluginFunctions::triMeshObject
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
Definition: PluginFunctionsTriangleMesh.cc:156
PluginFunctions::triMesh
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
Definition: PluginFunctionsTriangleMesh.cc:134
PluginFunctions::ALL_OBJECTS
const QStringList ALL_OBJECTS
Iterable object range.
Definition: PluginFunctions.hh:430
PluginFunctions::getMesh
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
Definition: PluginFunctionsPolyMesh.cc:101
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:294
TriMeshObject
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:67
BaseObject::NOOBJECT
static int NOOBJECT
Definition: BaseObject.hh:106
Types.hh
PluginFunctions::ObjectIterator
Core Data Iterator.
Definition: PluginFunctions.hh:441
PluginFunctions::objectsEnd
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsIterator.cc:177
PluginFunctions
Definition: PluginFunctions.cc:57
PluginFunctions::getTargetMeshes
bool getTargetMeshes(std::vector< PolyMesh *> &_meshes)
Get a pointer to every Poly Mesh which is marked as a target mesh.
Definition: PluginFunctionsPolyMesh.cc:73
DATA_TRIANGLE_MESH
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
BaseObjectData
Definition: BaseObjectData.hh:102
PluginFunctions::getSourceMeshes
bool getSourceMeshes(std::vector< PolyMesh *> &_meshes)
Get a pointer to every Poly Mesh which is marked as a source mesh.
Definition: PluginFunctionsPolyMesh.cc:61