MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/dem/graph.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso, Raul Durand                   *
00004  * Copyright (C) 2009 Sergio Galindo                                    *
00005  *                                                                      *
00006  * This program is free software: you can redistribute it and/or modify *
00007  * it under the terms of the GNU General Public License as published by *
00008  * the Free Software Foundation, either version 3 of the License, or    *
00009  * any later version.                                                   *
00010  *                                                                      *
00011  * This program is distributed in the hope that it will be useful,      *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00013  * MERCHANTABILITY or finNESS FOR A PARTICULAR PURPOSE. See the         *
00014  * GNU General Public License for more details.                         *
00015  *                                                                      *
00016  * You should have received a copy of the GNU General Public License    *
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00018  ************************************************************************/
00019 
00020 #ifndef MECHSYS_DEM_GRAPH_H
00021 #define MECHSYS_DEM_GRAPH_H
00022 
00023 // Std lib
00024 #include <iostream>
00025 
00026 // MechSys
00027 #include <mechsys/util/array.h>
00028 #include <mechsys/linalg/matvec.h>
00029 
00030 
00032 
00033 
00034 inline void POVHeader (std::ostream & os)
00035 {
00036     os << "#include \"colors.inc\" \n";
00037     os << "#include \"glass.inc\" \n";
00038     os << "#include \"transforms.inc\" \n";
00039     os << "background {color White} \n";
00040     //os << "light_source{<10,0,0> color White shadowless}  \n";
00041     //os << "light_source{<-10,0,0> color White shadowless}  \n";
00042     //os << "light_source{<0,10,0> color White shadowless}  \n";
00043     //os << "light_source{<0,-10,0> color White shadowless}  \n";
00044     //os << "light_source{<0,0,10> color White shadowless}  \n";
00045     //os << "light_source{<0,0,-10> color White shadowless}  \n";
00046 }   
00047 
00048 inline void POVSetCam (std::ostream & os, const Vec3_t & X, const Vec3_t & F)
00049 {
00050     os << "camera { location <"<<X(0)<<","<<X(1)<<","<<X(2)<<"> sky <0,0,1> look_at <"<<F(0)<<","<<F(1)<<","<<F(2)<<"> }\n";
00051     os << "light_source {<"<<X(0)<<","<<X(1)<<","<<X(2)<<"> color White }\n";
00052 }
00053 
00054 inline void POVDrawVert (Vec3_t const & V, std::ostream & os, double Radius=1.0, char const * Color="Blue")
00055 {
00056     os << "sphere  { <"<<V(0)<<","<<V(1)<<","<<V(2)<<">,"<<Radius<<"\n pigment { color "<<Color<<" } }\n";
00057 }
00058 
00059 inline void POVDrawPolygon (Array<Vec3_t> const & V, std::ostream & os, char const * Color="Blue")
00060 {
00061     size_t N = V.Size();
00062     Vec3_t mid;
00063     mid = 0.0, 0.0, 0.0;
00064     for (size_t i=0; i<V.Size(); i++) mid += V[i];
00065     mid /= V.Size();
00066     for (size_t i=0; i<V.Size(); i++)
00067     {
00068         os << "polygon {"<<3<<", \n";
00069         os << "<"<<V[i](0)<<","<<V[i](1)<<","<<V[i](2)<<">";
00070         os << ",<"<<V[(i+1)%N](0)<<","<<V[(i+1)%N](1)<<","<<V[(i+1)%N](2)<<">";
00071         os << ",<"<<mid(0)<<","<<mid(1)<<","<<mid(2)<<">";
00072         os <<"\n pigment { color "<<Color<<" } \n } \n ";
00073     }
00074 }
00075 
00077 
00078 
00079 inline void BPYHeader (std::ostream & os)
00080 {
00081     os << "from Blender import *\n";
00082     os << "from bpy import *\n";
00083     os << "from Blender import Mathutils\n";
00084     os << "from Blender.Mathutils import *\n";
00085     os << "s = data.scenes.active\n";
00086 }
00087 
00088 inline void BPYDrawVert (Vec3_t const & V, std::ostream & os, double Radius=1.0)
00089 {
00090     os << "m = Mesh.Primitives.UVsphere(32,32,"<<Radius*2.0<<")\n";
00091     os << "o = s.objects.new(m,'Sphere')\n";
00092     os << "o.setLocation("<<V(0)<<","<<V(1)<<","<<V(2)<<")\n";
00093 }
00094 
00095 inline void BPYDrawPolygon (Array<Vec3_t> const & V, std::ostream & os)
00096 {
00097     size_t N = V.Size();
00098     Vec3_t mid;
00099     mid = 0.0, 0.0, 0.0;
00100     for (size_t i=0; i<V.Size(); i++) mid += V[i];
00101     mid /= V.Size();
00102     for (size_t i=0; i<N; i++) 
00103     {   
00104         os << "m = data.meshes.new('Face') \no = s.objects.new(m,'Face') \nv = [["<<V[i](0)<<","<<V[i](1)<<","<<V[i](2)<<"],["<<V[(i+1)%N](0)<<","<<V[(i+1)%N](1)<<","<<V[(i+1)%N](2)<<"],["<<mid(0)<<","<<mid(1)<<","<<mid(2)<<"]]\n";
00105         os << "f = [[0,1,2]] \nm.verts.extend(v) \nm.faces.extend(f) \n";
00106     }
00107 }
00108 
00109 #endif // MECHSYS_DEM_GRAPH_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines