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 
50 template< class MeshT >
51 void MergePlugin::mergeMeshes(const std::vector< MeshT* >& _meshes)
52 {
53  typename MeshT::VertexHandle vhB;
54 
55  mergeMeshes(_meshes, vhB);
56 }
57 
59 template< class MeshT >
60 void 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  typename MeshT::VertexIter v_it;
80  typename MeshT::VertexIter v_end = _meshes[i]->vertices_end();
81 
82  //iterate over all vertices of the current mesh
83  for (v_it = _meshes[i]->vertices_begin(); v_it != v_end; ++v_it){
84  //add vertex to _meshes[0] and set vertexID property
85  typename MeshT::VertexHandle vh = _meshes[0]->add_vertex( _meshes[i]->point(*v_it) );
86  _meshes[i]->property(vertexID, *v_it) = vh;
87 
88  //map vertexHandle _vhB
89  if (*v_it == _vhB)
90  tmp = vh;
91  }
92 
93  // COPY FACES into the first mesh
94  //
95  typename MeshT::FaceIter f_it;
96  typename MeshT::FaceIter f_end = _meshes[i]->faces_end();
97 
98  //itertate over all faces of meshes[i]
99  for (f_it = _meshes[i]->faces_begin(); f_it != f_end; ++f_it){
100  //get corresponding VertexHandles
101  typename MeshT::FaceVertexIter fv_it;
102 
103  std::vector< typename MeshT::VertexHandle > vHandles;
104 
105  for (fv_it=_meshes[i]->fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
106  vHandles.push_back( _meshes[i]->property(vertexID, *fv_it) );
107 
108  //add faces to meshA
109  _meshes[0]->add_face(vHandles);
110  }
111 
112  _meshes[i]->remove_property( vertexID );
113 
114  }
115 
116  _vhB = tmp;
117 }
118 
119 template void MergePlugin::mergeMeshes(const std::vector< PolyMesh* >& _meshes);
120 template void MergePlugin::mergeMeshes(const std::vector< TriMesh* >& _meshes);
void mergeMeshes(const std::vector< MeshT * > &_meshes)
merges Meshes into the first mesh