bedding-planes.cpp

00001 /***********************************************************************************
00002  * YieldSurf - Simple generator of yield surface data                              *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>     *
00004  *                                                                                 *
00005  * This file is part of YieldSurf.                                                 *
00006  *                                                                                 *
00007  * YieldSurf is free software; you can redistribute it and/or modify it under the  *
00008  * terms of the GNU General Public License as published by the Free Software       *
00009  * Foundation; either version 2 of the License, or (at your option) any later      *
00010  * version.                                                                        *
00011  *                                                                                 *
00012  * YieldSurf is distributed in the hope that it will be useful, but WITHOUT ANY    *
00013  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
00014  * PARTICULAR PURPOSE. See the GNU General Public License for more details.        *
00015  *                                                                                 *
00016  * You should have received a copy of the GNU General Public License along with    *
00017  * YieldSurf; if not, write to the Free Software Foundation, Inc., 51 Franklin     *
00018  * Street, Fifth Floor, Boston, MA 02110-1301, USA                                 *
00019  ***********************************************************************************/
00020 
00021 // STL
00022 #include <algorithm>
00023 #include <iostream>
00024 
00025 // VTK
00026 #include "vtkLightKit.h"
00027 
00028 // MechSys
00029 #include "numerical/meshgrid.h"
00030 #include "vtkwrap/vtkwin.h"
00031 #include "vtkwrap/axes.h"
00032 #include "vtkwrap/arrow.h"
00033 #include "vtkwrap/cube.h"
00034 #include "vtkwrap/plane.h"
00035 #include "util/string.h"
00036 #include "util/util.h"
00037 #include "util/exception.h"
00038 
00039 using Util::Sq3;
00040 
00041 int main(int argc, char **argv) try
00042 {
00043     // Input
00044     int cam_key = 1;
00045     if (argc>=2) cam_key = atoi(argv[1]);
00046 
00047     // Window
00048     //VTKWin win(1280,1024);
00049     VTKWin win;
00050     switch (cam_key)
00051     {
00052         case 1: { win.GetCamera()->SetPosition(1,-0.25,0.25);    break; }
00053         case 2: { win.GetCamera()->SetPosition(1,-1,0);          break; }
00054         case 3: { win.SetViewPIplane();                          break; }
00055     }
00056 
00057     // Constants
00058     double L = 10;
00059     double Lmax = 1.3*L;
00060 
00061     // Axes
00062     Axes ax(Lmax,1.5*Lmax,Lmax, "x","y","z", "peacock","black", 0.010,0.002, false);
00063     ax.AddActorsTo(win);
00064 
00065     // Arrows
00066     double l = 0.3*L;
00067     double xa = 0.8*L;
00068     double ya = 0.8*L;
00069     Arrow::Geometry geom(/*BodyRadius*/0.010*Lmax, /*TipRadius*/0.020*Lmax,  /*TipMultiplier*/4.0, /*Resolution*/60);
00070     Arrow n (0 , 0 , -l , "blue" , L/2 , L/2 , L+l , &geom);
00071     Arrow a (0 , 0 , l  , "red"  , xa , ya , L   , &geom);
00072     win.AddActor(n.GetActor());
00073     win.AddActor(a.GetActor());
00074 
00075     // Cube
00076     Cube cu1(0.5*L, 0.5*L, 0.5*L, L,L,L, "wheat" ,0.2);
00077     cu1.WireWidth(2).WireColor("black");
00078     win.AddActor(cu1.GetActor());
00079     win.AddActor(cu1.GetWireActor());
00080 
00081     // Planes
00082     char const color[] = "wheat";
00083     double        opac = 0.7;
00084     double          dx = L/10.0;
00085     Plane  pl1(0,0,   dx,  0,L,   dx,  L,0,   dx, 0,0,1, color, opac);
00086     Plane  pl2(0,0, 2*dx,  0,L, 2*dx,  L,0, 2*dx, 0,0,1, color, opac);
00087     Plane  pl3(0,0, 3*dx,  0,L, 3*dx,  L,0, 3*dx, 0,0,1, color, opac);
00088     Plane  pl4(0,0, 4*dx,  0,L, 4*dx,  L,0, 4*dx, 0,0,1, color, opac);
00089     Plane  pl5(0,0, 5*dx,  0,L, 5*dx,  L,0, 5*dx, 0,0,1, color, opac);
00090     Plane  pl6(0,0, 6*dx,  0,L, 6*dx,  L,0, 6*dx, 0,0,1, color, opac);
00091     Plane  pl7(0,0, 7*dx,  0,L, 7*dx,  L,0, 7*dx, 0,0,1, color, opac);
00092     Plane  pl8(0,0, 8*dx,  0,L, 8*dx,  L,0, 8*dx, 0,0,1, color, opac);
00093     Plane  pl9(0,0, 9*dx,  0,L, 9*dx,  L,0, 9*dx, 0,0,1, color, opac);
00094     Plane pl10(0,0,10*dx,  0,L,10*dx,  L,0,10*dx, 0,0,1, color, opac);
00095     win.AddActor( pl1.GetActor());
00096     win.AddActor( pl2.GetActor());
00097     win.AddActor( pl3.GetActor());
00098     win.AddActor( pl4.GetActor());
00099     win.AddActor( pl5.GetActor());
00100     win.AddActor( pl6.GetActor());
00101     win.AddActor( pl7.GetActor());
00102     win.AddActor( pl8.GetActor());
00103     win.AddActor( pl9.GetActor());
00104     win.AddActor(pl10.GetActor());
00105 
00106     // Lights
00107     vtkLightKit * lk = vtkLightKit::New();
00108     lk->SetKeyLightIntensity(1.0);
00109     lk->AddLightsToRenderer(win.GetRen());
00110 
00111     // Show
00112     win.Show();
00113 
00114     // Write file
00115     win.WritePNG("bedding-planes.png");
00116     
00117     // Clean up
00118     lk->Delete();
00119     
00120     return 0;
00121 }
00122 catch (Exception * e) //{{{ 
00123 {
00124     e->Cout();
00125     if (e->IsFatal()) {delete e; exit(1);}
00126     delete e;
00127 }
00128 catch (char const * m)
00129 {
00130     std::cout << "Fatal: " << m << std::endl;
00131     exit (1);
00132 }
00133 catch (...)
00134 {
00135     std::cout << "Some exception (...) ocurred\n";
00136 } //}}} 
00137 
00138 // vim:fdm=marker

Generated on Wed Jan 24 15:56:28 2007 for MechSys by  doxygen 1.4.7