Mercurial > hg > kwantix
changeset 37:e87cb53283b4
imported patch vtk-patch
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Thu, 11 Mar 2010 23:55:38 -0600 |
parents | e32da6c38b59 |
children | cd3bd9ea53c5 |
files | src/CMakeLists.txt src/include/vtkplot.hpp src/vtkplot.cpp |
diffstat | 3 files changed, 87 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,8 @@ set(LAX_COMPILE_FLAGS "${LAX_COMPILE_FLAGS} -pg") endif() +include_directories("include/") + set(KWANTIX_SOURCES bvp ddm
new file mode 100644 --- /dev/null +++ b/src/include/vtkplot.hpp @@ -0,0 +1,47 @@ +#ifndef __VTKPLOTTING_HPP__ +#define __VTKPLOTTING_HPP__ + +#include <string> + +#include <vtkSmartPointer.h> +#include <vtkPolyData.h> + +#include "linalg.hpp" +namespace kwantix{ + + ///A class for creating VTK plots + class vtkplot{ + + public: + /*! \brief Constructor performs a Delaunay triangulation on data + * \param data - An \f$n \times 3\f$ matrix where the first two + * columns are points in the x-y plane on which a + * Delaunay triangulation will be done, and the + * third column is the value at this point. + */ + vtkplot(const matrix& data); + ///Defines the view direction when plotting. + void set_view_direction(const vector& dir); + ///Without changing the triangulation, update the values. + void update_values(const vector& values); + ///Enable offscreen plotting. + void plot_offscreen(bool yesno); + ///Set the base filename used for saving, to which numbers are appended. + void set_base_filename(const std::string& basename); + ///Actually do the plot, whether offscreen or onscreen. + void plot() const; + + private: + ///Base filename + string basename; + ///Direction from which to plot + vector view_direction; + ///The plot data + vtkSmartPointer<vtkDelaunay2D> delaunay; + ///Whether to plot offscreen or not + bool offscreen; + }; + +} + +#endif //__VTKPLOTTING_HPP__
--- a/src/vtkplot.cpp +++ b/src/vtkplot.cpp @@ -28,7 +28,44 @@ #include <string> using std::string; -#include "include/vtkplotting.hpp" +#include "include/vtkplot.hpp" +#include "include/error.hpp" + +namespace kwantix{ + vtkplot::vtkplot(const matrix& data) + { + if(data.cols() != 3) + { + badArgument exc; + exc.reason = "vtkplot only works with N x 3 matrices."; + exc.line = __LINE__; + exc.file = __FILE__; + throw exc; + } + + //perform initial triangulation + vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); + vtkSmartPointer<vtkDoubleArray> scalars = vtkSmartPointer<vtkDoubleArray>::New(); + + for(size_t i = 1; i < data.rows(); i++) + { + vtkIdType idx = points->InsertNextPoint(data(i,1), data(i,2), data(i,3) ); + scalars -> InsertTuple(idx, &data(i,3) ); + } + + //add the grid points to the polydata object + vtkSmartPointer<vtkPolyData> polydata = vtkPolyData::New(); + polydata->SetPoints(points); + polydata->GetPointData() -> SetScalars(scalars); + + //triangulate the grid points + vtkSmartPointer<vtkDelaunay2D> delaunay = vtkDelaunay2D::New(); + delaunay->SetInput(polydata); + delaunay->Update(); + } +} + +// *************** move this stuff into a class ************************ typedef double (*Func3d)(double, double);