![]() |
MechSys
1.0
Computing library for simulations in continuum and discrete mechanics
|
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_PLANE_H 00020 #define MECHSYS_PLANE_H 00021 00022 // Std Lib 00023 #include <string> 00024 00025 // VTK 00026 #include <vtkPlaneSource.h> 00027 #include <vtkPolyDataMapper.h> 00028 #include <vtkActor.h> 00029 #include <vtkProperty.h> 00030 00031 // MechSys 00032 #include <mechsys/vtk/win.h> 00033 #include <mechsys/util/colors.h> 00034 #include <mechsys/linalg/matvec.h> 00035 00036 namespace VTK 00037 { 00038 00039 class Plane 00040 { 00041 public: 00042 // Constructor and destructor 00043 Plane () { _create(); } 00044 ~Plane (); 00045 00046 // Alternative constructors 00047 Plane (Vec3_t const & Cen, Vec3_t const & n) { _create(); SetCen(Cen); SetNormal(n); } // centre, and normal 00048 Plane (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2); // origin, point1, point2 00049 Plane (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2, Vec3_t const & n); // origin, point1, point2, normal 00050 00051 // Set methods 00052 Plane & SetCen (Vec3_t const & Cen) { _plane->SetCenter (Cen(0), Cen(1), Cen(2)); return (*this); } 00053 Plane & SetNormal (Vec3_t const & n) { _plane->SetNormal ( n(0), n(1), n(2)); return (*this); } 00054 Plane & SetTuple (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2); 00055 Plane & SetTuple (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2, Vec3_t const & n); 00056 Plane & SetColor (char const * Name="light_salmon", double Opacity=0.5); 00057 Plane & SetWireColor (char const * Name="black"); 00058 Plane & SetWireWidth (int Width=1.0); 00059 00060 // Methods 00061 void AddTo (VTK::Win & win) { win.AddActor(_plane_actor); win.AddActor(_wire_actor); } 00062 00063 private: 00064 vtkPlaneSource * _plane; 00065 vtkPolyDataMapper * _plane_mapper; 00066 vtkActor * _plane_actor; 00067 vtkPolyDataMapper * _wire_mapper; 00068 vtkActor * _wire_actor; 00069 void _create (); 00070 }; 00071 00072 00074 00075 00076 inline Plane::Plane (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2) 00077 { 00078 _create (); 00079 SetTuple (Ori, Pt1, Pt2); 00080 } 00081 00082 inline Plane::Plane (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2, Vec3_t const & n) 00083 { 00084 _create (); 00085 SetTuple (Ori, Pt1, Pt2, n); 00086 } 00087 00088 inline Plane::~Plane () 00089 { 00090 _plane -> Delete(); 00091 _plane_mapper -> Delete(); 00092 _plane_actor -> Delete(); 00093 _wire_mapper -> Delete(); 00094 _wire_actor -> Delete(); 00095 } 00096 00097 inline Plane & Plane::SetTuple (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2) 00098 { 00099 _plane -> SetOrigin (Ori(0), Ori(1), Ori(2)); 00100 _plane -> SetPoint1 (Pt1(0), Pt1(1), Pt1(2)); 00101 _plane -> SetPoint2 (Pt2(0), Pt2(1), Pt2(2)); 00102 return (*this); 00103 } 00104 00105 inline Plane & Plane::SetTuple (Vec3_t const & Ori, Vec3_t const & Pt1, Vec3_t const & Pt2, Vec3_t const & n) 00106 { 00107 _plane -> SetOrigin (Ori(0), Ori(1), Ori(2)); 00108 _plane -> SetPoint1 (Pt1(0), Pt1(1), Pt1(2)); 00109 _plane -> SetPoint2 (Pt2(0), Pt2(1), Pt2(2)); 00110 _plane -> SetNormal ( n(0), n(1), n(2)); 00111 return (*this); 00112 } 00113 00114 inline Plane & Plane::SetColor (char const * Name, double Opacity) 00115 { 00116 Vec3_t c(Colors::Get(Name)); 00117 _plane_actor->GetProperty()->SetColor (c.data()); 00118 _plane_actor->GetProperty()->SetOpacity (Opacity); 00119 return (*this); 00120 } 00121 00122 inline Plane & Plane::SetWireColor (char const * Name) 00123 { 00124 Vec3_t c(Colors::Get(Name)); 00125 _wire_actor->GetProperty()->SetColor (c.data()); 00126 return (*this); 00127 } 00128 00129 inline Plane & Plane::SetWireWidth (int Width) 00130 { 00131 _wire_actor->GetProperty()->SetLineWidth(Width); 00132 return (*this); 00133 } 00134 00135 inline void Plane::_create () 00136 { 00137 // plane 00138 _plane = vtkPlaneSource ::New(); 00139 _plane_mapper = vtkPolyDataMapper ::New(); 00140 _plane_actor = vtkActor ::New(); 00141 _plane_mapper -> SetInputConnection (_plane->GetOutputPort()); 00142 _plane_actor -> SetMapper (_plane_mapper); 00143 00144 // borders 00145 _wire_mapper = vtkPolyDataMapper ::New(); 00146 _wire_actor = vtkActor ::New(); 00147 _wire_mapper -> SetInput (_plane->GetOutput()); 00148 _wire_mapper -> ScalarVisibilityOff (); 00149 _wire_actor -> SetMapper (_wire_mapper); 00150 _wire_actor -> GetProperty ()->SetRepresentationToWireframe(); 00151 00152 // set mapper 00153 _plane_mapper -> SetResolveCoincidentTopologyPolygonOffsetParameters (0,1); 00154 _plane_mapper -> SetResolveCoincidentTopologyToPolygonOffset (); 00155 _wire_mapper -> SetResolveCoincidentTopologyPolygonOffsetParameters (1,1); 00156 _wire_mapper -> SetResolveCoincidentTopologyToPolygonOffset (); 00157 00158 // same color for inside and outside edges 00159 _wire_mapper -> ScalarVisibilityOff (); 00160 _wire_actor -> GetProperty() -> SetAmbient (1.0); 00161 _wire_actor -> GetProperty() -> SetDiffuse (0.0); 00162 _wire_actor -> GetProperty() -> SetSpecular (0.0); 00163 00164 // set colors and wire width 00165 SetColor (); 00166 SetWireColor (); 00167 SetWireWidth (); 00168 } 00169 00170 }; // namespace VTK 00171 00172 #endif // MECHSYS_PLANE_H