Blender  V2.59
LOD_ExternBufferEditor.h
Go to the documentation of this file.
00001 /*
00002  * $Id: LOD_ExternBufferEditor.h 35147 2011-02-25 10:47:28Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00040 #ifndef NAN_INCLUDED_LOD_ExternBufferEditor_h
00041 #define NAN_INCLUDED_LOD_ExternBufferEditor_h
00042 
00043 #include "LOD_MeshPrimitives.h"
00044 #include <vector>
00045 #include "LOD_ManMesh2.h"
00046 #include "../extern/LOD_decimation.h"
00047 
00048 
00049 // This class syncs external vertex/face buffers 
00050 // with the internal mesh representation during
00051 // decimation.
00052 
00053 class LOD_ExternBufferEditor 
00054 {
00055 
00056 public :
00057 
00058         static 
00059                 LOD_ExternBufferEditor *
00060         New(
00061                 LOD_Decimation_InfoPtr extern_info
00062         ){
00063                 if (extern_info == NULL) return NULL;
00064                 return new LOD_ExternBufferEditor(extern_info);
00065         }
00066         
00067         // update the external vertex buffer with vertices
00068         // from the mesh
00069 
00070                 void
00071         CopyModifiedVerts(
00072                 LOD_ManMesh2 & mesh,
00073                 const std::vector<LOD_VertexInd> & mod_vertices
00074         ){
00075         
00076                 std::vector<LOD_VertexInd>::const_iterator v_start = mod_vertices.begin();
00077                 std::vector<LOD_VertexInd>::const_iterator v_end = mod_vertices.end();
00078 
00079                 std::vector<LOD_Vertex> & mesh_verts = mesh.VertexSet();
00080 
00081                 float * const extern_vertex_ptr = m_extern_info->vertex_buffer;
00082 
00083                 for (; v_start != v_end; ++v_start) {
00084                         float * mod_vert = extern_vertex_ptr + int(*v_start)*3;
00085                         mesh_verts[*v_start].CopyPosition(mod_vert);
00086                 }
00087         }                       
00088                 
00089         // update the external face buffer with faces from the mesh
00090 
00091                 void
00092         CopyModifiedFaces(
00093                 LOD_ManMesh2 & mesh,
00094                 const std::vector<LOD_FaceInd> & mod_faces
00095         ){
00096         
00097                 std::vector<LOD_FaceInd>::const_iterator f_start = mod_faces.begin();
00098                 std::vector<LOD_FaceInd>::const_iterator f_end = mod_faces.end();
00099 
00100                 std::vector<LOD_TriFace> &mesh_faces = mesh.FaceSet();
00101 
00102                 int * const extern_face_ptr = m_extern_info->triangle_index_buffer;
00103 
00104                 for (; f_start != f_end; ++f_start) {
00105                         int *mod_face = extern_face_ptr + 3*int(*f_start);
00106                         mesh_faces[*f_start].CopyVerts(mod_face);
00107                 }
00108         }
00109 
00110 
00111         // Copy the last vertex over the vertex specified by
00112         // vi. Decrement the size of the vertex array   
00113 
00114                 void
00115         CopyBackVertex(
00116                 LOD_VertexInd vi
00117         ){
00118 
00119                 float * const extern_vertex_ptr = m_extern_info->vertex_buffer;
00120                 int * extern_vertex_num = &(m_extern_info->vertex_num);
00121 
00122                 float * last_external_vert = extern_vertex_ptr + 3*((*extern_vertex_num) - 1);
00123                 float * external_vert = extern_vertex_ptr + 3*int(vi);
00124 
00125                 external_vert[0] = last_external_vert[0];
00126                 external_vert[1] = last_external_vert[1];
00127                 external_vert[2] = last_external_vert[2];
00128 
00129                 *extern_vertex_num -=1;
00130         }
00131 
00132         // Copy the last face over the face specified by fi
00133         // Decrement the size of the face array
00134 
00135                 void
00136         CopyBackFace(
00137                 LOD_FaceInd fi
00138         ) {
00139                 int * const extern_face_ptr = m_extern_info->triangle_index_buffer;
00140                 int * extern_face_num = &(m_extern_info->face_num);
00141                 
00142                 int * last_external_face = extern_face_ptr + 3*((*extern_face_num) -1);
00143                 int * external_face = extern_face_ptr + 3*int(fi);
00144                 external_face[0] = last_external_face[0];
00145                 external_face[1] = last_external_face[1];
00146                 external_face[2] = last_external_face[2];
00147 
00148                 *extern_face_num -=1;
00149         }       
00150 
00151 
00152 private :
00153                 
00154         LOD_ExternBufferEditor(
00155                 LOD_Decimation_InfoPtr extern_info      
00156         ) :
00157                 m_extern_info (extern_info)
00158         {
00159         }
00160 
00161         LOD_Decimation_InfoPtr const m_extern_info;
00162 
00163 };
00164 
00165 #endif
00166