Developer Documentation
MergePlugintemplate.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#define MERGEPLUGIN_C
43
44#include "MergePlugin.hh"
45#include <OpenMesh/Core/Utils/Property.hh>
48
50template< class MeshT >
51void MergePlugin::mergeMeshes(const std::vector< MeshT* >& _meshes)
52{
53 typename MeshT::VertexHandle vhB;
54
55 mergeMeshes(_meshes, vhB);
56}
57
59template< class MeshT >
60void MergePlugin::mergeMeshes(const std::vector< MeshT* >& _meshes, typename MeshT::VertexHandle& _vhB)
61{
62
63 for (uint i=0; i < _meshes.size(); i++)
64 if ( _meshes[i] == 0) {
65 emit log(LOGERR,"Unable to get Meshes.");
66 return;
67 }
68
69 typename MeshT::VertexHandle tmp;
70
71 for (uint i=1; i < _meshes.size(); i++){
72
73 // COPY VERTICES into the first mesh
74 //
75
77 _meshes[i]->add_property(vertexID, "Vertex ID Property" );
78
79 //iterate over all vertices of the current mesh
80 for (auto v_it : _meshes[i]->vertices()){
81 //add vertex to _meshes[0] and set vertexID property
82 typename MeshT::VertexHandle vh = _meshes[0]->add_vertex( _meshes[i]->point(v_it) );
83 _meshes[i]->property(vertexID, v_it) = vh;
84
85 //map vertexHandle _vhB
86 if (v_it == _vhB)
87 tmp = vh;
88 }
89
90 // COPY FACES into the first mesh
91 //
92
93 //itertate over all faces of meshes[i]
94 for (auto f_it : _meshes[i]->faces()){
95 //get corresponding VertexHandles
96 std::vector< typename MeshT::VertexHandle > vHandles;
97
98 for (auto fv_it : f_it.vertices())
99 vHandles.push_back( _meshes[i]->property(vertexID, fv_it) );
100
101 //add faces to meshA
102 _meshes[0]->add_face(vHandles);
103 }
104
105 _meshes[i]->remove_property( vertexID );
106
107 }
108
109 _vhB = tmp;
110}
111
112template void MergePlugin::mergeMeshes(const std::vector< PolyMesh* >& _meshes);
113template void MergePlugin::mergeMeshes(const std::vector< TriMesh* >& _meshes);
@ LOGERR
void mergeMeshes(const std::vector< MeshT * > &_meshes)
merges Meshes into the first mesh