![]() |
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_LINE_H 00020 #define MECHSYS_LINE_H 00021 00022 // VTK 00023 #include <vtkLineSource.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/util/string.h> 00032 #include <mechsys/linalg/matvec.h> 00033 00034 namespace VTK 00035 { 00036 00037 class Line 00038 { 00039 public: 00040 // Constructor & Destructor 00041 Line () { _create(); } 00042 ~Line (); 00043 00044 // Alternative constructor 00045 Line (Vec3_t const & P, Vec3_t const & Q) { _create(P(0),P(1),P(2), Q(0),Q(1),Q(2)); } 00046 00047 // Set methods 00048 //Line & SetLine (Vec3_t const & P, Vec3_t const & Q); 00049 Line & SetWireColor (char const * Name="black") { Vec3_t c(Colors::Get(Name)); _line_actor->GetProperty()->SetColor(c.data()); return (*this); } 00050 Line & SetWireWidth (int Width=1.0) { _line_actor->GetProperty()->SetLineWidth(Width); return (*this); } 00051 00052 // Methods 00053 void AddTo (VTK::Win & win) { win.AddActor(_line_actor); } 00054 00055 private: 00056 vtkLineSource * _line_source; 00057 vtkPolyDataMapper * _line_mapper; 00058 vtkActor * _line_actor; 00059 void _create (double P0=0, double P1=0, double P2=0, double Q0=1, double Q1=1, double Q2=1); 00060 }; 00061 00062 00064 00065 00066 inline Line::~Line () 00067 { 00068 _line_source -> Delete(); 00069 _line_mapper -> Delete(); 00070 _line_actor -> Delete(); 00071 } 00072 00073 inline void Line::_create (double P0, double P1, double P2, double Q0, double Q1, double Q2) 00074 { 00075 _line_source = vtkLineSource ::New(); 00076 _line_mapper = vtkPolyDataMapper ::New(); 00077 _line_actor = vtkActor ::New(); 00078 _line_source -> SetPoint1 (P0, P1, P2); 00079 _line_source -> SetPoint2 (Q0, Q1, Q2); 00080 _line_source -> Update (); 00081 _line_mapper -> SetInputConnection (_line_source->GetOutputPort()); 00082 _line_actor -> SetMapper (_line_mapper); 00083 SetWireColor(); 00084 } 00085 00086 }; // namespace VTK 00087 00088 #endif // MECHSYS_LINE_H