MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/vtk/ugrid.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_POLYGON_H
00020 #define MECHSYS_POLYGON_H
00021 
00022 // Std Lib
00023 #include <string>
00024 
00025 // VTK
00026 #include <vtkPoints.h>
00027 #include <vtkUnstructuredGrid.h>
00028 #include <vtkDataSetMapper.h>
00029 #include <vtkActor.h>
00030 #include <vtkProperty.h>
00031 
00032 // MechSys
00033 #include <mechsys/vtk/win.h>
00034 #include <mechsys/util/colors.h>
00035 #include <mechsys/linalg/matvec.h>
00036 
00037 class UGrid
00038 {
00039 public:
00040     // Constructors
00041     UGrid ();
00042 
00043     // Destructor
00044     ~UGrid ();
00045 
00046     // Methods
00047     void AddTo (VTK::Win & win) { win.AddActor(_grid_actor);  if (_wire_actor!=NULL) win.AddActor(_wire_actor); }
00048 
00049     // Add methods
00050     int InsertNextPoint (double X, double Y, double Z) { return _pnts->InsertNextPoint (X,Y,Z);      }
00051     int InsertNextCell  (int Type, vtkIdList * PtIds)  { return _grid->InsertNextCell  (Type,PtIds); }
00052 
00053     // Set methods
00054     UGrid & SetColor     (char const * Name="peacock", double Opacity=0.8);
00055     void    SetPoint     (int Id, double X, double Y, double Z) { _pnts->SetPoint (Id, X,Y,Z); }
00056     void    Modified     () { _grid->Modified(); }
00057     void    SetWire      (bool WithWireframe=true);
00058     void    SetMaterial  (double Ambient, double Diffuse, double Specular, double SpecularPower);
00059 
00060 private:
00061     vtkPoints           * _pnts;
00062     vtkUnstructuredGrid * _grid;
00063     vtkDataSetMapper    * _grid_mapper;
00064     vtkActor            * _grid_actor;
00065     vtkDataSetMapper    * _wire_mapper;
00066     vtkActor            * _wire_actor;
00067 };
00068 
00069 
00071 
00072 
00073 inline UGrid::UGrid ()
00074     : _wire_actor (NULL)
00075 {
00076     _pnts        = vtkPoints           ::New();
00077     _grid        = vtkUnstructuredGrid ::New();
00078     _grid_mapper = vtkDataSetMapper    ::New();
00079     _grid_actor  = vtkActor            ::New();
00080     _grid        -> SetPoints (_pnts);
00081     _grid_mapper -> SetInput  (_grid);
00082     _grid_actor  -> SetMapper (_grid_mapper);
00083     SetColor ();
00084 }
00085 
00086 inline UGrid::~UGrid ()
00087 {
00088     _pnts        -> Delete();
00089     _grid        -> Delete();
00090     _grid_mapper -> Delete();
00091     _grid_actor  -> Delete();
00092     if (_wire_actor!=NULL)
00093     {
00094         _wire_mapper -> Delete();
00095         _wire_actor  -> Delete();
00096     }
00097 }
00098 
00099 inline UGrid & UGrid::SetColor (char const * Name, double Opacity)
00100 {
00101     Vec3_t c(Colors::Get(Name));
00102     _grid_actor->GetProperty()->SetColor   (c(0), c(1), c(2));
00103     _grid_actor->GetProperty()->SetOpacity (Opacity);
00104     return (*this);
00105 }
00106 
00107 inline void UGrid::SetWire (bool WithWireframe)
00108 {
00109     if (_wire_actor!=NULL)
00110     {
00111         _wire_mapper -> Delete();
00112         _wire_actor  -> Delete();
00113     }
00114     if (WithWireframe)
00115     {
00116         _wire_mapper = vtkDataSetMapper     ::New();
00117         _wire_actor  = vtkActor             ::New();
00118         _wire_mapper -> SetInput            (_grid);
00119         _wire_mapper -> ScalarVisibilityOff ();
00120         _wire_actor  -> SetMapper           (_wire_mapper);
00121         _wire_actor  -> GetProperty         ()->SetRepresentationToWireframe();
00122         Vec3_t c(Colors::Get("black"));
00123         _wire_actor->GetProperty()->SetColor (c.data());
00124     }
00125 }
00126 
00127 inline void UGrid::SetMaterial (double Ambient, double Diffuse, double Specular, double SpecularPower)
00128 {
00129     _grid_actor->GetProperty()->SetAmbient       (Ambient);
00130     _grid_actor->GetProperty()->SetDiffuse       (Diffuse);
00131     _grid_actor->GetProperty()->SetSpecular      (Specular);
00132     _grid_actor->GetProperty()->SetSpecularPower (SpecularPower);
00133 }
00134 
00135 #endif // MECHSYS_POLYGON_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines