sphere.h

00001 /***********************************************************************************
00002  * VTKwrap - Simple VTK wrappers                                                   *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>     *
00004  *                                                                                 *
00005  * This file is part of VTKwrap.                                                   *
00006  *                                                                                 *
00007  * VTKwrap is free software; you can redistribute it and/or modify it under        *
00008  * the  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  * VTKwrap 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  * VTKwrap; if not, write to the Free Software Foundation, Inc., 51 Franklin       *
00018  * Street, Fifth Floor, Boston, MA 02110-1301, USA                                 *
00019  ***********************************************************************************/
00020 
00021 #ifndef VTKWRAP_SPHERE_H
00022 #define VTKWRAP_SPHERE_H
00023 
00024 #include <string>
00025 
00026 #include "vtkSphereSource.h"
00027 #include "vtkPolyDataMapper.h"
00028 #include "vtkActor.h"
00029 #include "vtkProperty.h"
00030 
00031 #include "colors.h"
00032 
00033 class Sphere
00034 {
00035     friend std::ostream & operator<< (std::ostream & os, Sphere const & hh);
00036 public:
00037     Sphere(double Xc, double Yc, double Zc, double Radius, char const * Color=NULL, double Opacity=1.0, int ThetaRes=20, int PhiRes=20)
00038     {
00039         // Color
00040         std::string * color;
00041         if (Color==NULL) color = new std::string ("red");
00042         else             color = new std::string (Color);
00043 
00044         // Create object
00045         _sphere        = vtkSphereSource   ::New();
00046         _sphere_mapper = vtkPolyDataMapper ::New();
00047         _sphere_actor  = vtkActor          ::New();
00048         _sphere        -> SetCenter                 (Xc,Yc,Zc);
00049         _sphere        -> SetRadius                 (Radius);
00050         _sphere        -> SetThetaResolution        (ThetaRes);
00051         _sphere        -> SetPhiResolution          (PhiRes);
00052         _sphere_mapper -> SetInputConnection        (_sphere->GetOutputPort());
00053         _sphere_actor  -> SetMapper                 (_sphere_mapper);
00054         _sphere_actor  -> GetProperty()->SetColor   (CLR[color->c_str()].C);    
00055         _sphere_actor  -> GetProperty()->SetOpacity (Opacity);
00056 
00057         // Clean up
00058         delete color;
00059     }
00060     ~Sphere()
00061     {
00062         _sphere        -> Delete();
00063         _sphere_mapper -> Delete();
00064         _sphere_actor  -> Delete();
00065     }
00066     vtkActor           * GetActor()      { return _sphere_actor;            }
00067     vtkAlgorithmOutput * GetOutputPort() { return _sphere->GetOutputPort(); }
00068     vtkSphereSource    * GetObject()     { return _sphere;                  }
00069 private:
00070     vtkSphereSource   * _sphere;
00071     vtkPolyDataMapper * _sphere_mapper;
00072     vtkActor          * _sphere_actor;
00073 }; // class Sphere
00074 
00075 std::ostream & operator<< (std::ostream & os, Sphere const & hh)
00076 {
00077     hh._sphere->Print(os);
00078     return os;
00079 }
00080 
00081 #endif // VTKWRAP_SPHERE_H
00082 
00083 // vim:fdm=marker

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