PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // SurfaceMesh.h 00004 // 00005 // Copyright (C) 2004 Pascal Lamblin 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 /* ******************************************************* 00036 * $Id: SurfaceMesh.h,v 1.13 2005/12/29 13:44:35 lamblinp Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Pascal Lamblin 00040 00044 #ifndef SurfaceMesh_INC 00045 #define SurfaceMesh_INC 00046 00047 #include <plearn/base/stringutils.h> 00048 #include <plearn/base/Object.h> 00049 #include "mesh_decl.h" 00050 #include "MeshFace.h" 00051 00052 00053 namespace PLearn { 00054 using namespace std; 00055 00056 class SurfaceMesh; 00057 typedef PP<SurfaceMesh> SurfMesh; 00058 00059 00060 class SurfaceMesh: public Object 00061 { 00062 00063 private: 00064 00065 typedef Object inherited; 00066 00067 protected: 00068 // ********************* 00069 // * protected options * 00070 // ********************* 00071 00072 MGraph mg; 00073 bool computed_vtx_norm; 00074 00075 public: 00076 00077 // ************************ 00078 // * public build options * 00079 // ************************ 00080 00081 Graph p_mesh; 00082 string mesh_type; 00083 00087 int verbosity; 00088 00089 // **************** 00090 // * Constructors * 00091 // **************** 00092 00094 SurfaceMesh(); 00095 00097 SurfaceMesh( Graph g ); 00098 00100 SurfaceMesh( const SurfaceMesh& m ); 00101 00102 00104 virtual ~SurfaceMesh(); 00105 00106 00107 // ****************** 00108 // * Object methods * 00109 // ****************** 00110 00111 private: 00113 void build_(); 00114 00115 protected: 00117 static void declareOptions(OptionList& ol); 00118 00119 public: 00120 // Declares other standard object methods. 00121 PLEARN_DECLARE_OBJECT(SurfaceMesh); 00122 00123 // simply calls inherited::build() then build_() 00124 virtual void build(); 00125 00127 // (PLEASE IMPLEMENT IN .cc) 00128 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00129 00130 protected: 00131 virtual bool readVRMLCoordinate3_( ifstream& in, 00132 TVec<vertex_descriptor>& vertices, 00133 Mat vtx_features = Mat() ); 00134 virtual bool readVRMLIndexedFaceSet_( ifstream& in, 00135 TVec<vertex_descriptor>& vertices ); 00136 virtual bool readVRMLIndexedLineSet_( ifstream& in, 00137 TVec<vertex_descriptor>& vertices ); 00138 00139 virtual void writeVRMLCoordinate3_( 00140 ofstream& out, 00141 map< vertex_descriptor, int >& pts_indices ); 00142 virtual void writeVRMLIndexedFaceSet_( 00143 ofstream& out, 00144 map< vertex_descriptor, int >& pts_indices ); 00145 virtual void writeVRMLIndexedLineSet_( 00146 ofstream& out, 00147 map< vertex_descriptor, int >& pts_indices ); 00148 00149 public: 00150 virtual bool readVRMLFile( string filename, Mat vtx_features = Mat() ); 00151 virtual bool readVRMLIndexedFaceSet( string filename, 00152 Mat vtx_features = Mat() ); 00153 virtual bool readVRMLIndexedLineSet( string filename, 00154 Mat vtx_features = Mat() ); 00155 00156 virtual void writeVRMLFile( string filename ); 00157 virtual void writeVRMLIndexedFaceSet( string filename ); 00158 virtual void writeVRMLIndexedLineSet( string filename ); 00159 virtual void writeVRMLBoundaries( string filename ); 00160 00161 virtual int createSurfaceMesh(); // to fix 00162 00163 virtual vertex_descriptor addVertex( MVertex mv ); 00164 virtual vertex_descriptor addVertex( Vec coord, Vec features = Vec() ); 00165 virtual vertex_descriptor addVertex( real x, real y, real z ); 00166 00167 virtual void delVertex( vertex_descriptor vtx ); 00168 virtual MVertex getVertex( vertex_descriptor vtx ); 00169 virtual void setVertex( vertex_descriptor vtx, const MVertex& mv ); 00170 00171 virtual Mat getVertexCoords(); 00172 virtual Mat getVertexCoordsAndFeatures(); 00173 virtual void setVertexCoords( const Mat& coords ); 00174 virtual void setVertexFeatures( const Mat& features ); 00175 virtual void setVertexCoordsAndFeatures( const Mat& coords, 00176 const Mat& features ); 00177 virtual int numVertices(); 00178 virtual TVec< vertex_descriptor > getVertexDescriptors(); 00179 00180 virtual Mat getVertexNorms(); 00181 virtual void setVertexNorms( const Mat& coords ); 00182 00183 virtual edge_descriptor addEdge( vertex_descriptor first, 00184 vertex_descriptor second, 00185 MEdge me = new MeshEdge() ); 00186 00187 virtual void delEdge( edge_descriptor ed ); 00188 virtual MEdge getEdge( edge_descriptor ed ); 00189 virtual void setEdge( edge_descriptor ed, const MEdge& me ); 00190 virtual int numEdges(); 00191 00192 virtual int addFace( MFace mf ); 00193 virtual int addFace( TVec<vertex_descriptor> pts ); 00194 virtual int addFace( vertex_descriptor first, 00195 vertex_descriptor second, 00196 vertex_descriptor third ); 00197 00198 virtual void delFace( int face_index ); 00199 virtual MFace getFace( int face_index ); 00200 virtual void setFace( int face_index, const MFace& mf ); 00201 virtual int numFaces(); 00202 virtual TVec< set<int> > cacheNeighborFaces(); 00203 00204 virtual int buildEdges(); 00205 virtual int buildBoundaries(); 00206 00207 virtual real getResolution(); 00208 virtual void setResolution( real resolution ); 00209 virtual real computeResolution(); 00210 00211 virtual void findNormals(); 00212 virtual real averageSphereRadius(); 00213 virtual int delOrphanVertices(); 00214 00215 virtual Mat boundingBox(); 00216 00217 00218 // ****************** 00219 // * Static methods * 00220 // ****************** 00221 00222 // static int compare( const SurfaceMesh& e, const SurfaceMesh& f ); 00223 00224 }; 00225 00226 // Declares a few other classes and functions related to this class 00227 DECLARE_OBJECT_PTR(SurfaceMesh); 00228 00229 std::pair< edge_descriptor, bool > 00230 add_edge_ifnew( const vertex_descriptor& u, const vertex_descriptor& v, 00231 const graph::edge_property_type& ep, graph& g ); 00232 00233 std::pair< edge_descriptor, bool > 00234 add_edge_ifnew( const vertex_descriptor& u, const vertex_descriptor& v, 00235 graph& g ); 00236 00237 } // end of namespace PLearn 00238 00239 #endif