vtkwrap_test03.cpp

00001 /***********************************************************************************
00002  * VTKwrap - Simple VTK wrappers                                                   *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>     *
00004  *                                                                                 *
00005  * This file is part of VTKwrap.                                                   *
00006  *                                                                                 *
00007  * VTKwrap is free software; you can redistribute it and/or modify it under        *
00008  * the  terms of the GNU General Public License as published by the Free Software  *
00009  * Foundation; either version 2 of the License, or (at your option) any later      *
00010  * version.                                                                        *
00011  *                                                                                 *
00012  * VTKwrap is distributed in the hope that it will be useful, but WITHOUT ANY      *
00013  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
00014  * PARTICULAR PURPOSE. See the GNU General Public License for more details.        *
00015  *                                                                                 *
00016  * You should have received a copy of the GNU General Public License along with    *
00017  * VTKwrap; if not, write to the Free Software Foundation, Inc., 51 Franklin       *
00018  * Street, Fifth Floor, Boston, MA 02110-1301, USA                                 *
00019  ***********************************************************************************/
00020 
00021 #include <iostream>
00022 #include <cmath>
00023 
00024 #include "numerical/meshgrid.h"
00025 
00026 #include "vtkwrap/structgrid.h"
00027 #include "vtkwrap/hedgehog.h"
00028 #include "vtkwrap/vtkwin.h"
00029 #include "vtkwrap/sgridoutline.h"
00030 #include "vtkwrap/sgridisosurf.h"
00031 #include "vtkwrap/axes.h"
00032 #include "vtkwrap/colors.h"
00033 
00034 using std::cout;
00035 using std::endl;
00036 
00037 int main(int argc, char **argv)
00038 {
00039     if (argc!=4)
00040     {
00041         cout << "Usage:\n";
00042         cout << "      " << argv[0] << " NP NQ NT\n";
00043         cout << endl;
00044         cout << "ex.:  " << argv[0] << " 20 20 20\n";
00045         cout << endl;
00046         return 1;
00047     }
00048 
00049     MeshGrid mg(0.0,1.0,atoi(argv[1]), 0.0,1.0,atoi(argv[2]), 0.0,1.0,atoi(argv[3]));
00050     //cout << mg << endl;
00051     
00052     double * F = new double [mg.Length()];
00053     double c[] = {0.5,0.5,0.5}; // center of sphere
00054     double   r = 0.25;          // radius of sphere
00055     for (int i=0; i<mg.Length(); ++i)
00056         F[i] = pow(mg.X(i)-c[0],2.0) + pow(mg.Y(i)-c[1],2.0) + pow(mg.Z(i)-c[2],2.0) - r*r;
00057 
00058 
00059     StructGrid::VectorTuple * V = new StructGrid::VectorTuple [mg.Length()];
00060     for (int i=0; i<mg.Length(); ++i)
00061     {
00062         V[i].vx = mg.X(i);
00063         V[i].vy = mg.Y(i);
00064         V[i].vz = mg.Z(i);
00065     }
00066 
00067     StructGrid sg(mg.X(),mg.nX(), mg.Y(),mg.nY(), mg.Z(),mg.nZ(), F, V);
00068     cout << sg << endl;
00069     sg.WriteFile("tmp.structgrid.vtk");
00070 
00071     HedgeHog hh(sg.GetGrid());
00072     cout << hh << endl;
00073 
00074     SGridOutline sgo(sg.GetGrid());
00075     cout << sgo << endl;
00076 
00077     vtkLookupTable * lt = vtkLookupTable::New();
00078     lt->SetNumberOfColors(1);
00079     lt->Build();
00080     lt->SetTableValue(0,CLR["blue"].C);
00081     SGridIsoSurf sgiso(sg.GetGrid(),0.0, lt);
00082     
00083     //ContrastTable ct;
00084     //SGridIsoSurf sgiso(sg.GetGrid(),4, -r*r, 0.18, ct.GetTable());
00085     sgiso.GetActor()->GetProperty()->SetOpacity(0.3);
00086     cout << sgiso << endl;
00087 
00088     Axes ax(1.2, true);
00089     cout << ax << endl;
00090 
00091     VTKWin win;
00092     win.AddActor(hh.GetActor());
00093     win.AddActor(sgo.GetActor());
00094     win.AddActor(sgiso.GetActor());
00095     win.AddActor(ax.GetActor());
00096     win.AddActor(ax.GetXLabelActor());
00097     win.AddActor(ax.GetYLabelActor());
00098     win.AddActor(ax.GetZLabelActor());
00099     win.Show();
00100 
00101     delete [] F;
00102     delete [] V;
00103 
00104     lt -> Delete();
00105 
00106     return 0;
00107 }

Generated on Wed Jan 24 15:56:28 2007 for MechSys by  doxygen 1.4.7