Blender V2.61 - r43446

LOD_ExternBufferEditor.h

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