Developer Documentation

PluginFunctionsPolyhedralMesh.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 #include <OpenFlipper/common/Types.hh>
44 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
45
46
47 #include <ObjectTypes/PolyhedralMesh/PluginFunctionsPolyhedralMesh.hh>
48
49 namespace PluginFunctions {
50
51 // ===============================================================================
52 // Get source meshes
53 // ===============================================================================
54
55
56 bool getSourceMeshes( std::vector<PolyhedralMesh*>& _meshes )
57 {
58 _meshes.clear();
59
60 for ( ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS,DATA_POLYHEDRAL_MESH) ;
61 o_it != PluginFunctions::objectsEnd(); ++o_it) {
62 _meshes.push_back ( PluginFunctions::polyhedralMesh( *o_it ) );
63 if( _meshes.back() == NULL)
64 std::cerr << "ERROR: PolyhedralMesh getSourceMeshes fatal error\n";
65 }
66
67 return ( !_meshes.empty() );
68 }
69
70
71 // ===============================================================================
72 // Get target meshes
73 // ===============================================================================
74
75
76 bool getTargetMeshes( std::vector<PolyhedralMesh*>& _meshes )
77 {
78 _meshes.clear();
79
80 for ( ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_POLYHEDRAL_MESH ) ;
81 o_it != PluginFunctions::objectsEnd(); ++o_it) {
82 _meshes.push_back ( PluginFunctions::polyhedralMesh( *o_it ) );
83 if( _meshes.back() == NULL)
84 std::cerr << "ERROR: PolyhedralMesh getTargetMeshes fatal error\n";
85 }
86
87 return ( !_meshes.empty() );
88 }
89
90
91 // ===============================================================================
92 // Get objects
93 // ===============================================================================
94
95 bool getObject( int _identifier, PolyhedralMeshObject*& _object ) {
96
97 if ( _identifier == BaseObject::NOOBJECT ) {
98 _object = 0;
99 return false;
100 }
101
102 // Get object by using the map accelerated plugin function
103 BaseObjectData* object = 0;
104 PluginFunctions::getObject(_identifier,object);
105
106 _object = object ? polyhedralMeshObject(object) : nullptr;
107 return ( _object != 0 );
108 }
109
110
111 // ===============================================================================
112 // Getting data from objects and casting between them
113 // ===============================================================================
114
115 PolyhedralMesh* polyhedralMesh( BaseObjectData* _object ) {
116
117 if ( _object->dataType(DATA_POLYHEDRAL_MESH) ) {
118 PolyhedralMeshObject* object = static_cast< PolyhedralMeshObject* >(_object);
119 return object->mesh();
120 } else
121 return 0;
122 }
123
124 PolyhedralMesh* polyhedralMesh( int _identifier ) {
125 PolyhedralMeshObject* object = polyhedralMeshObject(_identifier);
126
127 if ( object == 0)
128 return 0;
129 else
130 return object->mesh();
131 }
132
133
134 PolyhedralMeshObject* polyhedralMeshObject( BaseObjectData* _object ) {
135 if ( ! _object->dataType(DATA_POLYHEDRAL_MESH) )
136 return 0;
137 return static_cast< PolyhedralMeshObject* >( _object );
138 }
139
140
141 PolyhedralMeshObject* polyhedralMeshObject( int _identifier )
142 {
143 PolyhedralMeshObject* pol_obj;
144 if(getObject(_identifier, pol_obj))
145 return pol_obj;
146 else
147 return 0;
148 }
149
150
151 }
DATA_POLYHEDRAL_MESH
#define DATA_POLYHEDRAL_MESH
Definition: PolyhedralMesh.hh:54
PluginFunctions::polyhedralMeshObject
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
Definition: PluginFunctionsPolyhedralMesh.cc:134
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
PluginFunctionsPolyhedralMesh.hh
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
PluginFunctions::SOURCE_OBJECTS
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
PluginFunctions.hh
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
PluginFunctions::objectsEnd
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsIterator.cc:177
BaseObject::NOOBJECT
static int NOOBJECT
Definition: BaseObject.hh:106
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
BaseObjectData
Definition: BaseObjectData.hh:102
VolumeMeshObject
Definition: VolumeMeshObject.hh:63
PluginFunctions::TARGET_OBJECTS
const QStringList TARGET_OBJECTS("target")
Iterable object range.
OpenVolumeMesh::GeometryKernel
Definition: GeometryKernel.hh:47
PluginFunctions::polyhedralMesh
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.
Definition: PluginFunctionsPolyhedralMesh.cc:115
VolumeMeshObject::mesh
MeshT * mesh()
return a pointer to the mesh
Definition: VolumeMeshObjectT_impl.hh:212
Types.hh
PluginFunctions
Definition: PluginFunctions.cc:57