3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
29 /** \file decimation/intern/LOD_ExternBufferEditor.h
37 * Copyright (C) 2001 NaN Technologies B.V.
40 #ifndef NAN_INCLUDED_LOD_ExternBufferEditor_h
41 #define NAN_INCLUDED_LOD_ExternBufferEditor_h
43 #include "LOD_MeshPrimitives.h"
45 #include "LOD_ManMesh2.h"
46 #include "../extern/LOD_decimation.h"
49 // This class syncs external vertex/face buffers
50 // with the internal mesh representation during
53 class LOD_ExternBufferEditor
59 LOD_ExternBufferEditor *
61 LOD_Decimation_InfoPtr extern_info
63 if (extern_info == NULL) return NULL;
64 return new LOD_ExternBufferEditor(extern_info);
67 // update the external vertex buffer with vertices
73 const std::vector<LOD_VertexInd> & mod_vertices
76 std::vector<LOD_VertexInd>::const_iterator v_start = mod_vertices.begin();
77 std::vector<LOD_VertexInd>::const_iterator v_end = mod_vertices.end();
79 std::vector<LOD_Vertex> & mesh_verts = mesh.VertexSet();
81 float * const extern_vertex_ptr = m_extern_info->vertex_buffer;
83 for (; v_start != v_end; ++v_start) {
84 float * mod_vert = extern_vertex_ptr + int(*v_start)*3;
85 mesh_verts[*v_start].CopyPosition(mod_vert);
89 // update the external face buffer with faces from the mesh
94 const std::vector<LOD_FaceInd> & mod_faces
97 std::vector<LOD_FaceInd>::const_iterator f_start = mod_faces.begin();
98 std::vector<LOD_FaceInd>::const_iterator f_end = mod_faces.end();
100 std::vector<LOD_TriFace> &mesh_faces = mesh.FaceSet();
102 int * const extern_face_ptr = m_extern_info->triangle_index_buffer;
104 for (; f_start != f_end; ++f_start) {
105 int *mod_face = extern_face_ptr + 3*int(*f_start);
106 mesh_faces[*f_start].CopyVerts(mod_face);
111 // Copy the last vertex over the vertex specified by
112 // vi. Decrement the size of the vertex array
119 float * const extern_vertex_ptr = m_extern_info->vertex_buffer;
120 int * extern_vertex_num = &(m_extern_info->vertex_num);
122 float * last_external_vert = extern_vertex_ptr + 3*((*extern_vertex_num) - 1);
123 float * external_vert = extern_vertex_ptr + 3*int(vi);
125 external_vert[0] = last_external_vert[0];
126 external_vert[1] = last_external_vert[1];
127 external_vert[2] = last_external_vert[2];
129 *extern_vertex_num -=1;
132 // Copy the last face over the face specified by fi
133 // Decrement the size of the face array
139 int * const extern_face_ptr = m_extern_info->triangle_index_buffer;
140 int * extern_face_num = &(m_extern_info->face_num);
142 int * last_external_face = extern_face_ptr + 3*((*extern_face_num) -1);
143 int * external_face = extern_face_ptr + 3*int(fi);
144 external_face[0] = last_external_face[0];
145 external_face[1] = last_external_face[1];
146 external_face[2] = last_external_face[2];
148 *extern_face_num -=1;
154 LOD_ExternBufferEditor(
155 LOD_Decimation_InfoPtr extern_info
157 m_extern_info (extern_info)
161 LOD_Decimation_InfoPtr const m_extern_info;