MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/vtk/sphere.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso, Raúl D. D. Farfan             *
00004  *                                                                      *
00005  * This program is free software: you can redistribute it and/or modify *
00006  * it under the terms of the GNU General Public License as published by *
00007  * the Free Software Foundation, either version 3 of the License, or    *
00008  * any later version.                                                   *
00009  *                                                                      *
00010  * This program is distributed in the hope that it will be useful,      *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00013  * GNU General Public License for more details.                         *
00014  *                                                                      *
00015  * You should have received a copy of the GNU General Public License    *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00017  ************************************************************************/
00018 
00019 #ifndef MECHSYS_SPHERE_H
00020 #define MECHSYS_SPHERE_H
00021 
00022 // VTK
00023 #include <vtkSphereSource.h>
00024 #include <vtkPolyDataMapper.h>
00025 #include <vtkActor.h>
00026 #include <vtkProperty.h>
00027 
00028 // MechSys
00029 #include <mechsys/vtk/win.h>
00030 #include <mechsys/util/colors.h>
00031 #include <mechsys/linalg/matvec.h>
00032 
00033 namespace VTK
00034 {
00035 
00036 class Sphere
00037 {
00038 public:
00039     // Constructor & Destructor
00040      Sphere ();
00041     ~Sphere ();
00042 
00043     // Alternative constructor
00044     Sphere (Vec3_t const & X, double R, int ThetaRes=20, int PhiRes=20);
00045 
00046     // Set methods
00047     Sphere & SetCenter     (Vec3_t const & X);
00048     Sphere & SetRadius     (double R);
00049     Sphere & SetResolution (int ThetaRes=20, int PhiRes=20);
00050     Sphere & SetColor      (char const * Name="brown", double Opacity=0.8);
00051 
00052     // Methods
00053     void AddTo (VTK::Win & win, bool RstCam=true) { win.AddActor(_sphere_actor, RstCam); }
00054 
00055 private:
00056     vtkSphereSource   * _sphere;
00057     vtkPolyDataMapper * _sphere_mapper;
00058     vtkActor          * _sphere_actor;
00059     void _create ();
00060 };
00061 
00062 
00064 
00065 
00066 inline Sphere::Sphere ()
00067 {
00068     _create       ();
00069     SetResolution ();
00070     SetColor      ();
00071 }
00072 
00073 inline Sphere::Sphere (Vec3_t const & X, double R, int ThetaRes, int PhiRes)
00074 {
00075     _create       ();
00076     SetCenter     (X);
00077     SetRadius     (R);
00078     SetResolution (ThetaRes, PhiRes);
00079     SetColor      ();
00080 }
00081 
00082 inline Sphere::~Sphere ()
00083 {
00084     _sphere        -> Delete();
00085     _sphere_mapper -> Delete();
00086     _sphere_actor  -> Delete();
00087 }
00088 
00089 inline Sphere & Sphere::SetCenter (Vec3_t const & X)
00090 {
00091     _sphere -> SetCenter (X(0), X(1), X(2));
00092     return (*this);
00093 }
00094 
00095 inline Sphere & Sphere::SetRadius (double R)
00096 {
00097     _sphere -> SetRadius (R);
00098     return (*this);
00099 }
00100 
00101 inline Sphere & Sphere::SetResolution (int ThetaRes, int PhiRes)
00102 {
00103     _sphere -> SetThetaResolution (ThetaRes);
00104     _sphere -> SetPhiResolution   (PhiRes);
00105     return (*this);
00106 }
00107 
00108 inline Sphere & Sphere::SetColor (char const * Name, double Opacity)
00109 {
00110     Vec3_t c(Colors::Get(Name));
00111     _sphere_actor->GetProperty()->SetColor   (c.data());
00112     _sphere_actor->GetProperty()->SetOpacity (Opacity);
00113     return (*this);
00114 }
00115 
00116 inline void Sphere::_create ()
00117 {
00118     _sphere        = vtkSphereSource     ::New();
00119     _sphere_mapper = vtkPolyDataMapper   ::New();
00120     _sphere_actor  = vtkActor            ::New();
00121     _sphere_mapper -> SetInputConnection (_sphere->GetOutputPort());
00122     _sphere_actor  -> SetMapper          (_sphere_mapper);
00123 }
00124 
00125 }; // namespace VTK
00126 
00127 #endif // MECHSYS_SPHERE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines