plane.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_PLANE_H
00022 #define VTKWRAP_PLANE_H
00023 
00024 #include <string>
00025 
00026 #include "vtkPlaneSource.h"
00027 #include "vtkPolyDataMapper.h"
00028 #include "vtkActor.h"
00029 #include "vtkProperty.h"
00030 
00031 #include "colors.h"
00032 
00033 class Plane
00034 {
00035     friend std::ostream & operator<< (std::ostream & os, Plane const & hh);
00036 public:
00037     Plane(double Xc, double Yc, double Zc,
00038           double nx, double ny, double nz, char const * Color=NULL, double Opacity=1.0)
00039     {
00040         // Color
00041         std::string * color;
00042         if (Color==NULL) color = new std::string ("red");
00043         else             color = new std::string (Color);
00044 
00045         // Create object
00046         _plane        = vtkPlaneSource    ::New();
00047         _plane_mapper = vtkPolyDataMapper ::New();
00048         _plane_actor  = vtkActor          ::New();
00049         _plane        -> SetCenter                 (Xc,Yc,Zc);
00050         _plane        -> SetNormal                 (nx,ny,nz);
00051         _plane_mapper -> SetInputConnection        (_plane->GetOutputPort());
00052         _plane_actor  -> SetMapper                 (_plane_mapper);
00053         _plane_actor  -> GetProperty()->SetColor   (CLR[color->c_str()].C); 
00054         _plane_actor  -> GetProperty()->SetOpacity (Opacity);
00055 
00056         // Clean up
00057         delete color;
00058     }
00059     Plane(double Xo, double Yo, double Zo,
00060           double X1, double Y1, double Z1,
00061           double X2, double Y2, double Z2,
00062           double nx, double ny, double nz, char const * Color=NULL, double Opacity=1.0)
00063     {
00064         // Color
00065         std::string * color;
00066         if (Color==NULL) color = new std::string ("red");
00067         else             color = new std::string (Color);
00068 
00069         // Create object
00070         _plane        = vtkPlaneSource    ::New();
00071         _plane_mapper = vtkPolyDataMapper ::New();
00072         _plane_actor  = vtkActor          ::New();
00073         _plane        -> SetOrigin                 (Xo,Yo,Zo);
00074         _plane        -> SetNormal                 (nx,ny,nz);
00075         _plane        -> SetPoint1                 (X1,Y1,Z1);
00076         _plane        -> SetPoint2                 (X2,Y2,Z2);
00077         _plane_mapper -> SetInputConnection        (_plane->GetOutputPort());
00078         _plane_actor  -> SetMapper                 (_plane_mapper);
00079         _plane_actor  -> GetProperty()->SetColor   (CLR[color->c_str()].C); 
00080         _plane_actor  -> GetProperty()->SetOpacity (Opacity);
00081 
00082         // Clean up
00083         delete color;
00084     }
00085     ~Plane()
00086     {
00087         _plane        -> Delete();
00088         _plane_mapper -> Delete();
00089         _plane_actor  -> Delete();
00090     }
00091     vtkActor           * GetActor()      { return _plane_actor;            }
00092     vtkAlgorithmOutput * GetOutputPort() { return _plane->GetOutputPort(); }
00093     vtkPlaneSource     * GetObject()     { return _plane;                  }
00094 private:
00095     vtkPlaneSource    * _plane;
00096     vtkPolyDataMapper * _plane_mapper;
00097     vtkActor          * _plane_actor;
00098 }; // class Plane
00099 
00100 std::ostream & operator<< (std::ostream & os, Plane const & hh)
00101 {
00102     hh._plane->Print(os);
00103     return os;
00104 }
00105 
00106 #endif // VTKWRAP_PLANE_H
00107 
00108 // vim:fdm=marker

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