rtcTriMesh.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007
00003  * Robert Bosch LLC
00004  * Research and Technology Center North America
00005  * Palo Alto, California
00006  *
00007  * All rights reserved.
00008  *
00009  *------------------------------------------------------------------------------
00010  * project ....: PUMA: Probablistic Unsupervised Model Acquisition
00011  * file .......: mesh.cpp
00012  * authors ....: Benjamin Pitzer
00013  * organization: Robert Bosch LLC
00014  * creation ...: 03/28/2008
00015  * modified ...: $Date: 2008-12-19 10:32:32 -0800 (Fri, 19 Dec 2008) $
00016  * changed by .: $Author: wg75pal $
00017  * revision ...: $Revision: 615 $
00018  */
00019 
00020 //== INCLUDES ==================================================================
00021 #include "rtc/rtcTriMesh.h"
00022 
00023 //== NAMESPACES ================================================================
00024 namespace rtc {
00025 
00026 Vec3f point_to_vec(const Point& p)
00027 {
00028   return(Vec3f(p[0],p[1],p[2]));
00029 }
00030 
00031 Vec3f normal_to_vec(const Normal& p)
00032 {
00033   return(Vec3f(p[0],p[1],p[2]));
00034 }
00035 
00036 Vec3uc color_to_vec(const Color& p)
00037 {
00038   return(Vec3uc(p[0],p[1],p[2]));
00039 }
00040 
00041 Point vec_to_point(const Vec3f& v)
00042 {
00043   return(Point(v[0],v[1],v[2]));
00044 }
00045 
00046 Normal vec_to_normal(const Vec3f& v)
00047 {
00048   return(Normal(v[0],v[1],v[2]));
00049 }
00050 
00051 Color vec_to_color(const Vec3uc& v)
00052 {
00053   return(Color(v[0],v[1],v[2]));
00054 }
00055 
00056 void convertMeshToTriMesh(const Mesh3D& input, TriMesh& output)
00057 {
00058   output.request_vertex_normals();
00059   output.request_face_normals();
00060   output.request_vertex_colors();
00061 
00062   //== Vertices ==========================================================
00063   int nverts = (int)input.vertices.size();
00064   for (int i=0;i<nverts;++i)
00065   {
00066     Vec3f& p = input.vertices[i]->p;
00067     Vec3f& n = input.vertices[i]->n;
00068     Vec3uc& c = input.vertices[i]->c;
00069     VertexHandle vh = output.add_vertex(vec_to_point(p));
00070     output.set_normal(vh,vec_to_normal(n));
00071     output.set_color(vh,vec_to_color(c));
00072   }
00073 
00074   //== Faces ==========================================================
00075   int nfaces = (int)input.faces.size();
00076   std::vector<VertexHandle> newFace(3);
00077   for (int i=0;i<nfaces;++i)
00078   {
00079     Face3D* f = input.faces[i];
00080     newFace[0] = output.vertex_handle(f->v(0));
00081     newFace[1] = output.vertex_handle(f->v(1));
00082     newFace[2] = output.vertex_handle(f->v(2));
00083     FaceHandle fh = output.add_face(newFace);
00084     output.set_normal(fh,vec_to_normal(f->n));
00085   }
00086 }
00087 
00088 void convertTriMeshToMesh(const TriMesh& input, Mesh3D& output)
00089 {
00090   //== Vertices ==========================================================
00091   ConstVertexIter vIt, vEnd;
00092   ConstFaceIter fIt, fEnd;
00093   ConstFaceVertexIter cfvIt;
00094 
00095   // clean first
00096   output.clear();
00097 
00098   int i = 0;
00099   for(vIt=input.vertices_begin(), vEnd = input.vertices_end(); vIt != vEnd; ++vIt,++i) {
00100     Vec3f p = point_to_vec(input.point(vIt));
00101     Vertex3D* v = output.addVertex(p);
00102     v->n = normal_to_vec(input.normal(vIt));
00103     v->c = color_to_vec(input.color(vIt));
00104     v->setBoundary(input.is_boundary(vIt));
00105   }
00106 
00107   int face[3];
00108   for(fIt=input.faces_begin(), fEnd = input.faces_end(); fIt != fEnd; ++fIt) {
00109     // get triangle vertices
00110     cfvIt = input.cfv_iter(fIt);
00111     for(int j=0; j<3; j++) {
00112       face[j] = cfvIt.handle().idx();
00113       ++cfvIt;
00114     }
00115     Face3D* f = output.addFace(face);
00116     f->n = normal_to_vec(input.normal(cfvIt));
00117   }
00118 }
00119 
00120 
00121 //==============================================================================
00122 } // NAMESPACE puma
00123 //==============================================================================


rtc
Author(s): Benjamin Pitzer
autogenerated on Mon Oct 6 2014 10:07:35