00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <iostream>
00022
00023
00024 #include "vtkPoints.h"
00025 #include "vtkPolyData.h"
00026 #include "vtkDelaunay3D.h"
00027 #include "vtkShrinkFilter.h"
00028 #include "vtkDataSetMapper.h"
00029 #include "vtkOutlineFilter.h"
00030 #include "vtkProperty.h"
00031 #include "vtkPolyDataMapper.h"
00032
00033
00034 #include "util/exception.h"
00035 #include "numerical/meshgrid.h"
00036 #include "vtkwrap/vtkwin.h"
00037
00038 using std::cout;
00039 using std::endl;
00040
00041 int main(int argc, char **argv) try
00042 {
00043 if (argc!=2)
00044 {
00045 cout << "Usage:\n";
00046 cout << " " << argv[0] << " NPTS\n";
00047 cout << endl;
00048 cout << "ex.: " << argv[0] << " 6\n";
00049 cout << endl;
00050 return 1;
00051 }
00052
00053
00054 int N = atoi(argv[1]); if (N<2) throw new Fatal(_("NPTS must be greater than 1"));
00055 REAL L = 10.0;
00056 MeshGrid mg(0.0,L,atoi(argv[1]),
00057 0.0,L,atoi(argv[1]),
00058 0.0,L,atoi(argv[1]));
00059
00060
00061 vtkPoints * points = vtkPoints::New();
00062 points->Allocate(mg.Length());
00063 for (int i=0; i<mg.Length(); ++i)
00064 {
00065 double P[3] = {mg.X(i), mg.Y(i), mg.Z(i)};
00066 points->InsertPoint(i,P);
00067 }
00068
00069
00070
00071
00072
00073
00074 vtkPolyData * vertices = vtkPolyData::New();
00075 vtkDelaunay3D * delaunay = vtkDelaunay3D::New();
00076 vertices -> SetPoints(points);
00077 delaunay -> SetInput(vertices);
00078 delaunay -> SetTolerance(0.01);
00079
00080 delaunay -> SetAlpha(0);
00081 delaunay -> BoundingTriangulationOff();
00082
00083
00084 vtkShrinkFilter * shrink = vtkShrinkFilter::New();
00085 shrink -> SetInputConnection(delaunay->GetOutputPort());
00086 shrink -> SetShrinkFactor(0.9);
00087
00088
00089 vtkDataSetMapper * mapper = vtkDataSetMapper::New();
00090 vtkActor * actor = vtkActor::New();
00091 mapper -> SetInputConnection (shrink->GetOutputPort());
00092 actor -> SetMapper (mapper);
00093 actor -> GetProperty () -> SetColor(0,1,0);
00094
00095
00096 vtkOutlineFilter * outline = vtkOutlineFilter::New();
00097 vtkPolyDataMapper * outline_mapper = vtkPolyDataMapper::New();
00098 vtkActor * outline_actor = vtkActor::New();
00099 outline -> SetInputConnection(shrink->GetOutputPort());
00100 outline_mapper -> SetInput (outline->GetOutput());
00101 outline_actor -> SetMapper (outline_mapper);
00102 outline_actor -> GetProperty () -> SetColor(0,0,0);
00103
00104
00105 VTKWin win;
00106 win.AddActor(actor);
00107 win.AddActor(outline_actor);
00108 win.Show();
00109
00110
00111 points -> Delete();
00112 vertices -> Delete();
00113 delaunay -> Delete();
00114 shrink -> Delete();
00115 mapper -> Delete();
00116 actor -> Delete();
00117 outline -> Delete();
00118 outline_mapper -> Delete();
00119 outline_actor -> Delete();
00120
00121 return 0;
00122 }
00123 catch (Exception * e)
00124 {
00125 e->Cout();
00126 if (e->IsFatal()) {delete e; exit(1);}
00127 delete e;
00128 }
00129 catch (char const * m)
00130 {
00131 std::cout << "Fatal: " << m << std::endl;
00132 exit (1);
00133 }
00134 catch (...)
00135 {
00136 std::cout << "Some exception (...) ocurred\n";
00137 }
00138
00139